我对编程很陌生,所以我在这里寻求帮助。我有一个包含超过 20 万封电子邮件的电子邮件文件夹。我试图将它们全部删除,因为它们让我慢了下来。我使用 IMAPClient 在 Python 3.7.2 中编写了一个脚本来尝试将它们全部删除,但我一直收到错误消息。
我试图删除文件夹中的所有电子邮件,并且我试图删除一天的价值。平均一天有大约 2k 封电子邮件。同时使用 'ALL' 和 'ON DD-MMM-YYYY"
import imapclient
imapObj = imapclient.IMAPClient('imap.server.com', ssl=True)
imapObj.login('email', 'password')
import pprint
pprint.pprint(imapObj.list_folders())
[((b'\\NoInferiors',), b'/', 'INBOX'),
((b'\\HasNoChildren',), b'/', 'Folder I want to delete'),
--all folders--
imapObj.select_folder('Folder I want to delete', readonly=False)
{b'PERMANENTFLAGS': (b'\\Answered', b'\\Flagged', b'\\Draft',
b'\\Deleted', b'\\Seen', b'$Forwarded', b'$NotJunk', b'NotJunk',
b'$MailFlagBit1', b'$MailFlagBit0', b'$MailFlagBit2', b'\\*'),
b'FLAGS': (b'\\Answered', b'\\Flagged', b'\\Draft', b'\\Deleted',
b'\\Seen', b'$Forwarded', b'$NotJunk', b'NotJunk', b'$MailFlagBit1',
b'$MailFlagBit0', b'$MailFlagBit2'), b'EXISTS': 3792507, b'RECENT':
0, b'UNSEEN': [b'3792504'], b'UIDVALIDITY': 1398179813, b'UIDNEXT':
7577201, b'READ-WRITE': True}
UIDs = imapObj.search('ALL')
imapObj.delete_messages(UIDs)
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
imapObj.delete_messages(UIDs)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-
packages/imapclient/imapclient.py", line 1171, in delete_messages
return self.add_flags(messages, DELETED, silent=silent)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-
packages/imapclient/imapclient.py", line 1081, in add_flags
return self._store(b'+FLAGS', messages, flags, b'FLAGS',
silent=silent)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-
packages/imapclient/imapclient.py", line 1567, in _store
uid=True)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-
packages/imapclient/imapclient.py", line 1535, in
_command_and_check
typ, data = self._imap.uid(command, *args)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/imaplib
.py", line 879, in uid
typ, dat = self._simple_command(name, command, *args)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/imaplib
.py", line 1196, in _simple_command
return self._command_complete(name, self._command(name, *args))
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/imaplib
.py", line 1027, in _command_complete
raise self.error('%s command error: %s %s' % (name, typ, data))
imaplib.IMAP4.error: UID command error: BAD [b'Command line too large']
我希望电子邮件被删除,但命令只是错误地出现在上面。