https://gitlab.synchro.net/main/sbbs/-/commit/fe1c34ff9936852ee1052dd3
Added Files:
exec/tests/inet_domains/config/webmail_send.js webmail_send_child.inc exec/tests/webmail/address.js api_body.js api_drafts.js api_settings.js api_write.js contacts.js drafts.js mimewrite.js send.inc send.js send_recovery.js webmail/lib/address.js contacts.js drafts.js mimewrite.js send.js
Modified Files:
ctrl/modopts/webmail.ini exec/tests/webmail/api.js config.js download.js kit.js session.js shell.js strings.js userdata.js webmail/lib/api.js config.js download.js webmail/lib/locale/en_us.ini webmail/lib/session.js shell.js userdata.js webmail/root/api.ssjs
Log Message:
Web mail client: server side of acting on mail, writing and sending
The API (webmail/lib/api.js, root/api.ssjs) gains the calls that change
mail and the libraries behind writing and sending a message.
Acting on mail, each a thin call of the mailbox library's Store with
per-id results ({id, ok, new_id} or {id, error}) and the state token
after the write:
- message.set {ids, read, starred, spam} (at most 200 ids),
message.move, message.delete and message.undelete (at most 50),
trash.empty, folder.create, folder.rename, folder.delete (a refused
name comes back with the Store's reason), and message.original.
- folder.list reports the Inbox's age limit and the number of drafts.
message.get computes the sender's avatar only when asked.
A page acts only as its user: a request carries "as", the user number
the page was started for. When someone else has signed in since, the
whole request is refused ("stale") before any call runs. A signed-in
request holding a write must carry "as", and a request the client
makes on its own (background: true) cannot change mail.
The session cookie is SameSite=Lax, not Strict: with Strict, Safari on
iOS left the cookie out of a reload of the page one second after an
API request that carried it, so a signed-in user had to sign in again.
Requests another site makes from its own page still come without it.
Addresses (address.js): parse_list() reads a To, CC or BCC field and
refuses, naming the entry, control and bidirectional characters,
invalid UTF-8, unbalanced quoting, group syntax, source routes and
over-long input. resolve() classifies a recipient: a local user as the terminal's mail command finds one; an address at one of the system's
own domains only for a plain alias or name match (anything alias.cfg
or the mail server's own rules would treat differently stays Internet
mail); FidoNet as zone:net/node[.point]; QWK as name@QWKID when the
system has a route; an Internet domain must be a plain host name.
clean(), format() and identity() make names safe for a header and give
the sender name as the terminal writes it. The From domains a user may
use come from system.inet_domain_list and User.can_send_from_domain().
Drafts (drafts.js): each draft is a directory with a server-chosen
name under the user's web mail directory, holding draft.json and one
file per attachment. Every operation runs under one per-user lock.
save() carries a revision, so a second window cannot silently
overwrite the first. Attachments arrive in base64 pieces whose offset
must match the bytes received; a repeated last piece is acknowledged
without appending. A reply's recipients come from the Store's
structured lists; a forward copies the source's attachments all or
nothing. Stale uploads, empty drafts and leftovers go after 24 hours.
Sending (send.js, mimewrite.js): MimeWrite builds one text/plain UTF-8
part, or multipart/mixed with each attachment base64-encoded in
pieces, never held whole. Send.send() makes every check first
(recipients, the terminal's sending rules via User.can_send_mail(),
netmail cost against credits, the From domain, the limits), then the
Sent copy, then one save per kind of recipient, then the finish
(credits, counters, replied, the draft removed).
- A send claims its draft by renaming it and keeps a record with the
claim, written before each phase, with an owner token and a
heartbeat. Each send has its own random Message-ID, by which its
copies are found again.
- Once delivery has begun a message is never sent again as a whole:
recovery saves copies only for the recipients that have none, and
when that cannot be told the draft comes back marked "may have been
sent" and goes out again only after the user confirms.
- A failed delivery rolls back only when every copy could be recalled;
each recall is recorded so a recalled recipient is served again.
- A client key makes a repeated send return the recorded outcome.
- A claim with no heartbeat for 600 s is completed or given back by
the next draft.list or folder.list that is not a background request
(at most two per request); a claim that saved nothing comes back by
itself after an hour.
- A send adds its recipients to the sender's contacts by default.
- Parallel sends can exceed the daily limit and the credits by the
number of sends at once; send.js says why.
Contacts (contacts.js): the user's address book, at most 500 contacts
of 1 to 10 addresses, with suggestions that only ever read the user's
own book.
Settings (settings.get/set): display name, From domain, theme, the
senders whose images are always shown, the mail signature, and the
user's existing mail forwarding, written as the terminal writes it
with the terminal's address checks. Every argument is checked before
anything is written.
Request bodies: 256 KB, more only for a request of exactly one
draft.attach or draft.save call, never above the web server's 4 MiB;
api.ssjs applies the size, method, header, HTTPS and sign-in gates
before such a body is parsed.
Settings in ctrl/modopts/webmail.ini: max_body_bytes, max_recipients
(50), max_message_bytes (20 MB, the mail server's default MaxMsgSize), max_attachment_bytes (by default the largest file that fits a
message). The default poll_interval is half the web server's idle
limit (server.max_inactivity), between 15 and 60 seconds, so an open
page's check does not arrive just as its connection is closed.
Fewer file operations per request, for data and exec directories on a
network mount: libraries load on first use, one User object per
request, the drafts lock rewrites no file. Counted with strace on a
scratch web server: the check for new mail 367 before, 200 after;
folder.list 549, 406; message.get 848, 339; a send to a local user
1,823, 1,530.
Tests in exec/tests/webmail (21 files) use scratch bases and
directories; inet_domains/config/webmail_send.js sends with a real
User and domain list in a scratch configuration. The API was also
exercised through a scratch web server on a loopback port. Run on
Linux only.
Co-Authored-By: Claude Fable 5.2 <
noreply@anthropic.com>