2006年12月7日星期四

用abook来管理mutt的地址簿

平时与别人联系使用最多的恐怕就是email和电话了,既然mutt有邮件别名文件alias,那为什么不能利用它把邮件地址和电话号码都管理起来呢?

有很多工具可以,扩展mutt alias文件的用途,lbdb可以用来收集邮箱地址,并可以从不同格式的文件或数据库中进行查询,用于mutt; Rolo可以把地址存为vCard格式,不过好像2003年底就停止开发了,最后, abook可以让alias文件除了保存邮箱之外,再多几个保存其他信息的"字段"。

首先安装abook:apt-get instal abook。

然后来进行配置,首先创建abook的配置文件~/.abook/abookrc,内容如下,我把所有的配置都加上了说明:

# Auto save when exit
set autosave=true

# All email of a contact are shown in main list
set show_all_emails=true

# Display email from which column of screen
set emailpos=25

# Which field is to display in main list view as the third column
# frequently used values:
# -1 disabled
# phone Home Phone
# workphone Work Phone
# fax Fax
# mobile Mobile Phone
# nick Nickname/Alias
# url URL
# notes Notes
set extra_column=mobile

# If extra_column have no data, display this instead
set extra_alternative=workphone

# Extra field display from which column of screen
set extrapos=55

# Command used to start mutt
set mutt_command=mutt

# Return all email addresses to a mutt query
set mutt_return_all_emails=true

# Command used to print the addressbook
set print_command=lpr

# Command used to start the web browser to view a contact's URL
set www_command=firefox

# Address formatting used when export or print(eu,uk,us)
set address_style=us

# Use only ascii in abook file
set use_ascii_only=false

# Drop duplicate address in data?
set add_email_prevent_duplicates=true

# Sort addresses sort by which field?
set sort_field=nick

由于abook自己具备独立的功能,所以配合mutt使用还需要一个script,接下来创建可执行文件~/.abook/abook-autoexport如下:

#! /bin/sh
abook ${@}
abook –convert \
–informat abook –infile $HOME/.abook/addressbook \
–outformat mutt –outfile $HOME/.mutt/aliases.new
mv $HOME/.mutt/aliases $HOME/.mutt/aliases.bak
mv $HOME/.mutt/aliases.new $HOME/.mutt/aliases

可以看出,这个脚本的作用就是首先执行abook干活,然后把abook的数据文件转换为mutt的alias格式,然后替换掉原有的muttalias文件。

现在可以把原来的mutt alias文件转换为abook格式了,存储于~/.abook/addressbook中,这个是abook的默认数据文件:

abook –convert –informat mutt –infile $HOME/.mutt/aliases \
–outformat abook –outfile $HOME/.abook/addressbook

最后,配置muttrc,通过macro在mutt中调用abook,添加下面两句:

macro index,pager A "!~/.abook/abook-autoexport\n:source ~/.mutt/aliases\n" "Start abook"
macro index,pager a \
"|~/.abook/abook-autoexport –add-email-quiet\n:source ~/.mutt/aliases\n" \
"Create new alias from the actual message"

这样,在使用mutt的时候,按A就进入abook进行联系人管理了,按a则可以把当前邮件的sender保存到abook中。

一点使用感觉和经验:
abook肯定不是最好的联系人管理软件,不过他使用很方便,在联系人不超过几百个的情况下,应该没有问题,况且除了能够存储邮箱信息之外,还能够保存电话、手机等很多信息以及4个自定义信息,哪怕是脱离mutt使用,也十分方便,所以用来管理电话本应该是没有问题的。

abook的最大缺点是不能很好的处理一个联系人有多个邮箱的情况,我的解决办法是,再创建一个alias文件,把常用的包含多个收信人地址的别名都存到这里手工管理,abook只用来管理每个联系人一个邮箱的情况,在大多数情况下够用了。

还有一个缺点是如果发信人中有中文,则不能正确识别=GB2312….=这样的编码,不过可以自己写程序转换。

abook,管理我的联系人

abook,管理我的联系人

参考:

Source:http://www.fwolf.com/blog/post/263