Notmuch 是一個郵件索引器。從本質上講,它是 xapian 之上的一個非常小的前端。 與 Sup 一樣,它只專注於一件事:為電子郵件建立索引。Notmuch 可用作電子郵件閱讀器,也可簡單地用作其他 MUA(如 mutt)的索引器和搜索工具。
概述
Notmuch 由 C 語言編寫,速度比 sup-mail 快一個數量級。 Notmuch 可以在索引過程中終止,下次運行時會繼續上次的工作。 與 sup-mail 一樣,它也不提供永久刪除不需要的電子郵件的方法(不過,請參閱#永久刪除電子郵件)。 它不能獲取或發送郵件,也不能存儲你的電子郵件地址,你需要使用 OfflineIMAP、msmtp 和 abook 等程序來完成這些任務。
安裝 notmuch包 軟體包。它提供了 python、vim 和 emacs 綁定。
初次使用
安裝完成後,您可以運行以下程序進入交互式設置:
notmuch setup
程序會提示你輸入郵箱地址、主郵箱地址和副郵箱地址。你也可以直接編輯配置文件,該文件默認創建在 $HOME/.notmuch-config
。
郵件目錄的後續重新索引通過
notmuch new
前端
有 一系列使用 notmuch 的方法,包括 CLI 或 Unix $EDITORS
:
Emacs
notmuch 的默認前端是 Emacs。它是由開發 notmuch 的同一批人開發的。
Vim
notmuch-vim包 軟體包中包含一個 Vim 界面。要啟動它,請鍵入:
vim -c NotMuch
alot
alot 是用 Python 編寫的 notmuch 獨立 CLI 界面。它以 alot包 和 alot-gitAUR 的形式提供。
Alot 使用 mailcap 來處理不同類型的文件。目前包括 HTML 郵件,這意味著您需要配置一個 ~/.mailcap
文件才能查看 HTML 郵件。至少要在 ~/.mailcap
中加入這一行:
text/html; w3m -dump -o -document_charset=%{charset} %s; nametemplate=%s.html; copiousoutput
此處使用 w3m包,也可使用其他基於文本的客戶端,如 links包 或 lynx包,但它們的參數可能有所不同。
當然,還可以配置更多的文件處理程序。
bower
bower 是另一個 CLI 界面,使用 Mercury 編寫。可通過 bower-mailAUR 獲取。
Neomutt
Neomutt - 另一個包含許多功能補丁的 mutt fork,其中包括 Notmuch 集成補丁。安裝 neomutt包 或 neomutt-gitAUR 軟體包。
astroid
Astroid 是一款使用 C++ 和 GTK 編寫的圖形化 MUA 和 notmuch 界面。可通過 astroid包 或 astroid-gitAUR 安裝。GUI 設計非常快速,可預覽 HTML 和附件,並可通過鍵盤導航。它可以進行大量配置,你可以使用自己喜歡的嵌入式編輯器,也可以從外部啟動它。查看 Tour 了解如何使用 astroid 以及完整設置的說明,或查看 README 了解更多信息。
與 mutt 集成
如果你使用 mutt 作為你的 MUA,那麼 notmuch 就是你索引和搜索郵件的絕佳輔助工具。notmuch-mutt包 軟體包提供了將 notmuch 與 mutt 集成的腳本。
安裝 notmuch-mutt包 軟體包並配置 notmuch 後,在使用 notmuch 從 mutt 進行搜索前,只需添加按鍵綁定以從 mutt 調用 notmuch-mutt
perl 腳本。notmuch contrib source 建議在 .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
標記搜索結果。
與 NeoMutt 集成
如果使用 neomutt包,則不需要 notmuch-mutt包 軟體包。取而代之的是,創建一個包含一些基本(虛擬)郵箱的 ~/.mailboxes
。虛擬郵箱並非實際文件夾,而是 notmuch 查詢特定標記的結果:
~/.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"
接下來,啟用虛擬 spoolfile 並將其作為來源,讓 mutt 知曉虛擬郵箱:
~/.muttrc
set virtual_spoolfile=yes set folder=notmuch-root-folder source ~/.mailboxes
此時,mutt 仍然會把你的郵箱列為空郵箱,因為你的郵件還沒有被標記,所以查詢的郵件也不是很多。要填滿虛擬郵箱,首先需要標記郵件目錄中的郵件。一個非常簡單的方法是創建一個 shell 腳本,如下所示:
~/.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*'
將 shell 腳本設置為可執行並運行它:
~/.scripts/notmuch-hook.sh
為使上述示例有效,請確保 notmuch 將新信息標記為 'new':
~/.notmuch-config
[new] tags=new
最後,您的鉤子腳本需要在新郵件到達時重新運行。如果使用 offlineimap包 將 IMAP 同步到本地 maildir,則需要創建一個同步後鉤子:
~/.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"
永久刪除電子郵件
一種方法是為希望從磁碟中刪除的郵件保留一個標籤,例如 "已刪除"。然後,你可以將搜索標籤與 xargs
結合起來,永久刪除它們:
notmuch search --output=files --format=text0 tag:killed | xargs -r0 rm notmuch new
將此鉤子放入 notmuch 的 pre-new
鉤子中,就能確保在更新資料庫前刪除文件。
參見
- notmuch 官方網站
- notmuch 倉庫
- muchsync - 跨設備同步 Notmuch 郵件
- lieer - 快速獲取和發送電子郵件,並在 notmuch 和 GMail 之間實現雙向標籤同步