User:Clarkbw/STEEL Examples: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
(initial examples page)
No edit summary
Line 6: Line 6:


'''Here are some working examples of code using the STEEL API.'''
'''Here are some working examples of code using the STEEL API.'''
__TOC__


== Watching for New Mail ==
== Watching for New Mail ==

Revision as of 19:59, 19 March 2008

Here are your instructions

  1. Grab the STEEL extension for thunderbird from bug 408370
  2. Install the STEEL Extension
  3. Write Extensions that use the STEEL API

Here are some working examples of code using the STEEL API.

Watching for New Mail

Here's a snippet that listens for new mail arriving

var steelyournewmail = {
  onLoad: function() {
    // initialization code
    this.initialized = true;
    this.strings = document.getElementById("steelyournewmail-strings");

    // FIXME: currently we have to add our listener for new mail arriving in all folders
    for (var i = 0; i < Application.accounts.all.length; i++) {
      Application.console.log("looking in account: " + Application.accounts.all[i].displayName);
      for (var j = 0; j < Application.accounts.all[i].folders.length; j++) {
        Application.console.log("looking in folder: " + Application.accounts.all[i].folders[j].name);
        Application.accounts.all[i].folders[j].events.addListener("newMail", steelyournewmailListener);
      }
    }
  },
};

var steelyournewmailListener = {
  handleEvent : function (event) {
    var msg = event.data;
    Application.console.log("handleEvent: " + event.type); // newMail
    Application.console.log("handleEvent (msg.id): " + msg.id);
    Application.console.log("handleEvent (msg.from): " + msg.from);
    Application.console.log("handleEvent (msg.to): " + msg.to);
    Application.console.log("handleEvent (msg.cc): " + msg._xpcomMsg.ccList);
    Application.console.log("handleEvent (msg.date): " + msg.date);
    Application.console.log("handleEvent (msg.subject): " + msg.subject);
    Application.console.log("handleEvent (msg.unread): " + msg.unread);
    Application.console.log("handleEvent (msg.flagged): " + msg.flagged);
    Application.console.log("handleEvent (msg.priority): " + msg.priority);
    Application.console.log("handleEvent (msg.attachments): " + msg.attachments);
    Application.console.log("handleEvent (msg._xpcomMsg): " + msg._xpcomMsg);
  },
};

window.addEventListener("load", function(e) { steelyournewmail.onLoad(e); }, false);

The old version of watching for new mail still works