I wrote the VBA script using resources from StackOverflow and SuperUser if anyone is interested.
This script takes all incoming emails and counts the recipients in the To:
field,if recipient count is greater than 5, marks it as read, and moves is to a Gossip
folder.
There is also a secondary condition to check if subject contains CVS
(we get updates from our concurrent version system which has 10 recipients) and move is to the appropriate folder.
Sub moveOfficeGossip(item As Outlook.MailItem)
Dim strNames As String, i As Integer, j As Integer, cvs As String
Dim olApp As New Outlook.Application
Dim olNameSpace As Outlook.NameSpace
Dim olDestFolder As Outlook.MAPIFolder
j = 1
cvs = "CVS"
strNames = item.To
Set olNameSpace = olApp.GetNamespace("MAPI")
For i = 1 To Len(strNames)
If Mid(strNames, i, 1) = ";" Then j = j + 1
Next i
If (j >= 5) Then
If InStr(UCase(item.subject), cvs) Then
Set olDestFolder = olNameSpace.Folders("Personal Folders").Folders("Filtered").Folders("CVS")
item.Move olDestFolder
Else
Set olDestFolder = olNameSpace.Folders("Personal Folders").Folders("Filtered").Folders("Gossip")
item.UnRead = False
item.Move olDestFolder
End If
End If
End Sub
I apologize if this is not in the most formal format and I know that it can be organized a bit better, but this was my first attempt at using any Visual Basic syntax.
With VBA it should be very much possible. Here's a macro that counts the number of recipients in a mail being sent (Application_ItemSend() event). You should be able to tweak it to run when a mail is received, using either the NewMailEx() or Items.ItemAdd() events as detailed here.
– Karan – 2013-02-08T03:35:05.470