Skip to content

Instantly share code, notes, and snippets.

@lifuzu
Created October 4, 2013 20:46
Show Gist options
  • Save lifuzu/6832471 to your computer and use it in GitHub Desktop.
Save lifuzu/6832471 to your computer and use it in GitHub Desktop.
Remove duplicates email from Outlook
tell application "Finder"
display dialog "hello world!"
end tell
-- Remove Duplicate Message v2.1
-- An Applescript by Barry Wainwright, 15th October 2010
-- Detects and deletes duplicate messages within a selected folder
-- works on Message-ID header - uniquely identifying duplicates
-- Version History
-- v1.0 - 2002-03-18: First Release (For Microsoft Entourage)
-- v2.0 - 2010-10-07: modified to work with Microsoft Outlook for Mac
-- v2.1 - 2010-10-15: added final dialog to summarise messages removed
tell application "Microsoft Outlook"
set theMessages to current messages
if theMessages = {} then
try
set theFolder to selected folder
set mb to theFolder
on error
display dialog "In the folder listing, please select the folder you want to be scanned for duplicates" with icon stop buttons {"Quit"} default button 1
return -99
end try
else
set mb to folder of item 1 of theMessages
end if
set theName to name of mb
say "Removing duplicates from mail folder: " & theName
set y to count messages of mb
say "Number of messages to check, " & y
set IDlist to {}
repeat with x from y to 1 by -1
try
set theHeaders to (get headers of message x of mb)
set AppleScript's text item delimiters to {return & "Message-"}
set temp to text item 2 of theHeaders
set AppleScript's text item delimiters to {return}
set theId to text 5 through -1 of text item 1 of temp
on error
set theId to ""
end try
if theId is in my IDlist then
delete message x of mb
else if theId ≠ "" then
copy theId to end of IDlist
end if
if x mod 100 = 0 then say "" & x
end repeat
set removedCount to y - (count messages of mb)
if removedCount is 0 then
say "Finished. No duplicates detected"
else
say "Finished. " & removedCount & " duplicates removed"
end if
display dialog "" & y & " messages checked" & return & removedCount & " messages removed" buttons {"OK"} default button 1
set AppleScript's text item delimiters to {""}
end tell
@shape55
Copy link

shape55 commented Feb 24, 2015

thanks so much for this but Outlook 2011 is not recognizing the .script file. i put it in "Outlook Script Menu Items" but do i need to change the file extension? .scpt & .scptd don't work either.

@shape55
Copy link

shape55 commented Nov 9, 2015

I ended up finding this before in compressed cpgz format and got it working with Mac Outlook, as this script file here wouldn't open in Outlook.

Is there a way to easily remove the speech? The final notification when complete is fine but i'd rather not be notified every 100 messages.

thanks

@tomcurran7751
Copy link

Use this professional Outlook Items Duplicate Remover to remove all the duplicate items from in Outlook. It simply scan your device and finds out all the duplicate of PST emails. After listing, It gave you the option to delete the duplicate emails permanently in one clicks. An enhanced easy to use user friendly interface also provided by this software which enable the all users to use the software along with detailed instructions for each steps.

@chrisfisz
Copy link

Brilliant script! Strange thing happened initially. The script could not detect / recognise the existence of email duplicates. I checked the email message headers of some sample duplicate pairs. Strangely, the Message-ID of the exact email duplicates were completely different in my case, so that was the reason this script could not work since its logic is based on Message-ID. I found that LMTP id happened to be identical across the duplicates instead.

Therefore I modified the script to test the LMTP id (changed only one line actually and tried-by-error)

changed_line

-- set AppleScript's text item delimiters to {return & "Message-"}
set AppleScript's text item delimiters to {"with LMTP"}

With this modification it worked like a charm! lifuzu - great script, great work!

msg_id_fog2

@richardjcj
Copy link

Has anyone been able to update this script to be used in the 'new' version of outlook 16.71.1?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment