Wednesday, July 20, 2011

How to delete duplicate MS communicator conversation copied to outlook History folder ?

Recently I faced below problem and couldn't find any solution/tools in internet. I decided to solve the problem myself.

I have enabled the option to save MS communicator conversation in outlook and the conversation will be saved to outlook at particular intervals. In case the chat session go beyond this interval, multiple copies of session will be saved with the information at the moment of interval timeout. i.e . The recent copy of the conversation includes all information from previous copy and all older copies can be deleted from outlook folder.

The tools to delete duplicate items didn't help here so I wrote VB script to handle this task myself. Here is the logic
1)Open Conversation History folder
2)Sort items by subject then Received in ascending order to group the items by subject and get the oldest item first among the subject
3) In first step mark the first item as pointer and named as X
4) In subsequent steps compared the subject of current item and previous pointer item (X) and if matches then verified body of item X contained in body of current item
5) If so then delete the item X
6) Outside the loop make current item as X and continue the loop

VB Script:

Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set objFldr = objNamespace.Folders.Item("Mailbox - Ramasamy, Yuvaraj").Folders.Item("Conversation History")
Set colItems = objFldr.Items
colItems.Sort "[Subject][Received]", false
item_comp = Null
WScript.Echo colItems.count
For Each objItem in colItems

If isNUll(item_comp ) then
set item_comp = objItem
elseif (item_comp.subject = objItem.subject) then
If left(objItem.body,len(item_comp.body)) = item_comp.body then
item_comp.Delete
end if
end if
set item_comp = objItem
Next
WScript.Echo "all done"

1 comment:

Kimberley said...

Brilliant trick, thanks! Only modifications I made were to replace "WScript.Echo" with "Debug.Print" (I'm using Outlook 2007). Also, some conversations were copied 3 or 4 times so I needed to run it a few times to give it a thorough clean. Overall this halved the number of conversations in my outlook!

Enter your Comments