「Mutt」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
(翻訳)
(文字列「[[zh-CN:」を「[[zh-hans:」に置換)
3行目: 3行目:
 
[[es:Mutt]]
 
[[es:Mutt]]
 
[[it:Mutt]]
 
[[it:Mutt]]
[[zh-CN:Mutt]]
+
[[zh-hans:Mutt]]
 
[[zh-TW:Mutt]]
 
[[zh-TW:Mutt]]
 
{{Related articles start}}
 
{{Related articles start}}

2017年1月29日 (日) 00:36時点における版

関連記事

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, fetchmail, 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 の neomuttAURneomutt-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
ヒント: Continuing with the previous example, remember that Gmail requires your full email address (this is not standard):
set imap_user=your.username@gmail.com
imap_pass

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

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

Instead of a local directory which contains all your mail (and directories), use your server (and the highest folder in the hierarchy, if needed).

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

You do not have to use a folder, but it might be convenient if you have all your other folders inside your INBOX, for example. Whatever you set here as your folder can be accessed later in Mutt with just an equal sign (=) or a plus sign (+). Example:

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

It should be noted that for several accounts, it is best practice to use different folders -- e.g. for account-hook. If you have several Gmail account, use

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

instead, where your account is username@gmail.com. This way it will be possible to distinguish the different folders. Otherwise it would lead to authentication errors.

spoolfile

The spoolfile is the folder where your (unfiltered) e-mail arrives. Most e-mail services conventionally names it INBOX. You can now use '=' or '+' as a substitution for the full folder path that was configured above. For example:

set spoolfile=+INBOX
mailboxes

Any imap folders that should be checked regularly for new mail should be listed here:

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

Alternatively, check for all subscribed IMAP folders (as if all were added with a mailboxes line):

set imap_check_subscribed

These two versions are equivalent if you want to subscribe to all folders. So the second method is much more convenient, but the first one gives you more flexibility. Also, newer Mutt versions are configured by default to include a macro bound to the 'y' key which will allow you to change to any of the folders listed under mailboxes.

If you do not set this variable, the spoolfile will be used by default. This variable is also important for the sidebar.

まとめ

Using these options, you will be able to start Mutt, enter your IMAP password, and start reading your mail. Here is a muttrc snippet (for Gmail) with some other lines you might consider adding for better IMAP support.

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 is a generic and standardized format. Almost every MUA is able to handle Maildirs and Mutt's support is excellent. There are just a few simple things that you need to do to get Mutt to use them. Open your muttrc and add the following lines:

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

This is a minimal Configuration that enables you to access your Maildir and checks for new local Mails in INBOX. This configuration also caches the headers of the eMails to speed up directory-listings. It might not be enabled in your build (but it sure is in the Arch-Package). Note that this does not affect OfflineIMAP in any way. It always syncs the all directories on a Server. spoolfile tells Mutt which local directories to poll for new Mail. You might want to add more Spoolfiles (for example the Directories of Mailing-Lists) and maybe other things. But this is subject to the Mutt manual and beyond the scope of this document.

SMTP

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

フォルダ

There is basically only one important folder here: the one where all your sent e-mails will be saved.

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

Note that if your SMTP credentials are the same as your IMAP credentials, then you can use those variables:

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

You may need to tweak the security parameters. If you get an error like SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol, then your server probably uses the SMTP instead of SMTPS.

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

There are other variables that you may need to set. For example for use of STARTTLS:

set ssl_starttls = yes

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

外部の SMTP サポート

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

The sendmail variable in your muttrc determines the program and arguments used to deliver mail in mutt. Any additional arguments must be interpreted by the program as recipient addresses.

例えば、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.

Now all your accounts are set, start Mutt. To switch from one account to another, just change the folder (c key). Alternatively you can use the sidebar.

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>'

パスワード管理

Keep in mind that writing your password in .muttrc is a security risk, and it might be of your concern. The trivial way to keep your passwords safe is not writing them in the config file. Mutt will then prompt for it when needed. However, this is quite cumbersome in the long run, especiallly if you have several accounts.

Here follows a smart and convenient solution: all your passwords are encrypted into one file and Mutt will prompt for a passphrase on startup only. You can opt for a keyring tool (e.g. GPG, pwsafe) or an encryption tool like ccrypt, which may be more simple and straightforward to use. Since GPG is a Mutt dependency, we will use it here.

First create a pair of public/private keys:

gpg --gen-key

If you do not understand this process have a look at Wikipedia:Asymmetric cryptography.

Create a file in a secure environment since it will contain your passwords for a couple of seconds:

~/.my-pwds
set my_pw_personal = "first password"
set my_pw_work = "second password"
ノート: Remember that user defined variables must start with my_.

Now encrypt the file:

gpg -e -r 'your-name' ~/.my-pwds

Note that 'your-name' must match the one you provided at the gpg --gen-key step. Now you can wipe your file containing your passwords in clear:

shred -xu ~/.my-pwds

Back to your account dedicated files, e.g. .mutt/muttrc:

set imap_pass=$my_pw_personal
# Every time the password is needed, use $my_pw_personal variable.

And in your .muttrc, before you source any account dedicated file:

source "gpg2 -dq $HOME/.my-pwds.gpg |"
ノート: At the end of the line above, there is no space between the pipe and the double quote.
  • The -q parameter makes gpg2 quiet which prevents gpg2 output messing with Mutt interface.
  • The pipe | at the end of a string is the Mutt syntax to tell that you want the result of what is preceeding.

Explanation: when Mutt starts, it will first source the result of the password decryption, that's why it will prompt for a passphrase. Then all passwords will be stored in memory in specific variables for the time Mutt runs. Then, when a folder-hook is called, it sets the imap_pass variable to the variable holding the appropriate password. When switching accounts, the imap_pass variable will be set to another variable holding another password, etc.

If you use external tools like OfflineIMAP and msmtp, you need to set up an agent (e.g. gpg-agent, see GnuPG#gpg-agent) to keep the passphrase into cache and thus avoiding those tools always prompting for it.

セキュリティの問題

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

Tips and tricks

Guides to get you started with using & customizing Mutt :

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

キーバインディング

The default key bindings are quite far from the more common Emacs-like or Vi-like bindings. You can customize them to your preference. Mutt has a different set of bindings for the pager, the index, the attachment view, etc. Thus you need to specify which map you want to modify when you bind a key. You can review the list of commands and key bindings from Mutt's help page (default key: ?). Example of Vi-like bindings:

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

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

You may be concerned with sending e-mail in a decent character set (charset for short) like UTF-8. Nowadays UTF-8 is highly recommended to almost everyone.

When using Mutt there are two levels where the charset 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.

印刷

You can install muttprintAUR for fancier printing quality. In your muttrc file, insert:

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

カスタムメールヘッダ

One of the greatest thing in Mutt is that you can have full control over your mail header.

First, make your headers editable when you write e-mails:

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.

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>"

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

Mutt と 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"

Mutt と 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>"

連絡先の管理

アドレスのエイリアス

Aliases is the way Mutt manages contacts. An alias is 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 sorts in reverse order if set to yes.
  • 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

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 メールの作成

Since Mutt has nothing of a WYSIWIG client, HTML is quite straightforward, and you can do much more than with all WYSIWIG mail clients around since you edit the source code directly. Simply write your mail using HTML syntax. For example:

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

Now before sending the mail, use the edit-type command (default shortcut Ctrl+t), and replace text/plain by text/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 は使用しているターミナルに置き換えて下さい。

メールのアーカイブ化

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"

Mutt-Sidebar

Arch ではデフォルトでサイドバーが同梱されています。起動時にサイドバーの表示を選択するか、キーを使って手動で表示させることができます:

set sidebar_visible = yes
bind index,pager B sidebar-toggle-visible

You also probabaly need some shortcuts to navigate in the bar:

# Ctrl-n, Ctrl-p to select next, previous folder.
# Ctrl-o to open selected folder.
bind index,pager \CP sidebar-prev
bind index,pager \CN sidebar-next
bind index,pager \CO sidebar-open
ノート: 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.

If you have trouble with truncated names, set the option

set sidebar_short_path = yes

Finally, you may want to add a separator between different mailboxes. The sidebar patch does not currently provide any kind of separator option. A simple (and dirty) workaround is to add a fake folder to the list of folders:

mailboxes "+-- My mailbox -----------"

The dashes are not required, they are here just for fancy output.

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

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.

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

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.

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

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

set pager_index_lines=10

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

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

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

PGP で署名・暗号化されたメール

The official Mutt package is compiled with GPGME support. If you have a pair of keys in your GnuPG keyring, then it suffices to add this:

.muttrc
set crypt_use_gpgme=yes

For convenience, you can set further PGP settings:

.muttrc
set crypt_replysign=yes
set crypt_replysignencrypted=yes
set pgp_timeout=3600

See the pgp_* and crypt_* options in muttrc(5).

To be able to view the encrypted message to others, add either encrypt-to or hidden-encrypt-to in your ~/.gnupg/gpg.conf.

ページャの挙動

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|...

会話のグループ化

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

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)

This is certainly because you are using macros like this one:

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

This macro tells Mutt to sync (which is a write operation) before switching. Either use the sidebar or set another macro:

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 ページ

参照