X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=delay_mail;h=68e4d92f0e28fec10746eb3dd6072262f54345b1;hb=56c8d8b286ae38e170ce915472f9aa86fabf9fee;hp=6fca9398984bf155ebe99a991b950871f590fef4;hpb=1588757a3c7b1096138baeb8e03f60c87ffdbd10;p=bin.git diff --git a/delay_mail b/delay_mail index 6fca939..68e4d92 100755 --- a/delay_mail +++ b/delay_mail @@ -41,7 +41,8 @@ Enqueue a message which should be sent out later =item B<--delay> -Length of delay (man at for details of specification) +Length of delay (man at for details of specification; Debian systems +see /usr/share/doc/at/timespec) =item B<--email> @@ -49,9 +50,12 @@ The delay option is actually an email address; apply the following regex to parse it: $delay =~ m/[+-]d(?:ela?y?)?[-+]([^\@]+)/; - $delay = $1; $delay =~ s/_/ /; + $delay = $1; + $delay =~ s/_/ /g; + $delay =~ s/=/:/g; -Thus, foo-delay-now+5_min@bar.baz becomes now+5 min +Thus, foo-delay-now+5_min@bar.baz becomes now+5 min and +foo-del+00=30=00@bar.baz becomes 00:30:00 =item B<--list> @@ -90,6 +94,25 @@ Display this manual. =head1 EXAMPLES +The following entry in your procmailrc (or similar) will do the dirty +work: + + :0 Hhbw + * !Message-Id: .*delay[0-9]+@ + * ^TO \/you\+de[^@]+ + |delay_mail --mailto you@foo.com --enqueue --email --delay $MATCH + + delay_mail --list; + +and + + atq; + +will tell you that things are queued up and ready to go. + +You can then bounce messages that you want to deal with later to +you+delay+10=30am_tomorrow@foo.com or similar, and you'll receive the +message again at 10:30 AM tomorrow to deal with. =cut @@ -104,6 +127,7 @@ my %options = (debug => 0, GetOptions(\%options,'debug|d+','help|h|?','man|m', 'list|l','dequeue=s','process|p=s','enqueue|e', + 'queue=s', 'delay|D=s','email|E', 'mailto|mail-to|M=s', ); @@ -156,7 +180,9 @@ if (exists $options{enqueue}) { $delay =~ s/\n//g; if ($options{email}) { $delay =~ m/[+-]d(?:ela?y?)?[-+]([^\@]+)/; - $delay = $1; $delay =~ s/_/ /; + $delay = $1; + $delay =~ s/_/ /g; + $delay =~ s/=/:/g; } # slurp email local $/; @@ -181,7 +207,7 @@ if (exists $options{enqueue}) { my $at_fh; my $pid = open($at_fh,'|-','at',$delay) or exit 1; print {$at_fh} "$0 '--queue' '$options{queue}' '--process' '$queue_fn';\n"; - close $at_fh or exit $? + close $at_fh or exit $?; exit 0; } elsif ($options{list}) { @@ -220,22 +246,19 @@ elsif ($options{process}) { die "Unable to parse $options{process}"; } # munge the message id - my ($message_id) = $q_e->{email} =~ m/^Message-Id:\s*(.+)/; + my ($message_id) = $q_e->{email} =~ m/^Message-Id:\s*(.+)/mi; if (not $message_id =~ s/\@/delay$q_e->{entry}@/){ $message_id =~ s/(\w)/delay$q_e->{entry}$1/; } - $q_e->{email} =~ s/^(Message-Id:\s*)(.+)/$1$message_id/; + $q_e->{email} =~ s/^(Message-Id:\s*)(.+)/$1$message_id/mi; # send the message my $sendmail_fh; open($sendmail_fh,'|-','/usr/sbin/sendmail',$q_e->{mailto}) or die "Unable to open sendmail to send message"; print {$sendmail_fh} $q_e->{email}; - close($sendmail_fh); - waitpid(-1,0); - if ($?) { - print STDERR "Sendmail failed with $?\n"; - exit $?; - } + close($sendmail_fh) or + print STDERR "Sendmail failed with $?\n" and + exit $?; unlink("$options{queue}/$options{process}"); } else {