Closed Bug 1692439 Opened 3 years ago Closed 2 years ago

compose.getComposeDetails adds an extra newline in plainText mode

Categories

(Thunderbird :: Add-Ons: Extensions API, defect)

defect

Tracking

(Not tracked)

RESOLVED FIXED
102 Branch

People

(Reporter: lapo, Assigned: TbSync)

References

Details

Attachments

(1 file)

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.40 Safari/537.36

Steps to reproduce:

background.js:

browser.compose.onBeforeSend.addListener(async tab => {
browser.compose.setComposeDetails(tab.id, { plainTextBody: 'Ciao.' });
});

Actual results:

Mail was sent with an extra newline at the start of the message.

Expected results:

Keep the string as provided.

I tried with this extension, getting the same issue: https://github.com/thundernest/sample-extensions/tree/master/composeBody. First time a new line was inserted after the body, from the second on there is always a new line before the body.

What OS are you on? Is this bug still valid with TB 78.10 ?

I cannot reproduce this on Windows with TB 78.10, nor on Linux with TB 78.8

I have to correct myself, it is reproducible and it is not related to the onBeforeSend event (alone). It is related to calling getComposeDetails() on a plain text message. Just calling it alters the body (invisible). There is no need to call setComposeDetails to cause this bug.

The offending line is :
https://hg.mozilla.org/comm-central/file/4d9b779989fd8f4a85861d76ee07f52f2812fcd6/mail/components/extensions/parent/ext-compose.js#l328

Investigating.

Summary: compose.setComposeDetails adds an extra newline in plainText mode → compose.getComposeDetails adds an extra newline in plainText mode

The error is triggered by onBeforeSend, because it calls getComposeDetails() here:
https://searchfox.org/comm-central/rev/a5fca941432bc58f9eeeb4c3a2ecc39d9cc602da/mail/components/extensions/parent/ext-compose.js#812

If that is removed, the newline is not added any more.

What makes this bug really odd is that the reproducer code is not using the returned plain text content (which could include a false newline), but sets a new value. Having executed editor.outputToString("text/plain", Ci.nsIDocumentEncoder.OutputRaw) in getComposeDetails() on a plain text composer seems to enable a different mode which prepends a newline to any new value set, which is not visible in the composer but only in the send message. Looking for a replacement.

It is even worse than that, the reproducer code could just be

browser.compose.onBeforeSend.addListener(async tab => {
   console.log("Doing nothing");
});

So this bug is severe and prepends a new line to all outgoing plain text messages, if either onBeforeSend on getComposeDetails is used by any installed add-on. It is not required to actually use setComposeDetails().

Assignee: nobody → john
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true

Pushed by geoff@darktrojan.net:
https://hg.mozilla.org/comm-central/rev/b96d9df1eacc
Always use MsgUtils.convertToPlainText() to get around weird prepended empty lines. r=mkmelin

Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 102 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: