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 MailIte
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
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.
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
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