[英]Deleting with IMAP4.uid Apple Mail: UID command error
I'm trying to revive a python 2 code that I found on github to clean out my icloud mails.我正在尝试恢复在 github 上找到的 python 2代码,以清除我的 icloud 邮件。 My code logs in, selects INBOX and fetches status, IDs and UIDs successfully using
imaplib.IMAP4_ssl
as email_connection
.我的代码登录,选择 INBOX 并使用
imaplib.IMAP4_ssl
作为email_connection
成功获取状态、ID 和 UID。
It, then, should flag emails in Apple's icloud Mail for deletion:然后,它应该标记 Apple 的 icloud Mail 中的电子邮件以供删除:
email_connection.uid("STORE", email_uid, "+FLAGS", "(\\Deleted)")
but this is where it throws an但这是它抛出的地方
imaplib.error: UID command error: BAD [b'Parse Error (took 0 ms)']
The original code used int(email_uid)
at the same spot which I changed as it threw原始代码在同一位置使用了
int(email_uid)
,我在它抛出时更改了它
TypeError: can't concat int to bytes
email_uid
is now passed as a str
which produces the UID command error. email_uid
现在作为str
传递,这会产生 UID 命令错误。 Online research gave a lot of info that was gmail-specific.在线研究提供了很多特定于 gmail 的信息。 Anyone with experience of using imaplib on Apple Mail?
有人有在 Apple Mail 上使用 imaplib 的经验吗?
Thanks!谢谢!
Here is the debug log starting a few lines before the break:这是在中断前几行开始的调试日志:
06:34.78 < b'* 198 FETCH (UID 47520)'
06:34.78 matched b'\\* (?P<data>\\d+) (?P<type>[A-Z-]+)( (?P<data2>.*))?' => (b'198', b'FETCH', b' (UID 47520)', b'(UID 47520)')
06:34.78 untagged_responses[FETCH] 0 += ["b'198 (UID 47520)'"]
06:34.78 < b'IAFG4 OK FETCH completed (took 52 ms)'
06:34.78 matched b'(?P<tag>IAFG\\d+) (?P<type>[A-Z]+) (?P<data>.*)' => (b'IAFG4', b'OK', b'FETCH completed (took 52 ms)')
06:34.78 untagged_responses[FETCH] => [b'198 (UID 47520)']
06:34.78 > b'IAFG5 UID STORE 47520 +FLAGS (\\Deleted)'
06:34.89 < b'IAFG5 BAD Parse Error (took 0 ms)'
06:34.89 matched b'(?P<tag>IAFG\\d+) (?P<type>[A-Z]+) (?P<data>.*)' => (b'IAFG5', b'BAD', b'Parse Error (took 0 ms)')
06:34.89 BAD response: b'Parse Error (took 0 ms)'
The problem is the double space.问题是双重空间。
IMAP is strict about where space is required and permitted. IMAP 对需要和允许空间的地方很严格。 Space is only permitted where required, and required only where a delimiter is necessary to avoid misunderstandings.
只有在需要时才允许使用空格,并且只有在需要使用分隔符以避免误解时才需要使用空格。 A single space character is enough to avoid misunderstandings, and therefore the second space is an error.
单个空格字符足以避免误解,因此第二个空格是错误的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.