I made a new, simple, extension for changing the default file type for saved e-mail messages after BuBB1eS asked about it in #maildev.  You can change the type by going to the Preferences (Tools -> Add-ons -> Options under File Type Selector).  You should change it to only one of the following: txt, eml, html.  It will work if the period is included in the preference, too.  Let me know if you want to localize it; there are only two strings: “File Type Selector Preferences” and “Default extension for saved e-mail messages (ex txt, html, or eml)”. 😉

You can read about it and download it here.

How it works

It overrides the SaveAsFile function in mail/base/content/mailCommands.js from:

function SaveAsFile(uri)
{
  if (uri) {
    var filename = null;
    try {
      var subject = messenger.messageServiceFromURI(uri)
                             .messageURIToMsgHdr(uri).mime2DecodedSubject;
      filename = GenerateValidFilename(subject, ".eml");
    }
    catch (ex) {}
    messenger.saveAs(uri, true, null, filename);
  }
}

to:

function mySaveAsFile(aUri) {
  var type;
  try {
    // get the preference for the default extension type
    var prefBranch = Components.classes["@mozilla.org/preferences-service;1"]
                               .getService(Components.interfaces.nsIPrefService)
                               .getBranch("extensions.filetypeselector.")
                               .QueryInterface(Components.interfaces.nsIPrefBranch2);
    type = prefBranch.getCharPref("defaultExtension");
    if (type.indexOf(".") == -1)
      type = "." + type;
  } catch(e) {}
  // if there isn't a type set it to the .eml default
  if (!type)
    type = ".eml";
  if (aUri) {
   var filename = null;
    try {
      var subject = messenger.messageServiceFromURI(aUri)
                             .messageURIToMsgHdr(aUri)
                             .mime2DecodedSubject;
      filename = GenerateValidFilename(subject, type);
    } catch (ex) {}
    messenger.saveAs(aUri, true, null, filename);
  }
}

It overrides the SaveAsFile function by adding an overlay to both chrome://messenger/content/messenger.xul (the main TB window) and chrome://messenger/content/messageWindow.xul (the window for viewing messages) and setting an event listener that overrides the function when the window loads:

// when the window finishes loading, override the SaveAsFile function with
// the mySaveAsFile function below
window.addEventListener("load", function(e) { SaveAsFile = mySaveAsFile; }, false);
Categories: mozilla

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.