使用imaplib删除gmail中的电子邮件时出现问题 [英] Problem deleting emails in gmail using imaplib

查看:392
本文介绍了使用imaplib删除gmail中的电子邮件时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试从收件箱文件夹中移除邮件,并且一切正常,但是当我切换到所有邮件文件夹时,删除功能无法正常工作。 expunge()方法返回('OK',[None])并且消息未被删除:

 >>> import imaplib 
>>>伺服器= imaplib.IMAP4_SSL('imap.gmail.com ','993')
>>> server.login('likvidator89@gmail.com','密码')
>>> server.select('inbox')
>>> for i in server.search(None,'all')[1] [0] .split():
... print i +\\\
+ server .fetch(i,'(BODY [HEADER.FIELDS(Subject)])')[1] [0] [1]
...
#我怎么知道什么UID憎恶我的信息?我按主题选择
#....
#28
#Subject:1 Question有1个答案 - Stack Overflow


#29
#Subject:2222222222
#...
>>> server.store(29,'+ FLAGS','\\Deleted')
# ('OK',['29(FLAGS(\\\\\ Seen \\Deleted))'])
>>> server.expunge()
#('OK' ,['29'])
>>> server.select('[Gmail] / All Mail')
('OK',['47'])
>>>我在server.search(None,'all')[1] [0] .split():
... print i +\\\
+ server.fetch(i,'(BODY [HEADER .FIELDS(Subject)])')[1] [0] [1]
...
#....

#46
#标题:2222222222


#47
#主题:3333333333333333

#....
>>> ; server.store(47,'+ FLAGS','\\Deleted')
('OK',['47(FLAGS(\\Seen \\Deleted))'])
>>> server.expunge()
('OK',[None])


解决方案

正如它在 gmail博客网站,Google的IMAP实施有点不同。当你按照说明获得更平常的语义时,它有帮助吗?


对于那些还有一些比较模糊的
选项您想要
的人使Gmail的IMAP更像传统IMAP提供商的
一样工作:您可以
在不再是$ b $时关闭自动清除或垃圾邮件
b通过IMAP可见。

IMAP协议允许标记为
的消息被删除,
limbo状态消息仍为
出现在文件夹中,但预计会在
下次删除时被删除
。在我们的标准IMAP
实现中,当您将
消息标记为已删除时,Gmail不会让
在该状态中徘徊 - 它会删除
(或自动删除)它立即从文件夹
中删除。如果您想要两阶段
删除过程,在您启用
本实验室之后,只需在
下选择'不要
自动清除消息',然后选择'转发和POP /
设置中的IMAP选项卡。同样,大多数IMAP系统不会共享
的Gmail存档
消息(发送消息到
[Gmail] /所有邮件文件夹,而不是
[Gmail] /垃圾箱)。如果您希望
已删除的邮件不会保存在任何
中,则其他可见的IMAP文件夹将被发送到
[Gmail] /垃圾箱,高级IMAP
控件可让您设置您的偏好
这样。在转发和
POP / IMAP标签的'IMAP Access:'
部分中,找到'从最后
可见IMAP文件夹中删除
邮件时: ' 选项。选择
'将邮件移动到Gmail垃圾箱'
如果您想进一步使用
一步,您可以选择'立即
永远删除邮件' p>


I try to remove message from inbox folder and all alright, but when i switched to All Mail folder the removing does not work. expunge() method returns ('OK', [None]) and message was not removed:

>>>import imaplib
>>>server = imaplib.IMAP4_SSL('imap.gmail.com','993')
>>>server.login('likvidator89@gmail.com','Password')
>>>server.select('inbox')
>>>for i in server.search(None,'all')[1][0].split():
...    print i+"\n"+server.fetch(i,'(BODY[HEADER.FIELDS (Subject)])')[1][0][1]
...
#  that how i know what UID hame my message? I select by subject
#....
#28
#Subject: 1 Question Has 1 Answer - Stack Overflow
#
#
#29
#Subject: 2222222222
#...
>>>server.store(29,'+FLAGS','\\Deleted')
#('OK', ['29 (FLAGS (\\Seen \\Deleted))'])
>>>server.expunge()
#('OK', ['29'])
>>> server.select('[Gmail]/All Mail')
('OK', ['47'])
>>> for i in server.search(None,'all')[1][0].split():
...  print i+"\n"+server.fetch(i,'(BODY[HEADER.FIELDS (Subject)])')[1][0][1]
... 
#....
#
#46
#Subject: 2222222222
#
#
#47
#Subject: 3333333333333333
#
#....
>>> server.store(47,'+FLAGS','\\Deleted')
('OK', ['47 (FLAGS (\\Seen \\Deleted))'])
>>> server.expunge()
('OK', [None])

解决方案

As it says on the gmail blog site, Google's implementation of IMAP is a bit different. When you follow the instructions for getting more usual semantics, does it help?

There are also some more obscure options for those of you who want to make Gmail's IMAP work more like traditional IMAP providers: you can turn off auto-expunge or trash messages when they're no longer visible through IMAP.

The IMAP protocol allows messages to be marked for deletion, a sort of limbo state where a message is still present in the folder but slated to be deleted the next time the folder is expunged. In our standard IMAP implementation, when you mark a message as deleted, Gmail doesn't let it linger in that state -- it deletes (or auto-expunges) it from the folder right away. If you want the two-stage delete process, after you've enabled this Lab, just select 'Do not automatically expunge messages' under the 'Forwarding and POP/IMAP' tab in Settings.

Similarly, most IMAP systems don't share Gmail's concept of archiving messages (sending messages to the [Gmail]/All Mail folder rather than [Gmail]/Trash). If you'd prefer that deleted messages not remaining in any other visible IMAP folders are sent to [Gmail]/Trash instead, Advanced IMAP Controls lets you set your preferences this way. In the 'IMAP Access:' section of the 'Forwarding and POP/IMAP' tab, find the 'When a message is deleted from the last visible IMAP folder:' option. Select 'Move the message to the Gmail Trash.' If you want to take it one step further, you can select 'Immediately delete the message forever.'

这篇关于使用imaplib删除gmail中的电子邮件时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆