0

这让我发疯了。如果我使用此代码:

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)

但它也失败了。

4

1 回答 1

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 )
于 2017-08-14T11:26:49.577 回答