Outlook 2010: automated replies trigger spell-check


A recent case highlighted an unusual issue verified against Outlook 2010.  If you have spell-checking enabled (and it usually will be by default), and also have the “Ignore original message text in reply or forward” option checked (found in Mail Options), there is an issue when programmatically replying to an email in that this setting is ignored.

When you reply to a message, the original text is declared with an attribute that causes Word to ignore it when spell-checking.  Unfortunately, when you programmatically reply to a message, this does not happen.  As an example, attach this code to a UI button (this was tested in an Outlook add-in):

private void button1_Click(object sender, RibbonControlEventArgs e)
{
var inspector = ThisAddIn._Application.ActiveInspector();
if (inspector.CurrentItem is MailItem)
{
MailItem item = ((MailItem)inspector.CurrentItem).Reply();
item.Display(false);
}
}

The above is basically an implementation of the normal Reply button – or it should be.  However, if you do implement the above, and then use the new button to reply to a message, then as soon as you start typing in the reply window, a complete spell-check will be performed (i.e. if there were any spelling mistakes in the original message, these will be underlined in red).  If you use the built-in reply button this does not happen.

The underlying cause for this issue is still being investigated.  However, there is a simple workaround.  You can programmatically apply the attribute to the email body that will prevent Word from performing the spell-check.  To demonstrate, the above method can be modified like this:

private void button1_Click(object sender, RibbonControlEventArgs e)
{
var inspector = ThisAddIn._Application.ActiveInspector();

if (inspector.CurrentItem is MailItem)
{
MailItem item = ((MailItem)inspector.CurrentItem).Reply();
string sHtml = item.HTMLBody;
sHtml = sHtml.Replace("<w:WordDocument>", "<w:WordDocument><w:SpellingState>Clean</w:SpellingState>");
item.HTMLBody = sHtml;
item.Display(false);
}
}

 The above is a simple example, and has not been robustly tested, but should help until a fix is introduced.

Comments (5)

  1. Has a fix been developed for this issue yet?

  2. It is unlikely that a fix will be provided for Office 14 as the workaround above resolves the issue.

  3. How do you tell programatically if the "Ignore original message text in reply or forward" option is set?

  4. You can determin the status of this setting by inspecting the following registry key in Outlook 2010:

    HKEY_CURRENT_USERSoftwareMicrosoftOffice14.0CommonMailSettingsIgnoreReplySpelling

    – Not present means its on.

    – 1 means its on.

    – 0 means its off.

    Additionally you will find that the above fix only works successfully on a reply or forward to an e-Mail that is in HTML format. RTF and Plain Text e-Mails require an additional line of code to set their body format to HTML before you change the body text.

  5. The above method worked for HTML emails but a lot of our users crashed when this ran on plain text and RTF formatted emails (understandably) – and as Jim Nolan pointed out.  I'm hoping this other way works better for us.  It certainly does in testing – on all types of emails, in Outlook 2007 forward.  I added a reference to Word Interop since the inspector window is essentially a Word editor, and marked the text as spell-checked after displaying the response.

    Public Sub CallTheReplyAllMethod(itemToReplyAllTo As otk.MailItem)

       Dim response As otk.MailItem = Nothing

       Try

           If itemToReplyAllTo IsNot Nothing Then

               response = itemToReplyAllTo.ReplyAll() 'this will do the reply all without the handler

           End If

           If response IsNot Nothing Then

               REM Check the spell-check setting: "Ignore original message text in reply or forward"  and the setting "Close original message window when replying or forwarding" and close original message          

               Dim ignoreReplySpelling? As Integer = CType(Registry.GetValue("HKEY_CURRENT_USERSoftwareMicrosoftOffice14.0CommonMailSettings", "IgnoreReplySpelling", 1), Integer)

               Dim closeOrig? As Integer = CType(Registry.GetValue("HKEY_CURRENT_USERSoftwareMicrosoftOffice14.0OutlookPreferences", "CloseOrig", 1), Integer)

               REM Close the original email if setting requires that

               If closeOrig = 1 Then

                   itemToReplyAllTo.Close(otk.OlInspectorClose.olDiscard)

               End If

               REM Display the response email into the compose inspector window.

               response.Display(False)

               REM Mark the response email as spell-checked if user has setting on.

               If ignoreReplySpelling = 1 Then

                   Dim inspector As otk.Inspector = response.GetInspector

                   Dim doc As Word.Document = CType(inspector.WordEditor, Word.Document)

                   doc.Range.SpellingChecked = True

               End If

           End If

       Catch ex As Exception

           kePublic.LogIssue("KEOutlookAddin", "Ribbon_OnActionCallBack_Error setting ReplyAll handler for the mail item.", ex.ToString)

       Finally

           CallNAR(response)

       End Try

    End Sub