Talk about add-ons and extension development.
user2018
Posts: 87Joined: September 23rd, 2018, 11:07 am
Posted January 12th, 2021, 3:39 am
I have the following function defined in userChrome.js: - Code: Select all
function getMessageBody(aMessageHeader) { let messenger = Components.classes["@mozilla.org/messenger;1"].createInstance(Components.interfaces.nsIMessenger); let listener = Components.classes["@mozilla.org/network/sync-stream-listener;1"].createInstance(Components.interfaces.nsISyncStreamListener); let uri = aMessageHeader.folder.getUriForMsg(aMessageHeader); messenger.messageServiceFromURI(uri).streamMessage(uri, listener, null, null, false, ""); let folder = aMessageHeader.folder; return folder.getMsgTextFromStream(listener.inputStream, aMessageHeader.Charset, 65536, 32768, false, true, { }); }
This was working well, but I have noticed that now, when I use it to retrieve the body of a message as text, newlines are artificially inserted in the text retrieved (I do not see those newlines in the message view, they are not there). It seems like an artificial breakline is added to limit the line's lenght. This is inconvenient because then I have to manually remove the breaklines. This change might have been introduced with some Thunderbird's update, as I think this problem did not exist before. Any idea about how this could be solved? Thank you.
LIMPET235
Moderator

Posts: 39343Joined: October 19th, 2007, 1:53 amLocation: The South Coast of N.S.W. Oz.
Posted January 12th, 2021, 10:52 am
Moving this to the Extension Dev forum...
Ancient Amateur AstronomerWin-7-HP/IntelĀ® DualCore-2.0GHz/500G HDD/4 Gig Ram/550Watt PSU/350WattUPS/Firefox-20.0-62.0-70.0/T-bird-2.0.0.24/SnagIt-v10.0.1/MWP-7.12. W.M.Y.C.( Always choose the "Custom" Install.)
morat
Posts: 4194Joined: February 3rd, 2009, 6:29 pm
Posted January 12th, 2021, 12:48 pm
The following test code works for me. I don't see extra newlines. - Code: Select all
(function () { var msgHdr = gFolderDisplay.selectedMessage; var messenger = Components.classes["@mozilla.org/messenger;1"]. createInstance(Components.interfaces.nsIMessenger); var listener = Components.classes["@mozilla.org/network/sync-stream-listener;1"]. createInstance(Components.interfaces.nsISyncStreamListener); var uri = msgHdr.folder.getUriForMsg(msgHdr); messenger.messageServiceFromURI(uri).streamMessage(uri, listener, null, null, false, ""); var folder = msgHdr.folder; var text = folder.getMsgTextFromStream(listener.inputStream, msgHdr.Charset, 65536, 32768, false, true, {}); var clipboard = Components.classes["@mozilla.org/widget/clipboardhelper;1"]. getService(Components.interfaces.nsIClipboardHelper); clipboard.copyString(text); alert("Plain text message copied to clipboard."); })();
user2018
Posts: 87Joined: September 23rd, 2018, 11:07 am
Posted January 14th, 2021, 3:30 am
I tried the code above and I see the "extra" breaklines in the messages I receive. However, by playing with this I have realized that the breaklines actually seem to exist in the message received (if I save the email as .eml and I open it with a text editor, I also see the "extra" breaklines). However, they are not shown in the message view panel of Thunderbird, so if I copy and paste the contents of the message by selecting the text from the message view panel of Thunderbird the "extra" breaklines are not copied. I guess I have some property defined in Thunderbird to automatically remove the breaklines (not sure about this... I know is that I have auto-wrapping, but this seems to be something else).
It would be great if I could modify the JavaScript code to be able to get the text in the body as shown in the message view panel of Thunderbird (that is, without the "extra" breaklines), if possible.
Any suggestion is welcme.
morat
Posts: 4194Joined: February 3rd, 2009, 6:29 pm
Posted January 14th, 2021, 9:08 am
IMO, the getMsgTextFromStream method works correctly. You are stripping html tags from the output with the getMsgTextFromStream method. i.e. aStripHTMLTags param is true Reference http://searchfox.org/comm-esr78/search?q=getMsgTextFromStream&path=idlSo of course the .eml file will be different.
Return to Extension Development
Who is online
Users browsing this forum: No registered users and 0 guests
|