From 71320dae661a8ca351128d917c894b0f8318eaf3 Mon Sep 17 00:00:00 2001 From: Guy Pyrzak Date: Sun, 3 Oct 2010 13:44:42 -0700 Subject: Bug 65477: Send HTML bugmail r=mkanat, a=mkanat --- Bugzilla/BugMail.pm | 60 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 45 insertions(+), 15 deletions(-) (limited to 'Bugzilla/BugMail.pm') diff --git a/Bugzilla/BugMail.pm b/Bugzilla/BugMail.pm index 2ac575293..dfd7584ea 100644 --- a/Bugzilla/BugMail.pm +++ b/Bugzilla/BugMail.pm @@ -29,6 +29,7 @@ # Byron Jones # Reed Loden # Frédéric Buclin +# Guy Pyrzak use strict; @@ -83,10 +84,9 @@ sub Send { # can 'have' a role, if the person in that role has changed, or people are # watching. my @assignees = ($bug->assigned_to); - my @qa_contacts = ($bug->qa_contact); + my @qa_contacts = $bug->qa_contact || (); my @ccs = @{ $bug->cc_users }; - # Include the people passed in as being in particular roles. # This can include people who used to hold those roles. # At this point, we don't care if there are duplicates in these arrays. @@ -104,6 +104,7 @@ sub Send { push(@ccs, Bugzilla::User->check($cc)); } } + my %user_cache = map { $_->id => $_ } (@assignees, @qa_contacts, @ccs); my @diffs; if (!$start) { @@ -123,7 +124,7 @@ sub Send { blocker => $params->{blocker} }); } else { - push(@diffs, _get_diffs($bug, $end)); + push(@diffs, _get_diffs($bug, $end, \%user_cache)); } my $comments = $bug->comments({ after => $start, to => $end }); @@ -220,7 +221,8 @@ sub Send { foreach my $user_id (keys %recipients) { my %rels_which_want; my $sent_mail = 0; - my $user = new Bugzilla::User($user_id); + $user_cache{$user_id} ||= new Bugzilla::User($user_id); + my $user = $user_cache{$user_id}; # Deleted users must be excluded. next unless $user; @@ -353,19 +355,47 @@ sub sendMail { new_comments => \@send_comments, threadingmarker => build_thread_marker($bug->id, $user->id, !$bug->lastdiffed), }; - - my $msg; - my $template = Bugzilla->template_inner($user->settings->{'lang'}->{'value'}); - $template->process("email/newchangedmail.txt.tmpl", $vars, \$msg) - || ThrowTemplateError($template->error()); - + my $msg = _generate_bugmail($user, $vars); MessageToMTA($msg); return 1; } +sub _generate_bugmail { + my ($user, $vars) = @_; + my $template = Bugzilla->template_inner($user->settings->{'lang'}->{'value'}); + my ($msg_text, $msg_html, $msg_header); + + $template->process("email/bugmail-header.txt.tmpl", $vars, \$msg_header) + || ThrowTemplateError($template->error()); + $template->process("email/bugmail.txt.tmpl", $vars, \$msg_text) + || ThrowTemplateError($template->error()); + $template->process("email/bugmail.html.tmpl", $vars, \$msg_html) + || ThrowTemplateError($template->error()); + + my @parts = ( + Email::MIME->create( + attributes => { + content_type => "text/plain", + }, + body => $msg_text, + ), + Email::MIME->create( + attributes => { + content_type => "text/html", + }, + body => $msg_html, + ), + ); + + my $email = new Email::MIME($msg_header); + $email->parts_set(\@parts); + $email->content_type_set('multipart/alternative'); + return $email; +} + sub _get_diffs { - my ($bug, $end) = @_; + my ($bug, $end, $user_cache) = @_; my $dbh = Bugzilla->dbh; my @args = ($bug->id); @@ -377,20 +407,20 @@ sub _get_diffs { } my $diffs = $dbh->selectall_arrayref( - "SELECT profiles.login_name, profiles.realname, fielddefs.name AS field_name, + "SELECT fielddefs.name AS field_name, bugs_activity.bug_when, bugs_activity.removed AS old, bugs_activity.added AS new, bugs_activity.attach_id, - bugs_activity.comment_id + bugs_activity.comment_id, bugs_activity.who FROM bugs_activity INNER JOIN fielddefs ON fielddefs.id = bugs_activity.fieldid - INNER JOIN profiles - ON profiles.userid = bugs_activity.who WHERE bugs_activity.bug_id = ? $when_restriction ORDER BY bugs_activity.bug_when", {Slice=>{}}, @args); foreach my $diff (@$diffs) { + $user_cache->{$diff->{who}} ||= new Bugzilla::User($diff->{who}); + $diff->{who} = $user_cache->{$diff->{who}}; if ($diff->{attach_id}) { $diff->{isprivate} = $dbh->selectrow_array( 'SELECT isprivate FROM attachments WHERE attach_id = ?', -- cgit v1.2.3-24-g4f1b