![](/img/trans.png)
[英]Using python exchangelib, how to get total size of messages in mail folder
[英]How to get the parent folder name of Message with Exchangelib python
我有一個項目 object 通過在 python 3.7 中使用 exchangelib 過濾帳戶獲得。 它是 email object。 我需要找到該項目的父文件夾名稱。 我特別需要文件夾的名稱字段(這是用於跟蹤特定電子郵件在郵箱中的移動位置)。
我可以在 object 項目中看到一個字段 parent_folder_id,它返回我認為有效的文件夾 ID。 這也適用於生產郵箱,其中account.root.get_folder(folder_id=idObj)
由於我無法更改的 Exchange 設置而超時。 幾乎所有緩存的請求都會因超時而失敗。
account=Account(...)
mailItems=account.inbox.all().filter(subject="foo")
print([i.parent_folder_id.id for i in mailItems])
這將打印文件夾 ID 列表。 我需要這些文件夾的名稱。 不清楚如何進行。 任何幫助,將不勝感激
由於您只搜索account.inbox
而不是其子文件夾, parent_folder_id
將始終指向account.inbox
。
目前還沒有一個很好的 API 用於通過 ID 查找文件夾。 目前最好的解決方案是使用文件夾 QuerySet:
from exchangelib.folders import SingleFolderQuerySet
f = SingleFolderQuerySet(
account=account,
folder=account.root
).get(id=i.parent_folder_id.id)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.