[5.2] Bug 1837680: Add Message-ID header when missing at send by mrenvoize · Pull Request #205 · bugzilla/bugzilla · GitHub
Skip to content

[5.2] Bug 1837680: Add Message-ID header when missing at send#205

Open
mrenvoize wants to merge 4 commits into
bugzilla:5.2from
mrenvoize:bug_1837680
Open

[5.2] Bug 1837680: Add Message-ID header when missing at send#205
mrenvoize wants to merge 4 commits into
bugzilla:5.2from
mrenvoize:bug_1837680

Conversation

@mrenvoize

Copy link
Copy Markdown
Contributor

Details

Detect whether a Message-ID header has been included in the message passed to MessageToMTA and generate one if it's missing.

GMail and other modern mail services now expect a Message-ID as part of the message else they mark them as spam or drop them entirely.

Additional info

@mrenvoize

Copy link
Copy Markdown
Contributor Author

@justdave justdave self-requested a review June 21, 2026 03:05

@justdave justdave left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issues mentioned here apply to the Harmony PR as well (bugzilla/harmony#146)

Comment thread Bugzilla/Mailer.pm Outdated
Comment on lines +239 to +240
$sitespec =~ s/:\/\//\./; # Make the protocol look like part of the domain
$sitespec =~ s/^([^:\/]+):(\d+)/$1/; # Remove a port number, to relocate

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not appear to adequately sanitize the potential values of urlbase, since it might contain a path after the domain name and / is also an illegal character after the @ in the message ID.

for example, if urlbase = https://bugs.example.org/bugzilla/ then after these regexps, sitespec becomes roughly @https.bugs.example.org/bugzilla/

This is apparently an issue in the existing build_thread_marker that you probably copied this logic from, so would need to be dealt with in both places. Since the whole point of this bug is fixing acceptance and places that are strict about Message-IDs, that probably should be included in this patch.

Comment thread Bugzilla/Mailer.pm Outdated
Comment on lines +234 to +236
if (!defined $user_id) {
$user_id = Bugzilla->user->id;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are several places this MessageToMTA gets called from where there will be no user, and there's also a few places where the mail being sent may be irrelevant to the current logged in user. It might be safer to leave this blank or use a static string instead if it's not passed in, to avoid tagging a user to something they weren't responsible for. The random string added later should take care of it still being unique.

Comment thread Bugzilla/Mailer.pm Outdated
Comment on lines +241 to +242

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My syntax checker is warning me that $2 may contain values from a previous regexp match attempt if this one fails to match anything, since Perl doesn't clear them in between. It's suggesting the code should check if the regexp succeeded or not before depending on a match position variable to work.

mrenvoize and others added 3 commits June 22, 2026 22:29
Detect whether a Message-ID header has been included in the message
passed to MessageToMTA and generate one if it's missing.

GMail and other modern mail services now expect a Message-ID as part of
the message else they mark them as spam or drop them entirely.
- Strip path components from urlbase when building sitespec, as '/' is
  illegal after '@' in a Message-ID (affects both build_thread_marker
  and build_message_id)
- Fix stale $2 capture variable risk by conditioning port relocation on
  the substitution succeeding, in both functions
- Avoid falling back to Bugzilla->user->id in build_message_id, which
  is called from contexts with no logged-in user; random bits ensure
  uniqueness without a user identifier
- Omit the user_id segment entirely when absent to avoid a double-dash
  in the Message-ID local-part
Test the sitespec transformation for four urlbase forms (plain, with
path, with port, with port+path) to guard against regressions in the
'/' stripping and port relocation logic. Also covers user_id handling
in build_message_id (present, absent, no double-dash).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants