コマンドラインから使えるIMAP対応のメーラを使ってみたくなったので、インストールしてみました。
CLIのIMAPメーラとして有名なNeoMuttをつかうことにしました。
以下のサイトを参考に進めていきました。

インストール先は、RaspberryPie4上のArchLinuxです。
インストール
まずはPacmanでインストールしていきます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
[root@raspi ~]# pacman -S neomutt resolving dependencies... looking for conflicting packages... Packages (8) gmime3-3.2.6-1 kyotocabinet-1.2.77-1 lmdb-0.9.24-1 lua-5.3.5-3 notmuch-runtime-0.29.3-2 talloc-2.3.1-1 xapian-core-1:1.4.14-1 neomutt-20191207-3 Total Download Size: 5.45 MiB Total Installed Size: 37.76 MiB :: Proceed with installation? [Y/n] y :: Retrieving packages... lua-5.3.5-3-armv7h 198.0 KiB 825 KiB/s 00:00 [######################] 100% xapian-core-1:1.... 1716.8 KiB 1301 KiB/s 00:01 [######################] 100% gmime3-3.2.6-1-a... 345.4 KiB 987 KiB/s 00:00 [######################] 100% talloc-2.3.1-1-a... 51.2 KiB 1707 KiB/s 00:00 [######################] 100% lmdb-0.9.24-1-armv7h 71.7 KiB 717 KiB/s 00:00 [######################] 100% notmuch-runtime-... 212.0 KiB 883 KiB/s 00:00 [######################] 100% kyotocabinet-1.2... 1491.7 KiB 1888 KiB/s 00:01 [######################] 100% neomutt-20191207... 1495.4 KiB 1824 KiB/s 00:01 [######################] 100% (8/8) checking keys in keyring [######################] 100% (8/8) checking package integrity [######################] 100% (8/8) loading package files [######################] 100% (8/8) checking for file conflicts [######################] 100% (8/8) checking available disk space [######################] 100% :: Processing package changes... (1/8) installing lua [######################] 100% (2/8) installing xapian-core [######################] 100% (3/8) installing gmime3 [######################] 100% (4/8) installing talloc [######################] 100% Optional dependencies for talloc python: for python bindings (5/8) installing notmuch-runtime [######################] 100% (6/8) installing lmdb [######################] 100% (7/8) installing kyotocabinet [######################] 100% (8/8) installing neomutt [######################] 100% Optional dependencies for neomutt python: keybase.py perl: smime_keys [installed] ca-certificates: default CA certificates [installed] :: Running post-transaction hooks... (1/1) Arming ConditionNeedsUpdate... |
接続用パスワードの暗号化準備
IMAPメールボックスの接続用パスワードは、定義ファイルに記載することになりますが、平文で保存するのはセキュリティ的にいろいろとまずいので、暗号化して保存します。
まずは、GPGコマンドでパスワードファイルを暗号化する準備をしていきます。
[USERID][MAILADDRESS]部分は、各自の名前とメールアドレスに置き換えてください。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
[boz@raspi ~]$ gpg --gen-key gpg (GnuPG) 2.2.19; Copyright (C) 2019 Free Software Foundation, Inc. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Note: Use "gpg --full-generate-key" for a full featured key generation dialog. GnuPG needs to construct a user ID to identify your key. Real name: [USERID] Email address: [MAILADDRESS] You selected this USER-ID: "[USERID] <[MAILADDRESS]>" Change (N)ame, (E)mail, or (O)kay/(Q)uit? o We need to generate a lot of random bytes. It is a good idea to perform some other action (type on the keyboard, move the mouse, utilize the disks) during the prime generation; this gives the random number generator a better chance to gain enough entropy. We need to generate a lot of random bytes. It is a good idea to perform some other action (type on the keyboard, move the mouse, utilize the disks) during the prime generation; this gives the random number generator a better chance to gain enough entropy. gpg: /home/boz/.gnupg/trustdb.gpg: trustdb created gpg: key 84C1733775DD443D marked as ultimately trusted gpg: directory '/home/boz/.gnupg/openpgp-revocs.d' created gpg: revocation certificate stored as '/home/boz/.gnupg/openpgp-revocs.d/8BCE8DD958C7C03B1E64A5128CE72D1B5EE176F7.rev' public and secret key created and signed. pub rsa2048 2020-03-08 [SC] [expires: 2022-03-08] 8BCE8DD958C7C03B1E64A5128CE72D1B5EE176F7 uid [USERID] <[MAILADDRESS]> sub rsa2048 2020-03-08 [E] [expires: 2022-03-08] |
パスワード設定
設定ファイルを格納するディレクトリを作成します。
1 |
[boz@raspi ~]$ mkdir ~/.config/neomutt |
作成したディレクトリにパスワードファイル~/.config/neomutt/passwdを作成します。ファイル名は自由です。
[PASSWORD]部分は、接続するアカウントのパスワードに置き換えてください。
1 2 |
set imap_pass="[PASSWORD]" set smtp_pass="[PASSWORD]" |
作成したパスワードファイルを暗号化します。
[USERID]部分は、先ほどGPGコマンドの初期化時に指定したものを指定してください。
1 2 3 4 5 |
[boz@raspi ~]$ gpg -r [USERID] -e ~/.config/neomutt/passwd gpg: checking the trustdb gpg: marginals needed: 3 completes needed: 1 trust model: pgp gpg: depth: 0 valid: 1 signed: 0 trust: 0-, 0q, 0n, 0m, 0f, 1u gpg: next trustdb check due at 2022-03-08 |
拡張子.gpgのついたファイルが生成されています。
このファイルが暗号化されたパスワードファイルになります。
平文のファイルが残っていては意味が無いので、削除しておきます。
1 |
[boz@raspi ~]$ shred -u ~/.config/neomutt/passwd |
通常のrmコマンドではなく、shredコマンドで消しました。
気にしない人はrmコマンドでも良いと思います。
接続設定
次にIMAPサーバへの接続設定です。
設定ファイル~/.config/neomutt/neomuttrcを作ります。
[]でくくった部分は、各自の設定に置き換えてください。
キーバインディング設定は、Vim風のものをGithubから頂きました。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
source "gpg -d ~/.config/neomutt/passwd.gpg |" # パスワード読み込み # 送信者情報 set realname = "[送信者名]" # 送信者名 set from = "[送信者メールアドレス]" # 送信者メールアドレス # 接続先サーバ情報 set hostname = "gmail.com" # 接続先ホスト名 set smtp_url = "smtps://[送信者メールアドレス]@smtp.gmail.com:465/" set imap_user = "[送信者メールアドレス]" # IMAPユーザ名 set folder = "imaps://imap.gmail.com:993" # 受信メールのロード先 # セキュリティ設定 set ssl_starttls = yes # STARTTLSの有効化 set ssl_force_tls= yes # TLSの使用を強制 # 環境設定 set sidebar_visible = yes # サイドバーの表示 set sidebar_format = "%B%?F? [%F]?%* %?N?%N/?%S" # サイドバーの書式 set mail_check_stats # メールの定期チェック有効化 set sort_aux = date # メール一覧を日付昇順で整列 set use_from = yes # Fromヘッダ自動生成の有効化 set editor = "vim" # エディタとしてvimを使用 set charset = "utf-8" # ターミナル文字コードの設定 set assumed_charset = "utf-8:iso-2022-jp:euc-jp:shift_jis" # 文字コードの優先順位を設定 set mbox_type = "maildir" # メールの保存形式 # mbox: 複数メールを連結した形式で保存 # maildir: 1メール1ファイルの形式で保存 set spoolfile = "+INBOX" # 未フィルタメールの受信先 mailboxes = =INBOX # 受信するディレクトリ set certificate_file = "~/.mutt/certificates" # CA証明書格納先 # キャッシュ設定 set header_cache= "~/.mutt/cache/headers" # ヘッダキャッシュ格納先 set message_cachedir= "~/.mutt/cache/bodies" # 本文キャッシュ格納先 # キーバインディング # Moving around bind attach,browser,index g noop bind attach,browser,index gg first-entry bind attach,browser,index G last-entry bind pager g noop bind pager gg top bind pager G bottom bind pager k previous-line bind pager j next-line # Scrolling bind attach,browser,pager,index \CF next-page bind attach,browser,pager,index \CB previous-page bind attach,browser,pager,index \Cu half-up bind attach,browser,pager,index \Cd half-down bind browser,pager \Ce next-line bind browser,pager \Cy previous-line bind index \Ce next-line bind index \Cy previous-line bind pager,index d noop bind pager,index dd delete-message # Mail & Reply bind index <Return> display-message # Threads bind browser,pager,index N search-opposite bind pager,index dT delete-thread bind pager,index dt delete-subthread bind pager,index gt next-thread bind pager,index gT previous-thread bind index za collapse-thread bind index zA collapse-all # Missing :folddisable/foldenable |
環境設定
メールを読むための環境を設定していきます。
CA証明書の格納ディレクトリを作成します。
1 |
[boz@raspi ~]$ mkdir -p ~/.mutt/certificates |
キャッシュ格納ディレクトリを作成します。
1 2 |
[boz@raspi ~]$ mkdir -p ~/.mutt/cache/headers [boz@raspi ~]$ mkdir -p ~/.mutt/cache/bodies |
キャッシュファイルはRAM上に格納するように、tmpfs領域をマウントします。rootユーザで/etc/fstabに以下の内容を追記します。
RaspberryPieはOSがSDカードなので、極力延命するためです。
サイズは100Mにしてみました。様子を見て変更しようと思います。
1 2 |
tmpfs /home/boz/.mutt/cache/headers tmpfs rw,size=100M,noexec,nodev,nosuid 0 0 tmpfs /home/boz/.mutt/cache/bodies tmpfs rw,size=100M,noexec,nodev,nosuid 0 0 |
変更したらmount -aコマンドを実行するか、再起動します。
1 2 3 4 5 6 |
[root@raspi ~]# mount -a [root@raspi ~]# df ファイルシス 1K-ブロック 使用 使用可 使用% マウント位置 ~~~ 省略 ~~~ tmpfs 102400 0 102400 0% /home/boz/.mutt/cache/headers tmpfs 102400 0 102400 0% /home/boz/.mutt/cache/bodies |
NeoMuttの起動
ここまで設定できたら、起動します。
1 |
[boz@raspi ~]$ neomutt |
初回だけパスワードを聞かれます。GPGの初期化時に設定したパスワードを入れてください。(IMAPのパスワードではないので、注意)
コメント