0

我想使用雷鸟源代码保存电子邮件附件。我在您的论坛中获得了以下代码..但它不起作用

    alert("Messages selected: " + gFolderDisplay.selectedCount);
      let enumerator = gFolderDisplay.selectedMessages;
        for each (let msgHdr in fixIterator(enumerator, Ci.nsIMsgDBHdr)) {
          var messageID = msgHdr.messageId;
           alert("MessageID: " + messageID);
           var subject = msgHdr.mime2DecodedSubject;
          alert("Subject: " + subject);
            MsgHdrToMimeMessage(msgHdr, null, function (aMsgHdr, aMimeMsg) {
              try {
        alert("Size of the message: " + aMimeMsg.size);
            alert("Structure of the message:\n" + aMimeMsg.prettyString(true, undefined, true));
             let attachments = aMimeMsg.allUserAttachments || aMimeMsg.allAttachments;
             alert("Number of attachments: " + attachments.length);
                   for (let [index, att] in Iterator(attachments))
        {
            alert ("URL: " + att.url  + " Name: " + att.name);
            let ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);  
            let neckoURL = null;  
            neckoURL = ioService.newURI(att.url, null, null);  
            neckoURL.QueryInterface(Ci.nsIMsgMessageUrl);  
            let uri = neckoURL.uri;  
            let attInfo = new AttachmentInfo(att.contentType, att.url, att.name, uri, att.isExternal);
            attInfo.save();
        }
    } catch (err) {
        alert(err);
    }
}, true, { examineEncryptedParts: true, });
}

使用上面的代码,我可以浏览选定的消息。但不能保存附件。它显示附件的数量。而且我想为选定的邮件设置我自己的标签。我怎样才能做到这一点?请帮帮我...在此先感谢

4

1 回答 1

0

工作代码

      var enumerator = gFolderDisplay.selectedMessages;
        for each (var msgHdr in fixIterator(enumerator, Components.interfaces.nsIMsgDBHdr)) {
        msgHdr.setStringProperty("docuHive","dhivelabel");

            MsgHdrToMimeMessage(msgHdr, null, function (aMsgHdr, aMimeMsg) {
              try {
             var attachments = aMimeMsg.allUserAttachments || aMimeMsg.allAttachments;
                   for (var [index, att] in Iterator(attachments))
        {
            var ioService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);  
            var neckoURL = null;  
            neckoURL = ioService.newURI(att.url, null, null);  
            neckoURL.QueryInterface(Components.interfaces.nsIMsgMessageUrl);  
            var uri = neckoURL.uri;  
            var attInfo = new AttachmentInfo(att.contentType, att.url, att.name, uri, att.isExternal); 
            // getting the chrome directory
            var file = Components.classes["@mozilla.org/file/directory_service;1"].
           getService(Components.interfaces.nsIProperties).
           get("AChrom", Components.interfaces.nsIFile);

           var msguri = msgHdr.folder.getUriForMsg(msgHdr);

    messenger = Components.classes["@mozilla.org/messenger;1"]
                       .createInstance(Components.interfaces.nsIMessenger);
                       alert(messenger);
        messenger.saveAttachmentToFolder(att.contentType,att.url,"attachmentname.extension",msguri,file);

        }
    } catch (err) {
        alert(err);
    }
}, true, { examineEncryptedParts: true, });
}
于 2013-08-23T08:10:28.487 回答