#!/bin/sh # Delete duplicate messages in $1 based on the Message-ID header maildir=$1 echo -n 'Generating Message-ID table... ' msgid_file=`mktemp` grep -rH -m1 '^[Mm]essage-[Ii][Dd]:' "$maildir"| \ sed -r 's/(.*):[Mm]essage-[Ii][Dd]:\s*(\S.*)/\2:\1/'| \ sort -n>"$msgid_file" echo 'done' < "$msgid_file" sed 's/:.*//'|uniq -d|while read msgid; do echo "Removing dups of $msgid" < "$msgid_file" sed -n "s/^$msgid://p"|sed 1d|xargs -d'\n' rm -fv|sed 's/./ &/' done rm -f "$msgid_file"