MozillaZine


getMsgTextFromStream: inserting breaklines problem

Talk about add-ons and extension development.
user2018
 
Posts: 92
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["@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.

morat
 
Posts: 4345
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.

Reference
http://searchfox.org/comm-esr78/search?q=calendarItemFromMessage

P.S.

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

LIMPET235
Moderator

User avatar
 
Posts: 39430
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-79.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: 4345
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["@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: 92
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.

morat
 
Posts: 4345
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

Reference
http://searchfox.org/comm-esr78/search?q=getMsgTextFromStream&path=idl

So of course the .eml file will be different.

user2018
 
Posts: 92
Joined: September 23rd, 2018, 11:07 am

Post Posted January 24th, 2021, 3:54 pm

I continued trying to find a solution for my problem. The problem has nothing to do with HTML contents, as this happens to me with plain text.

I suspect that it has something to do with a Config Editor property (or maybe several of them). In particular, I thought that "mailnews.wraplength" was the culprit, as its default value is 72, which is about the maximum number of characters in the text lines I get (it is like an artificial break line is added if the line is going to exceed that length). However, I still cannot make it work. Could this be a good hint? Any ideas are welcome.

morat
 
Posts: 4345
Joined: February 3rd, 2009, 6:29 pm

Post Posted January 24th, 2021, 6:14 pm

I can't reproduce the problem so I really have no idea.

More info about plain text wrapping
http://kb.mozillazine.org/Plain_text_e-mail_-_Thunderbird#Advanced

Return to Extension Development


Who is online

Users browsing this forum: No registered users and 2 guests