Search code examples
thunderbird-addon

TB Plugin errors after updating TB from 38.7.2 to 45.1.0


Several years ago I made a private Thunderbird plugin for automatically processing paypal emails about subscriptions. The user has to put the paypal emails in a certain folder "PaypalMsgs", and the plugin reads them one by one, finds out if it is a payment, a cancellation etc. and then updates the "Other" field of the person in the address book.

The plugin got broken with the recent update of Thunderbird to 45.1.0 because it cannot find the folder PaypalMsgs any more.

This is the code for finding the folder:

// determine the local root folder
var localRootFolder = Components
  .classes["@mozilla.org/messenger/account-manager;1"]
  .getService(Components.interfaces.nsIMsgAccountManager)
  .localFoldersServer
  .rootFolder;
// start with root folder to find folder with given name
this.ppPaypalFldr = this.findFldrDeep(localRootFolder, "PaypalMsgs");

// recursive function to find a folder fldr with the name fldrName
findFldrDeep: function(fldr, fldrName) {
if(fldr.name == fldrName) {
    return fldr;
} else {
    if(fldr.hasSubFolders) {
        var fldrEnum = fldr.subFolders;
        while(fldrEnum.hasMoreElements()) {
            var sfldr = fldrEnum.getNext();
            var result = this.findFldrDeep(sfldr, fldrName);
            if(result) {
                return result;
            }
        }
    } else {
        return null;
    }
}

},

When executed nothing happens and TB's error console shows:

Error: TypeError: this.ppPaypalFldr undefined

at the first location where this.ppPaypalFldr is used

It might be an easy thing, like the definition of the services of nsIMsgAccountManager might have changed or the folder type suddenly has different functions, but I have a really hard time to find reliable documentation or even the source for TB 45.

Thank you for any hints and support!


Solution

  • After more seach, debugging and thinking (sic!) I found the problem: At the line

    var sfldr = fldrEnum.getNext();
    

    The interface is missing and it looks like in TB45 something has changed so the interface is not automatically retrieved from somewhere (the software worked without this interface since about 4 or 5 years).

    So the correct line is:

    var sfldr = fldrEnum.getNext().QueryInterface(Components.interfaces.nsIMsgFolder);
    

    I also checked all of the plugin and added all interfaces - now it works like a charm.

    Writing the problem here alone has helped me a lot to find the solution ;-)