From 43b7dc314234e476a80d9acbd07292d7286cca5a Mon Sep 17 00:00:00 2001 From: "lpsolit%gmail.com" <> Date: Wed, 2 Apr 2008 22:42:25 +0000 Subject: Bug 405946: Some emails are not sent in the language chosen by the addressee - Patch by Frédéric Buclin r=wurblzap a=LpSolit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bugzilla/Flag.pm | 58 +++++++++++++++++++++++++++----------------------------- 1 file changed, 28 insertions(+), 30 deletions(-) (limited to 'Bugzilla/Flag.pm') diff --git a/Bugzilla/Flag.pm b/Bugzilla/Flag.pm index f8c43b508..a65a8268b 100644 --- a/Bugzilla/Flag.pm +++ b/Bugzilla/Flag.pm @@ -1063,56 +1063,54 @@ or deleted. sub notify { my ($flag, $bug, $attachment) = @_; - my $template = Bugzilla->template; - # There is nobody to notify. return unless ($flag->{'addressee'} || $flag->type->cc_list); - my $attachment_is_private = $attachment ? $attachment->isprivate : undef; - # If the target bug is restricted to one or more groups, then we need # to make sure we don't send email about it to unauthorized users # on the request type's CC: list, so we have to trawl the list for users # not in those groups or email addresses that don't have an account. my @bug_in_groups = grep {$_->{'ison'} || $_->{'mandatory'}} @{$bug->groups}; + my $attachment_is_private = $attachment ? $attachment->isprivate : undef; - if (scalar(@bug_in_groups) || $attachment_is_private) { - my @new_cc_list; - foreach my $cc (split(/[, ]+/, $flag->type->cc_list)) { - my $ccuser = new Bugzilla::User({ name => $cc }) || next; - - next if (scalar(@bug_in_groups) && !$ccuser->can_see_bug($bug->bug_id)); - next if $attachment_is_private - && Bugzilla->params->{"insidergroup"} - && !$ccuser->in_group(Bugzilla->params->{"insidergroup"}); - push(@new_cc_list, $cc); - } - $flag->type->{'cc_list'} = join(", ", @new_cc_list); + my %recipients; + foreach my $cc (split(/[, ]+/, $flag->type->cc_list)) { + my $ccuser = new Bugzilla::User({ name => $cc }); + next if (scalar(@bug_in_groups) && (!$ccuser || !$ccuser->can_see_bug($bug->bug_id))); + next if $attachment_is_private && (!$ccuser || !$ccuser->is_insider); + # Prevent duplicated entries due to case sensitivity. + $cc = $ccuser ? $ccuser->email : $cc; + $recipients{$cc} = $ccuser; } - # If there is nobody left to notify, return. - return unless ($flag->{'addressee'} || $flag->type->cc_list); - - my @recipients = split(/[, ]+/, $flag->type->cc_list); # Only notify if the addressee is allowed to receive the email. if ($flag->{'addressee'} && $flag->{'addressee'}->email_enabled) { - push @recipients, $flag->{'addressee'}->email; + $recipients{$flag->{'addressee'}->email} = $flag->{'addressee'}; } - # Process and send notification for each recipient - foreach my $to (@recipients) - { - next unless $to; + # Process and send notification for each recipient. + # If there are users in the CC list who don't have an account, + # use the default language for email notifications. + my $default_lang; + if (grep { !$_ } values %recipients) { + my $default_user = new Bugzilla::User(); + $default_lang = $default_user->settings->{'lang'}->{'value'}; + } + + foreach my $to (keys %recipients) { my $vars = { 'flag' => $flag, 'to' => $to, 'bug' => $bug, 'attachment' => $attachment}; + + my $lang = $recipients{$to} ? + $recipients{$to}->settings->{'lang'}->{'value'} : $default_lang; + + my $template = Bugzilla->template_inner($lang); my $message; - my $rv = $template->process("request/email.txt.tmpl", $vars, \$message); - if (!$rv) { - Bugzilla->cgi->header(); - ThrowTemplateError($template->error()); - } + $template->process("request/email.txt.tmpl", $vars, \$message) + || ThrowTemplateError($template->error()); + Bugzilla->template_inner(""); MessageToMTA($message); } } -- cgit v1.2.3-24-g4f1b