如何通过Thunderbird中的IMAP将邮件下载到本地计算机?

时间:2016-11-08 06:56:25

标签: javascript email attachment thunderbird thunderbird-addon

我通过gloda模块函数MsgHdrToMimeMessage

接收附件
MsgHdrToMimeMessage(msgHdr, null, function(aMsgHdr, aMimeMsg) {
  let attachments = aMimeMsg.parts[0].parts;
  log(attachments);

}, false, {
  saneBodySize: false,
});

如何使用(imap://)链接将消息本地下载到计算机?

我尝试使用this。但我有错误。

MsgHdrToMimeMessage(msgHdr, null, function(aMsgHdr, aMimeMsg) {
      try {
        var attachments = aMimeMsg.allAttachments;
        for (var [index, att] in Iterator(attachments)) {
          var ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
          var attURL = null;
          attURL = ioService.newURI(att.url, null, null);

          attURL.QueryInterface(Ci.nsIMsgMessageUrl);
          log(attURL)

          var uri = attURL.uri;

          // not work in this place.
          // console.log: ReferenceError {}
          var file = FileUtils.getFile("TmpD", [att.name]);
          file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE);

          messenger.saveAttachmentToFile(file, att.url, uri, att.contentType, null);

        }
      } catch (err) {
        log(err);
      }

    }, false, {
      saneBodySize: false,
    });

1 个答案:

答案 0 :(得分:0)

解决了问题。从服务器实施附件下载:

// Initialize.
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;

Cu.import("resource:///modules/mailServices.js");
Cu.import("resource:///modules/iteratorUtils.jsm");
Cu.import("resource:///modules/Services.jsm");
Cu.import("resource:///modules/gloda/mimemsg.js");
Cu.import("resource:///modules/FileUtils.jsm");

MsgHdrToMimeMessage(msgHdr, null, function(aMsgHdr, aMimeMsg) {
  let attachments = aMimeMsg.allAttachments;

  for (let [index, att] in Iterator(attachments)) {
    let ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);

    let attURL = ioService.newURI(att.url, null, null);
    attURL.QueryInterface(Ci.nsIMsgMessageUrl);
    let uri = attURL.uri;

    let file = FileUtils.getFile("TmpD", [att.name]);
    file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE);

    let messenger = Cc["@mozilla.org/messenger;1"].createInstance(Ci.nsIMessenger);
    messenger.saveAttachmentToFile(file, att.url, uri, att.contentType, null);
  }

}, false, {});