| File: | bin/mail-dkim |
| Coverage: | 97.0% |
| line | stmt | bran | cond | sub | time | code |
|---|---|---|---|---|---|---|
| 1 | #!/usr/bin/env perl | |||||
| 2 | # | |||||
| 3 | # mail-dkim - sign a message that arrives on stdin, then hand it to sendmail(1) | |||||
| 4 | # with the arguments given on the command line. | |||||
| 5 | # | |||||
| 6 | # It exists to be dropped where a CGI script or a cron job calls | |||||
| 7 | # /usr/sbin/sendmail directly: those messages go out with no signature, so a | |||||
| 8 | # forwarded copy looks exactly like a forgery to the receiving site. Pointing | |||||
| 9 | # that one call at this instead signs the mail without touching the script. | |||||
| 10 | # | |||||
| 11 | # The signing is in Mail::Send::DKIM; this is the command line around it, so | |||||
| 12 | # that the module can be used and tested without a process and a pipe. | |||||
| 13 | ||||||
| 14 | 4 4 4 | 8267 1 66 | use strict; | |||
| 15 | 4 4 4 | 6 2 82 | use warnings; | |||
| 16 | ||||||
| 17 | 4 4 4 | 638 2032 282 | use FindBin qw($Bin); | |||
| 18 | # Where the module is: beside this script in a checkout, and one level down | |||||
| 19 | # under lib/perl5 when the distribution was installed with INSTALL_BASE - which | |||||
| 20 | # is how perlbrew, local::lib and cpanm -l put it, and where @INC does not | |||||
| 21 | # reach unless PERL5LIB is set for every caller, cron included. | |||||
| 22 | 4 4 4 8 8 | 668 1112 6 42 9 | use lib grep { -d } map { "$Bin/../$_" } qw(lib lib/perl5); | |||
| 23 | 4 4 4 | 834 13 3319 | use Mail::Send::DKIM; | |||
| 24 | ||||||
| 25 | 4 | 314548 | my $dkim = Mail::Send::DKIM->new(); | |||
| 26 | ||||||
| 27 | 4 4 4 | 58 8 59 | my $message = do { local $/; <STDIN> } // ''; | |||
| 28 | 4 | 12 | my $signed = $dkim->sign($message); | |||
| 29 | 4 | 7 | $message = $signed if(defined($signed)); | |||
| 30 | ||||||
| 31 | 4 | 13 | exit($dkim->send($message, @ARGV)); | |||
| 32 | ||||||