I used a combination of the other answer post, and this article to write my own macro that uses the Redemption library to merge the conversations.
This scans the current folder, picking out any jira emails, extracts the issue key from the subject.
If it's not seen that key before, it saves the conversation index in a collection based on the issue key, and if it has seen it before, it updates the email with the saved conversation index.
Dim ConversationIndexes As New Collection
Sub GroupJira()
Dim MapiNamespace As Object
Dim RdoSession As Object
Dim Item As Object
Dim RdoItem As Object
Dim ConversationKey As String
Dim ConversationIndex As String
' Get all the required handles
Set MapiNamespace = Outlook.GetNamespace("MAPI")
MapiNamespace.Logon
Set RdoSession = CreateObject("Redemption.RDOSession")
RdoSession.MAPIOBJECT = MapiNamespace.MAPIOBJECT
'Setup some subject patterns to extract the issue key
Dim Matches As MatchCollection
Dim UpdateSubjectPattern As New RegExp
UpdateSubjectPattern.Pattern = "\[JIRA\] \(([A-Z]+-[0-9]+)\) .*"
Dim MentionedSubjectPattern As New RegExp
MentionedSubjectPattern.Pattern = "\[JIRA\] .* mentioned you on ([A-Z]+-[0-9]+) \(JIRA\)"
For Each Item In Outlook.ActiveExplorer.CurrentFolder.Items
If TypeOf Item Is MailItem Then
If Left(Item.Subject, 7) = "[JIRA] " Then
' Get a key for this conversation, opic for now
ConversationKey = Item.ConversationTopic
Set Matches = UpdateSubjectPattern.Execute(Item.Subject)
If Matches.Count >= 1 Then ConversationKey = Matches(0).SubMatches(0)
Set Matches = MentionedSubjectPattern.Execute(Item.Subject)
If Matches.Count >= 1 Then ConversationKey = Matches(0).SubMatches(0)
' Get any saved indexes
ConversationIndex = ""
On Error Resume Next
ConversationIndex = ConversationIndexes.Item(ConversationKey)
On Error GoTo 0
If ConversationIndex = "" Then
' Save this index if not seen yet
ConversationIndexes.Add Item.ConversationIndex, ConversationKey
ElseIf Item.ConversationIndex <> ConversationIndex Then
' Set the item's index if it has
Set RdoItem = RdoSession.GetMessageFromID(Item.EntryID, Item.Parent.StoreID)
RdoItem.ConversationIndex = ConversationIndex
RdoItem.Save
End If
End If
End If
Next Item
End Sub
This requires the following libraries:
- Redemption library for full RDO access, required to set the conversation index (this does not require elevation to register it)
- A reference to the
Microsoft VBScript Regular Expressions 5.5
library to extract issue keys from the mail subjects.
Oh, and you also need to knobble your macro security settings to run it.