「Mutt」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
170行目: 170行目:
 
}}
 
}}
   
  +
SMTP 資格情報が IMAP 資格情報と同じである場合、これらの変数を使用できることに注意してください。
Note that if your SMTP credentials are the same as your IMAP credentials, then you can use those variables:
 
   
 
{{bc|1=
 
{{bc|1=

2020年8月27日 (木) 02:39時点における版

関連記事

Mutt は強力な機能を持っていることで知られているテキストベースのメールクライアントです。20年以上前に作られたメールクライアントでありながら、Mutt は今でも多くのパワーユーザーから愛用されています。

Mutt は主にメールユーザエージェント (MUA) として開発されており、最初はメールを読むために書かれました。他のメールアプリケーションと比べて後の実装 (メールの取得・送信・フィルタリングの追加) はシンプルとなっており、ユーザーは外部のアプリケーションを使って Mutt の機能を拡張できます。

しかしながら、Arch Linux の mutt パッケージは IMAP や POP3、SMTP のサポートを有効にしてコンパイルされているため、外部アプリケーションの必要はありません。

この記事ではネイティブの IMAP を使ってメールを送受信する方法と、OfflineIMAPgetmail (POP3) を使ってメールを取得し、POP3 の場合 procmail でフィルタリングして、msmtp でメールを送信する方法の両方を説明します。

目次

インストール

mutt パッケージをインストールしてください。

任意で isync, OfflineIMAP, msmtp などの外部のヘルパーアプリケーションをインストールしてください (IMAP セットアップをする場合)。

もしくは (POP3 を使う場合) getmail, fetchmailAUR, fdm, procmail をインストールしてください。

ノート:
  • LOGIN と PLAIN で認証するだけであれば、依存パッケージの libsasl だけで使うことができます。
  • CRAM-MD5, GSSAPI, DIGEST-MD5 を使用する場合は cyrus-sasl-gssapi パッケージをインストールしてください。
  • SMTP サーバーとして Gmail を使用する場合は cyrus-sasl パッケージもインストールする必要があります。

NeoMutt

NeoMutt プロジェクトは Mutt にあらゆるパッチを適用しています。パッチによって膨大な数の 機能 が追加されます。古い Mutt のパッチの多くは更新・整理されドキュメント化されています。

AUR には mutt の別バージョンのパッケージが存在していますが、NeoMutt は適切なコンパイルオプションを実行することでそれらを置き換えます。現在、NeoMutt は AUR の neomuttneomutt-gitAUR でインストールできます。

設定

このセクションでは #IMAP, #POP3, #Maildir, #SMTP の設定を扱います。

デフォルトで Mutt は2つのディレクトリから設定ファイルを認識します: ~/.muttrc~/.mutt/muttrc。どちらでも問題ありません。別の場所に設定ファイルを配置したい場合は $ mutt -F /path/to/.muttrc を使ってください。また、Mutt の設定の要件をある程度知る必要があります。Mutt の構文は Bourne Shell とよく似ています。例えば、別の設定ファイルを読み込むには:

source /path/to/other/config/file

シェルコマンドの結果を変数に入れることができます:

set editor=`echo \$EDITOR`

ここで $ はエスケープされるためシェルに渡される前に Mutt によって置き換えることはありません。Bash 構文の $(...) は使えないためバッククォートを使用することを覚えておいてください。Mutt には定義済み変数がたくさん存在しますが、自分で設定することもできます。ユーザー変数には必ず前に "my" を付ける必要があります:

set my_name = "John Doe"

IMAP

ネイティブの IMAP サポート

mutt パッケージは IMAP のサポートを有効にしてコンパイルされています。最低でも muttrc ファイルに4行を記述すればメールにアクセスすることができます。

imap_user
set imap_user=USERNAME
ヒント: 前の例を続けると、Gmailには完全なメールアドレスが必要です(これは標準ではありません)
set imap_user=your.username@gmail.com
imap_pass

設定されていない場合、パスワードが要求されます。

set imap_pass=SECRET
ヒント: Gmail で2段階認証を有効にしている場合、Mutt のためにアプリケーションパスワードを追加して、通常の Gmail パスワードの代わりに使うことができます。
folder

ローカルディレクトリに全てのメール (とディレクトリ) を保存するかわりに、サーバーを使用します (必要であれば最上階のフォルダも)。

set folder=imap[s]://imap.server.domain[:port]/[folder/]

フォルダを使用する必要はありませんが、他のフォルダが全て受信フォルダの中にある場合などに有用です。設定したフォルダは Mutt でイコール記号 (=) とプラス記号 (+) を使ってアクセスできます。例:

set folder=imaps://imap.gmail.com/

複数のアカウントを使用する場合、フォルダを分けるのがベストプラクティスです (例: account-hook)。複数の Gmail アカウントを持っている場合:

set folder=imaps://username@imap.gmail.com/

username@gmail.com はあなたのアカウントに置き換えてください。こうすることでフォルダを区別できるようになります。設定しないと認証エラーが発生します。

spoolfile

スプールファイルは、(フィルタリングされていない)電子メールが到着するフォルダーです。ほとんどの電子メールサービスでは、通常、INBOX という名前が付けられています。上記で設定したフル folder パスの代わりに「=」または「+」を使用できるようになりました。例えば:

mailboxes

新着メールがないか定期的にチェックする必要がある imap フォルダーをここにリストします。

mailboxes =INBOX =family
mailboxes imaps://imap.gmail.com/INBOX imaps://imap.gmail.com/family

または、すべてのサブスクライブされた IMAP フォルダーを確認します(すべての mailboxes で追加)

set imap_check_subscribed

これら2つのバージョンは、すべてのフォルダーをサブスクライブする場合は同等です。したがって、2番目の方法の方がはるかに便利ですが、最初の方法の方が柔軟性が高くなります。また、新しいバージョンの Mutt は、デフォルトで「y」キーにバインドされたマクロを含むように設定されており、メールボックスの下にリストされているフォルダーのいずれかに変更できます。

変数を設定しなかった場合、デフォルトで spoolfile が使われます。サイドバーでも使用する変数です。

まとめ

これらのオプションを使用すると、Mutt を起動し、IMAP パスワードを入力して、メールの読み取りを開始できます。以下は、IMAP サポートを改善するために追加を検討する可能性のある他の行を含む muttrc スニペット (Gmail用) です。

set folder      = imaps://imap.gmail.com/
set imap_user   = your.username@gmail.com
set imap_pass   = your-imap-password
set spoolfile   = +INBOX
mailboxes       = +INBOX

# Store message headers locally to speed things up.
# If hcache is a folder, Mutt will create sub cache folders for each account which may speeds things up even more.
set header_cache = ~/.cache/mutt

# Store messages locally to speed things up, like searching message bodies.
# Can be the same folder as header_cache.
# This will cost important disk usage according to your e-mail amount.
set message_cachedir = "~/.cache/mutt"

# Specify where to save and/or look for postponed messages.
set postponed = +[Gmail]/Drafts

# Allow Mutt to open new imap connection automatically.
unset imap_passive

# Keep IMAP connection alive by polling intermittently (time in seconds).
set imap_keepalive = 300

# How often to check for new mail (time in seconds).
set mail_check = 120

外部の IMAP サポート

IMAP のサポートは Mutt に組み込まれていますが、オフラインで読むためにメールをダウンロードすることはしません。OfflineIMAPisync などの外部のアプリケーションを使うことでメールをローカルフォルダにダウンロードして、それを Mutt で処理することが可能です。

メールをソートしたい場合は spamassassinimapfilterAUR などのアプリケーションを使います。

POP3

mutt パッケージは POP3 のサポートを有効にしてコンパイルされています。muttrc(5) で説明されているように pop_* 変数で設定できます。

また、外部のプログラムを使って POP3 でメールを取得することもできます。メールの取得には getmail を使ってメールのフィルタリングには procmail を使うのが人気のある選択肢です。

Maildir

Maildir は汎用・標準のフォーマットです。ほとんど全ての MUA が Maildir を処理でき、Mutt もサポートしています。Mutt で Maildir を使用するために必要な設定は少しだけです。muttrc を開いて以下の行を追加してください:

set mbox_type=Maildir
set folder=~/mail
set spoolfile=+/
set header_cache=~/.cache/mutt

上記は Maildir にアクセスして INBOX に新しいローカルメールが存在しないか確認するだけの最小設定です。上記の設定はメールのヘッダーをキャッシュしてディレクトリの表示を高速化します。(Arch の公式パッケージを使っていない場合) キャッシュは使用できない可能性があります。上記の設定は OfflineIMAP には影響を与えないので注意してください。常にサーバー上の全てのディレクトリを同期します。spoolfile は Mutt が新しいメールが来ていないか問い合わせるローカルディレクトリです。メーリングリストのディレクトリなどスプールファイルは追加することができます。詳しい設定方法は Mutt のマニュアルを参照してください。

SMTP

POP や IMAP を使ってメールを受け取る場合でもメールを送信するときは SMTP を使います。

フォルダ

ここには基本的に重要なフォルダが1つだけあります。送信されたすべての電子メールが保存されるフォルダです。

set record = +Sent

Gmail は送信したメールを自動的に +[Gmail]/Sent に保存するため、重複させないようにします:

unset record

ネイティブの SMTP サポート

公式の mutt は SMTP のサポートを有効にしてコンパイルされています。

例:

set my_pass='mysecretpass'
set my_user=myname

set realname = 'Your Real Name'
set from = your-email-address
set use_from = yes

set smtp_url=smtps://$my_user:$my_pass@smtp.domain.tld
set ssl_force_tls = yes

SMTP 資格情報が IMAP 資格情報と同じである場合、これらの変数を使用できることに注意してください。

set smtp_url=smtps://$imap_user:$imap_pass@smtp.domain.tld

セキュリティパラメータは変更する必要があるかもしれません。例えば以下のようなエラーが表示される場合:

SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol

サーバーは SMTPS ではなく SMTP を使っているため、以下のように設定する必要があります:

set smtp_url=smtp://$imap_user:$imap_pass@smtp.domain.tld

他にも設定する必要がある変数が存在します。例えば STARTTLS を使用する場合:

set ssl_starttls = yes

詳しくは man 5 muttrc を見て下さい。

外部の SMTP サポート

msmtp, SSMTP, opensmtpd など外部の SMTP エージェントを使うこともできます。

muttrcsendmail 変数で mutt でメールを配達するのに使用するプログラムと引数を定義できます。追加引数はプログラムによって受取人のアドレスとして解釈されます。

例えば、msmtp を使う場合:

muttrc
set realname='Disgruntled Kangaroo'

set sendmail="/usr/bin/msmtp"

set edit_headers=yes
set folder=~/mail
set mbox=+mbox
set spoolfile=+inbox
set record=+sent
set postponed=+drafts
set mbox_type=Maildir

mailboxes +inbox +lovey-dovey +happy-kangaroos

Mutt からメールを送信

設定したら mutt を起動してください:

~/mail/inbox にあるメールが全て表示されます。m を押すとメールを書くことができます。EDITOR 環境変数で設定されたエディタが使われます。変数が設定されていない場合、Mutt を起動する前に設定できます:

$ export EDITOR=your-favorite-editor
$ mutt

EDITOR はシェルの設定ファイル (bashrc など) に保存するべきです。Mutt の設定ファイルでエディタを設定することもできます:

.muttrc
set editor=your-favorite-editor

For testing purposes, address the letter to yourself. After you have written the letter, save and exit the editor. You will return to Mutt, which will now show information about your e-mail. Press y to send it.

警告: If at this point you press q by accident, Mutt will ask you Postpone this message? ([yes]/no). This is really asking whether you want to save the message you just wrote. If you press "n" (perhaps because you want to edit the message again) the message will be permanently deleted. When using Mutt, always remember that "Postpone this message?" really means "Save this message?".

マルチアカウント

Now you should have a working configuration for one account at least. You might wonder how to use several accounts, since we put everything into a single file.

Well all you need is to write account-specific parameters to their respective files and source them. All the IMAP/POP3/SMTP config for each account should go to its respective folder.

警告: When one account is setting a variable that is not specified for other accounts, you must unset it for them, otherwise configuration will overlap and you will most certainly experience unexpected behaviour.

Mutt can handle this thanks to one of its most powerful features: hooks. Basically a hook is a command that gets executed before a specific action. There are several hooks available. For multiple accounts, you must use account-hooks and folder-hooks.

  • Folder-hooks will run a command before switching folders. This is mostly useful to set the appropriate SMTP parameters when you are in a specific folder. For instance when you are in your work mailbox and you send a e-mail, it will automatically use your work account as sender.
  • Account-hooks will run a command everytime Mutt calls a function related to an account, like IMAP syncing. It does not require you to switch to any folder.

Hooks take two parameters:

account-hook [!]regex command
folder-hook [!]regex command

The regex is the folder to be matched (or not if preceded by the !). The command tells what to do.

Let us give a full example:

.muttrc
## General options
set header_cache = "~/.cache/mutt"
set imap_check_subscribed
set imap_keepalive = 300
unset imap_passive
set mail_check = 60
set mbox_type=Maildir

## ACCOUNT1
source "~/.mutt/work"
# Here we use the $folder variable that has just been set in the sourced file.
# We must set it right now otherwise the 'folder' variable will change in the next sourced file.
folder-hook $folder 'source ~/.mutt/work'

## ACCOUNT2
source "~/.mutt/personal"
folder-hook *user@gmail.com/ 'source ~/.mutt/personal'
folder-hook *user@gmail.com/Family 'set realname="Bob"'
.mutt/work
## Receive options.
set imap_user=user@gmail.com
set imap_pass=****
set folder = imaps://user@imap.gmail.com/
set spoolfile = +INBOX
set postponed = +Drafts
set record = +Sent

## Send options.
set smtp_url=smtps://user:****@smtp.gmail.com
set realname='User X'
set from=user@gmail.com
set hostname="gmail.com"
set signature="John Doe"
# Connection options
set ssl_force_tls = yes
unset ssl_starttls

## Hook -- IMPORTANT!
account-hook $folder "set imap_user=user@gmail.com imap_pass=****"

Finally .mutt/personal should be similar to .mutt/work.

全てのアカウントを設定したら Mutt を起動してください。フォルダを変えればアカウントを切り替えることができます (c キー)。もしくはサイドバーを使うこともできます。

To change folder for different mailboxes you have to type the complete address -- for IMAP/POP3 folders, this may be quite inconvenient -- let us bind some key to it.

## Shortcuts
macro index,pager <f2> '<sync-mailbox><enter-command>source ~/.mutt/personal<enter><change-folder>!<enter>'
macro index,pager <f3> '<sync-mailbox><enter-command>source ~/.mutt/work<enter><change-folder>!<enter>'

With the above shortcuts (or with the sidebar) you will find that changing folders (with c by default) is not contextual, i.e. it will not list the folders of the current mailbox, but of the one used the last time you changed folders. To make the behaviour more contextual, the trick is to press = or + for current mailbox. You can automate this with the following macro:

macro index 'c' '<change-folder>?<change-dir><home>^K=<enter>'

パスワード管理

.muttrc にパスワードを記述することはセキュリティ的に問題があります。毎回手動でパスワードを入力するという方法もありますが、面倒です。

GnuPG を使ってパスワードを暗号化しファイルに保存するという解決方法が存在します。まだキーペアを設定していない場合、先に作成してください。以下の内容で tmpfs にファイルを作成:

set my_pass = " password"
ノート: ユーザー定義変数は必ず最初に my_ を付ける必要があります。

あなた自身を受取人としてファイルを暗号化し、アクセス可能なディレクトリに移動してください。以下の例では暗号化したファイルを $HOME/.my-pwds.gpg に配置しています。

mutt の設定ファイルに以下を追加 (アカウントの前に追加してください):

source "gpg -dq $HOME/.my-pwds.gpg |"
ノート: 上記の行の末尾にあるパイプとダブルクォートの間に空白は挟みません。

上記の設定でファイルが復号化され my_pass 変数が設定されます。source された後は変数を自由に使うことができます。例:

set imap_pass=$my_pass

OfflineIMAP や msmtp などの外部ツールを使用する場合、エージェント (例: gpg-agent、GnuPG#gpg-agent を参照) を設定してパスフレーズをキャッシュに保存して何度もパスワードが聞かれないようにしてください。

セキュリティの問題

If enter-command is available from the UI, it is possible to see the password unencrypted, which may be undesired if anybody else than you has access to your session while Mutt is running. You may want to disable it for this reason. As a consequence, every command that the user intends to use must be bound to a key in advance, otherwise it will never be accessible.

.muttrc
 bind generic,alias,attach,browser,editor,index,compose,pager,pgp,postpone ':' noop

ヒントとテクニック

Guides to get you started with using & customizing Mutt :

Mutt について何か疑問があったら、IRC チャンネルで質問してください。

キーバインディング

デフォルトのキーバインドは Emacs や Vi などの一般的なバインドとかけ離れています。自由に設定することができます。Mutt にはページャ・インデックス・添付ビューなどに様々なバインドのセットが用意されています。キーをバインドしたいときは編集したいマップを指定してください。Mutt のヘルプページからコマンドとキーバインドのリストを確認できます (デフォルトキー: ?)。Vi ライクなバインドの例:

muttrc
bind pager j next-line
bind pager k previous-line
bind attach,index,pager \CD next-page
bind attach,index,pager \CU previous-page
bind pager g top
bind pager G bottom
bind attach,index g first-entry
bind attach,index G last-entry

作成

メールの暗号化と署名 (GnuPG)

GnuPG を使って mutt でメールを暗号化するには /usr/share/doc/mutt/samples/gpg.rc を mutt の設定フォルダにコピーしてください (例: ~/.mutt/gpg.rc)。そして mutt の設定ファイルに以下を追加してください (例: ~/.mutt/mutrrc):

source ~/.mutt/gpg.rc

コンポーズビューで p を押すことで暗号化オプションを使うことができるようになります。

詳しくは muttrc(5)pgp_*crypt_* オプションを見てください。

メールの文字エンコーディング

When using Mutt there are two levels where the character sets that must be specified:

  • The text editor used to write the e-mail must save it in the desired encoding.
  • Mutt will then check the e-mail and determine which encoding is the more appropriate according to the priority you specified in the send_charset variable. Default: "us-ascii:iso-8859-1:utf-8".

So if you write an e-mail with characters allowed in ISO-8859-1 (like 'résumé'), but without characters specific to Unicode, then Mutt will set the encoding to ISO-8859-1.

To avoid this behaviour, set the variable in your muttrc:

set send_charset="us-ascii:utf-8"

or even

set send_charset="utf-8"

The first compatible charset starting from the left will be used. Since UTF-8 is a superset of US-ASCII it does not harm to leave it in front of UTF-8, it may ensure old MUA will not get confused when seeing the charset in the e-mail header.

カスタムメールヘッダ

Mutt ではメールヘッダを完全に制御することができます。

メールを書くときにヘッダを編集できるようにするには:

set edit_headers=yes

Mutt also features a special function my_hdr for customizing your header. Yes, it is named just like a variable, but in fact it is a function.

You can clear it completely, which you should do when switching accounts with different headers, otherwise they will overlap:

unmy_hdr *

Other variables have also an impact on the headers, so it is wise to clear them before using my_hdr:

unset use_from
unset use_domain
unset user_agent

Now, you can add any field you want -- even non-standard one -- to your header using the following syntax:

my_hdr <FIELD>: <VALUE>

Note that <VALUE> can be the result of a command.

Example:

## Extra info.
my_hdr X-Info: Keep It Simple, Stupid.

## OS Info.
my_hdr X-Operating-System: `uname -s`, kernel `uname -r`

## This header only appears to MS Outlook users
my_hdr X-Message-Flag: WARNING!! Outlook sucks

## Custom Mail-User-Agent ID.
my_hdr User-Agent: Every email client sucks, this one just sucks less.

署名ブロック

ホームディレクトリに .signature を作成してください。署名はメールの末尾に追加されます。もしくは Mutt の設定でファイルを指定することもできます:

set signature="path/to/sig/file"
ランダム署名

fortune (パッケージ: fortune-mod) を使うことで Mutt にランダムに署名を追加することができます。

fortune ファイルを作成して以下の行を .muttrc に追加してください:

set signature="fortune pathtofortunefile|"

Note the pipe at the end. It tells Mutt that the specified string is not a file, but a command.

Mutt を使ってコマンドラインからメールを送信

Man pages will show all available commands and how to use them, but here are a couple of examples. You could use Mutt to send alerts, logs or some other system information, triggered by login through .bash_profile, or as a regular cron job.

メッセージを送信:

mutt -s "Subject" somejoeorjane@someserver.com < /var/log/somelog

添付ファイルを付けてメッセージを送信:

mutt -s "Subject" somejoeorjane@someserver.com -a somefile < /tmp/sometext.txt

HTML メールの作成

Mutt は WYSIWIG クライアントではないため、HTML はそのままソースコードを直接編集して扱うことができます。HTML 構文を使ってメールを書くだけです。例:

This is normal text<br>
<b>This is bold text</b>

メールを送信する前に、edit-type コマンドを使って (デフォルトのショートカット: Ctrl+t)、text/plaintext/html に置き換えてください。

ノート: HTML e-mails are regarded by many people as useless, cumbersome, and subject to reading issues. Mutt can read HTML mails with a text browser like w3m or lynx, but it has clearly no advantage over a plain-text e-mail. You should avoid writing HTML e-mails when possible.

作成中に他のメールを表示

Mutt のよくある不満として、新しいメール (あるいは返信) を作成しているときに、現在のメールを閉じないと (後回しにしないと) 他のメールを開けないというものがあります。以下の方法で解決できます:

まず、通常通り Mutt を立ち上げてください。そして、別のターミナルウィンドウを起動します。そして次のコマンドで新しい Mutt を起動:

mutt -R

これで読み取り専用モードで Mutt が起動するので、他のメールを自由に閲覧することができます。2番目の Mutt は必ず読み取り専用モードで起動することを強く推奨します。衝突が発生してしまう可能性があるためです。

ノート: When changing folders (with c or y) the read-only mode is not preserved. Instead Esc c has to be used.
ヒント: 上記の解決法では多少入力が必要になるため、キーボードショートカットに以下のコマンドをバインドすると良いでしょう (詳しくは特別なキーボードキーを参照):
$TERMINAL -e mutt -R
$TERMINAL は使用しているターミナルに置き換えて下さい。

印刷

muttprintAUR をインストールすることで印刷の品質を向上することができます。muttrc ファイルに以下の行を追加してください:

set print_command="/usr/bin/muttprint %s -p {PrinterName}"

コンテンツの表示

URL を表示 & ウェブブラウザの起動

Your should start by creating a .mutt directory in $HOME if not done yet. There, create a file named macros. Insert the following:

 macro pager \cb <pipe-entry>'urlview'<enter> 'Follow links with urlview'

Then install the urlviewAUR package.

Create a .urlview in $HOME and insert the following:

REGEXP (((http|https|ftp|gopher)|mailto)[.:][^ >"\t]*|www\.[-a-z0-9.]+)[^ .,;\t>">\):]
COMMAND <your-browser> %s

When you read an email on the pager, hitting ctrl+b will list all the urls from the email. Navigate up or down with arrow keys and hit enter on the desired url. Your browser will start and go to the selected site.

Some browser will require additional arguments to work properly. For example, Luakit will close on Mutt exit. You need to fork it to background, using the -n parameter:

COMMAND luakit -n %s 2>/dev/null

The 2>/dev/null is to make it quiet, i.e. to prevent useless message printing where you do not want them to.

ノート: urlview has a few deficiencies (e.g. the inability to handle certain email encodings) and is fairly feature-bare (e.g. it does not provide context for links it finds). There are a couple alternatives that do better. One, which can handle all email encodings and provides link context, is extract_url.pl. Another, which can also provide link context but cannot handle all email encodings, is urlscan-gitAUR. Both are drop-in replacements for urlview, though extract_url has features which benefit from additional configuration changes.

HTML の表示

It is possible to pass the html body to an external HTML program and then dump it, keeping email viewing uniform and unobtrusive. Three programs are described here: lynx, w3m and elinks (make sure the selected package is installed).

If ~/.mutt/mailcap does not exist you will need to create it and save the following to it.

text/html; lynx -assume_charset=%{charset} -display_charset=utf-8 -dump %s; nametemplate=%s.html; copiousoutput

or, in case of w3m,

text/html; w3m -I %{charset} -T text/html; copiousoutput;

or, in case of elinks,

text/html; elinks -dump ; copiousoutput;

Edit muttrc and add the following,

set mailcap_path 	= ~/.mutt/mailcap

To automatically open HTML messages in lynx, w3m or elinks add this additional line to the muttrc:

auto_view text/html

The beauty of this is, instead of seeing an html body as source or being opened by a separate program, in this case lynx, you see the formatted content directly, and any url links within the email can be displayed with Ctrl+b, assuming you have urlviewAUR installed.

If you receive many emails with multiple or alternate encodings Mutt may default to treating every email as html. To avoid this, add the following variable to your ~/.muttrc to have Mutt default to text when available and use w3m/lynx only when no text version is availble in the email:

alternative_order text/plain text/html

Some HTML mails may not display correctly in a text-based web browser. As a fallback solution, you can bind a key to open a graphical browser in such cases. The following macro will open the HTML mail selected from the attachment view in the web browser defined in the environment. (Feel free to adapt the ~/.cache/mutt/ folder).

macro attach 'V' "<pipe-entry>cat >~/.cache/mutt/mail.html && $BROWSER ~/.cache/mutt/mail.html && rm ~/.cache/mutt/mail.html<enter>"

メッセージビューのフィルタリング

You can restrict the view to e-mails matching a pattern and specific properties with the limit command (default shortcut: l).

To view all e-mails containing "foo" in the header, simply write "foo" and you are done. To remove the filter, use the "all" keyword.

To view all flagged messages, use

~F

To view all unread messages that are either of size ≥1MB or from johndoe, use

~U (~z 1M- | ~f johndoe)

All possible patterns are listed in the official manual.

会話のグループ化

The default sort order is by date. Use the sort-mailbox command (default key: o) to change the sorting option. You can group e-mails by conversation/thread, in which case you can define how to sort threads and how to sort within a thread.

In the following example, threads are sorted according to the date of their last e-mail.

muttrc
set sort=threads
set sort_aux=last-date-received

mutt とエディタの設定

vim

  • To limit the width of text to 72 characters, edit your .vimrc file and add:
au BufRead /tmp/mutt-* set tw=72
  • Another choice is to use Vim's mail filetype plugin to enable other mail-centric options besides 72 character width. Edit ~/.vim/filetype.vim, creating it if unpresent, and add:
augroup filetypedetect
  " Mail
  autocmd BufRead,BufNewFile *mutt-*              setfiletype mail
augroup END
  • To set a different tmp directory, e.g. ~/.tmp, add a line to your muttrc as follows:
set tmpdir="~/.tmp"
  • To reformat a modified text see the Vim context help
:h 10.7

GNU nano

nano is another nice console editor to use with Mutt.

To limit the width of text to 72 characters, edit your .nanorc file and add:

set fill 72

Also, in muttrc file, you can specify the line to start editing so that you will skip the mail header:

set editor="nano +7"

Emacs

Emacs には mailmessage メジャーモードが存在します。Mutt から Emacs が呼び出されたときに自動的に mail-mode に切り替えるには、.emacs に以下を追加:

.emacs
;; Mutt support.
(setq auto-mode-alist (append '(("/tmp/mutt.*" . mail-mode)) auto-mode-alist))

Emacs デーモンを使っている場合、Mutt から接続するには以下を .muttrc に追加:

.muttrc
set editor="emacsclient -a \"\" -t"

表示設定

カラー

.muttrc ファイルにサンプルのカラー定義を追加してから自由にカスタマイズしてください:

$ cat /usr/share/doc/mutt/samples/colors.linux >> ~/.muttrc

The actual color each of these settings will produce depends on the colors set in your ~/.Xresources file.

Alternatively, you can source any file you want containing colors (and thus act as a theme file):

source ~/.mutt/colors.zenburn

テーマのサンプルは [1] を見てください。

インデックスフォーマット

Here follows a quick example to put in your .muttrc to customize the Index Format, i.e. the columns displayed in the folder view.

set date_format="%y-%m-%d %T"
set index_format="%2C | %Z [%d] %-30.30F (%-4.4c) %s"

詳しくは Mutt Reference, man 3 strftime, man 3 printf を見てください。

"Sent" フォルダビューで送信者ではなく受信者を表示

By default Mutt will display the sender in the index view. It is fine for most folders, but rather useless for the one where you store a copy of your sent e-mails since it will always display your name.

The easiest way to fix this is to set up your alternative email addresses in muttrc. If the sender address matches with one of your alternative email addresses, Mutt will automatically display "To <recipient>" in the index.

可変幅のカラム

If you resize the window, the subject might get truncated while there is still unused space left for some fields, like for the sender. You can get the maximum number of columns supported by your terminal (i.e. the width) using a shell call to tput cols. With this value, you can set a percentage of the width to fields like Sender and Subject.

Example using the above folder-hook and a sidebar width of 24:

muttrc
## From field gets 30% of remaining space, Subject gets 70%.
## Remaining space is the total width minus the other fields (35), minus the sidebar (24)
set my_index_format_pre='set my_col_from = `echo $((30 * ($(tput cols)-35-24) / 100))`; set my_col_subject = `echo $((70 * ($(tput cols)-35-24) / 100))`; set index_format="%2C | %Z [%d] %-$my_col_from.${my_col_from}'
set my_index_format_post=' (%-4.4c) %?M?<%M> ?%-$my_col_subject.${my_col_subject}s"'

folder-hook .*[sS]ent.* "$my_index_format_pre"t"$my_index_format_post"
folder-hook ! .*[sS]ent.* "$my_index_format_pre"F"$my_index_format_post"

We must set the variables my_col_from and my_col_from from within the hooks. Otherwise, the column values will not get re-computed.

We can add a binding to force re-computing the index format without changing folder:

muttrc
macro index,pager \CL "<enter-command>$my_index_format_pre"F"$my_index_format_post<enter><redraw-screen>"

サイドバー

サイドバーの設定例は /usr/share/doc/mutt/samples/sample.muttrc-sidebar にあり、キーバインドも定義されています。あなたの mutt 設定ファイルにコピー・編集したり source してください。set sidebar_visible = yes に必ず変更してください。

以下を追加することでサイドバーの表示を切り替えられます:

bind index,pager B sidebar-toggle-visible
ノート: You must set the mailboxes variables or the imap_check_subscribed to tell the sidebar which folder should be displayed. See the mailboxes section.

Note that with the mailboxes option, folders appear in the order they were set to mailboxes if you do not use the sidebar_sort_method option.

ヒント: To add a separator between different mailboxes, add a fake folder to the list of folders For example add: mailboxes "+-- My mailbox -----------"

ページャビューの上にインデックスを表示

muttrc で以下の変数を設定してください:

set pager_index_lines=10

連絡先の管理

アドレスのエイリアス

Mutt ではエイリアスを使って連絡先を管理します。エイリアスは nickname [longname] <address> です。

  • The nickname is what you will type in Mutt to get your contact address. One word only, and should be easy to remember.
  • The longname is optional. It may be several words.
  • An <address> must be in a valid form (i.e. with an @).

It is quite simple indeed. Add this to .muttrc:

set alias_file = "~/.mutt/aliases"
set sort_alias = alias
set reverse_alias = yes
source $alias_file

Explanation:

  • alias_file is the file where the information is getting stored when you add an alias from within Mutt.
  • sort_alias specifies which field to use to sort the alias list when displayed in Mutt. Possible values: alias, address.
  • reverse_alias if set to yes mutt will display the "personal" name from your aliases in the index menu if it finds an alias that matches the message's sender.
  • source $alias_file tells Mutt to read aliases on startup. Needed for auto-completion.

Now all you have to do when prompted To: is writing the alias instead of the full address. The beauty of it is that you can auto-complete the alias using Tab. Autocompleting a wrong or an empty string will display the full list. You can select the alias as usual, or by typing its index number.

There are two ways to create aliases:

  • From Mutt, press a when an e-mail of the targetted person if selected.
  • Edit the alias_file manually. The syntax is really simple:
alias nickname Long Name <my-friend@domain.tld>

Abook

abook は連絡先管理のための専用のスタンドアロンプログラムです。とてもシンプルなテキストベースのインターフェースで人間が読めるプレーンテキストのデータベースに連絡先が保存されます。そして連絡先のプロパティは自由に拡張できます (誕生日, 住所, FAX など)。

Abook is specifically designed to be interfaced with Mutt, so that it can serve as a full, more featured replacement of Mutt internal aliases. If you want to use Abook instead of aliases, remove the aliases configuration in .muttrc and add this:

muttrc
## Abook
set query_command= "abook --mutt-query '%s'"
macro index,pager  a "<pipe-message>abook --add-email-quiet<return>" "Add this sender to Abook"
bind editor        <Tab> complete-query

詳しい解説や設定例は abookabookrc の man ページを見てください。

Goobook

goobook-gitAUR パッケージをインストールして Goobook を使うことでコマンドラインや Mutt の中から Google コンタクトを検索することができます。

goobook を使用する前に ~/.goobookrc を設定してください。デフォルトテンプレートを生成するには:

$ goobook config-template > ~/.goobookrc

設定オプションについては ~/.goobookrc を見てください。最低でも、emailpassword は入力する必要があります。

ノート: Google アカウントで2段階認証を有効にしている場合、アプリケーションパスワードを生成する必要があります。

If you want to use Goobook instead of aliases, remove any alias configuration in .muttrc and add:

muttrc
## GooBook
set query_command="goobook query '%s'"
macro index,pager a "<pipe-message>goobook add<return>" "add sender to google contacts"
bind editor <Tab> complete-query

When composing an email message within mutt, Tab will now search your Google contacts. While viewing messages a will add the sender to Google contacts.

複数の送信者アカウントの管理

If you use multiple sender accounts, you can automatically associate a specific sender account with a recipient. mutt-vidAUR scans sent emails for the most recent "From" details associated with specific recipients, saving these in a file for mutt to source. The next time you email this recipient, mutt will automatically invoke a send-hook with the same email address and real name that you used previously. See mutt-vid's homepage for more details.

手動で IMAP のメール取得をリクエスト

If you do not want to wait for the next automatic IMAP fetching (or if you did not enable it), you might want to fetch mails manually. There is a mutt command imap-fetch-mail for that. Alternatively, you could bind it to a key:

bind index "^" imap-fetch-mail

カラー化によって巨大なフォルダのインデックスが遅くなる (IMAP)

Index highlighting by regex is nice, but can lead to slow folder viewing if your regex checks the body of the message.

Use folder-hook for only highlighting in for example the inbox (if you manage to empty your mailbox effiently):

folder-hook . 'uncolor index "~b \"Hi Joe\" ~R !~T !~F !~p !~P"'
folder-hook ""!"" 'color index brightyellow black "~b \"Hi Joe\" ~N !~T !~F !~p !~P"'

フォルダの切り替えの高速化

以下を .muttrc に追加してください:

set sleep_time = 0

メールのアーカイブ化

When you read an e-mail, you have four choices: Answer it, Flag it, Archive it or Delete it. If you have this in mind, you can keep your inbox slim and fit with this macro (set up for Gmail):

macro index \' "<tag-pattern>~R !~D !~F<enter>\
<tag-prefix><save-message>+[Gmail]/All <enter>" \
"Archive"

他のコンピュータにメールを移動

In case you are transfering your mails to a new machine (copy&paste), you probably need to delete the header cache (a file or folder like ~/.cache/mutt if you followed the above configuration) to make Mutt able to read your migrated E-Mails. Otherwise Mutt may freeze.

Note that if you had a folder created for you header cache, all mailboxes will have their own cache file, so you can delete caches individually without having to remove everything.

添付ファイルを保存するデフォルトフォルダ

デフォルトでは Mutt は添付ファイルを起動したときのフォルダに保存します。添付ファイルの保存場所を常に ~/attachments にしたい場合、以下のエイリアスを作成することで ~/attachments から Mutt が起動するようになります:

alias mutt='cd ~/attachments && mutt'

ページャの挙動

Show context lines when going to next page:

set pager_context=3

Stop at the end instead of displaying next mail:

set pager_stop=yes

クイック返信

By default Mutt will ask to confirm the recipient and the subject when you reply to an e-mail. It will also ask if you want to include the original mail in your answer. If you assume you will always stick to the default values, you can set up Mutt to skip these questions:

muttrc
set fast_reply=yes
set include=yes

You can still edit the recipient and the subject before sending.

グループ返信のメールアドレスを無視

Mutt will include your e-mail address(es) in the recipient list when you group-reply to a mail you were CC'ed. You can ask Mutt to ignore some addresses with:

alternates mail1@server1|mail2@server2|...

IMAP メッセージキャッシュ

When using the built-in IMAP support, e-mails are fetched in memory by default. Retrieving a big e-mail several times will download it from your IMAP server that many times.

Alternatively, you can ask Mutt to store all fetched messages on disk:

muttrc
set message_cachedir=~/.cache/mutt/messages

(The folder must exist.) This will make any future retrieval instantaneous, even with big attachments.

If you want to purge the cache from its oldest e-mails exceeding a limit of, say, 50MB, you can use a script like the following:

~/.mutt/purgecache.sh
#!/bin/sh

## In KB.
CACHE_LIMIT=51200

cd "$1" 2>/dev/null
[ $? -ne 0 ] && exit

[ $(du -s . | cut -f1 -d'	') -lt $CACHE_LIMIT ] && exit
while IFS= read -r i; do
	rm "$i"
	[ $(du -s . | cut -f1 -d'	') -lt $CACHE_LIMIT ] && exit
done <<EOF
$(find . -type f -exec ls -rt1 {} +)
EOF

and call it on startup:

muttrc
set message_cachedir=~/.cache/mutt/messages
source "~/.mutt/purgecache.sh '$message_cachedir'|"

トラブルシューティング

Mutt でバックスペースが使えない

This is a common problem with some xterm-like terminals. Two solutions:

  • Either rebind the key in .muttrc
bind index,pager ^? previous-line

Note that ^? is one single character representing backspace in caret notation. To type in Emacs, use Ctrl+q Backspace, in Vim Ctrl+v Backspace.

  • Or fix your terminal:
$ infocmp > termbs.src

Edit termbs.src and change kbs=^H to kbs=\177, then:

$ tic -x termbs.src

change-folder 機能で同一のメールボックスが表示される

これはバグではありません、仕様です。詳しくはマルチアカウントのセクションを見て下さい。

Mutt を読み取り専用で使った時にフォルダが変えられない (Mutt -R)

以下のようなマクロを使用していることが原因です:

macro index,pager <f2> '<sync-mailbox><enter-command>source ~/.mutt/personal<enter><change-folder>!<enter>'

上記のマクロはフォルダを切り替える前に同期を行います (同期は書き込み操作です)。サイドバーを使用するか別のマクロを設定してください:

macro index,pager <f3> '<enter-command>source ~/.mutt/personal<enter><change-folder>!<enter>'

Error sending message, child exited 127 (Exec error)

This is an SMTP error. It means that mutt does not know how to send the message. You can either try installing sendmail and see if that solves your issue, or you can set the smtp_url variable. If you use gmail, you can add the following to your muttrc to tell mutt to use gmails smtp server.

set smtp_url=smtps://$imap_user:$imap_pass@smtp.gmail.com

Take note of the smtps protocol, it is important. This should solve the problem.

文字エンコーディングの問題

文字列のエンコーディングに問題がある場合、まずは Mutt の wiki の こちらのセクション を見てください。

If Chinese text is still garbled, it may help to decode with GBK even when GB2312 is specified in the header. You can do this with iconv by adding the following to your mailcap file:

text/plain; iconv -f gbk -t utf-8 %s; test=echo "%{charset}" | grep -ic "gb2312"; copiousoutput;

and enabling it by adding a line to your .muttrc:

auto_view text/plain

For HTML emails, you can edit the relevant line of your mailcap by replacing %{charset} with $(echo %{charset} | sed s/gb2312/gbk/I), for example:

text/html; w3m -dump -I $(echo %{charset} | sed s/gb2312/gbk/I) %s; nametemplate=%s.html; copiousoutput

GMail にログインできない

Gmail は mutt などのアプリからのアクセスを無効にしています。こちら の手順に従うことでアクセスが可能になります。

ドキュメント

初心者は Mutt のヘルプを見つけるのにも苦労するかもしれませんが、公式ドキュメントでほとんどのトピックについて書かれています。公式ドキュメントを読むことを推奨します。

  • 公式マニュアル。Arch Linux の標準パッケージの mutt は HTML とプレーンテキストのマニュアルを /usr/share/doc/mutt/ にインストールします。
  • muttmuttrcman ページ

参照