【问题标题】:How to download a message to the local computer via IMAP in Thunderbird?如何在 Thunderbird 中通过 IMAP 将消息下载到本地计算机?
【发布时间】:2016-11-08 06:56:24
【问题描述】:

我通过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,
    });

【问题讨论】:

    标签: javascript email attachment thunderbird thunderbird-addon


    【解决方案1】:

    已解决问题。从服务器下载附件的实现:

    // 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, {});
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-24
      • 2019-01-04
      • 2019-09-20
      • 2019-07-03
      • 2017-02-22
      • 2016-07-21
      • 1970-01-01
      • 2018-10-18
      相关资源
      最近更新 更多