--- /var/tmp/anubis-3.9.95/contrib/msg2smtp.pl Wed Feb 12 13:31:28 2003 +++ /usr/local/bin/msg2smtp.pl Sun Sep 5 15:16:40 2004 @@ -15,6 +15,11 @@ -U USERNAME (ESMTP auth username) -P PASSWORD (ESMTP auth password) -m MECHANISM (ESMTP auth mechanism - default is PLAIN) + -M mutt mode - ie destinee(s) are non opt args: + msg2smtp.pl [opts] -- address@hidden address@hidden ... + Use this mode with mutt, otherwise BCC: won't get the msg + and bouncing won't work. + If @domain is missing, defaults to @localhost -d (shows SMTP conversation and perl debugging) !; @@ -61,7 +66,7 @@ use warnings; use strict; use Getopt::Std; -use vars qw!$opt_h $opt_p $opt_e $opt_U $opt_P $opt_d $opt_m!; +use vars qw!$opt_h $opt_p $opt_e $opt_U $opt_P $opt_M $opt_d $opt_m!; # REQUIRED MODULES: use Mail::Address; @@ -83,7 +88,8 @@ #------------------------------------------ # 2. Set options by Command-line Arguments -getopts('dh:p:e:U:P:m:'); +getopts('Mdh:p:e:U:P:m:'); + my (%smtp_options, $host, $username, $password, $auth_mech); @@ -115,16 +121,28 @@ my ($tmp, $readyflag, $chunk, @to_addresses); $readyflag = 0; -HEAD: while ($tmp = ) { +# Mutt mode - get destinee(s) from non-opt (remaining) args +if ($opt_M) { + foreach my $r (@ARGV) { + $r .="address@hidden" if ($r !~ /\@/); + push @rcpt, $r; + $readyflag=1; + #print STDERR "To: $r\n"; + } +} + +HEAD: while ($tmp = ) { # Rule 1: If the line is a blank line, exit HEAD section if ($tmp =~ /^$/) { - if ($readyflag eq 1) { + # don't use the $readyflag flag, if we got a blank line we exit + # headers parser anyway - we'll check later if we got To: and From: + # if ($readyflag eq 1) { last; - } - else { - next HEAD; - } + # } + # else { + # next HEAD; + # } } # Rule 2: If it is a folded line, add line to $chunk, skip to next line @@ -139,13 +157,27 @@ $from = pop(@from_addresses)->address; die "From: address invalid" unless $from; die "there is more than one From: address" if @from_addresses; - $readyflag = 1; + $from .="address@hidden" if ($from !~ /\@/); + } elsif (/^From /i) { + # get rid of spurious 'From ' line + $chunk = ''; } elsif (/^(To|CC|BCC):/i) { - s/^(To|CC|BCC)://i; - @to_addresses = (); # re-initialize because we re-enter this loop - @to_addresses = Mail::Address->parse($_); - foreach my $obj (@to_addresses) { - push @rcpt, $obj->address; + # remove BCC: infos anyway + if (/^BCC:/i) { + $chunk=''; + } + if (!$opt_M) { + s/^(To|CC|BCC)://i; + @to_addresses = (); # re-initialize because we re-enter this loop + @to_addresses = Mail::Address->parse($_); + foreach my $obj (@to_addresses) { + if ($obj->address !~ /\@/) { + push @rcpt, $obj->address . "address@hidden"; + } else { + push @rcpt, $obj->address; + } + } + $readyflag = 1; } } $txt_head .= $chunk if ($chunk); @@ -154,16 +186,26 @@ $chunk = $tmp; } +# if we did not see a 'From:' line, synthetize a reasonable default +$from = "$ENV{'USER'address@hidden" if(!$from); +# we really must have one of these +die "To|Cc|Bcc: address(es) invalid or missing" unless $readyflag; + while () { $txt_body .= $_; } -#if ($smtp_options{Debug}) { -# print "\n---BEGINNING OF DEBUG---\n"; -# print "From: $from\n"; map {print "To: $_\n"} @rcpt; -# print "MsgBody:\n$txt_body\n"; -# print "---END OF DEBUG---\n"; -#} +if ($smtp_options{Debug}) { + print STDERR "\n---BEGINNING OF DEBUG---\n"; + print STDERR "--From:, To:--\n"; + print STDERR "From: $from\n" if ($from); + map {print STDERR "To: $_\n"} @rcpt; + print STDERR "\n--All headers:--\n"; + print STDERR "$txt_head\n" if($txt_head); + print STDERR "--MsgBody:--\n"; + print STDERR "$txt_body\n" if($txt_body); + print STDERR "---END OF DEBUG---\n"; +} #------------------------------------------ # 4. Extend Net::SMTP to allow us to choose and auth mechanism