python - 在 Python 中禁用 IMAP 注销
问题描述
好的,所以我今天决定从旧电子邮件帐户中删除所有旧电子邮件。现在我有大约 40,000 多封电子邮件需要删除,所以我采用了显而易见的方法并制作了一个脚本来为我执行此操作。
一切正常运行了大约10 分钟,直到我遇到 IMAP 给出 Loggout 错误的障碍。代码运行良好,我只需要知道是否有办法禁用或绕过它,这样我就可以运行这个脚本,直到我的所有电子邮件都被删除。
这是脚本(由于明显的原因更改了用户名和密码):
import imaplib
import email
from tqdm import tqdm
from email.header import decode_header
# Account credentials
username = "username@domain.com"
password = "password"
imap = imaplib.IMAP4_SSL("imap.mail.yahoo.com")
imap.login(username, password)
imap.select("Archive")
status, messages = imap.search(None, "ALL")
messages = messages[0].split(b' ')
amtOfMessages = len(messages)
print("Clearing all emails in the ARCHIVE folder")
print("Total emails in folder: ", amtOfMessages)
#tqdm is a library I'm using to display a progress bar in the cmd line
for i in tqdm(range(amtOfMessages)):
_, msg = imap.fetch(messages[i], "(RFC822)")
imap.store(messages[i], "+FLAGS", "\\Deleted")
imap.expunge()
imap.close()
imap.logout()
print("ALL MESSAGES DELETED FROM ARCHIVE FOLDER")
print("Logged out of account...")
最后,这是我得到的错误的回溯
Traceback (most recent call last):
File "/Documents/EmailScripts/quickstart.py", line 27, in <module>
_, msg = imap.fetch(messages[i], "(RFC822)")
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/imaplib.py", line 548, in fetch
typ, dat = self._simple_command(name, message_set, message_parts)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/imaplib.py", line 1230, in _simple_command
return self._command_complete(name, self._command(name, *args))
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/imaplib.py", line 1049, in _command_complete
raise self.abort('command: %s => %s' % (name, val))
imaplib.abort: command: FETCH => IMAP4rev1 Server logging out
编辑:说“超时”时说错了。意思是注销。已进行更改。
解决方案
推荐阅读
- objective-c - 在 FSCalendar ObjC 中禁用对日期范围的选择
- umbraco - 为什么我的 umbraco 实例没有正确命名按钮?
- r - 如何使 purrr invoke_map 与闭包一起使用
- angular - 导出csv时如何从angular2中的ag网格中的导出CSV中删除第一列?
- vba - 如何从相应 Excel 表中的用户表单中的特定单元格范围开始搜索(A8)
- docker - 创建大小有限的 docker 卷
- java - 是什么导致幸存者在 Eden GC 后不会从 1 切换到 0
- swift - 如何从锁定屏幕访问设备电池电量
- javascript - hyperHTML:自定义布尔属性
- python - 是否可以在 python 中获取临时文件的 md5 哈希?