oliver-zehentleitner / maity
clean-up: Mail and notifications: mail texts in the human's language, the old-address notice, stale context entries, shared mail builders
tsk-y5hkg2ztvwq9 Done An agent
From the clean-up audit tsk-hgnbapyw7hnh, area 12 (Mail and notifications). Read at 80647565; all line numbers are from that commit. Finding numbers are the audit's (seqs 125423 and 125453). (Code names are written without backticks: the inline body cannot carry them.)
Order: do this after tsk-dv8f620hjebf and tsk-e2m6krwdk5rg. Both change notifications/mailer.py (subjects, defanging), and item 13 reshapes the same builders.
9. design / docs drift: the address-verification mail and the old-address notice are hard-coded English, while every other mail to a known human goes through the catalog
- Files:
- notifications/preferences.py:642-654 (apply_address: "[Maity] Confirm your address", English body);
- preferences.py:842-877 (_tell_old_address: English subject and body, with "a browser" and "an unknown system" literals).
Compare mailer.py:563-593, which uses catalog.section("mail"/"notify", text_language) for the same kind of security mail.
- Contradicts hub/context/notifications.md 5fa1d7c2 ("Mails, link pages, bell titles ... all go this way", meaning text_language plus catalog) and f1bba221 (the hub's own texts follow the human's language). The human is known in both cases, unlike registration and invitation mail (mail.md 158a003c records why those are English).
- Proposal: move both texts into words/<lang>.json under mail and compose them with preferences.text_language(conn, human_id), as _password_reset_mail does.
- Effort: S. Risk: low. The texts are only moved; regenerate the words meta with make -C web fixtures.
10. docs drift (or bug): the notice to the old address after a verified change carries no browser, OS or IP, though the contract says it does
- Files: notifications/preferences.py:729-734. verify calls _tell_old_address(..., None, public_url) with session=None. _tell_old_address (842-877) adds the "From: <browser> on <os>, <ip>" line only when a session is given (859-863). Only removal (apply_address, 612-613) passes one.
- Contract: docs/api.md:23188-23193 (§18.4: "When the new address is verified ... from which browser, operating system and IP address") and docs/api.md:1759-1764 (§2.6.3).
- What's wrong: the common case, a change confirmed by its link, sends the notice without the "where" that the contract promises.
- Open question (needs a decision): either
- (a) store the requesting session's browser, OS and IP with the pending address at apply_address (beside pending_nonce) and use them at verify, as registration_mail.py:90-97 does from its pending row; or
- (b) change §2.6.3 and §18.4 to give the "where" on removal only.
- Effort: S for (b), M for (a) (columns plus a migration). Risk: low.
11. docs drift: two hub/context/notifications.md entries describe code that no longer exists
- f1bba221 (hub/context/notifications.md:835-864) still says the titles are in email.language, "en or de", through "Scope.say, items.WORDS".
- items.WORDS is gone.
- The language is preferences.text_language (preferences.py:179-184) over the catalog's languages (items.py:80-81), as 5fa1d7c2 (lines 6-34) records.
- The stray comment at items.py:38 ("# The texts the hub itself composes for a human ...") is a leftover of items.WORDS; remove it.
- e29065f2 (lines 36-74, Status needs-review) still says "Counts, filters, the cursor and positions all work on that list in Python" and "The only stored state is the read marks".
- The bell now reads derive_page, count_items and pinned (items.py:193, 486, 516) and notification_recipient (items.py:357-378).
- Only the mailer (mailer.py:185) and routes/notifications.py:357 still call the full derive.
- Proposal: mark f1bba221 superseded by 5fa1d7c2. Settle e29065f2 by rewriting its body to the current split, or supersede it by the entries at lines 466, 544 and 1183.
- Effort: S. Risk: none.
13. duplication: the four mail builders in the notification mailer repeat the footer, the account-record read and the unsubscribe headers
- Files: notifications/mailer.py:399-432 (_send), 492-530 (_sign_in_mail), 533-560 (_two_factor_mail), 563-593 (_password_reset_mail).
- Each repeats:
- words = catalog.section("mail", ...);
- the settings/only footer lines;
- the select(t.account_record).where(n == item.record).one() read, with the same %Y-%m-%d %H:%M %Z formatting;
- (twice) the List-Unsubscribe / List-Unsubscribe-Post pair.
- Proposal: helpers _footer(words, public_url, unsubscribe=None), _record(conn, item) and _unsubscribe_headers(link).
- Effort: S. Risk: low (tests compare the bodies).
Left out as duplicates: none. tsk-e2m6krwdk5rg defangs notification subjects and tsk-dv8f620hjebf cleans header values; neither covers these items, but they touch the same files (see Order). Searched: defang, old address, _tell_old_address, text_language, notifications/preferences.py, items.py.