Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7734195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:11:21+00:00 2026-06-01T07:11:21+00:00

I’m trying to save the e-mail body and its attachments from javascript using a

  • 0

I’m trying to save the e-mail body and its attachments from javascript using a custom addin, and I’m not able to do it as described in http://forums.mozillazine.org/viewtopic.php?f=19&t=2030903 Do you have any suggestions? Does the e-mail body can be saved into the native EML format? Thank you!

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

[EDIT] The above code does save the attachments but it opens the SaveAs dialog. Can it be done quietly? Does the e-mail body can be saved into the native EML format? Thank you! [/EDIT]

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T07:11:23+00:00Added an answer on June 1, 2026 at 7:11 am

    I wrote the example above. You’re almost done, and you figured out the hardest parts. Here’s what I just did to figure out how to answer your question.

    1. I ran an mxr search on AttachmentInfo which turns out to be defined at http://mxr.mozilla.org/comm-central/source/mail/base/content/msgHdrViewOverlay.js#1643
    2. Turns out save is just a proxy for nsIMessenger::saveAttachment, defined at http://mxr.mozilla.org/comm-central/source/mailnews/base/public/nsIMessenger.idl#81
    3. It also turns out that there’s a saveAttachmentToFile method there! Probably what you need. Reading the definition, it seems like a good candidate http://mxr.mozilla.org/comm-central/source/mailnews/base/src/nsMessenger.cpp#614

    You probably need to pass the function an already opened nsIFile (see https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIFile as there’s good reference material there), as well as the URI of the attachment (available as uri in your code), the message’s uri (probably something along the lines of msgHdr.folder.getUriForMsg(msgHdr)), the content type (att.contentType here), and a listener implementing nsIUrlListener (defined here: http://mxr.mozilla.org/comm-central/source/mailnews/base/public/nsIUrlListener.idl#48, see https://github.com/protz/GMail-Conversation-View/blob/master/modules/message.js#L1492 for a very barebones implementation — you should probably hook your own functions there to check that everything went fine).

    I didn’t try this code but I’m pretty confident the guidelines are sound.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.