【发布时间】:2022-08-03 15:12:24
【问题描述】:
我想浏览我的电子邮件并将大附件保存在文件夹中。保存附件后,我想将附件替换为在哪里可以找到原始附件的注释。
我的理解是我必须制作原始电子邮件的修改副本(带有通知而不是原始附件)并删除原始电子邮件。
现在我的问题是,如何使用imap_tools 在原始电子邮件的基础上创建新电子邮件,而无需删除要删除的附件,而是使用纯文本消息。
这就是我现在的位置:
from copy import copy
from imap_tools import MailBox, A, U
msgId = \"30214\"
mailbox = MailBox(\"imap.gmail.com\").login(user, password)
mailbox.folder.set(\'[Gmail]/All Mail\')
for msg in mailbox.fetch(A(uid=U(msgId))):
print(f\"{i:>5}: {msg.date}, {msg.subject}, Attachments: {len(msg.attachments)}, Size: {msg.size}\")
newMsg = copy(msg)
for i, att in enumerate(newMsg.attachments):
print(i)
if att.size > 100_000:
print(f\"{i}: {att.filename}: {att.size}\")
# remove att from newMessage
# add a new attachement (e.g. text/plain with text denoting where I saved the original)
# add newMsg to mailbox
# remove msg from mailbox
标签: python imap-tools