IMAP在“发件人"字段中搜索电子邮件地址 [英] IMAP search for email address in the from field
问题描述
我正在尝试使用python的imaplib搜索和过滤我的imap邮件.我在搜索命令中遇到了一个非常奇怪的问题,即在FROM
字段中搜索电子邮件地址.我有以下脚本,
I am trying to search and filter my imap mails using python's imaplib. I am running into a quite strange problem with the search command, searching for email addresses in the FROM
field. I have the following script,
print('search with name')
status, results = con.search(None, '(FROM "Shrikant Sharat")')
if status == 'OK':
if results[0]:
mid = results[0].split()[0]
print('mail id', mid)
print(con.fetch(mid, '(UID BODY[HEADER.FIELDS (FROM)])'))
else:
print('No results yielded')
else:
print('unable to search', results)
print()
print('search with email')
status, results = con.search(None, '(FROM "shrikantsharat.k@gmail.com")')
if status == 'OK':
if results[0]:
mid = results[0].split()[0]
print('mail id', mid)
print(con.fetch(mid, '(UID BODY[HEADER.FIELDS (FROM)])'))
else:
print('No results yielded')
else:
print('unable to search', results)
为此,我得到以下结果,
for which, I get the following result,
search with name
mail id 2155
('OK', [('2155 (UID 5340 BODY[HEADER.FIELDS (FROM)] {54}', 'From: Shrikant Sharat <shrikantsharat.k@gmail.com>\r\n\r\n'), ' FLAGS (\\Seen))'])
search with email
No results yielded
为什么第二次搜索失败?电子邮件地址显示在From
字段中,如先前的搜索所示.第二个搜索应该匹配此邮件吗?
Why does the second search fail? The email address is present in the From
field as shown by the previous search. The second search should've matched this mail right?
这不是在From
字段中搜索电子邮件地址的方法吗?我正在把头发分开.有什么想法吗?
Is this not the way to search for email address in the From
field? I am pulling my hair apart on this one. Any ideas?
编辑(如果相关),我正在尝试使用MS Exchange(我认为是2007年)公开的IMAP服务器.
Edit If relevant, I am trying this with an IMAP server exposed by MS Exchange (2007, I think).
推荐答案
使用此作为您的过滤器:
use this as your filter:
(HEADER FROM "shrikantsharat.k@gmail.com")
这篇关于IMAP在“发件人"字段中搜索电子邮件地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!