Python 和 Outlook - 将消息线程标记为 'read'

Python and Outlook - Marking message thread as 'read'

我的公司使用 JIRA 来跟踪问题,并设置为在问题更新完成时向所有观察者和标记用户发送电子邮件。我们还有一些自动化功能,可以在问题关闭时调整问题的字段(如冲刺编号)(这也会发送一封电子邮件)。我在 Outlook 中还有一个过滤器,可以将来自 JIRA 的所有电子邮件放入单独的子文件夹 'JIRA'.

我经常收到有关已关闭问题的电子邮件。我正在尝试编写一个小的 Python 脚本,如果 JIRA 问题已经关闭,它将把所有这些电子邮件标记为已读。基本想法是我可以 运行 这个脚本每周一次左右来清理我的邮箱。

我正在使用 pywin32 和 jira 包来执行此操作,但我不知道如何更改消息状态。文档稀缺这一事实无济于事...

我有:

import re
import textwrap

from jira import JIRA
import pandas as pd
import win32com.client

jira = JIRA("<JIRA URL>", None, ("<USER>", "<JIRA API key>"))
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
wrapper = textwrap.TextWrapper(initial_indent="", width=100, subsequent_indent=" " * 4)
days_back = 10
start_time = pd.to_datetime("now").floor("D") - pd.to_timedelta(days_back, unit="D")
for message in outlook.getDefaultFolder(6).Folders.Item("JIRA").Items.Restrict(f"[ReceivedTime] >= '{start_time.strftime('%d/%m/%Y %H:%M %p')}'"):
    if message.Unread:
        jira_issue = re.search("\[JIRA\] \([A-Z0-9-]+\)", str(message)).group().split()[1][1:-1]
        print(message, jira_issue)
        print(message.body)
        issue = jira.issue(jira_issue)
        status = issue.fields.status
        if status in ("Done", "Checked"):
            message.Unread = False

this SO issue 中所述。这似乎没有将任何电子邮件标记为已读。

这是我在 Python 中甚至可以做的事情吗?如果是这样,如何?如果不是,有什么替代方法?

您可以使用 Categories property to assign a red category to items in Outlook. Categories is a delimited string of category names that have been assigned to an Outlook item. This property uses the character specified in the value name, sList, under HKEY_CURRENT_USER\Control Panel\International in the Windows registry, as the delimiter for multiple categories. See Setting an Outlook mailitem's category programmatically? 获取更多信息。