#!/bin/sh # # $Id: uidl,v 1.3 2008/01/27 04:28:43 vogelke Exp $ # # should work on stdin or a file, header only or full message. # use SHA1 on header to generate UIDL. # requires these programs: mktemp formail shasum PATH=/bin:/usr/bin:/usr/local/bin:/opt/sfw/bin export PATH tag=`basename $0` die () { echo "$@" >& 2 exit 1 } tmp=`mktemp -q /tmp/${tag}.XXXXXX` case "$?" in 0) ;; *) die "mktemp failed" ;; esac # # Remove any existing UIDL fields from the header. # Keep the body, if any. # case "$#" in 0) formail -k -I X-UIDL: -I UIDL: -X "" > $tmp ;; *) file="$1" test -f "$file" || die "$file not found" formail -k -I X-UIDL: -I UIDL: -X "" < $file > $tmp ;; esac # # Use some fields to generate a new UIDL, and append it. # Don't use fields likely to change, like Lines or Status; # the same email message should generate the same UIDL. # set X `formail -zf -XFrom: -XMessage-Id: -XDate: -XReceived: -XTo: \ -XCc: -XReply-To: -XSubject: -XReturn-Path: < $tmp | shasum` formail -k -X "" -a "X-UIDL: $2" < $tmp rm $tmp exit 0