MozillaZine

Saving email to disk on TB 60.8

Talk about add-ons and extension development.
ManOfOrange
 
Posts: 3
Joined: January 23rd, 2019, 12:31 am

Post Posted August 12th, 2019, 7:50 am

Hello all!

I have a ThunderBird extention that saving email to disk. It using function SaveMessageToDisk and before all was OK.
As i remember on version TB 60.4 it worked fine, but on TB 60.8 all incoming letters automatically marked as read by this function.

I try to write saving to disk by myself. I try example from here: https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMsgMessageService#streamMessage().
Code: Select all
var content = "";
  var MessageURI = GetFirstSelectedMessage();
  var MsgService = messenger.messageServiceFromURI(MessageURI);
  var MsgStream =  Components.classes["@mozilla.org/network/sync-stream-listener;1"].createInstance();
  var consumer = MsgStream.QueryInterface(Components.interfaces.nsIInputStream);
  var ScriptInput = Components.classes["@mozilla.org/scriptableinputstream;1"].createInstance();
  var ScriptInputStream = ScriptInput.QueryInterface(Components.interfaces.nsIScriptableInputStream);
  ScriptInputStream.init(consumer);
  try {
    MsgService.streamMessage(MessageURI, MsgStream, msgWindow, null, false, null);
  } catch (ex) {
    alert("error: "+ex)
  }
  ScriptInputStream.available();
  while (ScriptInputStream.available()) {
    content = content + ScriptInputStream.read(512);
  }


But on line «ScriptInputStream.available()» it is stopped and no execute after tis line. Sometimes after about ten minutes TB crushed.
Just for test i tryed use only «ScriptInputStream.read(512)» — same result.

Then i found topic: http://forums.mozillazine.org/viewtopic.php?f=19&p=14756968 and use example with function getMsgTextFromStream:
Code: Select all
var msgHdr = gFolderDisplay.selectedMessage;
var msgUri = msgHdr.folder.getUriForMsg(msgHdr);
var messenger = Components.classes["@mozilla.org/messenger;1"].
  createInstance(Components.interfaces.nsIMessenger);
var msgService = messenger.messageServiceFromURI(msgUri);
var syncStreamListener = Components.classes["@mozilla.org/network/sync-stream-listener;1"].
  createInstance(Components.interfaces.nsISyncStreamListener);
msgService.streamMessage(msgUri, syncStreamListener, null, null, false, "", true);
var contentType = new Object();
var data = msgHdr.folder.getMsgTextFromStream(
  syncStreamListener.inputStream, msgHdr.Charset, 65536, 32768, false, true, contentType);

And again — on line with getMsgTextFromStream function it stopped and sometimes crashed after few minutes.

So, i have two questions:
1) Is there any way to use the function SaveMessageToDisk so that it doesn't mark emails as read?
2) If not — how to make the way with the functions streamMessage or getMsgTextFromStream work?

tanstaafl
Moderator

User avatar
 
Posts: 45550
Joined: July 30th, 2003, 5:06 pm

Post Posted August 26th, 2019, 5:23 pm

Thunderbird 68.0 will be out soon. Right now its undergoing smoke testing. They will try to retain support for legacy add-ons (though you will need to make some changes) but its very webextension-centric. I suggest you look at the source code for "ImportExportTools NG", the webextension based replacement for the ImportExportTools add-on. That add-on imports/exports mail to mbox files.

https://github.com/thundernest/import-export-tools-ng

I suggest you read https://developer.thunderbird.net/add-ons/updates and then https://developer.thunderbird.net/ .

Return to Extension Development


Who is online

Users browsing this forum: No registered users and 1 guest