New account types in JavaScript for Thunderbird (Part 1)

By | December 27, 2010

For the month of December, I took a reprieve from ExQuilla, my Exchange Web Services extension, and decided to tackle the issue of trying to create new account types in JavaScript in a Thunderbird extension. This blog post is an introduction to that project. More detailed posts on specific issues should follow shortly.

Introduction to SkinkGlue

I’ve learned a lot about how to create account types in an extension while working with ExQuilla. While ExQuilla is written principally in C++, many of its concepts could be adapted to javascript. I decided to write TweeQuilla, a demonstration extension in javascript that will implement Twitter as an account type in Thunderbird to test the concepts.

Unfortunately it is not as simple as just writing stuff in javascript, as Joshua Cranmer discovered in his never-finished series of blog posts attempting to do just that. There are complex interactions between javascript objects, C++ objects, and xpconnect that make it difficult or impossible with the existing core code to create a new account in javascript. I have not really solved that problem completely. Instead, I have created a C++ layer that I call Skinkglue. (Skink, as my loyal fans know, is my personal term for the mass of code that implements the basic mailnews functionality in Thunderbird and related products such as SeaMonkey.)

Now Skinkglue is written in C++, and needs to be available before the javascript-only TweeQuilla will work. But Skinkglue does not contain any twitter-specific functionality. In fact, the same Skinkglue code is also used by my ExQuilla addon to implement a new account type using C++.

My intentions are that Skinkglue will get implemented in core as a publically available interface. For that reason, I am making that code available using the standard MPL tri-license. Hopefully that would solve the issues of trying to use a C++ layer in an extension, as it would just be a part of the core that would be available in the standard distribution, so extension writers would not need to compile the C++.

Introduction to TweeQuilla

I chose Twitter as a demonstration because it is likely to be useful, because it is quite simple, and because there has been a lot of work already on the Mozilla platform in developing code for basic Twitter functionality. In particular, I am indebted to the SocialMail addon for the most recent set of updates to that work, though that addon built largely on earlier contributions.

I am not releasing TweeQuilla for public consumption yet on AMO because it is not at all ready (though I am starting to use it myself in my standard email profile.) But the main point is really to demonstrate that this can be done at all, and the extension as it stands makes that point.

Here are a few images of TweeQuilla:

A new twitter account is added using Account Actions in the Account Manager:

When you add a new twitter account, you must fill out an OAuth screen (this one is largely borrowed from SocialMail):

When the account is created, you see different types of twitter searches as mailnews folders. Currently I only have two implemented, one a list of the items that you have sent, and the other your full timeline:

For tweets that just consist of text, the “message body” and the subject are both just the text of the tweet. For tweets with embedded html links, I am currently loading the html link as the “message body”.

Getting the source

Both Skinkglue and TweeQuilla are available for the curious on my Mozilla mercurial site. The TweeQuilla version that exists there includes a compiled version of Skinkglue that will work if you are running Thunderbird on version 3.1.x under windows. Others are out of luck for now. The code at the moment is not easy to understand. I hope to remedy that by some comment cleanup, as well as documenting issues in further posts on this site.