我通过gloda模块函数MsgHdrToMimeMessage
接收附件
MsgHdrToMimeMessage(msgHdr, null, function(aMsgHdr, aMimeMsg) {
let attachments = aMimeMsg.parts[0].parts;
log(attachments);
}, false, {
saneBodySize: false,
});
如何使用(imap://)链接将消息本地下载到计算机上?
我试着用这个。但是我有错误。
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,
});
问题解决。从服务器下载附件的实现:
// 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, {});