summaryrefslogtreecommitdiffstats
path: root/Bugzilla/BugMail.pm
diff options
context:
space:
mode:
authorGuy Pyrzak <guy.pyrzak@gmail.com>2010-10-03 22:44:42 +0200
committerGuy Pyrzak <guy.pyrzak@gmail.com>2010-10-03 22:44:42 +0200
commit71320dae661a8ca351128d917c894b0f8318eaf3 (patch)
tree7a868603eae8d17bb069d5d54d4635ee41ba1a5a /Bugzilla/BugMail.pm
parent22c1448223846c21addc7c1b1896989191163429 (diff)
downloadbugzilla-71320dae661a8ca351128d917c894b0f8318eaf3.tar.gz
bugzilla-71320dae661a8ca351128d917c894b0f8318eaf3.tar.xz
Bug 65477: Send HTML bugmail
r=mkanat, a=mkanat
Diffstat (limited to 'Bugzilla/BugMail.pm')
-rw-r--r--Bugzilla/BugMail.pm60
1 files changed, 45 insertions, 15 deletions
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 <bugzilla@glob.com.au>
# Reed Loden <reed@reedloden.com>
# Frédéric Buclin <LpSolit@gmail.com>
+# Guy Pyrzak <guy.pyrzak@gmail.com>
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 = ?',