我可以打印每封电子邮件。我想要做的是在每封电子邮件中搜索一个字符串,如果它有字符串,则返回 true 或 false。我怎样msg
才能做到这一点?
conn.select(readonly=1) # Select inbox or default namespace
(retcode, messages) = conn.search(None, '(UNSEEN)')
if retcode == 'OK':
for num in messages[0].split(' '):
print 'Processing :', messages
typ, data = conn.fetch(num,'(RFC822)')
msg = email.message_from_string(data[0][1])
typ, data = conn.store(num,'-FLAGS','\\Seen')
if retcode == 'OK':
print data,'\n',30*'-'
for line in msg:
if "Subject: Thanks for your Walmart.com Order" in line:
print line
conn.close()