Closed Bug 1525274 Opened 6 years ago Closed 5 years ago

Support for raw message source in WebExtensions messages API

Categories

(Thunderbird :: Add-Ons: Extensions API, enhancement, P2)

enhancement

Tracking

(thunderbird_esr68 fixed)

RESOLVED FIXED
Thunderbird 72.0
Tracking Status
thunderbird_esr68 --- fixed

People

(Reporter: liliakai, Assigned: darktrojan)

References

Details

Attachments

(1 file, 1 obsolete file)

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36

Steps to reproduce:

In TB67, browser.messages.getFull will return a JS object representing the parsed mime message.

As an extension developer, I want an API to retrieve the original raw message source, meaning a single Blob containing the full headers and mime-encoded contents, as rendered when selecting "View Source" in the UI.

Blocks: webext-tb
Status: UNCONFIRMED → NEW
Type: defect → enhancement
Ever confirmed: true

Can you provide some uses cases you are looking to fulfill with a raw API?

Priority: -- → P3

I maintain a web extension which submits suspicious emails to a 3rd party service for analysis. The service expects raw mime-encoded emails as input.

I want to do the same thing.... are you possibly talking about the postmark spam check?

I need it for DKIM verification. There I need to calculate a hash over the complete body, and some header fields.

For that I need the complete body as one big unparsed blob (with things like whitespace preserved).

The header fields I also need unparsed, with whitespace (including newlines if it goes over multiple lines) preserved. And if a header field exist multiple times, I need to get them in the same order as in the mail.
Haven't yet looked in detail at the existing web extension API for getting the headers. Could be that it is sufficient for me for getting the headers.

For me it is unimportant whether I get the complete mail as one block (and do the parsing of the headers myself), or just the complete body, and a separate API for getting the (unparsed) header values for the header fileds.

Thanks for the use cases folks. I'm wondering if it makes sense to consolidate get and getFull into one function, e.g.

messenger.messages.get(messageId);
messenger.messages.get(messageId, { mode: "full" });
messenger.messages.get(messageId, { mode: "raw" });

A similar option could be supported in the query and list functions. I'm also not sure what full in getFull means in this context. If raw is fuller than full, maybe it makes sense to use something more explicit?

Priority: P3 → P2

my guess is that "full" at least in this context means the complete message, which includes headers and body not just the body or the messageID

I've stared on this and have a mostly working patch that adds a getRaw function. I don't think it's a good idea to return raw messages for queries as there's a cost to getting them (potentially including downloading from the server, depending on the settings).

Marvin's going to look at writing some tests if we can get him set up to build things.

Assignee: nobody → geoff
Status: NEW → ASSIGNED
Attached patch 1525274-messages-getraw-1.diff (obsolete) (deleted) — Splinter Review
Attachment #9107103 - Flags: review?(mkmelin+mozilla)
Comment on attachment 9107103 [details] [diff] [review] 1525274-messages-getraw-1.diff Review of attachment 9107103 [details] [diff] [review]: ----------------------------------------------------------------- ::: mail/components/extensions/parent/ext-messages.js @@ +184,5 @@ > + }, > + false, > + "" > + ); > + }); Hmm, doesn't this need some error handling for reject? ::: mail/components/extensions/test/xpcshell/test_ext_messages_get.js @@ +22,5 @@ > +var { PromiseTestUtils } = ChromeUtils.import( > + "resource://testing-common/mailnews/PromiseTestUtils.jsm" > +); > + > +// Create a local mail account and add a message. please use /** */ style comments for the documentations
Attachment #9107103 - Flags: review?(mkmelin+mozilla)
Attached patch 1525274-messages-getraw-2.diff (deleted) — Splinter Review
Attachment #9107103 - Attachment is obsolete: true
Attachment #9107998 - Flags: review?(mkmelin+mozilla)
Comment on attachment 9107998 [details] [diff] [review] 1525274-messages-getraw-2.diff Review of attachment 9107998 [details] [diff] [review]: ----------------------------------------------------------------- ::: mail/components/extensions/parent/ext-messages.js @@ +180,5 @@ > + { > + OnStartRunningUrl() {}, > + OnStopRunningUrl(url, exitCode) { > + if (exitCode !== 0) { > + reject(exitCode); and return @@ +191,5 @@ > + ); > + }); > + } catch (ex) { > + Cu.reportError(ex); > + throw new ExtensionError(`Error reading message ${messageId}`); Not sure this is 100% correct, is it? Is that an exception getting thrown from the reject? Could be nicer to just await new Promise(....).catch(reason => throw new ExtensionError(`Error reading message ${messageId}`); ); ... or some such?
Attachment #9107998 - Flags: review?(mkmelin+mozilla) → review+

Pushed by geoff@darktrojan.net:
https://hg.mozilla.org/comm-central/rev/0658b2e48cab
Support for raw message source in WebExtensions messages API; r=mkmelin

Status: ASSIGNED → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → Thunderbird 72.0
Attachment #9107998 - Flags: approval-comm-esr68?
Comment on attachment 9107998 [details] [diff] [review] 1525274-messages-getraw-2.diff Approved for ESR
Attachment #9107998 - Flags: approval-comm-esr68? → approval-comm-esr68+
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: