Skip to content

Instantly share code, notes, and snippets.

@np np/email-reminder
Created Oct 1, 2009

Embed
What would you like to do?
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 john.doe@example.com)"
[ ! -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
You can’t perform that action at this time.