How can I modify conversationTopic so emails with different subjects are put in the same thread?
Asked Answered
B

4

8

I want to help Outlook 2010 thread my emails. My understanding is that it bases the conversation view off of the conversationTopic property of the MailItem. I wrote the following method and created a rule so it would trigger on email subjects like "Order# 345 - Reply from vendor" and "Order # 345 - Reply from customer" and put them in the same thread. Unfortunately the conversationTopic is a read only property.

Does anyone know a way around this or perhaps a better way of accomplishing the same task? Thanks!

Sub ModifyConversationTopic(Item As Outlook.MailItem)
    Dim regex As RegExp
    Dim newMailItem As Outlook.MailItem
    newMailItem = Item.Copy
    Set regex = New RegExp
    regex.IgnoreCase = False
    regex.Global = True
    regex.Pattern = "(Order# [0-9]+) .*"
    If regex.Test(newMailItem.Subject) Then
        Dim matches As MatchCollection
        Set matches = regex.Execute(newMailItem.Subject)
        Set topic = matches.Item(0)
        MsgBox ("OH YEAH" + topic)
        newMailItem.ConversationTopic = topic
        newMailItem.Save
    End If
End Sub
Breastplate answered 10/1, 2012 at 16:38 Comment(1)
Did you ever get this working? I'm trying to do a similar thing with minimal success!Aneto
D
5

Was looking for pretty much the exact same thing, this doesn't seem to be possible with normally exposed objects as you point out, but VBA macro + Outlook Redemption allows conversation topic to be tweaked easily. Bonus, the original message subject is unchanged, but the messages still show in a nice neat conversation group.

Something like this, thrown into VBA Macro and then run this script as a Rule action when messages are received with whatever criteria you determine:

Sub MsgProcess(msg As MailItem)
    Dim oNS As Object
    Dim oRDOSess As Object
    Dim oRDOItem As Object
    Dim sEntryID As String
    Dim sStoreID As String

    Dim NewConversationTopic As String


    Set oRDOSess = CreateObject("Redemption.RDOSession")
    Set oNS = Nothing
    Set oNS = Outlook.GetNamespace("MAPI")
    oNS.Logon
    oRDOSess.MAPIOBJECT = oNS.MAPIOBJECT

    sEntryID = msg.EntryID
    sStoreID = msg.Parent.StoreID
    Set oRDOItem = oRDOSess.GetMessageFromID(sEntryID, sStoreID)

    'Apply what modifications to topic you want here - dumb example string manipulation shown
    NewConversationTopic = Replace(oRDOItem.ConversationTopic, "BLACK", "WHITE")

    oRDOItem.ConversationTopic = NewConversationTopic
    oRDOItem.Save
End Sub
Desultory answered 20/4, 2012 at 22:27 Comment(2)
Trying this in latest versions of Outlook they added more conversation properties - visually they have the same conversation title, but they don't group properly anymore. Any ideas on how to update this answer (or a new answer) for later Outlook versions?Coracoid
Actually, I figured it out myself - you also have to give them the same ConversationIndex property, specifically the first several bytes are the same for all messages in the same conversation, and the later bytes are for identifying order within the conversation. You can find more details by debugging through the VBA and looking at / modifying this property.Coracoid
I
1

Using Outlook Redemption, I was able to merge selected Mail Items into a single conversation with the following code. I modeled it off of @fredless's answer above for my needs.

Public Sub MergeConversations()

Dim NewConversationTopic As String
Dim msg As MailItem
Dim msgSel As Selection
Dim oRDOSess, oNS, objRDOitem As Object

Set msgSel = Nothing
Set msgSel = Application.ActiveExplorer.Selection

If msgSel.Count <= 1 Then
   MsgBox ("Multiple Mail Items have not been selected!")
   Set msgSel = Nothing
   Exit Sub
End If

Set msg = msgSel.Item(1)

NewConversationTopic = msg.ConversationTopic

Set msg = Nothing

Set oRDOSess = CreateObject("Redemption.RDOSession")
Set oNS = Nothing
Set oNS = Outlook.GetNamespace("MAPI")
oNS.Logon
oRDOSess.MAPIOBJECT = oNS.MAPIOBJECT

For Each msg In msgSel
   Set objRDOitem = oRDOSess.GetMessageFromID(msg.EntryID, msg.Parent.StoreID)
   objRDOitem.ConversationTopic = NewConversationTopic

'the following line is from this answer

   objRDOitem.Fields("http://schemas.microsoft.com/mapi/proptag/0x00710102") = Null
   objRDOitem.Save
   Set objRDOitem = Nothing
Next msg

Set msgSel = Nothing
Set msg = Nothing

End Sub
Indictment answered 31/7, 2015 at 13:1 Comment(0)
A
1

Here's a variation on @JoeFletch's script with some performance optimizations, something to keep it from freezing outlook, and optional additional macros for running it on all selected emails, and for running it when each new mail arrives.

Option Explicit

' This requires: http://www.dimastr.com/redemption/download.htm
Const ConversationIndexField As String = "http://schemas.microsoft.com/mapi/proptag/0x00710102"

Private oRDOSess As Redemption.RDOSession
Private WithEvents Items As Outlook.Items

Public Sub ClearSelectedConversationIds()
    Dim Message As Object
    For Each Message In Application.ActiveExplorer.Selection
        ClearConversationId Message
        DoEvents
        DoEvents
    Next Message
    Debug.Print "Finished Processing All Selected Messages"
End Sub

Private Sub Application_Startup()
    Dim olNS As Outlook.NameSpace
    Dim Inbox  As Outlook.MAPIFolder

    Set olNS = Application.GetNamespace("MAPI")
    Set Inbox = olNS.GetDefaultFolder(olFolderInbox)
    Set Items = Inbox.Items
End Sub

Private Sub Items_ItemAdd(ByVal Item As Object)
    If TypeOf Item Is Outlook.MailItem Then
        ClearConversationId Item
    End If
End Sub

Main Sub:

Public Sub ClearConversationId(ByVal Item As Object)
    On Error GoTo Reset

    ' Initialize the Redemption instance if doesn't already exist
    If oRDOSess Is Nothing Then
        Debug.Print "Creating Redemption Object ..."
        Set oRDOSess = New Redemption.RDOSession
        With Outlook.GetNamespace("MAPI")
             .Logon
            oRDOSess.MAPIOBJECT = .MAPIOBJECT
        End With
    End If

    Dim oRDOItem As Object
    Set oRDOItem = oRDOSess.GetMessageFromID(Item.EntryID, Item.Parent.StoreID)

    If oRDOItem.ConversationTopic <> Item.Subject Or Not IsEmpty(oRDOItem.Fields(ConversationIndexField)) Then
        Debug.Print "Fixing " & Item.Subject
        oRDOItem.ConversationTopic = Item.Subject
        oRDOItem.Fields(ConversationIndexField) = Null
        oRDOItem.Save
    End If
    Exit Sub
Reset:
    Debug.Print "Error: " + Err.Description
    Set oRDOSess = Nothing
    End Sub
Attach answered 4/7, 2018 at 18:12 Comment(0)
F
0

You will need to construct the PR_CONVERSATION_INDEX property the right way - see http://msdn.microsoft.com/en-us/library/office/cc765583.aspx. The property can be set either using MailItem.PropertyAccessor or RDOMail.Fields[] in Redemption.

Fail answered 1/2, 2013 at 13:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.