Created
February 13, 2013 09:05
-
-
Save kimburgess/4943217 to your computer and use it in GitHub Desktop.
Quick outlook filter to make XTrack notifications suck less.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' Rewrite the subject of auto generated emails from XTrack so that they can be | |
' handled neatly by Outlook subject grouping | |
Sub XTrackRewrite(Item As Outlook.MailItem) | |
Dim ID As String | |
Dim c As String | |
ID = getXTrackID(Item) | |
If (ID = "") Then | |
Return | |
End If | |
Problem = getProblem(Item) | |
' Change the sender name to the actual person who triggered the update than support@amx.com | |
Item.SentOnBehalfOfName = getPerson(Item) | |
' Nuke all the excess crap from responses | |
If (InStr(Item.Subject, "Response Notification " + ID)) Then | |
Dim startIdx, endIdx As Integer | |
startIdx = InStr(Item.Body, "# " + ID) | |
startIdx = startIdx + Len(ID) + 8 | |
endIdx = InStr(startIdx, Item.Body, "To respond, please use this link ") - 3 | |
Item.Body = Mid(Item.Body, startIdx, endIdx - startIdx) | |
Item.BodyFormat = olFormatRichText | |
End If | |
' Set the subject to something more useful and standardise to allow grouping | |
Item.Subject = "[" + ID + "] " + Problem | |
Item.Save | |
End Sub | |
' Get the XTrack RFI number | |
Function getXTrackID(Item As Outlook.MailItem) As String | |
Dim RE As RegExp | |
Dim M As MatchCollection | |
Set RE = New RegExp | |
RE.Pattern = "response\.aspx?\?e=(\d+)" | |
If RE.Test(Item.Body) Then | |
Set M = RE.Execute(Item.Body) | |
getXTrackID = M(0).SubMatches(0) | |
End If | |
End Function | |
' Get the XTrack 1 liner summary | |
Function getProblem(Item As Outlook.MailItem) As String | |
Dim RE As RegExp | |
Dim M As MatchCollection | |
Set RE = New RegExp | |
RE.Pattern = "Problem:\s*(.*)\nPriority" | |
If RE.Test(Item.Body) Then | |
Set M = RE.Execute(Item.Body) | |
getProblem = M(0).SubMatches(0) | |
End If | |
End Function | |
' Get the name of the person who triggered the update | |
Function getPerson(Item As Outlook.MailItem) As String | |
Dim RE As RegExp | |
Dim M As MatchCollection | |
Set RE = New RegExp | |
RE.Pattern = "(( was entered by )|( was submited by )|( has been Escalated by ))(.*)(( to )|\.|( on ))" | |
If RE.Test(Item.Body) Then | |
Set M = RE.Execute(Item.Body) | |
getPerson = M(0).SubMatches(4) | |
End If | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment