简体   繁体   English

IMAP 命令 UID FETCH:参数太长

[英]IMAP command UID FETCH: Too long argument

I'm using imaplib (imap4) with Python 3.7.0 and I'm trying to fetch a large folder and I'm getting我正在将 imaplib (imap4) 与 Python 3.7.0 一起使用,我正在尝试获取一个大文件夹,我得到了

FETCH command error: BAD [b'Error in IMAP command UID FETCH: Too long argument (0.001 + 0.122 + 0.122 secs).']

the code I'm using is below我正在使用的代码如下

    def run(self, verifyQueue):
        config = json.load(open("config.json", "r+"))
        client = IMAPClient(host=config.get('imapHost'))
        while True:
            try:
                client.login(config.get('imapUsername'), config.get('imapPassword'))
                client.select_folder(config.get('imapFolder'))
                self.log('Loaded')
                while True:
                    try:
                        client.idle()
                        responses = client.idle_check(timeout=30)
                        if responses:
                            client.idle_done()
                            messages = client.search("UNSEEN")
                            for uid, message_data in client.fetch(messages, "RFC822").items():
                                emailMSG = email.message_from_bytes(message_data[b"RFC822"])

This works perfectly for small folders but this folder has over a few thousand emails这非常适用于小文件夹,但这个文件夹有几千封电子邮件

Splitting the messages seems to have solved the problem拆分消息似乎已经解决了问题

messages = client.search("UNSEEN")
for i in range(0, len(messages), 500):
    for uid, message_data in client.fetch(messages[i:i + 500], "RFC822").items():

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM