@divine/uri-smtp-protocol
v2.0.0-v2.1
Published
Adds support for mailto/smtp/smtps/lmtp to @divine/uri
Readme
SMTP protocol
This module provides SMTP, SMTPS and LMTP transport through URI.append(), using
a bundle of Nodemailer's SMTP connection code and WSF's MIME serializers.
Compliance and interoperability assessment
Assessment date: 2026-12-02.
Status: not fully RFC-compliant or broadly interoperability-tested. The strongest supported path is conventional mail through a configured relay, with ASCII envelope addresses, correctly labeled MIME bodies, and safe transfer encodings. The findings below are a backlog, not changes already implemented.
Evidence and limits
- Existing targeted tests passed: 5 SMTP, 23 headers and 21 MIME/form tests.
- Twelve temporary loopback SMTP scenarios captured envelope commands and DATA. Python's standard-library email parser independently decoded the messages. A separate probe checked RFC 2231 filename continuations.
- The SMTP fixture deliberately accepted messages. Its
250replies establish what this implementation sent, not acceptance by a real mail server. - The temporary probes were not retained as regression tests. The permanent SMTP tests cover input and transfer-encoding rejection, not successful delivery.
- This assessment did not exercise live Gmail, Outlook/Exchange, Apple Mail or Thunderbird, or live TLS, authentication and LMTP interoperability.
Observed working paths:
- ASCII message delivery, envelope recipients, Bcc removal and dot-stuffing.
- Q-encoded international subjects decoded correctly.
- UTF-8 text with
Content-Type: text/plain; charset=utf-8decoded correctly. - Multipart text and binary attachment bytes survived correctly; attachment names have separate limitations below.
- For
message/global, an SMTPUTF8-capable fixture receivedMAIL FROM:<[email protected]> SMTPUTF8. Without that capability, sending failed beforeMAIL FROM.
Confirmed findings and follow-up work
1. Incomplete SMTPUTF8 enforcement
Priority: high.
The explicit capability check in SMTPURI.append only
applies when sendCT.type === 'message/global'. Nodemailer's envelope handling
adds SMTPUTF8 for non-ASCII addresses when the server supports it, but does not
reject such addresses when the extension is absent.
Observed cases against a fixture that did not advertise SMTPUTF8:
| Input | Observed wire behavior |
| --- | --- |
| message/global with a non-ASCII subject | Rejected before MAIL FROM; expected behavior. |
| message/rfc822, envelope sender "\[email protected]" (JavaScript notation) | Sent MAIL FROM containing the UTF-8 address without SMTPUTF8. |
| ASCII envelope, headers: { 'reply-to': '\[email protected]' } | Sent raw UTF-8 in the message headers without requesting SMTPUTF8. |
RFC 6531 section 3.2 prohibits sending internationalized addresses or headers to a server that does not offer SMTPUTF8. Section 3.4 requires the MAIL parameter when the envelope or message needs the extension.
Successful encoding of international display names and subjects is not the same as complete support for internationalized email addresses.
- [ ] Define and enforce the supported internationalized-message contract,
covering envelope addresses and header-only addresses as well as
message/global. - [ ] Retain regression cases for capability present/absent, ASCII envelopes with internationalized headers, and no duplicate SMTPUTF8 parameter.
2. Headers can exceed the hard line-length limit
Priority: high.
Input headers: { subject: 'x'.repeat(1100) } produced a physical line of
1,101 bytes, excluding CRLF.
In MessageParser._encodeHeader, folding searches for whitespace. If there is no suitable split, it can leave an oversized token on the line. This is different from merely exceeding the recommended display width.
RFC 5322 section 2.1.1 sets a hard limit of 998 characters and a recommendation of 78, excluding CRLF. For internationalized headers, RFC 6532 section 3.4 expresses the hard limit in octets. Overlong output is a rejection/truncation risk.
- [ ] Ensure generated header lines never exceed the hard limit. Use a valid, semantics-preserving representation or reject a value that cannot be folded; do not insert arbitrary whitespace into structured tokens.
- [ ] Test an unbroken subject and a long structured parameter, including the continuation-line whitespace in the byte count.
3. Generated Date headers use obsolete syntax
Priority: small compliance correction; low interoperability risk.
SMTPURI.append defaults the date with
new Date().toUTCString(). Captured messages consequently used the zone GMT.
RFC 5322 section 4
requires receivers to accept obsolete syntax but prohibits conforming generators
from producing it. GMT is an
obsolete zone;
a numeric zone such as +0000 is appropriate.
- [ ] Generate a modern date with a numeric zone.
- [ ] Check the generated header while preserving an explicitly supplied date.
4. Text newlines are not canonicalized before base64 encoding
Priority: MIME correctness.
For headers: { 'content-type': 'text/plain; charset=utf-8' } and
value: 'one\ntwo', the message used base64, but decoding its payload recovered
the bare LF rather than CRLF.
The path is StringParser.serialize, which encodes the string's bytes, followed by MessageParser.serialize and Base64Encoder. SMTP-level newline normalization happens too late to repair line breaks already inside the encoded payload.
RFC 2045 section 6.8 requires text line breaks to be converted to CRLF before base64 encoding.
- [ ] Canonicalize MIME text in the appropriate email serialization path, without altering binary attachments or unrelated HTTP serialization.
- [ ] Test LF and existing CRLF text, plus byte preservation for binary data.
5. Attachment-name support needs interoperability work
Priority: shared MIME/header compatibility.
There are two distinct findings in ContentHeader / ContentDisposition:
Receiving-side continuation support is incomplete. Parsing the valid header below did not reconstruct
ContentDisposition.filename; it wasundefinedinstead of"r\u00e4kor.bin":attachment; filename*0*=utf-8''r%C3%A4; filename*1*=kor.binRFC 2231 section 3 defines ordered parameter continuations, including their combination with charset encoding in section 4.1.
Outgoing fallback selection differs between parsers. For the filename
"r\u00e4kor.bin", serialization emitted:content-disposition: attachment;filename=r_kor.bin;filename*=utf-8''r%C3%A4kor.binPython's email parser selected
r_kor.bin. Attachment bytes were intact. This demonstrates a compatibility difference, not that every mail client mishandles the extended parameter or that this output is necessarily invalid.
- [ ] Support and test RFC 2231 continuations in the shared header parser.
- [ ] Check non-ASCII and long attachment names in actual mail clients before choosing an outgoing compatibility strategy. Preserve existing HTTP behavior.
Deliberate limitations and caller responsibilities
These are not requests to reintroduce previously rejected features.
Transfer encodings
Raw 8BITMIME support remains out of scope. The SMTP wrapper rejects top-level
8bit and binary transfer encodings, but does not recursively validate parts.
Both of these probes sent high-bit body bytes without negotiating 8BITMIME:
- A
multipart/mixedbody containing a UTF-8 text part explicitly marked8bit. - A UTF-8 body explicitly, incorrectly marked
7bit.
The latter contradicts RFC 2045 section 6.2. The automatic base64 default is useful, but explicit declarations are trusted; the current check is not a guarantee of 7-bit-safe output. Any future validation or broader transport support needs a separate scope decision.
Input shapes
For message/*, input must be a structured object containing headers or
value. The shape guard prevents obvious malformed inputs from silently
becoming empty messages; it is not full RFC validation.
Raw message strings and Buffers are intentionally unsupported. Ordinary string
bodies with a non-message type such as text/plain remain supported.
Plain string bodies can be serialized as text/plain;charset=utf-8 without an
explicit Content-Type header. If a body contains text supplied as a Buffer or
byte stream, declare its media type and charset; the serializer does not infer
the encoding of those bytes.
Real-world validation backlog
- [ ] Turn the important loopback scenarios above into permanent tests, including strict server rejection paths rather than unconditional acceptance.
- [ ] Exercise authenticated submission, STARTTLS required/optional behavior, implicit TLS, certificate/SNI handling, IPv6 and LMTP with real servers.
- [ ] Verify ordinary mail, Unicode headers/bodies and attachment names in Gmail, Outlook/Exchange, Apple Mail and Thunderbird.
- [ ] Exercise SMTPUTF8 across downstream relays, not just the first accepting hop.
- [ ] Investigate internationalized hostname/SNI handling; it was not validated by this assessment.
Postfix's SMTPUTF8 documentation describes tolerance for some undeclared UTF-8. Successful delivery through a permissive server can therefore conceal standards violations.
Deliverability additionally depends on relay configuration, DNS, authentication and provider policy. For example, Gmail's sender requirements include domain authentication, DNS and TLS requirements. These are deployment concerns, not all responsibilities of this library. Plain SMTP remains an intentional library capability.
Other previously identified API follow-ups, separate from RFC compliance:
SMTPResponseis not connected to the generic return type ofappend().- The
subjectURI query parameter is not applied tomessage/*objects.
Re-running the existing tests
From the repository root, run each command in its own shell:
make -C modules/uri-smtp-protocol build && cd modules/uri-smtp-protocol && pnpm exec jest --runInBand --coverage=falsemake -C modules/headers build && cd modules/headers && pnpm exec jest --runInBand --coverage=falsemake -C modules/uri build && cd modules/uri && pnpm exec jest --runInBand --coverage=false test/parsers/formsThese passing suites are a baseline, not a complete conformance suite. Update the evidence, status and checklists above as fixes and interoperability tests land.
