Deduping Messages in OS X Mail.app

Finally, after finding fragments of the necessary code hither and yon across the aether, I pieced together the steps necessary to kill duplicate messages in Mail.app. I keep winding up with multiple copies of old messages in Mac OS X (Panther) Mail when, for some reason, either the server or the mail app itself decides it's time to re-download hundreds of previous emails every month or so.

The example here partially fixes a broken script in a comment on Macosxhints.com, but I was still having trouble with it. Finally, this is what I came up with that seemed to work.



(For the love of pete, back up all of your mail before doing anything like this. Attempt this at your own risk, I disavow all responsibility for lost data, et cetera.)



Create a shell script wherever it is you like to put shell scripts, say /usr/local/bin, and name it something like maildedupe.sh. Be sure to chmod so as to be executable. In the script, put the following:

#!/bin/sh                                                                                                        
echo "Deduping $1..."                                                                                            
formail -D 1000000 idcache  '$1.ztmp' && mv '$1.ztmp' '$1'                                              
rm idcache

This is basically the same as Jeremy's script linked above, with a couple of improvements:

  1. single quotes around mailbox filenames keep the script from breaking if you happen to have a mailbox with a space in its name.
  2. using '$1.ztmp' instead of 'ztmp' assures that the temp file will be created in the same place as the mailbox being deduped.

To auto-run this script an all of your mailboxes automagically (You did back them up, right?), go to the terminal, and type

cd ~/Library/Mail

Then type:

find . -name 'mbox' -exec /usr/local/bin/maildedupe.sh {} \;

All of the affected messages will suddenly appear as being unread, but at least you won't have more than one copy of each any more.

Syndicate content

Twitter

  • @ernestkoe basically this script with duration set to 25 minutes, and limited to tracks 3 minutes & under: http://t.co/bupgfBH 2 years 45 weeks ago
  • @ernestkoe has got me digging Pomodoro. I modified one of my iTunes applescripts to make me nice 25 minute playlists. 2 years 45 weeks ago
  • @tommysalami I'm planning to tear it down and make a static site with links to activity streams elsewhere; it's hardly a destination. 2 years 46 weeks ago
  • @tommysalami I think you may be the one person on the internets subscribed to my RSS feed. That was the first thing I've posted all year! 2 years 46 weeks ago
  • Possibly the most simultaneously hilarious and disturbing video you'll watch today. http://sgp.cm/6f9b89 2 years 48 weeks ago

Older

Contact

Andy Chase
(978) 297-6402
andychase [at] gmail.com
GPG/PGP Public Key