[英]Python 3: Move email to trash by uid (imaplib)
I want to move an email from my inbox to the trash folder, I do not want the email permanently deleted, I want it to go through the process of waiting 30 days in the trash to be permanently deleted. 我想将收件箱中的电子邮件移至垃圾箱文件夹,我不希望电子邮件被永久删除,我希望它能够在垃圾箱中等待30天才能永久删除。
mail = imaplib.IMAP4_SSL('imap.gmail.com')
mail.login("example@gmail.com", "example")
mail.select("inbox")
result, data = mail.uid('search', None, "ALL")
uidList = data[0].split()
#processEmails returns the uids of the emails that I need
#not really important for the purposes of this question
newUidList = processEmails(uidList)
newUidList
newUidList
for uid in newUidList:
mail.uid('STORE',uid, '+FLAGS', '(\\Deleted)')
I thought that this line mail.uid('STORE',uid, '+FLAGS', '(\\\\Deleted)')
would solve the problem (because that's what I found on the internet). 我认为这行
mail.uid('STORE',uid, '+FLAGS', '(\\\\Deleted)')
可以解决问题(因为这是我在互联网上找到的)。 But being here asking this question, you probably have correctly guessed that it did not. 但是在这里问这个问题,你可能已经正确地猜到它没有。
When I executed this script, the emails disappeared from the inbox just as planned. 当我执行此脚本时,电子邮件按计划从收件箱中消失。 But when I visit the trash folder, there is nothing there.
但是当我访问垃圾文件夹时,那里什么都没有。 So I thought maybe they were permanently deleted.
所以我想也许他们被永久删除了。
But they were not. 但他们不是。 I noticed this when I saw that my email storage space is filling up quick which means my emails were still there somewhere.
当我看到我的电子邮件存储空间快速填满时,我注意到了这一点,这意味着我的电子邮件仍在那里。
I go into the "All Emails" folder and there they are. 我进入“All Emails”文件夹,他们就在那里。
mail.uid('STORE',uid, '+FLAGS', '(\\\\Deleted)')
mail.uid('STORE',uid, '+FLAGS', '(\\\\Deleted)')
Thank you for your input :) 谢谢您的意见 :)
So for anyone having the same problem, I found out how to move your email to the trash by uid. 因此,对于遇到相同问题的任何人,我发现了如何通过uid将您的电子邮件移至垃圾箱。 referring back to my post, I should have put
mail.uid('STORE', uid, '+X-GM-LABELS', '\\\\Trash')
instead of mail.uid('STORE',uid, '+FLAGS', '(\\\\Deleted)')
回到我的帖子,我应该把
mail.uid('STORE', uid, '+X-GM-LABELS', '\\\\Trash')
而不是mail.uid('STORE',uid, '+FLAGS', '(\\\\Deleted)')
And there you have it :) 你有它:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.