summaryrefslogtreecommitdiffstats
path: root/Bugzilla/BugMail.pm
diff options
context:
space:
mode:
authorlpsolit%gmail.com <>2006-06-02 19:50:15 +0200
committerlpsolit%gmail.com <>2006-06-02 19:50:15 +0200
commit2b9f5bf80911872ca809061bd46d8fc7f64c2929 (patch)
tree29443975af530533739b1d7c442e8ebed5254430 /Bugzilla/BugMail.pm
parent24a02ebf00c318c3406fc4c4f38a8f93480b0548 (diff)
downloadbugzilla-2b9f5bf80911872ca809061bd46d8fc7f64c2929.tar.gz
bugzilla-2b9f5bf80911872ca809061bd46d8fc7f64c2929.tar.xz
Bug 339862: Move Bugzilla::BugMail::MessageToMTA() in a separate module - Patch by Frédéric Buclin <LpSolit@gmail.com> r=mkanat a=justdave
Diffstat (limited to 'Bugzilla/BugMail.pm')
-rw-r--r--Bugzilla/BugMail.pm167
1 files changed, 1 insertions, 166 deletions
diff --git a/Bugzilla/BugMail.pm b/Bugzilla/BugMail.pm
index 74e1145a7..ab8ca2f6f 100644
--- a/Bugzilla/BugMail.pm
+++ b/Bugzilla/BugMail.pm
@@ -39,15 +39,10 @@ use Bugzilla::Config qw(:DEFAULT $datadir);
use Bugzilla::Util;
use Bugzilla::Bug;
use Bugzilla::Component;
+use Bugzilla::Mailer;
use Date::Parse;
use Date::Format;
-use Mail::Mailer;
-use Mail::Header;
-use MIME::Base64;
-use MIME::QuotedPrint;
-use MIME::Parser;
-use Mail::Address;
use constant BIT_DIRECT => 1;
use constant BIT_WATCHING => 2;
@@ -670,166 +665,6 @@ sub sendMail {
return 1;
}
-sub MessageToMTA {
- my ($msg) = (@_);
- return if (Param('mail_delivery_method') eq "none");
-
- my ($header, $body) = $msg =~ /(.*?\n)\n(.*)/s ? ($1, $2) : ('', $msg);
- my $headers;
-
- if (Param('utf8') and (!is_7bit_clean($header) or !is_7bit_clean($body))) {
- ($headers, $body) = encode_message($msg);
- } else {
- my @header_lines = split(/\n/, $header);
- $headers = new Mail::Header \@header_lines, Modify => 0;
- }
-
- # Use trim to remove any whitespace (incl. newlines)
- my $from = trim($headers->get('from'));
-
- if (Param("mail_delivery_method") eq "sendmail" && $^O =~ /MSWin32/i) {
- my $cmd = '|' . SENDMAIL_EXE . ' -t -i';
- if ($from) {
- # We're on Windows, thus no danger of command injection
- # via $from. In other words, it is safe to embed $from.
- $cmd .= qq# -f"$from"#;
- }
- open(SENDMAIL, $cmd) ||
- die "Failed to execute " . SENDMAIL_EXE . ": $!\n";
- print SENDMAIL $headers->as_string;
- print SENDMAIL "\n";
- print SENDMAIL $body;
- close SENDMAIL;
- return;
- }
-
- my @args;
- if (Param("mail_delivery_method") eq "sendmail") {
- push @args, "-i";
- if ($from) {
- push(@args, "-f$from");
- }
- }
- if (Param("mail_delivery_method") eq "sendmail" && !Param("sendmailnow")) {
- push @args, "-ODeliveryMode=deferred";
- }
- if (Param("mail_delivery_method") eq "smtp") {
- push @args, Server => Param("smtpserver");
- if ($from) {
- $ENV{'MAILADDRESS'} = $from;
- }
- }
- my $mailer = new Mail::Mailer Param("mail_delivery_method"), @args;
- if (Param("mail_delivery_method") eq "testfile") {
- $Mail::Mailer::testfile::config{outfile} = "$datadir/mailer.testfile";
- }
-
- $mailer->open($headers->header_hashref);
- print $mailer $body;
- $mailer->close;
-}
-
-sub encode_qp_words {
- my ($line) = (@_);
- my @encoded;
- foreach my $word (split / /, $line) {
- if (!is_7bit_clean($word)) {
- push @encoded, '=?UTF-8?Q?_' . encode_qp($word, '') . '?=';
- } else {
- push @encoded, $word;
- }
- }
- return join(' ', @encoded);
-}
-
-sub encode_message {
- my ($msg) = @_;
-
- my $parser = MIME::Parser->new;
- $parser->output_to_core(1);
- $parser->tmp_to_core(1);
- my $entity = $parser->parse_data($msg);
- $entity = encode_message_entity($entity);
-
- my @header_lines = split(/\n/, $entity->header_as_string);
- my $head = new Mail::Header \@header_lines, Modify => 0;
-
- my $body = $entity->body_as_string;
-
- return ($head, $body);
-}
-
-sub encode_message_entity {
- my ($entity) = @_;
-
- my $head = $entity->head;
-
- # encode the subject
-
- my $subject = $head->get('subject');
- if (defined $subject && !is_7bit_clean($subject)) {
- $subject =~ s/[\r\n]+$//;
- $head->replace('subject', encode_qp_words($subject));
- }
-
- # encode addresses
-
- foreach my $field (qw(from to cc reply-to sender errors-to)) {
- my $high = $head->count($field) - 1;
- foreach my $index (0..$high) {
- my $value = $head->get($field, $index);
- my @addresses;
- my $changed = 0;
- foreach my $addr (Mail::Address->parse($value)) {
- my $phrase = $addr->phrase;
- if (is_7bit_clean($phrase)) {
- push @addresses, $addr->format;
- } else {
- push @addresses, encode_qp_phrase($phrase) .
- ' <' . $addr->address . '>';
- $changed = 1;
- }
- }
- $changed && $head->replace($field, join(', ', @addresses), $index);
- }
- }
-
- # process the body
-
- if (scalar($entity->parts)) {
- my $newparts = [];
- foreach my $part ($entity->parts) {
- my $newpart = encode_message_entity($part);
- push @$newparts, $newpart;
- }
- $entity->parts($newparts);
- }
- else {
- # Extract the body from the entity, for examination
- # At this point, we can rely on MIME::Tools to do our encoding for us!
- my $bodyhandle = $entity->bodyhandle;
- my $body = $bodyhandle->as_string;
- if (!is_7bit_clean($body)) {
- # count number of 7-bit chars, and use quoted-printable if more
- # than half the message is 7-bit clean
- my $count = ($body =~ tr/\x20-\x7E\x0A\x0D//);
- if ($count > length($body) / 2) {
- $head->mime_attr('Content-Transfer-Encoding' => 'quoted-printable');
- } else {
- $head->mime_attr('Content-Transfer-Encoding' => 'base64');
- }
- }
-
- # Set the content/type and charset of the part, if not set
- $head->mime_attr('Content-Type' => 'text/plain')
- unless defined $head->mime_attr('content-type');
- $head->mime_attr('Content-Type.charset' => 'UTF-8');
- }
-
- $head->fold(75);
- return $entity;
-}
-
# Send the login name and password of the newly created account to the user.
sub MailPassword {
my ($login, $password) = (@_);