]> git.donarmstrong.com Git - debbugs.git/blobdiff - Debbugs/Mail.pm
don't go past end of @msg when setting
[debbugs.git] / Debbugs / Mail.pm
index 032dea9c714d9b35e200087fe082f453aca04dfd..9fa282b1b53689447621513908d3092d57ebc65b 100644 (file)
@@ -43,20 +43,24 @@ use base qw(Exporter);
 
 use IPC::Open3;
 use POSIX qw(:sys_wait_h strftime);
-use Time::HiRes qw(usleep);
+use Time::HiRes qw(usleep gettimeofday);
 use Mail::Address ();
 use Debbugs::MIME qw(encode_rfc1522);
 use Debbugs::Config qw(:config);
 use Params::Validate qw(:types validate_with);
+use Encode qw(encode is_utf8);
+use Debbugs::UTF8 qw(encode_utf8_safely);
+
+use Debbugs::Packages;
 
 BEGIN{
      ($VERSION) = q$Revision: 1.1 $ =~ /^Revision:\s+([^\s+])/;
      $DEBUG = 0 unless defined $DEBUG;
 
      @EXPORT = ();
-     %EXPORT_TAGS = (addresses => qw(get_addresses),
-                    misc      => qw(rfc822_date),
-                    mail      => qw(send_mail_message encode_headers default_headers),
+     %EXPORT_TAGS = (addresses => [qw(get_addresses)],
+                    misc      => [qw(rfc822_date)],
+                    mail      => [qw(send_mail_message encode_headers default_headers)],
                    );
      @EXPORT_OK = ();
      Exporter::export_ok_tags(keys %EXPORT_TAGS);
@@ -101,6 +105,8 @@ In list context, returns an array of headers. In scalar context,
 returns headers for shoving in a mail message after encoding using
 encode_headers.
 
+=head3 options
+
 =over
 
 =item queue_file -- the queue file which will generate this set of
@@ -123,24 +129,54 @@ passed through.
 
 =back
 
+=head3 default headers
+
+=over
+
+=item X-Loop -- set to the maintainer e-mail
+
+=item From -- set to the maintainer e-mail
+
+=item To -- set to Unknown recipients
+
+=item Subject -- set to Unknown subject
+
+=item Message-ID -- set appropriately (see code)
+
+=item Precedence -- set to bulk
+
+=item References -- set to the full set of message ids that are known
+(from data and the msgid option)
+
+=item In-Reply-To -- set to msg id or the msgid from data
+
+=item X-Project-PR-Message -- set to pr_msg with the bug number appended
+
+=item X-Project-PR-Package -- set to the package of the bug
+
+=item X-Project-PR-Keywords -- set to the keywords of the bug
+
+=item X-Project-PR-Source -- set to the source of the bug
+
+=back
+
 =cut
 
 sub default_headers {
     my %param = validate_with(params => \@_,
-                             spec   => {queue_file => {type => SCALAR,
+                             spec   => {queue_file => {type => SCALAR|UNDEF,
                                                        optional => 1,
                                                       },
                                         data       => {type => HASHREF,
                                                        optional => 1,
                                                       },
-                                        msgid      => {type => SCALAR,
+                                        msgid      => {type => SCALAR|UNDEF,
                                                        optional => 1,
                                                       },
-                                        msgtype    => {type => SCALAR,
+                                        msgtype    => {type => SCALAR|UNDEF,
                                                        default => 'misc',
-                                                       optional => 1,
                                                       },
-                                        pr_msg     => {type => SCALAR,
+                                        pr_msg     => {type => SCALAR|UNDEF,
                                                        default => 'misc',
                                                       },
                                         headers    => {type => ARRAYREF,
@@ -150,6 +186,17 @@ sub default_headers {
                             );
     my @header_order = (qw(X-Loop From To subject),
                        qw(Message-ID In-Reply-To References));
+    # handle various things being undefined
+    if (not exists $param{queue_file} or
+       not defined $param{queue_file}) {
+       $param{queue_file} = join('',gettimeofday())
+    }
+    for (qw(msgtype pr_msg)) {
+       if (not exists $param{$_} or
+           not defined $param{$_}) {
+           $param{$_} = 'misc';
+       }
+    }
     my %header_order;
     @header_order{map {lc $_} @header_order} = 0..$#header_order;
     my %set_headers;
@@ -203,7 +250,7 @@ sub default_headers {
                $default_header{"X-$config{project}-PR-Source"} = $1;
            }
            else {
-               my $pkg_src = getpkgsrc();
+               my $pkg_src = Debbugs::Packages::getpkgsrc();
                $default_header{"X-$config{project}-PR-Source"} = $pkg_src->{$param{data}{package}};
            }
        }
@@ -215,7 +262,7 @@ sub default_headers {
                ($header,$default_header{$header});
        }
        else {
-           push @other_headers,($header,$header_order{lc($header)});
+           push @other_headers,($header,$default_header{$header});
        }
     }
     my @headers;
@@ -275,7 +322,7 @@ using warn.
 sub send_mail_message{
      my %param = validate_with(params => \@_,
                               spec  => {sendmail_arguments => {type => ARRAYREF,
-                                                               default => [qw(-odq -oem -oi)],
+                                                               default => $config{sendmail_arguments},
                                                               },
                                         parse_for_recipients => {type => BOOLEAN,
                                                                  default => 0,
@@ -293,7 +340,7 @@ sub send_mail_message{
                                                                 },
                                        },
                              );
-     my @sendmail_arguments = qw(-odq -oem -oi);
+     my @sendmail_arguments = @{$param{sendmail_arguments}};
      push @sendmail_arguments, '-f', $param{envelope_from} if exists $param{envelope_from};
 
      my @recipients;
@@ -352,7 +399,7 @@ sub encode_headers{
 
      my ($header,$body) = split /\n\n/, $message, 2;
      $header = encode_rfc1522($header);
-     return $header . qq(\n\n). $body;
+     return $header . qq(\n\n). encode_utf8_safely($body);
 }
 
 =head2 rfc822_date