summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2013-12-03 13:27:36 -0500
committerLuke Shumaker <LukeShu@sbcglobal.net>2013-12-03 13:27:36 -0500
commit50c03668d1d81c93d9c540e6a8c45e604068cc45 (patch)
treec5d363918f919bc5fc6e19490b04f84cb703c92d
parenta36ecefba2a3d54feba3206e058df5c33aba4af9 (diff)
maidups: clean up using trap
-rw-r--r--maildups.sh14
1 files changed, 7 insertions, 7 deletions
diff --git a/maildups.sh b/maildups.sh
index 9c78bd6..7f39a58 100644
--- a/maildups.sh
+++ b/maildups.sh
@@ -3,16 +3,16 @@
maildir=$1
+msgid_file="$(mktemp --tmpdir "${0##*/}.XXXXXXXXXX")"
+trap "rm -f $(printf '%q' "$msgid_file")" EXIT
+
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"
+ 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/./ &/'
+ 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"