抱着学习的态度研究了一下,觉得挺好玩的。原来的脚本只显示最新邮件计数,我作了一下修改,使它还能显示最新邮件的主题。要作到这一点,首先要研究一下gmail邮件列表的feed文件格式是什么,大概是这个样子。
代码: 全选
<?xml version="1.0" encoding="UTF-8"?>
<feed version="0.3" xmlns="http://purl.org/atom/ns#">
<title>Gmail - Inbox for ******@gmail.com</title> <------------标题
......
<fullcount>2</fullcount> <--------新邮件计数
......
<entry>
<title>测试 test!</title> <------------邮件主题
....
</entry>
<entry>
<title>2 new messages in 2 topics - digest</title> <------------邮件主题
......
</entry>
</feed>
下面是我后的脚本。
代码: 全选
#!/bin/bash
gmail_login="usrname" #replace it with your username
gmail_password="password" #replace it with your password
dane="$(wget --secure-protocol=TLSv1 --timeout=3 -t 1 -q -O - \
https://${gmail_login}:${gmail_password}@mail.google.com/mail/feed/atom \
|egrep 'fullcount|title' \
|sed -e '2,$s/.*<fullcount>//' -e '2,$s/<\/fullcount>//' -e '2,$s/.*<title>//' -e '2,$s/<\/title>//' \
|sed -n '2,$p' \
|sed '1s/$/& new mail(s)/' )"
if [ -z "$dane" ]; then
echo "Error"
else
echo "$dane"
fi
代码: 全选
${color}${font WenQuanYi Zen Hei:size=8}${execi 600 ~/script/checkmail.sh}
这样,每隔10分钟半自动执行脚本,并显示gmail邮件信息。附上一张在我机器上显示的图片。