Repository navigation
feat(providers): add one-click List-Unsubscribe to mail messages - #61
Merged
Merged
Conversation
MailMessage.list_unsubscribe emits List-Unsubscribe and List-Unsubscribe-Post (RFC 8058). The SMTP email policy folds a long token-only header value into RFC 2047 encoded-words, which a mailbox provider cannot read as a URL, so List-Unsubscribe is written by a header class of its own that never folds, and the URL is capped so the line fits in 998 characters. Raising the whole policy's line length instead would break RFC 2045 (base64/quoted-printable body lines) and RFC 2047 (encoded-word length) limits. Closes #56 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 29 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
7 of 13 tasks
# Conflicts: # CHANGELOG.md # docs/providers-and-backends.md # jasil/providers.py # tests/test_mail.py
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What does this PR do?
Adds
MailMessage.list_unsubscribe: str | None = None. When set,build_mimeemits:This is the RFC 8058 one-click unsubscribe that Gmail and Yahoo require of bulk senders.
httpsURL with a host, printable ASCII, no spaces,<,>or,, at most 978 characters. Anything else is aValueErrorthat does not echo the value.policy.SMTPwraps at 78 characters, and a long value with no spaces is turned into RFC 2047 encoded-words (=?utf-8?q?=3Chttps=3A//...?=), which a mailbox provider cannot read as a URL.List-Unsubscribetherefore uses a small header class (_VerbatimHeader) registered on aHeaderRegistryof JASIL's own. Every other header folds exactly as before.List-Unsubscribe: <url>fit in RFC 5322's 998-character line limit (MAX_UNSUBSCRIBE_URL_LENGTH, computed from that).Additive: a new
MailMessagefield with a default.Related issue
Closes #56
Type of change
Checklist
Notes for the reviewer
max_line_lengthon the whole MIME policy to 998. I tested it: base64 body lines became 996 characters (RFC 2045 allows 76), and a non-ASCII subject became a 988-character encoded-word (RFC 2047 allows 75). It would make normal mail non-compliant.HeaderRegistry: the default one is a class attribute shared by everyEmailPolicyin the process, so_VerbatimHeaderis registered on a separate instance and the host's own email parsing is unaffected.mailto:is out of scope.MailMessage/__hash__and with the others inCHANGELOG.md. I'll rebase as they merge.Checks run: ruff, ruff format, lint-imports, mypy, pytest (3662 passed, 139 skipped, 97.80% coverage),
check_module_coverage.py,check_docs_api.py.🤖 Generated with Claude Code