OfflineIMAP と Gmail
ふと Gmail が Emacs (Spacemacs) で 読みたくなったのと mu4e が気になってきたので、準備している。
mu4e はmu のフロントエンドであり、mu そのものには IMAP を使う術を持ち合わせていないために、OfflineIMAP を以って手許の Maildir と同期させる必要がある。
期待を裏切らず Archlinux Wiki の OfflineIMAP 項 が参考になる。また、本家マニュアル Gmail configuration (Mu4e 1.2.0 user manual) や A Complete Guide to Email in Emacs using Mu and Mu4e も参考にした。
Google 側の設定
Google アカウント設定 でメール専用パスワードを発行する。詳しくは Sign in using App Passwords - Google Account Help を見よ。
その後、GMail の設定項目欄にて IMAP を有効化する。
OfflineIMAP の設定
# ~/.offlineimaprc [general] accounts = Gmail maxsyncaccounts = 2 pythonfile = ~/.offlineimaprc.py [Account Gmail] localrepository = LocalGmail remoterepository = RepositoryGmail autorefresh = 5 quick = 10 postsynchook = mu index --maildir ~/Maildir [Repository LocalGmail] type = Maildir localfolders = ~/Maildir/Gmail [Repository RepositoryGmail] type = Gmail maxconnections = 2 remoteuser = <account>@gmail.com remotepass = <password> # folderfilter = lambda foldername: foldername not in ['[Gmail]/All Mail', '[Gmail]/Important'] sslcacertfile = /usr/local/etc/openssl/cert.pem
メールの件数にもよるが、信じられない程の時間が掛かる(体感0.7秒毎通)ので、もしかすると、[Gmail]/All Mail
と '[Gmail]/Important
は同期対象から外した方が良いのかもしれない。
パスワードを Mac OS X のキーチェーンに格納したい場合には Use Mac OS X's Keychain for Password Retrieval in OfflineIMAP が参考になる。
また、IMAP4 ではメールボックス名は修正 UTF-7 でエンコードされていて、これは mu 等のメールクライアントの期待する形式ではない為に、非 ASCII 文字を含む mailbox 名を使いたければ、これを変換する必要がある。Utf 8 issues · sup-heliotrope/sup Wiki · GitHub を見よ。
mu4e の設定
Gmail configuration (Mu4e 1.2.0 user manual) を見よ。
(setq mu4e-maildir "~/Maildir/Gmail" mu4e-drafts-folder "/[Gmail].Drafts" mu4e-sent-folder "/[Gmail].Sent Mail" mu4e-trash-folder "/[Gmail].Trash") ;; don't save message to Sent Messages, Gmail/IMAP takes care of this (setq mu4e-sent-messages-behavior 'delete) ;; (See the documentation for `mu4e-sent-messages-behavior' if you have ;; additional non-Gmail addresses and want assign them different ;; behavior.) (setq user-mail-address "<username>@gmail.com" user-full-name "<name>" mu4e-compose-signature (concat "<name>\n")) (setq message-send-mail-function 'smtpmail-send-it smtpmail-stream-type 'starttls smtpmail-default-smtp-server "smtp.gmail.com" smtpmail-smtp-server "smtp.gmail.com" smtpmail-smtp-service 587)