gpt4 book ai didi

Python imaplib 不会将消息标记为看不见

转载 作者:太空宇宙 更新时间:2023-11-04 03:08:40 25 4
gpt4 key购买 nike

我正在开发一个从电子邮件中收集数据的功能,并有一个开关可以将消息标记为未看到。在开发过程中它开始失败我不知道为什么。我在文档中查找了它,我搜索了 stackoverflow(找到了 this 线程,但它没有帮助)。反正。这是代码:

    mail = imaplib.IMAP4_SSL('imap.gmail.com', '993')
mail.login(settings.INVOICES_LOGIN, settings.INVOICES_PASSWORD)
mail.select('inbox')

result, data = mail.uid('search', '(UNSEEN)', 'X-GM-RAW',
'SUBJECT: "{0}" FROM: "{1}"'.format(attachment_subject, attachment_from))
uids = data[0].split()
for uid in uids:
result, data = mail.uid('fetch', uid, '(RFC822)')
m = email.message_from_string(data[0][1])

if m.get_content_maintype() == 'multipart':
for part in m.walk():
if part.get_content_maintype() == 'multipart':
continue
if part.get('Content-Disposition') is None:
continue
if re.match(attachment_filename_re, part.get_filename()):
attachments.append({'uid': uid, 'data': part.get_payload(decode=True)})

if set_not_read:
mail.store(uid, '-FLAGS', '(\Seen)')

我已经调试过了,我确信使用这个标志 mail.store(uid, '-FLAGS', '(\Seen)') 部分被输入了,我也尝试切换到 \SEEN\Seen 而不是 (\Seen)。

编辑:

我想做的是制作一个脚本,允许用户将电子邮件标记为 unseen(未读),这会重置 Seen 标志,并且不允许它将电子邮件标记为已读(已读)。

最佳答案

我相信你想要

mail.store(uid, '+FLAGS', '(\\Seen)')

我认为您现在正在做的是移除看到的旗帜。但我会查看 RFC 以确保确定。

编辑:是的。这就是RFC says

-FLAGS <flag list>
Remove the argument from the flags for the message. The new
value of the flags is returned as if a FETCH of those flags was
done.

您可能会发现相关的其他位:

The currently defined data items that can be stored are:

FLAGS <flag list>
Replace the flags for the message (other than \Recent) with the
argument. The new value of the flags is returned as if a FETCH
of those flags was done.

FLAGS.SILENT <flag list>
Equivalent to FLAGS, but without returning a new value.

+FLAGS <flag list>
Add the argument to the flags for the message. The new value
of the flags is returned as if a FETCH of those flags was done.

+FLAGS.SILENT <flag list>
Equivalent to +FLAGS, but without returning a new value.

-FLAGS <flag list>
Remove the argument from the flags for the message. The new
value of the flags is returned as if a FETCH of those flags was
done.

-FLAGS.SILENT <flag list>
Equivalent to -FLAGS, but without returning a new value.

关于Python imaplib 不会将消息标记为看不见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38744885/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com