Skip to content

Instantly share code, notes, and snippets.

@np
Created October 1, 2009 19:49
Show Gist options
  • Save np/199197 to your computer and use it in GitHub Desktop.
Save np/199197 to your computer and use it in GitHub Desktop.
email-reminder
#!/bin/bash -e
perr(){
echo "$@" > /dev/stderr
}
usage(){
perr "Usage: cat <email> | email-reminder <at(1)-arguments>*"
perr "$@"
exit 1
}
timespec="$1"
shift || usage "missing argument"
[ ! -z "$EMAIL" ] || usage "EMAIL is undefined (example [email protected])"
[ ! -z "$FULLNAME" ] || usage "FULLNAME is undefined (example John Doe)"
fields=$(grep -Ei '^(Message-ID: *<.*> *|Subject: .*)$')
export messageid=$(echo "$fields" | grep -i '^Message-ID' | grep -oi '<.*>' | head -n 1)
export subjectline=$(echo "$fields" | grep -i '^Subject' | head -n 1)
if [ -z "$SENDMAIL" ]; then
SENDMAIL='msmtp -t --read-envelope-from'
fi
at $timespec <<EOS
date=\`date +'%a, %d %b %Y %T %z (%Z)'\`
salt="$timespec $EMAIL $FULLNAME \$messageid \$date"
echo "From: $FULLNAME <$EMAIL>
To: $FULLNAME <$EMAIL>
\$subjectline
Message-ID: <\`echo "\$salt" | md5sum | cut -d' ' -f1\`@email-reminder>
Date: \$date
In-Reply-To: \$messageid
References: \$messageid
Reminder!" | $SENDMAIL
EOS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment