Skip to content

fix(messages): read undownloaded Microsoft Graph messages and report unavailable bodies clearly - #291

Open
sjmurdoch wants to merge 4 commits into
TKasperczyk:mainfrom
sjmurdoch:fix/graph-undownloaded-messages
Open

sjmurdoch wants to merge 4 commits into
TKasperczyk:mainfrom
sjmurdoch:fix/graph-undownloaded-messages

Conversation

@sjmurdoch

Copy link
Copy Markdown

Problem

On Thunderbird's native Microsoft Graph accounts (server type graph, folder URIs graph://…), Thunderbird doesn't download a message body until the message is displayed, and the Offline flag stays clear until then. Since 0.10.0 every read first goes through readCompleteRawMessage, which streams a message from the server only for imap. Every other server type falls back to the local store, which is empty for these messages. So for any Graph message that hasn't been opened in Thunderbird:

Both errors come from the same missing-body path.

Changes

  1. Includes fix(messages): read add-on provider (Owl/Exchange) messages through the raw gate #262 unchanged (commit by @andrei-rizoiu, author preserved). Every non-local server type is treated the way IMAP is: the Offline flag marks a complete local copy, and otherwise the message is streamed through the folder's own message service (streamMessage). This covers Graph as well as Owl/EWS, with no scheme-specific code. If fix(messages): read add-on provider (Owl/Exchange) messages through the raw gate #262 is merged first, this PR reduces to the three commits after it.

  2. Clear errors when the body still can't be fetched. A failed server fetch (non-success stop status, or the message service failing synchronously) is marked isBodyUnavailable in readCompleteRawMessage.

    • getMessage returns Message body is not available offline and could not be downloaded from the server.
    • The direct-send preflight returns a matching refusal.
    • saveAsDraft now tells apart content that was read and is protected or unknown (the existing encryption error, unchanged), an original that couldn't be retrieved within the drafting limits, and a body that couldn't be downloaded.
  3. Fallback for Thunderbird 128/140 in fix(messages): read add-on provider (Owl/Exchange) messages through the raw gate #262's stream opener. In ESR 128 and 140, the nsMsgDBFolder base implementation of getLocalMsgStream returns NS_ERROR_NOT_IMPLEMENTED, but the typeof check still passes. A throw now falls back to getMsgInputStream. The comment in fix(messages): read add-on provider (Owl/Exchange) messages through the raw gate #262 also cites bug 1968399 for the 145+ change, but that bug is an unrelated GeckoView one, so the reference probably needs correcting.

All three error cases in change 2 still refuse; only the wording changes. Originals are still classified from their raw bytes before Gloda runs: encrypted ones are still blocked, and clear-signed ones are handled as on v0.10.0.

Testing

  • npm test: all tests pass, plus 12 new ones in test/privacy-messages.test.cjs ("undownloaded Microsoft Graph messages"). They cover getMessage (body and rawSource) on an undownloaded Graph message, an already-downloaded one, both kinds of fetch failure (for getMessage, saveAsDraft and direct reply), a successful draft from a server-streamed copy, an encrypted server copy that is still blocked, and a local folder that never downloads. 10 of them fail on v0.10.0, and 6 still fail with fix(messages): read add-on provider (Owl/Exchange) messages through the raw gate #262 alone. A further test covers the getLocalMsgStream fallback.
  • One existing test (message-headers.test.cjs, "collects all fresh handles before resuming lookup-without-direct") hit its 15 s timeout in 1 of 3 full-suite runs. It passes in isolation with and without this change, and the code it covers isn't touched here.
  • npx eslint .: no errors (the 5 warnings already on main are unchanged).
  • Manual, on Thunderbird 160.0 (macOS) with a Microsoft 365 account using the native Graph account type, an IMAP account and Local Folders:
    • Graph, never opened: getMessage returned the body for all 12 unread Inbox messages (about 0.3 s each). None of them were marked read.
    • Graph attachments: saveAttachments: true saved 3 PDF attachments at their declared sizes.
    • Graph drafts: replyToMessage with saveAsDraft: true saved a threaded, quoted draft in Drafts (Re: subject, In-Reply-To/References, cited body). This held both for an Inbox message and for a 2014 list message that had never been fetched. Thunderbird 160 then shows "FCC copy failed", which is bug 2092297, fixed for 162: the draft is created on the server and then moved into the folder it is already in. deleteMessages moved the test drafts to Deleted Items.
    • Already downloaded Graph, IMAP and Local Folders messages: unchanged.
    • OpenPGP multipart/encrypted originals: still refused by saveAsDraft, and still withheld by getMessage.
    • PGP clear-signed originals: drafted, as on v0.10.0. Signed but unencrypted content is classified as clear.
    • Thunderbird offline (File › Work Offline), never-fetched Graph message: getMessage (body and rawSource) returned "Message body is not available offline and could not be downloaded from the server", and saveAsDraft returned the matching drafting error. All three came back at once, with no hang. A Graph message downloaded earlier still read normally while offline.

Fixes #265
Fixes #275
Builds on #262

🤖 Generated with Claude Code

andrei-rizoiu and others added 4 commits November 25, 2026 11:40
Since 0.10.0 every read goes through readCompleteRawMessage before
Thunderbird parses the message. Four things broke that for add-on
providers such as Owl (Exchange/Office 365):

- Only IMAP messages were streamed from the server when no complete
  local copy exists. An Owl message that was never opened in Thunderbird
  has no offline copy, and the read failed ("Failed to get message",
  "Failed to read message for display") even with encrypted-message
  access enabled. Treat every non-local server type the way IMAP is
  treated: the Offline flag marks a complete local copy, otherwise the
  message service streams it. Owl maintains the same flag and offline
  store. An empty server type stays local-only.

- The local copy was opened with getMsgInputStream, which reads the
  store from the message's offset until it recognises the next
  separator. Owl writes "From - <date>" plus X-Mozilla-* headers in
  front of every message it caches, the store escapes that line to
  ">From ", and the mbox reader does not accept such a line as the start
  of a header block, so the read ran on into the following messages
  (observed: a 14 KB message read back as 50 KB holding three messages,
  bounded only by the server-reported size). That snapshot fails every
  gate, and rawSource returned other messages' content. Open the stored
  copy through getLocalMsgStream (Thunderbird 145+, bug 1968399), which
  is bounded to the message and which providers implement with their
  own slice; keep getMsgInputStream for older builds.

- The ">From - <date>" envelope line itself made the strict raw gate
  reject every cached Owl message as "encryption status could not be
  determined" while the opt-in was off, with the subject shown as
  "[Encrypted message]". libmime skips such a line (mimehdrs.cpp, the BSD
  mailbox delimiter hack). Drop a leading envelope line from local and
  streamed copies before classification; rawSource no longer carries it
  either. A header field name cannot contain a space, so the pattern
  never matches header text.

- Owl records offlineMessageSize before the store escapes that line, so
  its bounded slice ends one byte short, inside the final CRLF (every
  cached copy checked ended in "--\r"). A lone CR fails both gates, but
  a bare CR at the very end has nothing after it to hide: complete it to
  CRLF. A bare CR anywhere else is still withheld.

LOCAL_SERVER_TYPES moves next to the raw readers so both callers share
it.
…cted content

Thunderbird's native Microsoft Graph accounts (server type "graph") do not
download a message body until it is displayed. With the previous commit
such messages are now streamed through the folder's message service, like
IMAP and Owl. When that download still fails (offline, server error, or a
message service that refuses), two misleading errors remained:

- getMessage returned the generic "Failed to get message" / "Failed to
  read raw source".
- replyToMessage with saveAsDraft mapped every failed preflight read to
  "Automatic drafting of encrypted messages is blocked, including
  protected or unknown MIME content", although nothing had been read or
  classified.

readCompleteRawMessage now marks a failed server fetch (non-success
stop status, or a synchronous failure to look up or start the message
service) as isBodyUnavailable. getMessage reports it as "Message body
is not available offline and could not be downloaded from the server".
The direct-send preflight returns a matching refusal, and saveAsDraft
distinguishes three cases: content that was read and is protected or
unknown (unchanged encryption error), an original that could not be
retrieved within the drafting limits, and a body that could not be
downloaded. All three still refuse; only the wording changes. Encrypted
and signed originals are still classified from the raw bytes before
Gloda runs and are still blocked.

Tests cover undownloaded Graph messages for getMessage, rawSource,
saveAsDraft and direct reply, including an encrypted server copy and
both kinds of fetch failure, and check that a local folder still never
downloads.

Fixes TKasperczyk#265
Fixes TKasperczyk#275

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…throws

Thunderbird 128 and 140 ESR (the extension's minimum is 128) declare
nsIMsgFolder.getLocalMsgStream on every folder, but the nsMsgDBFolder
base implementation returns NS_ERROR_NOT_IMPLEMENTED. The typeof check
added for add-on providers is true there, so a folder class that does
not override it would fail every stored-message read instead of using
getMsgInputStream as before. Fall back to getMsgInputStream when
getLocalMsgStream throws.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DIRECT_SEND_RAW_ERROR covers any read failure that is not a failed
download, including an unreadable local store, so the saveAsDraft
message no longer claims the original was too large or too slow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sjmurdoch
sjmurdoch marked this pull request as ready for review November 25, 2026 14:55

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants