From d2f99f46c6b10cc9e6694b0a08d91971a508d320 Mon Sep 17 00:00:00 2001 From: David Lawrence Date: Tue, 24 Nov 2026 12:01:42 -0500 Subject: [PATCH 1/5] Bug 2097284 - Add a flag identifier to the subject line of emails where you are being requested for something such as needinfo, etc. --- t/bmo/bugmail-flag-events.t | 42 +++++++++++++++++++ .../en/default/email/bugmail-header.txt.tmpl | 17 +++++++- 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/t/bmo/bugmail-flag-events.t b/t/bmo/bugmail-flag-events.t index abfd5907a1..f70f8e0c7e 100644 --- a/t/bmo/bugmail-flag-events.t +++ b/t/bmo/bugmail-flag-events.t @@ -269,6 +269,48 @@ 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" + ); + } +} + # Send: cancelling your own request doesn't mail you. { my $bug = new_bug(); diff --git a/template/en/default/email/bugmail-header.txt.tmpl b/template/en/default/email/bugmail-header.txt.tmpl index db292acb7a..25c05f6baf 100644 --- a/template/en/default/email/bugmail-header.txt.tmpl +++ b/template/en/default/email/bugmail-header.txt.tmpl @@ -25,10 +25,25 @@ [% 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. %] +[% flag_prefix = '' %] +[% 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 %] 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 %] Date: [% date %] X-Bugzilla-Reason: [% reasonsheader %] X-Bugzilla-Type: [% bugmailtype %] From 4599e45afedf8e1ea0b7e4f16900fc8884869b12 Mon Sep 17 00:00:00 2001 From: David Lawrence Date: Tue, 24 Nov 2026 12:32:06 -0500 Subject: [PATCH 2/5] Copilot review fixes --- extensions/Splinter/lib/Util.pm | 9 ++--- extensions/TagNewUsers/Extension.pm | 4 ++- t/bmo/bugmail-flag-events.t | 54 +++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 5 deletions(-) diff --git a/extensions/Splinter/lib/Util.pm b/extensions/Splinter/lib/Util.pm index c3f7d51207..0deb1e9ecb 100644 --- a/extensions/Splinter/lib/Util.pm +++ b/extensions/Splinter/lib/Util.pm @@ -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; diff --git a/extensions/TagNewUsers/Extension.pm b/extensions/TagNewUsers/Extension.pm index ba8f294469..edd5304aef 100644 --- a/extensions/TagNewUsers/Extension.pm +++ b/extensions/TagNewUsers/Extension.pm @@ -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'); diff --git a/t/bmo/bugmail-flag-events.t b/t/bmo/bugmail-flag-events.t index f70f8e0c7e..d6f3dcfa3d 100644 --- a/t/bmo/bugmail-flag-events.t +++ b/t/bmo/bugmail-flag-events.t @@ -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; @@ -311,6 +312,59 @@ foreach my $later_first (0, 1) { } } +# 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' + ); +} + # Send: cancelling your own request doesn't mail you. { my $bug = new_bug(); From 107a17ab39f5b9f0de6a47688d8226bebfb2306d Mon Sep 17 00:00:00 2001 From: David Lawrence Date: Tue, 24 Nov 2026 13:24:03 -0500 Subject: [PATCH 3/5] Copilot review fixes --- extensions/SecureMail/Extension.pm | 13 +++++---- t/bmo/bugmail-flag-events.t | 45 ++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/extensions/SecureMail/Extension.pm b/extensions/SecureMail/Extension.pm index 35bd4c6397..e63d6ad311 100644 --- a/extensions/SecureMail/Extension.pm +++ b/extensions/SecureMail/Extension.pm @@ -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; @@ -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/) { @@ -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; diff --git a/t/bmo/bugmail-flag-events.t b/t/bmo/bugmail-flag-events.t index d6f3dcfa3d..57be860eff 100644 --- a/t/bmo/bugmail-flag-events.t +++ b/t/bmo/bugmail-flag-events.t @@ -365,6 +365,51 @@ foreach my $later_first (0, 1) { ); } +# 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. { my $bug = new_bug(); From 3e1e77b7656b45fbffc32a9e59ff839a29e817b5 Mon Sep 17 00:00:00 2001 From: David Lawrence Date: Wed, 25 Nov 2026 15:27:43 -0500 Subject: [PATCH 4/5] Added user preference to enable/disable the flag subject prefix --- Bugzilla/Install.pm | 8 +++++++ scripts/generate_bmo_data.pl | 1 + t/bmo/bugmail-flag-events.t | 14 +++++++++++++ .../en/default/email/bugmail-header.txt.tmpl | 21 +++++++++++-------- .../en/default/global/setting-descs.none.tmpl | 1 + 5 files changed, 36 insertions(+), 9 deletions(-) diff --git a/Bugzilla/Install.pm b/Bugzilla/Install.pm index 534a502b2f..fe851509a9 100644 --- a/Bugzilla/Install.pm +++ b/Bugzilla/Install.pm @@ -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 => 'on', + category => 'Email Notifications' + }, + # 2013-07-26 joshi_sunil@in.com -- Bug 669535 { name => 'possible_duplicates', diff --git a/scripts/generate_bmo_data.pl b/scripts/generate_bmo_data.pl index 269a3f1501..b69c671f42 100755 --- a/scripts/generate_bmo_data.pl +++ b/scripts/generate_bmo_data.pl @@ -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 => ',', diff --git a/t/bmo/bugmail-flag-events.t b/t/bmo/bugmail-flag-events.t index 57be860eff..322bf03e0b 100644 --- a/t/bmo/bugmail-flag-events.t +++ b/t/bmo/bugmail-flag-events.t @@ -310,6 +310,20 @@ foreach my $later_first (0, 1) { "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 diff --git a/template/en/default/email/bugmail-header.txt.tmpl b/template/en/default/email/bugmail-header.txt.tmpl index 25c05f6baf..9310d1267c 100644 --- a/template/en/default/email/bugmail-header.txt.tmpl +++ b/template/en/default/email/bugmail-header.txt.tmpl @@ -28,17 +28,20 @@ [%# 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. %] + # 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 = '' %] -[% 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}: " %] +[% 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 %] - [% LAST IF flag_prefix %] [% END %] From: [% Param('mailfrom') %] diff --git a/template/en/default/global/setting-descs.none.tmpl b/template/en/default/global/setting-descs.none.tmpl index 6cbee0b835..7f09a255c4 100644 --- a/template/en/default/global/setting-descs.none.tmpl +++ b/template/en/default/global/setting-descs.none.tmpl @@ -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", From 6d4074d596d8722987f807dd1930cb1c9702abf3 Mon Sep 17 00:00:00 2001 From: David Lawrence Date: Wed, 25 Nov 2026 21:40:40 -0500 Subject: [PATCH 5/5] Review fixes --- Bugzilla/Install.pm | 2 +- t/bmo/bugmail-flag-events.t | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Bugzilla/Install.pm b/Bugzilla/Install.pm index fe851509a9..15b65fb3fe 100644 --- a/Bugzilla/Install.pm +++ b/Bugzilla/Install.pm @@ -177,7 +177,7 @@ sub SETTINGS { { name => 'bugmail_flag_prefix', options => ['on', 'off'], - default => 'on', + default => 'off', category => 'Email Notifications' }, diff --git a/t/bmo/bugmail-flag-events.t b/t/bmo/bugmail-flag-events.t index 322bf03e0b..ba310a22be 100644 --- a/t/bmo/bugmail-flag-events.t +++ b/t/bmo/bugmail-flag-events.t @@ -424,6 +424,7 @@ foreach my $later_first (0, 1) { ); } } + # Send: cancelling your own request doesn't mail you. { my $bug = new_bug();