Thunderbird拡張機能のつくり方メモ

元ネタ:Building a Thunderbird extension 1: introduction - MDC

上記ページを元にThunderbird拡張機能(add-on)を作ってみたので簡単にメモ
以下、Macでの手順が元になっているので、Windowsの場合はパス名とかは適宜読み替える必要あり。

作業用フォルダを作る

まず適当な場所に作業用のフォルダを作る。
たとえば、~/thunderbird/hello というフォルダをadd-on開発用として使用する。

最低限のフォルダ/ファイルを用意する

作業フォルダの中に、最低限以下のファイルが必要

install.rdfはadd-onの名前とか作者とか、Thunderbirdがadd-on自体を識別管理するための情報を記載するためのファイル。
chrome.manifestはadd-onの構成するファイル/フォルダを記載するためのファイル。

install.rdfを作る

とりあえず、以下の内容で作業フォルダ直下に install.rdf ファイルを作成する。

<?xml version="1.0"?>

<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
     xmlns:em="http://www.mozilla.org/2004/em-rdf#">

  <Description about="urn:mozilla:install-manifest">
    <em:id>myfirstext@snaka</em:id>
    <em:name>My First Extension</em:name>
    <em:version>1.0</em:version>
    <em:creator>snaka</em:creator>
   
    <em:targetApplication>
      <Description>
        <em:id>{3550f703-e582-4d05-9a08-453d09bdfdc6}</em:id>
        <em:minVersion>1.5</em:minVersion>
        <em:maxVersion>3.0.*</em:maxVersion>
      </Description>
    </em:targetApplication>
   
  </Description>      
</RDF>

<em:id>myfirstext@snaka</em:id>の部分はadd-onを識別するためのid, たいてい、拡張機能名@作者名 または、{GUID} という形式。

chrome.manifestを作る

とりあえず、以下の内容で作業フォルダ直下に chrome.manifest ファイルを作る。

content     myfirstext    content/
overlay chrome://messenger/content/messenger.xul chrome://myfirstext/content/myhelloworld.xul

myhelloworld.xulを作る

contentフォルダの中に、以下の内容で myhelloworld.xul ファイルを作る。

<?xml version="1.0"?>
<overlay id="sample" 
  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 <statusbar id="status-bar">
  <statusbarpanel id="my-panel" label="Hello, World" onclick="alert('hello')"/>
 </statusbar>
</overlay>

動かしてみる

Thunderbirdのプロファイル格納フォルダ内extensionsフォルダ配下に、作業フォルダの場所を記載したテキストファイルを作成する。

そのときのテキストファイルは、install.rdfの<em:id>で指定したadd-onのidと一致させることに注意。

この例では以下のような内容でファイルを作った。

/Users/snaka/thunderbird/hello/

そうしてThunderbirdを起動(すでに起動していたら再起動)する。

すると、自動的にadd-onを認識して、以下のようにThunderbirdのステータスバーに "Hello,world"と表示されるはず。

前述のxulファイルの中で、このstatusbarpanel要素のonclick属性にalert()を記述しているので、試しにクリックしてみると...

このように、alert()を表示することも出来る。

javascriptさえ使えれば、あとはxul独自の要素(タグ)の使い方の話なので割と簡単に拡張機能は作ることができる。