summaryrefslogtreecommitdiffstats
path: root/Bugzilla/Mailer.pm
diff options
context:
space:
mode:
authorByron Jones <glob@mozilla.com>2015-08-31 06:20:49 +0200
committerByron Jones <glob@mozilla.com>2015-08-31 06:20:49 +0200
commitfedc614940493768c53791939065fcf72ac5414b (patch)
tree4c3556fb667410cf1039168c1a17d3b90d7979c1 /Bugzilla/Mailer.pm
parent48649030bf8536d8b9cf9df522c39438a06ec56c (diff)
downloadbugzilla-fedc614940493768c53791939065fcf72ac5414b.tar.gz
bugzilla-fedc614940493768c53791939065fcf72ac5414b.tar.xz
Bug 714724 - correctly encode emails as quoted-printable
r=LpSolit,a=sgreen
Diffstat (limited to 'Bugzilla/Mailer.pm')
-rw-r--r--Bugzilla/Mailer.pm106
1 files changed, 23 insertions, 83 deletions
diff --git a/Bugzilla/Mailer.pm b/Bugzilla/Mailer.pm
index 69db9c557..593a1067a 100644
--- a/Bugzilla/Mailer.pm
+++ b/Bugzilla/Mailer.pm
@@ -17,6 +17,7 @@ use parent qw(Exporter);
use Bugzilla::Constants;
use Bugzilla::Error;
use Bugzilla::Hook;
+use Bugzilla::MIME;
use Bugzilla::User;
use Bugzilla::Util;
@@ -24,7 +25,6 @@ use Date::Format qw(time2str);
use Encode qw(encode);
use Encode::MIME::Header;
-use Email::MIME;
use Email::Sender::Simple qw(sendmail);
use Email::Sender::Transport::SMTP::Persistent;
use Bugzilla::Sender::Transport::Sendmail;
@@ -34,17 +34,17 @@ sub generate_email {
my ($lang, $email_format, $msg_text, $msg_html, $msg_header);
if ($vars->{to_user}) {
- $lang = $vars->{to_user}->setting('lang');
- $email_format = $vars->{to_user}->setting('email_format');
+ $lang = $vars->{to_user}->setting('lang');
+ $email_format = $vars->{to_user}->setting('email_format');
} else {
- # If there are users in the CC list who don't have an account,
- # use the default language for email notifications.
- $lang = Bugzilla::User->new()->setting('lang');
- # However we cannot fall back to the default email_format, since
- # it may be HTML, and many of the includes used in the HTML
- # template require a valid user object. Instead we fall back to
- # the plaintext template.
- $email_format = 'text_only';
+ # If there are users in the CC list who don't have an account,
+ # use the default language for email notifications.
+ $lang = Bugzilla::User->new()->setting('lang');
+ # However we cannot fall back to the default email_format, since
+ # it may be HTML, and many of the includes used in the HTML
+ # template require a valid user object. Instead we fall back to
+ # the plaintext template.
+ $email_format = 'text_only';
}
my $template = Bugzilla->template_inner($lang);
@@ -55,26 +55,29 @@ sub generate_email {
|| ThrowTemplateError($template->error());
my @parts = (
- Email::MIME->create(
+ Bugzilla::MIME->create(
attributes => {
- content_type => "text/plain",
+ content_type => 'text/plain',
+ charset => 'UTF-8',
+ encoding => 'quoted-printable',
},
- body => $msg_text,
+ body_str => $msg_text,
)
);
if ($templates->{html} && $email_format eq 'html') {
$template->process($templates->{html}, $vars, \$msg_html)
|| ThrowTemplateError($template->error());
- push @parts, Email::MIME->create(
+ push @parts, Bugzilla::MIME->create(
attributes => {
- content_type => "text/html",
+ content_type => 'text/html',
+ charset => 'UTF-8',
+ encoding => 'quoted-printable',
},
- body => $msg_html,
+ body_str => $msg_html,
);
}
- # TT trims the trailing newline, and threadingmarker may be ignored.
- my $email = new Email::MIME("$msg_header\n");
+ my $email = Bugzilla::MIME->new($msg_header);
if (scalar(@parts) == 1) {
$email->content_type_set($parts[0]->content_type);
} else {
@@ -101,18 +104,7 @@ sub MessageToMTA {
my $dbh = Bugzilla->dbh;
- my $email;
- if (ref $msg) {
- $email = $msg;
- }
- else {
- # RFC 2822 requires us to have CRLF for our line endings and
- # Email::MIME doesn't do this for us. We use \015 (CR) and \012 (LF)
- # directly because Perl translates "\n" depending on what platform
- # you're running on. See http://perldoc.perl.org/perlport.html#Newlines
- $msg =~ s/(?:\015+)?\012/\015\012/msg;
- $email = new Email::MIME($msg);
- }
+ my $email = ref($msg) ? $msg : Bugzilla::MIME->new($msg);
# If we're called from within a transaction, we don't want to send the
# email immediately, in case the transaction is rolled back. Instead we
@@ -165,37 +157,6 @@ sub MessageToMTA {
}
}
- # We add this header to uniquely identify all email that we
- # send as coming from this Bugzilla installation.
- #
- # We don't use correct_urlbase, because we want this URL to
- # *always* be the same for this Bugzilla, in every email,
- # even if the admin changes the "ssl_redirect" parameter some day.
- $email->header_set('X-Bugzilla-URL', Bugzilla->params->{'urlbase'});
-
- # We add this header to mark the mail as "auto-generated" and
- # thus to hopefully avoid auto replies.
- $email->header_set('Auto-Submitted', 'auto-generated');
-
- # MIME-Version must be set otherwise some mailsystems ignore the charset
- $email->header_set('MIME-Version', '1.0') if !$email->header('MIME-Version');
-
- # Encode the headers correctly in quoted-printable
- foreach my $header ($email->header_names) {
- my @values = $email->header($header);
- # We don't recode headers that happen multiple times.
- next if scalar(@values) > 1;
- if (my $value = $values[0]) {
- utf8::decode($value) unless utf8::is_utf8($value);
-
- # avoid excessive line wrapping done by Encode.
- local $Encode::Encoding{'MIME-Q'}->{'bpl'} = 998;
-
- my $encoded = encode('MIME-Q', $value);
- $email->header_set($header, $encoded);
- }
- }
-
my $from = $email->header('From');
my $hostname;
@@ -240,27 +201,6 @@ sub MessageToMTA {
return if $email->header('to') eq '';
- $email->walk_parts(sub {
- my ($part) = @_;
- return if $part->parts > 1; # Top-level
- my $content_type = $part->content_type || '';
- $content_type =~ /charset=['"](.+)['"]/;
- # If no charset is defined or is the default us-ascii,
- # then we encode the email to UTF-8.
- # XXX - This is a hack to workaround bug 723944.
- if (!$1 || $1 eq 'us-ascii') {
- my $body = $part->body;
- $part->charset_set('UTF-8');
- # encoding_set works only with bytes, not with utf8 strings.
- my $raw = $part->body_raw;
- if (utf8::is_utf8($raw)) {
- utf8::encode($raw);
- $part->body_set($raw);
- }
- $part->encoding_set('quoted-printable') if !is_7bit_clean($body);
- }
- });
-
if ($method eq "Test") {
my $filename = bz_locations()->{'datadir'} . '/mailer.testfile';
open TESTFILE, '>>:encoding(UTF-8)', $filename;