使用 Python 解析 Gmail 并将所有早于日期的内容标记为“已读"

2022-01-23 00:00:00 python email imap gmail pop3

问题描述

长话短说,我创建了一个新的 gmail 帐户,并将其他几个帐户关联到该帐户(每个帐户都有 1000 条消息),我正在导入这些帐户.所有导入的邮件都以未读的形式到达,但我需要它们显示为已读.

Long story short, I created a new gmail account, and linked several other accounts to it (each with 1000s of messages), which I am importing. All imported messages arrive as unread, but I need them to appear as read.

我对python有一点经验,但是我只使用过mail和imaplib模块来发送邮件,没有处理账户.

I have a little experience with python, but I've only used mail and imaplib modules for sending mail, not processing accounts.

有没有办法批量处理收件箱中的所有项目,并将早于指定日期的邮件标记为已读?

Is there a way to bulk process all items in an inbox, and simply mark messages older than a specified date as read?


解决方案

typ, data = M.search(None, '(BEFORE 01-Jan-2009)')
for num in data[0].split():
   M.store(num, '+FLAGS', '\Seen')

这是对 imaplib 文档页面中的代码的轻微修改存储方法.我从 RFC 3501 中找到了要使用的搜索条件.这应该可以帮助您入门.

This is a slight modification of the code in the imaplib doc page for the store method. I found the search criteria to use from RFC 3501. This should get you started.

相关文章