getMsgTextFromStream: inserting breaklines problem

Talk about add-ons and extension development.
Posts: 87
Joined: September 23rd, 2018, 11:07 am

Post 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[";1"].createInstance(Components.interfaces.nsIMessenger);
   let listener = Components.classes[";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.

Posts: 4197
Joined: February 3rd, 2009, 6:29 pm

Post Posted January 12th, 2021, 10:13 am

I don't know. That exact code is still being used in a calendar function.



It's best to post the Thunderbird userChrome.js topics in the Extension Development forum.


User avatar
Posts: 39348
Joined: October 19th, 2007, 1:53 am
Location: The South Coast of N.S.W. Oz.

Post Posted January 12th, 2021, 10:52 am

Moving this to the Extension Dev forum...
Ancient Amateur Astronomer
Win-7-HP/IntelĀ® DualCore-2.0GHz/500G HDD/4 Gig Ram/550Watt PSU/350WattUPS/Firefox-20.0-62.0-70.0/T-bird-
(Always choose the "Custom" Install.)

Posts: 4197
Joined: February 3rd, 2009, 6:29 pm

Post 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[";1"].
  var listener = Components.classes[";1"].
  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[";1"].
  alert("Plain text message copied to clipboard.");

Posts: 87
Joined: September 23rd, 2018, 11:07 am

Post 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.

Posts: 4197
Joined: February 3rd, 2009, 6:29 pm

Post 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


So of course the .eml file will be different.

Return to Extension Development

Who is online

Users browsing this forum: No registered users and 1 guest