简体   繁体   English

使用Python库在IMAP中移动邮件

[英]Move mail in IMAP with Python library

Moving a message to a different folder seems quite difficult in IMAP. 在IMAP中,将邮件移到另一个文件夹似乎非常困难。

See IMAP: how to move a message from one folder to another 请参阅IMAP:如何将邮件从一个文件夹移动到另一个文件夹

How can I do this in Python without coding too much? 我如何在Python中做到这一点而无需编写太多代码?

I prefer to reuse :-) 我更喜欢重用:-)

The imaplib standard module is at your service. imaplib标准模块随时为您服务。

Apart from the method in the linked question, you can use a nonstandard MOVE command with IMAP4._simple_command (see copy() implementation, its syntax is the same) after checking self.capabilities for "MOVE" presence. 除了链接问题中的方法外,在检查self.capabilities是否存在"MOVE"之后,还可以对IMAP4._simple_command使用非标准的MOVE命令(请参见copy()实现,其语法相同)。

The question which you linked to has an answer which explains what the features of the IMAP protocol are. 您链接到的问题有一个答案 ,解释了IMAP协议的功能。 Chances are that such a command is too fresh to be available via the Python's standard imaplib . 可能这样的命令太新了,无法通过Python的标准imaplib If that is the case, your best bet is to send them a patch so that it is included in future releases. 如果是这种情况,最好的选择是向他们发送一个补丁,以便将来的发行版中包含该补丁。 That's how it works -- if nobody bothers to add support for new commands, it won't get added. 这就是它的工作方式-如果没有人愿意添加对新命令的支持,它将不会被添加。

The imaplib is a rather low-level package, so I do not expect that it will ever implement a nice way of moving messages around. imaplib是一个相当底层的软件包,因此我不希望它会实现一种移动消息的好方法。 My suggestion would be to either use another library which provides a higher-level view of IMAP ("hey server, how many messages are there in INBOX? Show me the MIME structure of the last one, please..."). 我的建议是使用另一个提供IMAP更高级别视图的库(“嘿,服务器,INBOX中有多少消息?请向我显示最后一个的MIME结构,请...”)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM