Handle message body in browser.compose API functions
Categories
(Thunderbird :: Add-Ons: Extensions API, enhancement)
Tracking
(Not tracked)
People
(Reporter: darktrojan, Assigned: darktrojan)
References
Details
Attachments
(2 files, 2 obsolete files)
(deleted),
patch
|
mkmelin
:
review+
|
Details | Diff | Splinter Review |
(deleted),
patch
|
mkmelin
:
review+
|
Details | Diff | Splinter Review |
Assignee | ||
Comment 1•5 years ago
|
||
This seems too easy. Is it really that easy?
While we're here it seems like a good time to work out what to do with plain-text/HTML choices. At the moment I'm just returning from getComposeDetails with a "bodyIsHTML" flag based on the compose window state, and ignoring the issue in all other places. Presumably the extension should be able to send HTML or plain text and have the composer respond. I don't know if that's feasible or a good idea. Thoughts?
Comment 2•5 years ago
|
||
Comment 3•5 years ago
|
||
Hi, A legacy add-on I maintain would be a user of this API on MX migration. I want to provide my add-on as a use case example if it is of some help.
The add-on code that modify the message body is here.
My add-on behaves like following:
- User can choose either plain-text/HTML in pref of the add-on
- Gets the mode of the editor via
IsHTMLEditor()
- If the editor is in plain-text mode, regardless of the user choice, the add-on modifies the message body as a plain-text.
- If the editor is in HTML mode, and user chooses plain-text, the add-on modifies the message body as a plain-text.
- If the editor is in HTML mode, and user chooses HTML, the add-on modifies the message body as a HTML.
That is, at least in my use case, the functionality to switching between plain-text/HTML is not needed.
My add-on expects that:
- Getting whether the body is in plain-text or HTML (
IsHTMLEditor()
utility equivalent) - Getting the body as a whole plain-text is always available (
outputToString("text/plain")
) - Getting the body as a whole HTML is always available (
outputToString("text/html")
) - Setting the body as a whole plain-text is always available (
insertText
equivalent) - Setting the body as a whole HTML is available only if the editor is in HTML mode (equivalent to
rebuildDocumentFromSource("")
followed byinsertHTML
)
Assignee | ||
Updated•5 years ago
|
Assignee | ||
Comment 4•5 years ago
|
||
Comment 5•5 years ago
|
||
Assignee | ||
Comment 6•5 years ago
|
||
(In reply to Magnus Melin [:mkmelin] from comment #5)
maybe it still would be preferable to just have body + isPlainText
Or was the idea that both parts should be accessible? I guess for that case
it still shouldn't be possible to pass in more than one body.
We already have the plainTextBody in the schema due to using the same object type for other things, so I decided to use it here. My thinking is that by forcing the extension writer to do something different (use plainTextBody instead of body) they're less likely to accidentally put HTML where it shouldn't be. They've already had to set isPlainText to get here, so choosing which field to put the body in shouldn't be too unexpected.
I guess we should trim the output? I wouldn't expect to get a text starting
with a newline from that.
Yes, I think there's a defect in the existing code here. I thought this might depend on the current identity's replyOnTop setting, but that isn't the case. I'll file a new bug about it and handle it separately.
Assignee | ||
Comment 7•5 years ago
|
||
This mostly the same. I've renamed the html
and plainText
properties in the test to htmlIncludes
and plainTextIs
to make it clearer what's being checked. I've figured out where the stray paragraph comes from and will fix that in another patch.
Assignee | ||
Comment 8•5 years ago
|
||
Comment 9•5 years ago
|
||
Assignee | ||
Updated•5 years ago
|
Comment 10•5 years ago
|
||
Assignee | ||
Comment 11•5 years ago
|
||
Oops, got in a bit early with the checkin-needed. I added the > and < to say I don't really care what the surrounding tag is as long as there's not white-space. I guess in all these cases it probably is <p> with no attributes now.
Comment 12•5 years ago
|
||
Pushed by geoff@darktrojan.net:
https://hg.mozilla.org/comm-central/rev/381b9496d886
Handle message body in browser.compose API functions. r=mkmelin
https://hg.mozilla.org/comm-central/rev/42930fd343fe
If a message body is specified, do not insert a paragraph at the start. r=mkmelin
Assignee | ||
Comment 13•5 years ago
|
||
Actually in most cases the outer tag was <body>
, and in plain text messages it has a style attribute. I've included those in the version just landed.
Assignee | ||
Updated•5 years ago
|
Comment 14•5 years ago
|
||
Assignee | ||
Comment 15•5 years ago
|
||
Bah! My follow-up needs a follow-up because it doesn't work on beta. Apparently .replaceAll
isn't a thing there yet.
Assignee | ||
Comment 16•5 years ago
|
||
Landed the fix on beta, I'll push it to central when I next push things:
https://hg.mozilla.org/releases/comm-beta/rev/485543f1353223fea59fbc2e781bc0efcbf8d526
Comment 17•5 years ago
|
||
Description
•