当前位置:嗨网首页>书籍在线阅读

06-从Gmail账户中搜索邮件

  
选择背景色: 黄橙 洋红 淡粉 水蓝 草绿 白色 选择字体: 宋体 黑体 微软雅黑 楷体 选择字体大小: 恢复默认

18.1.4 从Gmail账户中搜索邮件

除了使用 ezgmail.unread()ezgmail.recent() ,你还可以通过调用 ezgmail. search() 来搜索特定的邮件,就像你在邮箱的搜索框中查询一样:

>>> resultThreads = ezgmail.search('RoboCop')
>>> len(resultThreads)
1
>>> ezgmail.summary(resultThreads)
Al, Jon - Do you want to watch RoboCop this weekend? - Dec 09

前面的 search() 调用得到的结果,应该与在搜索框中输入“RoboCop”相同,如图18-1所示。

133.png

图18-1 在Gmail网站上搜索“RoboCop”邮件

unread()recent() 一样, search() 函数也会返回一个 GmailThread 对象的列表。你也可以将任何一个可以输入搜索框中的特殊搜索操作符传递给 search() 函数,如下面这些。

'label:UNREAD' 用于未读邮件。

'from:[email protected]' 用于来自 [email protected] 的邮件。

'subject:hello' 用于主题中包含hello的邮件。

'has:attachment' 用于有附件的邮件。

可以在Google的支持页面找到完整的搜索操作符列表。