简体   繁体   English

Python exchangelib - 将项目标记为已读

[英]Python exchangelib - mark item as read

I am trying to accomplish one task in my mailbox using Python's exchangelib module - how to move a certain email to a folder if it contains specific subject and has 'unread' status.我正在尝试使用 Python 的 exchangelib 模块在我的邮箱中完成一项任务 - 如果某个电子邮件包含特定主题并且具有“未读”状态,则如何将其移动到文件夹中。

while True:
    print("Checking inbox...")
    for msg in acc.inbox.filter(subject="Kontrol fra EVT...", is_read=False):
        if "SOS" in msg.text_body:
            pass
        else:
            msg.is_read = True
            print("Moving to EVT folder...")
            msg.move(archive)
            time.sleep(0.5)
    time.sleep(5)

Everything appears to be working except for msg.is_read = True part.除了msg.is_read = True部分,一切似乎都在工作。 The message remains unread, despite being successfully moved to the required folder.尽管已成功移动到所需的文件夹,但消息仍未读。

I believe I am missing something simple here.我相信我在这里遗漏了一些简单的东西。 I tried googling and using official module's documentation but came up empty in this regard.我尝试使用谷歌搜索并使用官方模块的文档,但在这方面却是空的。 Could find only one person with the same question as mine: Mark email as read with exchangelib只能找到一个和我有同样问题的人: 用 exchangelib 将电子邮件标记为已读

Thank you!谢谢!

Found the answer myself while digging through modules' files.在挖掘模块文件时自己找到了答案。 Apparently you have to "save" the item after flagging it.显然,您必须在标记后“保存”该项目。 In the end my code should look like this:最后我的代码应该是这样的:

while True:
    print("Checking inbox...")
    for msg in acc.inbox.filter(subject="Kontrol fra EVT...", is_read=False):
        if "SOS" in msg.text_body:
            pass
        else:
            msg.is_read = True
            msg.save()
            print("Moving to EVT folder...")
            msg.move(archive)
            time.sleep(0.5)
    time.sleep(5)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM