这让我疯了。如果我使用此代码:
while msgnums == ['']: # wait until message list from server isn't empty
typ, msgnums = gmail.m.uid('search', None, 'To', new_user)
print '\n', new_user, sec_waiting, typ, msgnums
输出结果为:
qatestdata+auto20111104113143@gmail.com 300 OK ['']
换句话说,它没有找到我的信息。但是,如果我像这样硬编码:
typ, msgnums = gmail.m.uid('search', None, 'To', 'qatestdata+auto20111104113143@gmail.com')
输出结果为:
qatestdata+auto20111104113844@gmail.com 0 OK ['19']
(它找到了消息。)new_user是一个字符串。我不明白为什么它不起作用。
我也尝试过:
search_string = '(To \"' + created_username + '\")'
while msg_uid == ['']: # wait until message list from server isn't empty
resp, msg_uid = gmail.m.search(None, search_string)
但它也失败了。
答案 0 :(得分:1)
我遇到了同样的问题。我用引号引用了一些变化来解决它。
我想搜索一下:
resp, items = m.search(None, '(FROM "*" SUBJECT "<root@doire> test.sh > /dev/null")')
硬编码工作,但循环不起作用,虽然看起来是正确的。
email_subjects_with_del = [ "<root@doire> test.sh > /dev/null" ]
for sub in email_subjects_with_del:
text = "%s%s%s" % ("'(FROM \"*\" SUBJECT \"", sub, "\")'")
print text
resp, items = m.search(None, text )
但这有效(没有'引号)
for sub in email_subjects_with_del:
text = "%s%s%s" % ("(FROM \"*\" SUBJECT \"", sub, "\")")
print text
resp, items = m.search(None, text )