Refresh mail folder list in Thunderbird

I’m trying to add a feature to my add-on that automatically refreshes the mail folder list in Thunderbird. This is needed, for example, in the case of IMAP servers where a folder may be created on the server but Thunderbird is not aware of its existence.

I’ve read online that the way to refresh the folder list manually through the user interface is to just collapse and expand the server in the folder pane. I’ve tried to mimic this using the following code:

let serverCount = MailServices.accounts.allServers.length;
for (let i = 0; i < serverCount; i++) {
    let server = MailServices.accounts.allServers.queryElementAt(i, Components.interfaces.nsIMsgIncomingServer);
    server.performExpand(msgWindow);
}

However, the implementation of nsIMsgIncomingServer.performExpand() only returns an OK status code without doing anything else. The implementation in nsImapIncomingServer (an IMAP specific implementation) looks like it will do what I need but that interface is not accessible as far as I can tell.

I also simply tried calling MailUtils.discoverFolders() but that function will only do an initial population of the server’s folders. It won’t rediscover folders on subsequent calls.

Does anyone have any suggestions as to how to go about doing this?

Any help is appreciated.

You might find more help for this here - http://forums.mozillazine.org/viewforum.php?f=19 - they have more thunderbid addon devs there. :frowning: