Thunderbird extension の tips

XPCOM から Thunderbird の Application オブジェクトを得る

var Application = Components.classes['@mozilla.org/steel/application;1'].getService(Components.interfaces.steelIApplication);

How do I search for multiple contacts?

アドレス帳から検索する場合、条件式を LISP みたいな式でコードに渡せるがかなり癖がある。
Address Book examples - MDC
http://mxr.mozilla.org/comm-central/source/mail/base/content/ABSearchDialog.js#187
まず、ルートの式は and/or (not?) じゃないとダメ。
あと encodeURIComponent() は '(' と ')' をエスケープしないので検索に失敗することがある。
以下のような関数でエスケープする:

function escapeQueryParam(value){
    const escapeChars = '()'
    value = encodeURIComponent(value);
    for each (var c in escapeChars){
        value = value.replace(c, '%' + c.charCodeAt(0).toString(16));
    }
    return value;
}

ついでにソースを見れば分かるが実装されていない演算子がある。
http://mxr.mozilla.org/comm-central/source/mailnews/addrbook/src/nsAbDirectoryQuery.cpp#498

jquery.js

jquery.js が内部にある。

Components.classes['@mozilla.org/moz/jssubscript-loader;1']
    .getService(Components.interfaces.mozIJSSubScriptLoader)
    .loadSubScript('chrome://messenger/content/jquery.js');