Repository navigation
Give every outgoing mail a Date, a Message-ID and an encoded subject - #420
Merged
abhishekgahlot2 merged 2 commits intoNov 5, 2026
Merged
abhishekgahlot2 merged 2 commits into
abhishekgahlot2 merged 2 commits into
Conversation
sendSmtp wrote a header block with no Date and no Message-ID, and put the subject and the From display name on the wire as raw text. That affects every mail UseAgent sends: invitations, sign-up confirmations and the email connector's run digests. - RFC 5322 requires Date, and every message should carry a Message-ID. Relays often add neither for a client that connects over the network, spam filters score their absence, and some providers refuse a message without a Message-ID. - Invitation subjects repeat the names people typed, and digest subjects repeat the prompt and end in an ellipsis. Raw UTF-8 in a header says nothing about its charset, so clients and relays that do not assume UTF-8 show the names garbled. - The connector's generic sendMessage uses the whole first line of the content as the subject. A line over 998 characters breaks the header line limit, and a bare carriage return in it reached the wire. Every message now has a Date in RFC 5322 form (UTC, "+0000") and a random Message-ID under the sender's domain. Subject and display name text that is not printable ASCII, contains "=?", or is longer than one header line comfortably holds is sent as RFC 2047 encoded words of UTF-8. Each word holds at most 45 bytes, so it stays within 75 characters. Words are cut on character boundaries and folded onto continuation lines. Plain ASCII subjects and names go out as before. New cases in test/smtp-message.test.ts read the captured DATA section of a real SMTP dialog. They decode the encoded words with a decoder in the test itself and check the Date, the Message-ID, the line limit and the carriage return. The four cases for new behaviour fail without the change. Fixes useagenthq#418
Contributor
Author
|
The one |
# Conflicts: # backend/test/smtp-message.test.ts
Contributor
|
Merged, thanks @officialasishkumar. Encoding the subject also closes a header injection through a carriage return, which the new test pins down. I merged main into the branch to resolve the test-file conflict with #419. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
By opening this pull request you agree to the Contributor License Agreement. On your first pull request a bot asks you to sign it with a one-line comment.
Fixes #418
Every mail UseAgent sends goes through
sendSmtp: invitations, sign-up confirmations and email connector run digests. Its header block had noDateand noMessage-ID. It also put the subject and theFromdisplay name on the wire as raw text. Invitation subjects repeat the names people typed, and digest subjects repeat the prompt and end in…. Raw UTF-8 headers do not name their charset, so some clients show those names garbled. A subject fromEmailTransport.sendMessageis the whole first line of the content, with no length cap, so it could pass the 998-character header line limit and carry a bare\r.What changed
All changes are in
backend/src/connectors/email/smtp.ts:Date:in RFC 5322 form (UTC,+0000) andMessage-ID: <random uuid@sender's domain>on every message. If the sender address has no usable domain, the Message-ID useslocalhost.encodeHeaderText: plain printable ASCII up to 900 characters goes out as typed, so existing ASCII subjects and the"UseAgent"display name are unchanged on the wire. Other text becomes RFC 2047=?UTF-8?B?...?=words. That covers non-ASCII text, control characters, text containing=?, and longer text. Each word holds at most 45 bytes, so it stays within 75 characters. Words are cut on character boundaries and folded onto continuation lines.fromHeaderquotes an ASCII display name as before and encodes any other name.Tests
New cases in
backend/test/smtp-message.test.ts. Each one captures the DATA section of a real SMTP dialog over a local socket and decodes it with a small decoder defined in the test:Datematches RFC 5322 form and falls between the start and end of the send.Message-IDis a uuid under the sender's domain and differs between two sends.\rcannot start a header of its own.The four cases for new behaviour fail on
main. I also parsed captured messages with Python'semailpackage (policy.default). The subject and display name decode exactly,Dateparses, and the parser reports no defects.Checks, run with Bun 1.3.14 against
pgvector/pgvector:0.8.6-pg16-bookworm:cd backend && bunx -p typescript@5.9.3 tsc --noEmit: passesbun test test/smtp-message.test.ts test/smtp-timeout.test.ts src/connectorsplus the invitation and connector tests: 52 pass, 0 failThis touches the same file as #419, but different lines. Either can merge first.
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.