【问题标题】:IMAP command UID FETCH: Too long argumentIMAP 命令 UID FETCH:参数太长
【发布时间】:2022-01-24 03:30:57
【问题描述】:

我正在将 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).']

我使用的代码如下

    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"])

这对于小型文件夹非常有效,但这个文件夹有几千封电子邮件

【问题讨论】:

    标签: python python-3.x python-3.7 imaplib


    【解决方案1】:

    拆分消息似乎已经解决了问题

    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():
    

    【讨论】:

      猜你喜欢
      • 2017-10-30
      • 2014-09-08
      • 1970-01-01
      • 2015-01-14
      • 2013-02-02
      • 1970-01-01
      • 2014-12-03
      • 1970-01-01
      • 2013-05-30
      相关资源
      最近更新 更多