Pi’s Blog

My blog about Thunderbird and GSoC 2008

New Extension

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)
      filename = GenerateValidFilename(subject, ".eml");
    catch (ex) {}
    messenger.saveAs(uri, true, null, filename);


function mySaveAsFile(aUri) {
  var type;
  try {
    // get the preference for the default extension type
    var prefBranch = Components.classes["@mozilla.org/preferences-service;1"]
    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)
      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);

July 21, 2008 - Posted by | thunderbird

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: