Python库imapclient空闲标记电子邮件为已读

时间:2018-05-10 22:57:10

标签: python imap

我正在尝试使用imapclient库的空闲模式。仅使用他们给定的example处于空闲模式时进入的电子邮件被标记为已读。我首先得到服务器响应,看到消息,但似乎图书馆正在获取电子邮件并设置看到的标志。这是它应该是的方式还是我错过了什么? 这是输出的样子:

Connection is now in IDLE mode, send yourself an email or quit with ^c
('Server sent:', [(330, 'EXISTS')])
('Server sent:', [(330, 'FETCH', ('UID', 484, 'FLAGS', ('\\Seen',)))])

这是打开调试的输出。 好像它是的imapclient进行获取。

('Server sent:', 'nothing')
2018-05-10 21:00:13,325 - DEBUG: < * 328 EXISTS
('Server sent:', [(328, 'EXISTS')])
2018-05-10 21:00:28,342 - DEBUG: < * 328 FETCH (UID 513 FLAGS (\Seen))
('Server sent:', [(328, 'FETCH', ('UID', 513, 'FLAGS', ('\\Seen',)))])

以下是我使用的 [完整]代码的相关部分:

# Open a connection in IDLE mode and wait for notifications from the
# server.

from imapclient import IMAPClient

HOST = 'imap.host.com'
USERNAME = 'someuser'
PASSWORD = 'password'

server = IMAPClient(HOST)
server.login(USERNAME, PASSWORD)
server.select_folder('INBOX')

# Start IDLE mode
server.idle()
print("Connection is now in IDLE mode, send yourself an email or quit with ^c")

while True:
    try:
        # Wait for up to 30 seconds for an IDLE response
        responses = server.idle_check(timeout=30)
        print("Server sent:", responses if responses else "nothing")
    except KeyboardInterrupt:
        break

server.idle_done()
print("\nIDLE mode done")
server.logout()

0 个答案:

没有答案