Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Bugzilla/Install.pm
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,14 @@ sub SETTINGS {
category => 'Email Notifications'
},

# 2026-11-25 dkl@mozilla.com -- Bug 2097284
{
name => 'bugmail_flag_prefix',
options => ['on', 'off'],
default => 'off',
category => 'Email Notifications'
},

# 2013-07-26 joshi_sunil@in.com -- Bug 669535
{
name => 'possible_duplicates',
Expand Down
13 changes: 7 additions & 6 deletions extensions/SecureMail/Extension.pm
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,9 @@ sub mailer_before_send {

if ($is_bugmail) {

# This is also a bit of a hack, but there's no header with the
# bug ID in. So we take the first number in the subject.
my ($bug_id) = ($email->header('Subject') =~ /\[\D+(\d+)\]/);
# The bug ID comes from its header: the subject can lead with a flag
# event, whose name can hold brackets and digits (bug 2097284).
my $bug_id = $email->header('X-Bugzilla-ID');
my $bug = new Bugzilla::Bug($bug_id);
if (!_should_secure_bug($bug)) {
$make_secure = SECURE_NONE;
Expand Down Expand Up @@ -442,7 +442,7 @@ sub _make_secure {
$email->header_set('X-Bugzilla-Secure-Email', 'Yes');

my $subject = $email->header('Subject');
my ($bug_id) = $subject =~ /\[\D+(\d+)\]/;
my $bug_id = $email->header('X-Bugzilla-ID');

my $key_type = 0;
if ($key && $key =~ /PUBLIC KEY/) {
Expand Down Expand Up @@ -583,9 +583,10 @@ sub _make_secure {
my $component = $email->header('X-Bugzilla-Component');

# Note: the $bug_id is required within the parentheses in order to keep
# Gmail's threading algorithm happy.
# Gmail's threading algorithm happy. The '[Bug N]' token is matched by
# the space before the ID, which a leading flag name can't hold.
$subject
=~ s/($bug_id\])\s+(.*)$/$1$new (Secure bug $bug_id in $product :: $component)/;
=~ s/(\[\D*\s$bug_id\])\s+(.*)$/$1$new (Secure bug $bug_id in $product :: $component)/;
{
# avoid excessive line wrapping done by Encode.
local $Encode::Encoding{'MIME-Q'}->{'bpl'} = 998;
Expand Down
9 changes: 5 additions & 4 deletions extensions/Splinter/lib/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,11 @@ sub add_review_links_to_email {
my $new_body = 0;
my $bug;

if ($email->header('Subject') =~ /^\[Bug\s+(\d+)\]/
&& Bugzilla->user->can_see_bug($1))
{
$bug = Bugzilla::Bug->new({id => $1, cache => 1});
# The bug ID comes from its header: the subject can lead with a flag
# event (bug 2097284).
my $bug_id = $email->header('X-Bugzilla-ID');
if ($bug_id && Bugzilla->user->can_see_bug($bug_id)) {
$bug = Bugzilla::Bug->new({id => $bug_id, cache => 1});
}

return unless defined $bug;
Expand Down
4 changes: 3 additions & 1 deletion extensions/TagNewUsers/Extension.pm
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,9 @@ sub mailer_before_send {
my ($self, $args) = @_;
my $email = $args->{email};

my ($bug_id) = ($email->header('Subject') =~ /^[^\d]+(\d+)/);
# The bug ID comes from its header: the subject can lead with a flag
# event, whose name can hold digits (bug 2097284).
my $bug_id = $email->header('X-Bugzilla-ID');
my $changer_login = $email->header('X-Bugzilla-Who');
my $changed_fields = $email->header('X-Bugzilla-Changed-Fields');

Expand Down
1 change: 1 addition & 0 deletions scripts/generate_bmo_data.pl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
my %user_prefs = (
post_bug_submit_action => 'nothing',
bugmail_new_prefix => 'on',
bugmail_flag_prefix => 'on',
comment_box_position => 'after_comments',
comment_sort_order => 'oldest_to_newest',
csv_colsepchar => ',',
Expand Down
156 changes: 156 additions & 0 deletions t/bmo/bugmail-flag-events.t
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use strict;
use warnings;
use lib qw(. lib local/lib/perl5);
use Test::More;
use Email::MIME;

use Bugzilla;
use Bugzilla::Constants;
Expand Down Expand Up @@ -269,6 +270,161 @@ foreach my $later_first (0, 1) {
is($mail->{bugmailtype}, 'changed request', 'an answer is marked as request mail');
}

# Bug 2097284: the subject leads with the recipient's own flag event.
{
# The Subject header of each recipient's mail, by login.
my $subjects = sub {
my ($bug, $changer) = @_;
my %subject;
no warnings 'redefine';
local *Bugzilla::BugMail::MessageToMTA = sub {
my ($email) = @_;
$subject{$email->header('To')} = $email->header('Subject') if ref $email;
};
Bugzilla::BugMail::Send($bug->id, {changer => $changer});
return \%subject;
};

my $bug = new_bug();
add_activity($bug, $next_flag_id++, '2000-01-01 00:00:10', '?', $requester,
$requestee);
my $subject = $subjects->($bug, $requester);
is(
$subject->{$requestee->email},
'flagmail-test requested: [Bug ' . $bug->id . '] Flag mail test',
'a request is named in the requestee subject'
);
like($subject->{$type_cc->email}, qr/^\[Bug \d+\]/,
'but not in the flag type cc_list subject');

foreach my $answer (['+', 'granted'], ['-', 'denied'], ['X', 'cleared']) {
my ($status, $word) = @$answer;
$bug = new_bug();
my $flag_id = $next_flag_id++;
add_activity($bug, $flag_id, '1999-12-31 23:00:00', '?', $requester,
$requestee);
add_activity($bug, $flag_id, '2000-01-01 00:00:10', $status, $requestee);
is(
$subjects->($bug, $requestee)->{$requester->email},
"flagmail-test $word: [Bug " . $bug->id . '] Flag mail test',
"an answer ($status) is named in the requester subject"
);
}

# The requestees above have the default 'on'; one who turned the
# bugmail_flag_prefix setting off gets the plain subject.
my $no_prefix = create_user('flagmail-noprefix@mozilla.example', '*');
$no_prefix->settings->{bugmail_flag_prefix}->set('off');
Bugzilla::User::Setting::clear_settings_cache($no_prefix->id);
$bug = new_bug();
add_activity($bug, $next_flag_id++, '2000-01-01 00:00:10', '?', $requester,
$no_prefix);
is(
$subjects->($bug, $requester)->{$no_prefix->email},
'[Bug ' . $bug->id . '] Flag mail test',
'a requestee who turned the setting off gets the plain subject'
);
}

# Bug 2097284: mailer_before_send hooks still find the bug when the subject
# leads with a flag event, here one whose name holds digits.
{
my $esr_type = flag_type('flagmail-esr140', 'b');
my $patcher = create_user('flagmail-patcher@mozilla.example', '*');
my $bug = new_bug();
add_activity($bug, $next_flag_id++, '2000-01-01 00:00:10',
'?', $patcher, $requestee, type_id => $esr_type);

my $mail;
{
no warnings 'redefine';
local *Bugzilla::BugMail::MessageToMTA = sub {
$mail = $_[0] if ref $_[0] && $_[0]->header('To') eq $requestee->email;
};
Bugzilla::BugMail::Send($bug->id, {changer => $patcher});
}
like(
$mail->header('Subject'),
qr/^flagmail-esr140 requested: \[Bug \d+\]/,
'the subject leads with a flag name holding digits'
);

# TagNewUsers marks the changer's first patch from the bug ID.
$dbh->do('UPDATE profiles SET first_patch_bug_id = ? WHERE userid = ?',
undef, $bug->id, $patcher->id);
Bugzilla->memcached->clear({table => 'profiles', id => $patcher->id});
$mail->header_set('X-Bugzilla-Changed-Fields' => 'attachments.created');
Bugzilla::Extension::TagNewUsers->mailer_before_send({email => $mail});
is($mail->header('X-Bugzilla-FirstPatch'),
$bug->id, 'TagNewUsers finds the bug, not the digits in the flag name');

# Splinter adds review links to a plain text mail with that subject.
my $text = Email::MIME->create(
header_str => [
Subject => $mail->header('Subject'),
'X-Bugzilla-ID' => $mail->header('X-Bugzilla-ID'),
],
attributes => {
content_type => 'text/plain',
charset => 'UTF-8',
encoding => 'quoted-printable',
},
body_str => "Review of attachment 5:\015\012\015\012Looks good.\015\012",
);
Bugzilla::Extension::Splinter::Util::add_review_links_to_email($text);
like(
$text->body_str,
qr/bug=@{[$bug->id]}&attachment=5/,
'Splinter adds the review link'
);
}

# Bug 2097284: SecureMail finds the bug from its header, not from a leading
# flag name holding brackets and digits, so a secure bug's mail is secured
# and its rewritten subject keeps the '[Bug N]' token.
{
my $reader = create_user('flagmail-securereader@mozilla.example', '*');
my $group = group_with('flagmail-securemail', $reader);
$dbh->do('UPDATE `groups` SET secure_mail = 1 WHERE id = ?', undef, $group->id);
Bugzilla->memcached->clear({table => 'groups', id => $group->id});

my $public = new_bug();
my $secure = new_bug();
$dbh->do('INSERT INTO bug_group_map (bug_id, group_id) VALUES (?, ?)',
undef, $secure->id, $group->id);
my $id = $secure->id;

# The flag name holds the public bug's ID, then the secure bug's own.
foreach my $flag_id ($public->id, $id) {
my $mail = Email::MIME->create(
header_str => [
To => $reader->email,
Subject => "flagmail[esr$flag_id] requested: [Bug $id] Flag mail test",
'X-Bugzilla-ID' => $id,
'X-Bugzilla-Status' => 'NEW',
'X-Bugzilla-Type' => 'changed',
'X-Bugzilla-Product' => 'Firefox',
'X-Bugzilla-Component' => 'General',
],
attributes => {
content_type => 'text/plain',
charset => 'UTF-8',
encoding => 'quoted-printable',
},
body_str => "Flag mail test\015\012",
);
Bugzilla::Extension::SecureMail->mailer_before_send({email => $mail});
is($mail->header('X-Bugzilla-Secure-Email'),
'Yes', "flag name holding bug $flag_id: the secure bug's mail is secured");
is(
$mail->header('Subject'),
"flagmail[esr$flag_id] requested: [Bug $id]"
. " (Secure bug $id in Firefox :: General)",
"flag name holding bug $flag_id: the subject keeps the bug token"
);
}
}

# Send: cancelling your own request doesn't mail you.
Comment thread
dklawren marked this conversation as resolved.
Resolved
{
my $bug = new_bug();
Expand Down
20 changes: 19 additions & 1 deletion template/en/default/email/bugmail-header.txt.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,28 @@
[% isnew = bug.lastdiffed ? 0 : 1 %]
[% show_new = isnew
&& (to_user.settings.bugmail_new_prefix.value == 'on') %]
[%# Bug 2097284: lead the subject with the recipient's own flag event, so a
# request from them or an answer to their request stands out. flag_events
# is already filtered per recipient; only 'requested' and 'answered' are
# about them (others are generic 'set' events). The first one wins. The
# recipient can turn this off with the bugmail_flag_prefix setting. %]
[% flag_prefix = '' %]
[% IF to_user.settings.bugmail_flag_prefix.value == 'on' %]
[% FOREACH event = flag_events %]
[% IF event.action == 'requested' %]
[% flag_prefix = "${event.type.name} requested: " %]
[% ELSIF event.action == 'answered' %]
[% status_word = event.status == '+' ? 'granted'
: event.status == '-' ? 'denied' : 'cleared' %]
[% flag_prefix = "${event.type.name} ${status_word}: " %]
[% END %]
[% LAST IF flag_prefix %]
[% END %]
[% END %]

From: [% Param('mailfrom') %]
To: [% to_user.email %]
Subject: [[% terms.Bug %] [%+ bug.id %]] [% 'New: ' IF show_new %][%+ bug.short_desc %]
Subject: [% flag_prefix %][[% terms.Bug %] [%+ bug.id %]] [% 'New: ' IF show_new %][%+ bug.short_desc %]
Comment thread
dklawren marked this conversation as resolved.
Resolved
Comment thread
dklawren marked this conversation as resolved.
Resolved
Date: [% date %]
X-Bugzilla-Reason: [% reasonsheader %]
X-Bugzilla-Type: [% bugmailtype %]
Expand Down
1 change: 1 addition & 0 deletions template/en/default/global/setting-descs.none.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"html" => "HTML",
"text_only" => "Text Only",
"bugmail_new_prefix" => "Add 'New:' to subject line of email sent when a new $terms.bug is filed",
"bugmail_flag_prefix" => "Add the flag request or answer (e.g. 'needinfo requested:') to the start of the subject line of email about flags requested of me or answered for me",
"possible_duplicates" => "Display possible duplicates when reporting a new $terms.bug",
"requestee_cc" => "Automatically add me to the CC list of $terms.bugs I am requested to review",
"api_key_only" => "Require API key authentication for API requests",
Expand Down