Notmuch

提供: ArchWiki
ナビゲーションに移動 検索に移動

関連記事

Notmuch はメールインデックス作成プログラムです。原則、xapian 上で動作するフロントエンドであり、Sup と同じように、一つのことに焦点を置いています: メールメッセージのインデックスを作成すること。Notmuch はメールリーダーとして使うことも、mutt などの他の MUA のインデクサや検索ツールとして使うこともできます。

概要

Notmuch は C で書かれており sup-mail より数倍高速に動作します。Notmuch はインデックスの作成中に終了することもでき、次の起動時に続きからインデックス作成を続行します。sup-mail と同じように、不要なメールメッセージを永久に削除する手段は用意していません。メールの取得や送信、メールアドレスの保存などは行わないため OfflineIMAP, msmtp, abook などのプログラムを使う必要があります。

Notmuch は notmuch パッケージでインストールできます。

公式パッケージでは python, vim, emacs バインディングを提供します。

初期設定

インストール後、以下を実行することでインタラクティブなセットアップを起動できます:

$ notmuch setup

プログラムはメールディレクトリの場所、そしてプライマリメールアドレス・セカンダリメールアドレスを尋ねます。設定ファイルを直接編集することもできます。設定ファイルはデフォルトでは $HOME/.notmuch-config に作成されます。

設定後、以下のコマンドでメールディレクトリの再インデックスを行います:

$ notmuch new

フロントエンド

notmuch を使用する様々な方法が存在し [1]、cli あるいは Unix エディタが使えます。

Emacs

notmuch のデフォルトフロントエンドは Emacs です。notmuch を開発したのと同じ人によって開発されています。

Vim

vim インターフェイスは notmuch-vim に含まれています。起動するには:

$ vim -c NotMuch

alot

alot は notmuch のスタンドアロンな CLI インターフェイスで、python で書かれています。AURalotalot-gitAUR でインストールできます。

Alot は mailcap を使用して様々な種類のファイルを処理します。html メールも含まれているため、html メールを表示するには ~/.mailcap ファイルの設定が必要です。~/.mailcap に以下の行を記述してください:

text/html; w3m -dump -o -document_charset=%{charset} %s; nametemplate=%s.html; copiousoutput

上記では w3m を使用していますが、他のテキストベースクライアント (linkslynx) も使えます。ただし引数は違うかもしれません。

もちろん他のファイルハンドラを設定することも可能です。

bower

bowerMercury によって書かれた、もうひとつの CLI インターフェイスです。bower-mailAUR パッケージでインストールすることができます。

Neomutt

Neomutt は多数のパッチが適用された mutt のフォークです。Notmuch の統合パッチも含まれています。neomutt または neomutt-gitAUR パッケージでインストールできます。

astroid

Astroid は C++ と GTK+ で書かれたグラフィカルな MUA で notmuch のインターフェイスです。astroidAUR (安定版) または astroid-gitAUR (開発版) パッケージでインストールできます。高速な GUI を備えており、HTML や添付ファイルをプレビューしたり、キーボードで操作することができます。設定項目が多く、お好きなエディタを使うことが可能です。詳しくは wikiREADME を参照してください。

ner

ノート: Ner は開発が活発には行われなくなっています。GitHub の最後のコミットは2012年5月です。

ner - notmuch email reader - はまた別の CLI インターフェイスで、C++ によって書かれています。

ner-gitAUR[リンク切れ: アーカイブ: aur-mirror]AUR からインストールできます。

mutt の統合

mutt を MUA として使う場合、notmuch はメールのインデックス作成・検索を行う補完ツールとして役に立ちます。notmuch-mutt パッケージに mutt と notmuch を統合するスクリプトが含まれています。

notmuch-mutt パッケージをインストールして notmuch を設定したら、mutt から notmuch-mutt スクリプトを呼び出すキーバインドを追加してください。.muttrc に以下のコードを追加することを推奨します:

macro index <F8> \
"<enter-command>set my_old_pipe_decode=\$pipe_decode my_old_wait_key=\$wait_key nopipe_decode nowait_key<enter>\
<shell-escape>notmuch-mutt -r --prompt search<enter>\
<change-folder-readonly>`echo ${XDG_CACHE_HOME:-$HOME/.cache}/notmuch/mutt/results`<enter>\
<enter-command>set pipe_decode=\$my_old_pipe_decode wait_key=\$my_old_wait_key<enter>" \
"notmuch: search mail"

macro index <F9> \
"<enter-command>set my_old_pipe_decode=\$pipe_decode my_old_wait_key=\$wait_key nopipe_decode nowait_key<enter>\
<pipe-message>notmuch-mutt -r thread<enter>\
<change-folder-readonly>`echo ${XDG_CACHE_HOME:-$HOME/.cache}/notmuch/mutt/results`<enter>\
<enter-command>set pipe_decode=\$my_old_pipe_decode wait_key=\$my_old_wait_key<enter>" \
"notmuch: reconstruct thread"

macro index <F6> \
"<enter-command>set my_old_pipe_decode=\$pipe_decode my_old_wait_key=\$wait_key nopipe_decode nowait_key<enter>\
<pipe-message>notmuch-mutt tag -- -inbox<enter>\
<enter-command>set pipe_decode=\$my_old_pipe_decode wait_key=\$my_old_wait_key<enter>" \
"notmuch: remove message from inbox"

上記のコードでは F8 で notmuch を使って受信ボックスを検索し、F9 で検索結果からスレッドを作成し、F6 で検索結果にタグを付けます。

notmuch-mutt の問題

cpan/cpanm でインストールされた perl モジュールと pacman でインストールした perl モジュールが一致しないために、以下のようなエラーが表示されることがあります:

Gnu.c: loadable library and perl binaries are mismatched (got handshake key 0xdb00080, needed 0xdb80080)

notmuch-mutt の依存パッケージを cpan か pacman どちらかでインストールするようにしてください。

NeoMutt の統合

neomutt を使用する場合、notmuch-mutt パッケージは必要ありません。かわりに、~/.mailboxes を作成して基本的な (仮想) メールボックスを記述してください:

~/.mailboxes
virtual-mailboxes "inbox" "notmuch://?query=tag:inbox"
virtual-mailboxes "archive" "notmuch://?query=tag:archive"
virtual-mailboxes "sent" "notmuch://?query=tag:sent"
virtual-mailboxes "newsletters" "notmuch://?query=tag:newsletters"

そして、仮想スプールファイルを有効化して mutt から仮想メールボックスを使えるようにしてください:

~/.muttrc
set virtual_spoolfile=yes
set folder=notmuch-root-folder
source ~/.mailboxes

この段階ではメールはまだタグ付けされていないため、mutt でメールボックスを見ても空のままです。仮想メールボックスを使うために、メールディレクトリのメールにタグを付ける必要があります。以下のようにシェルスクリプトを作成すると簡単です:

~/.scripts/notmuch-hook.sh
#!/bin/sh
notmuch new
# retag all "new" messages "inbox" and "unread"
notmuch tag +inbox +unread -new -- tag:new
# tag all messages from "me" as sent and remove tags inbox and unread
notmuch tag -new -inbox +sent -- from:me@example.org or from:me@myself.com
# tag newsletters, but dont show them in inbox
notmuch tag +newsletters +unread -new -- from:newsletter@example.org or subject:'newsletter*'

シェルスクリプトに実行可能属性を付与して実行:

$ chmod +x ~/.scripts/notmuch-hook.sh
$ ~/.scripts/notmuch-hook.sh

notmuch が新しいメッセージに 'new' とタグを付けるようになっていることを確認:

~/.notmuch-config
[new]
tags=new

最後に、新しいメールが来たときにフックスクリプトを実行するようにしてください。offlineimap を使って IMAP をローカルのメールディレクトリに同期している場合、以下の同期フックを作成:

~/.offlineimaprc
[Account myaccount]
postsynchook = ~/.scripts/notmuch-hook.sh

便利なキーバインド:

~/.muttrc
macro index A "<modify-labels>+archive -unread -inbox\\n" "Archive message"
macro index c "<change-vfolder>?" "Change to vfolder overview"
macro index \\\\ "<vfolder-from-query>" "Search mailbox"