#!/bin/sh # maildelayline - a script to resend emails at arbitrary times # Copyright © 2007 MJ Ray - see end for zlib-like terms # # Make sure you can catch bounces from the resent emails # - probably you should add a -f flag to the sendmail call. # # Also, keep your delayline incoming address secure somehow, else you'll spam outdir=/home/mjr/outbox sendmail="/usr/sbin/sendmail" # Capture the email to a temporary file mailfile=$(mktemp $outdir/incoming.XXXXXXXXXX) cat - >$mailfile # Extract the desired sending time senddate="$(grep -m 1 '^X-Send-At: ' $mailfile | cut -f2- -d:)" # Build mail to send: extract relevant headers and pseudo-headers outmail=$(mktemp $outdir/mail.XXXXXXXXXX) sed -n -e '/^\(message-id:\|in-reply-to:\|subject:\|references:\|from:\|sender:\|reply-to:\|content-\)/I,/^[^ ]/{;/^\(message-id:\|in-reply-to:\|subject:\|references:\|from:\|sender:\|reply-to:\|content-\|[ ]\)/Ip;};/^$/q' $mailfile >$outmail sed -n -e '/^X-Send-At: /,/^$/{;/^X-Send-At: /!p;/^$/q;}' $mailfile >>$outmail # Build mail to send: extract cleaned email body sed -e '1,/^$/d;/^X-Send-At: /,/^$/d' $mailfile >>$outmail # Put the email into the at queue echo $sendmail -t '<' $outmail '&&' rm $outmail $mailfile | at "$senddate" || rm $outmail $mailfile exit 0 # This software is provided 'as-is', without any express or implied # warranty. In no event will the authors be held liable for any damages # arising from the use of this software. # # Permission is granted to anyone to use this software for any purpose, # including commercial applications, and to alter it and redistribute it # freely, subject to the following restrictions: # # 1. The origin of this software must not be misrepresented; you must not # claim that you wrote the original software. If you use this software # in a product, an acknowledgment in the product documentation would be # appreciated but is not required. # 2. Altered source versions must be plainly marked as such, and must not be # misrepresented as being the original software. # 3. This notice may not be removed or altered from any source distribution.