在mutt中使用Gmail地址簿
这又是关于mutt的记事。公司的IT着实非常落后,至今我们仍在使用微软的Office outlook作邮件客户端。没有gmail,没有webmail,倒是直到上周才为每位员工购买了一款叫做Good的Android软件来查看邮件。可是无论怎样,mutt一直是我钟爱的一款邮件客户端。它已经长在我的手指上。现在在公司的开发机器上我已经可以使用IMAP和SMTP收发邮件,也可以在mutt中使用全公司的LDAP来查找地址,所以,整个功能跟低效的Outlook没有区别,处理邮件的速度却比使用Outlook提高了至少两倍。特别是遇到跟工程师之间通信需要贴代码或者发git patch的时候尤其如此。当通过mutt使用自己的gmail的时候,我遇到了一问题,就是Gmail本身并没有提供LDAP接口用来查询地址,于是我无法套用使用公司邮件的配置来查找地址了。昨天在github上发现了一个perl脚本可以解决这个问题。
Gmail提供了API可以帮助外部应用程序取得地址簿中的数据。Ajnasz的这个脚本可以取得地址簿数据并且用查询字符串匹配,从而找到联系人的邮件地址。但是,但是原来的脚本有一个小问题——无法使用中文或者日语姓名作为查询字符串。自己动手,丰衣足食。我在原代码的基础只添加了两行代码,现在查询中文姓名也没有问题了。如果你有兴趣可以从这里拿到代码。
git clone git://github.com/jcadam/Google-Contacts-for-Mutt.git gc-mutt
这个脚本需要一个简单的配置文件用来取得Gmail数据的访问权限。你可以仿照下面这个例子做自己的配置文件。
$ vi ~/.google.ini
[account] email = 'youraccount@gmail.com' password = 'Passw0rd'
为了防止其他用户访问你的文件增强安全,你可将文件的属性设置成所有者只读。
$ chmod 400 ~/.google.ini
进入contacts.pl脚本所在目录,然后不带任何参数运行这个脚本,你就可以得到整个Gmail联系人名簿。可以先测试一下。
$ cd$ ./contacts.pl
接着,在PATH变量中的任何一个目录中,通常是/usr/local/bin/或者~/bin,建立一个Shell helper了查询数据。
$ vi ~/bin/contracts
#!/usr/bin/env bash
${HOME}/github/gc-mutt/contacts.pl ${1}
然后告诉mutt查询联系人时使用这个helper脚本查询。在~/.muttrc中添加如下一行即可。
set query_command="~/bin/contacts '%s'"
测试一下。在mutt中新建邮件(m),在To:栏中直接输入联系人的名字,比如”Mark Brown”,
然后按”ctrl-t”查找地址簿。
mutt会自动查询地址布并且取回Mark的邮件地址。
相关日志
嘿~,如果您喜欢我的博客,您可以通过RSS.链接将本博客的最新文章传输到您喜欢的阅读器。




一月 18th, 2012 at 23:34
Nice blog. I step to mutt few month ago and using ‘goobook’ for synchronizing the contact between gmail and the mutt. You can add complete your contact with completion and what’s, a new contact can added to gmail contact pool immediately in mutt whiling reading mails in mutt without opening web page client for gmail.
BTW, I love the fonts whiling I am typing this message. It feels comfortable.
一月 19th, 2012 at 15:25
Thank you! I gave a shot on goobook. It works fine. Now, I am thinking about switch to it.
>> BTW, I love the fonts whiling I am typing this message. It feels comfortable.
Good to know. :) though I am not confident on aethethics, I can tell you Dejavu Font family servers the best shapes of your glyph. Take a look at
http://dejavu-fonts.org
Wish you like it.