none
What is the best way to determine a new email item RRS feed

  • Question

  • Hi, I have a plugin that presents a dialog box to the user if certain conditions are not meet. The problem is that this prompt is also displayed on forwards and replies. How can I distinguish a new message from a reply or a forward? My program runs after the user clicks the send button.

    I read through this post - link and it was mentioned that the ConversationIndex should be null with a newly composed email and they are but when I click send ConversationIndex is assigned a value.

    Is there a way to store a string integer for ConversationIndex value = null before the send button is clicked or is there another way?

    Thanks!!

                ((Outlook.ApplicationEvents_Event)this.Application).ItemSend += new ApplicationEvents_ItemSendEventHandler(ThisAddIn_ClassificationCheck);
            
            
            }
    
            // Prompts user to select a Classification if enabled in the usercontrol page
            void ThisAddIn_ClassificationCheck(object Item, ref bool Cancel) 
            {
                Outlook.MAPIFolder selectedFolder = this.Application.ActiveExplorer().CurrentFolder;
                String expMessage = "Your current folder is " + selectedFolder.Name + ".\n";
                String itemMessage = "Item is unknown.";
    
                try
                {
                    if (this.Application.ActiveExplorer().Selection.Count > 0)
                    {
    
                        Object selObject = this.Application.ActiveExplorer().Selection[1];
    
                        if (selObject is Outlook.MailItem)
                        {
                            Outlook.MailItem mailItem = (selObject as Outlook.MailItem);
    
                            string classstate = "";
                            String AppData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
                            string[] readfileclassstate = File.ReadAllLines(AppData + @"\KPlugin" + @"\ClassificationPrompt.txt");
                            foreach (string val in readfileclassstate)
                                classstate += val;
    
                            if (classstate == "ClassificationPrompt=1")  
                            {
                                MessageBox.Show(mailItem.ConversationID); // a value is set here
                                MessageBox.Show(mailItem.ConversationIndex); // a value is set here
    
                                MessageBox.Show(classificationSetCheck);
                                //if ((classificationSetCheck == null) && (mailItem.ConversationID == null))
                                if (classificationSetCheck == null)
                               {
                                   
                                    System.Windows.Forms.MessageBox.Show("You must select an Email Classification before sending this message");
                                    Cancel = true;
                                    return;
                                    
                                }
                            }
    
                            else
                            {
                                MessageBox.Show("The option to set a classification is not set, so we will do nothing");
                            }
    
    
                        }

    Monday, June 2, 2014 3:07 AM

Answers

  • You can either:

    1. Check the subject prefix (RE, FW, etc.) - this will be locale specific of course.

    2. Check the length of the ConversationIndex property: it will be 44 for the brand new messages and longer for the forwards/replies.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    • Marked as answer by Kevin P Moore Tuesday, June 3, 2014 3:52 AM
    Monday, June 2, 2014 6:16 AM
  • You might way to replace

    if ((convID.Length.ToString() == "44")

    with

    if ((convID.Length == 44)


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!


    Tuesday, June 3, 2014 4:54 AM

All replies

  • You can either:

    1. Check the subject prefix (RE, FW, etc.) - this will be locale specific of course.

    2. Check the length of the ConversationIndex property: it will be 44 for the brand new messages and longer for the forwards/replies.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    • Marked as answer by Kevin P Moore Tuesday, June 3, 2014 3:52 AM
    Monday, June 2, 2014 6:16 AM
  • Both solutions are based on the subject line. If an end user changes the subject, none of these will help.

    > My program runs after the user clicks the send button.

    Why don't you just intercept the buttons in the UI? Thus, you will be sure what action should be run - initial send or forward. You can read more about this in the Temporarily Repurpose Commands on the Office Fluent Ribbonarticle. Also you may find the following series of articles in MSDN helpful:

    Customizing the 2007 Office Fluent Ribbon for Developers (Part 1 of 3)

    Customizing the 2007 Office Fluent Ribbon for Developers (Part 2 of 3)

    Customizing the 2007 Office Fluent Ribbon for Developers (Part 3 of 3)

    Monday, June 2, 2014 8:38 AM
  • ConversationIndex does not change if the end user changes the subject.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Monday, June 2, 2014 1:19 PM
  • Thanks Eugene those solutions are helpful but I'm kind of concerned about the user changing the subject line. After all "users will be users" and eventually one of them will change the subject a whine about the issue. I'll go with checking the subject line if I have to but I was  wondering, is there a way to record the conversationId when the user clicks the "New E-mail" button from the explorer view?

    At this point it looks like the conversationID is always null when I check the value with OutlookSpy-


    Monday, June 2, 2014 1:21 PM
  • The conversation related properties are added after. However, you can try to use the GetConversation method of the Outlook items. Here is what MSDN states:


    GetConversation returns Null (Nothing in Visual Basic) if no conversation exists for the item. No conversation exists for an item in the following scenarios:           

      • The item has not been saved.
        An item can be saved programmatically, by user action, or by auto-save.

      • For an item that can be sent (for example, a mail item, appointment item, or contact item), the item has not been sent.

      • Conversations have been disabled through the Windows registry.

      • The store does not support Conversation view (for example, Outlook is running in classic online mode against a version of Microsoft Exchange earlier than Microsoft Exchange Server 2010). Use the IsConversationEnabled property of the Store object to determine whether the store supports Conversation view.


                 

    Monday, June 2, 2014 1:33 PM
  • As Dmitry said using ConversationIndex is the best way to go. That won't change even if the Subjest is changed at any point in the conversation, and by the time the item has been sent that property is set.

    It's what I'd use without trying to get overly complicated.


    Ken Slovak MVP - Outlook

    Monday, June 2, 2014 2:54 PM
    Moderator
  • Thank You all for your help, this forum is fantastic!

    I ended up keeping it simple-

    Outlook.MailItem mi = Item as Outlook.MailItem;
    string convID = mi.ConversationIndex;
    
    if ((convID.Length.ToString() == "44") 
    

    Tuesday, June 3, 2014 3:52 AM
  • You might way to replace

    if ((convID.Length.ToString() == "44")

    with

    if ((convID.Length == 44)


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!


    Tuesday, June 3, 2014 4:54 AM
  • ah, right thanks Dmitry!

    I just did a copy paste from the messagebox.show but you're right.

    Tuesday, June 3, 2014 3:03 PM
  • During my testing I ran into another issue.

    If you reply to a message and then save it as a draft the ConversationIndex will = 54 characters but if you open the saved draft and send it the ConversationIndex is reset with a new value of 44 characters. Essentially like a new message again even though it's a reply or forward.  So I'll need to also check the subject prefix.

    Wednesday, June 4, 2014 1:44 AM
  • If you look at the sent message in the Sent Items folder, what do you see for PR_CONVERSATION_INDEX in OutlookSpy (click IMessage)?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Wednesday, June 4, 2014 3:50 AM