為什麼是mutt? 為什麼mutt需要那麼多其他工具才能完成郵件處理?你應該看看王垠的介紹:
[url]http://www.kreny.com/docs/mutt.htm[/url]
本文隻雜亂談一下我的配置經驗
先說說~/.muttrc幾個基本問題,
1.建立郵箱,mutt的郵箱有兩種,一種是單檔案(所有郵件放到一個檔案裡),另一種是mail dir形式,後一種目錄形式比較好,推薦使用。
## folder & spool
set spoolfile = ~/Mail/inbox
set folder = ~/Mail
set tmpdir = ~/.mutt/tmp
set mbox_type = Maildir
set mbox = +inbox
set record = +sent
set postponed = +postponed
mailboxes \
$MAIL \
=inbox \
=junkmail \
=favorites \
=archive
在mailboxes行裡,可以定義自己想建立的郵箱,如favorites, archive, junkmail等。
2.編碼問題
# locale
set charset = UTF-8
set locale = zh_CN.UTF-8
# hook charset
charset-hook !UTF-8 gbk
charset-hook "^us-ascii$" "utf-8"
# send charset
set send_charset="us-ascii:iso-8859-1:utf-8:gbk"
set rfc2047_parameters=yes
charset-hook裡設定裡非utf-8郵件使用gbk檢視
3.增加垃圾箱,雖然不是很完善
#trash
folder-hook . 'macro index d "s$folder/trash\r"'
folder-hook $folder/trash 'bind index d delete-message'
4.排序
#sort
set sort = reverse-date
set sort_aux = threads
5.快捷鍵,
我是這樣設定的
#key binding getmail
macro index G "!~/.getmail/getmail\n" "Invoke getmail"
macro pager G "!~/.getmail/getmail\n" "Invoke getmail"
#enter mailbox
macro index A "c=archive\r"
macro pager A "c=archive\r"
macro index I "c!\n" "Go to Inbox"
macro pager I "c!\n" "Go to Inbox"
macro index F "c=favorites\r"
macro pager F "c=favorites\r"
macro index J "c=junkmail\r"
macro pager J "c=junkmail\r"
前面一部分是收郵件(getmail),快捷鍵是shift+g,(參見下面getmail配置)
後面一部分是進入各個郵箱的快捷鍵。
6.多賬号發送問題,方法是通過判斷來信郵件頭來選擇,局限是隻能在回信時自動選擇。
以下是完整的發信部分設定
#send hook
send-hook . 'my_hdr from:[email protected]'
send-hook . 'set sendmail="/usr/bin/msmtp"'
reply-hook . 'my_hdr reply-to:[email protected]'
send-hook '~t .*@163\.com$' 'my_hdr from:[email protected]'
send-hook '~t .*@163\.com$' 'my_hdr reply-to:[email protected]'
send-hook '~t .*@163\.com$' 'set sendmail="/usr/bin/msmtp -a 163"'
reply-hook '~t .*@163\.com$' 'my_hdr from:[email protected]'
reply-hook '~t .*@163\.com$' 'my_hdr reply-to:[email protected]'
reply-hook '~t .*@163\.com$' 'set sendmail="/usr/bin/msmtp -a 163"'
前面一段是預設的賬号,後面兩段是用163賬号來發送(後面提到msmtp的配置)。
msmtp的配置:
defaults
tls on
auth on
tls_certcheck off
logfile ~/.msmtplog
# Gmail service
account gmail
host smtp.gmail.com
from [email][email protected][/email]
port 587
user [email][email protected][/email]
password xxxxxx
# 163 service
account 163
tls off
auth plain
host smtp.163.com
from [email][email protected][/email]
user [email][email protected][/email]
# Set a default account
account default : gmail這裡就定義了發送的賬号,包括gmail和163
getmail的配置
對多賬号來說,getmail比fetchmail配置要複雜,但感覺收郵件的表現getmail比fetchmail要好。
多賬号配置,首先建立~/.getmail目錄,編寫~/.getmail/getmailrc.163檔案:
[retriever]
type = SimplePOP3Retriever
server = pop.163.com
username = [email][email protected][/email]
password = xxxxxx
[destination]
type = Maildir
path = ~/Mail/inbox/
[options]
verbose = 0
delete = false
message_log = ~/.getmail/getmail.log
諸如此類,編寫~/.getmail/getmailrc.gmail檔案
type = SimplePOP3SSLRetriever
server = pop.gmail.com
port = 995
username = [email][email protected][/email]
你可以寫更多.....
然後寫一個收郵件的腳本檔案~/.getmail/getmail
#!/bin/bash
#getmail for dream
getmail -v -n -r ~/.getmail/getmailrc.sina -r ~/.getmail/getmailrc.163 -r ~/.getmail/getmailrc.gmail
注意把它設為可運作(+x)。
于是有了上面.muttrc裡快捷鍵收郵件那部配置設定置。
附上我完整的~/.muttrc以供參考
#号開頭是注釋
## user
set realname = "rzli"
set move = no
#Flag
# " "(空): 表示這封郵件不是給你的,也就是說 To: 和 Cc: Bcc: 都沒有你的位址,
# 很多轉發的郵件,未确認的郵件清單郵件,垃圾郵件都有這個特征。
# +: 表示你是收件人(To: 是你的位址之一),而且是唯一的收件人。
# T: 表示你是收件人(To: 包括了你的位址之一),但是你不是唯一的收件人。這是一封群體信件。
# C: 表示你的位址出現在 CC:,但是你不是唯一的被抄送的人。
# F: 表示這封郵件是你發出去的。
# L: 表示這是一封你已經加入的郵件清單寄來的。
# Set header
ignore headers *
unignore headers from: to: cc: subject date
set header=no
# set index
set index_format="%4C %Z %{%y年%b%d} %-15.15L (%?l?%4l&%4c?) %s"
#score
#score "~N" +4 #新信件
#score "~D" -5 #有删除标記
#score "~O" +1 #上次沒有讀
#score "~f huiqin" +2 #來自 xxxx
#score "~s xxxx" + 3 #主題上有 xxxx
#confirm
set confirmappend = no
# wrap & stop @ last mail
set pager_stop = yes
set smart_wrap = yes
set pager_index_lines = 5
# message editor
set editor = "vim"
set fast_reply = yes
set edit_headers = yes
# ext app to view p_w_upload
set mailcap_path="~/.mutt/mailcap"
# wait too see output info while quit
set wait_key=yes
#Alias
set alias_file = ~/.mutt/alias
source ~/.mutt/alias
# Attachment
set attach_format = "%u%D%I %t%4n %T%.40d%> [%.7m/%.10M, %.6e%?C?, %C?, %s] "
set attach_sep = "\n"
set attach_split = yes
# Color
color hdrdefault black cyan
color quoted red white
color signature brightblack white
color indicator brightwhite magenta
color p_w_upload black green
color error red white
color message blue white
color search brightwhite magenta
color status brightyellow blue
color tree red white
color normal blue white
color tilde green white
color bold brightyellow white
color markers red white
color index brightwhite red ~N
color index red default ~O
color index brightblack default ~D
mono bold bold
mono underline underline
mono indicator reverse
#
auto_view text/html
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=:-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# include original content when reply
set include = yes
# from
set envelope_from = yes
set encode_from = yes
#End of muttrc, but it could be more and more and more:)