使用IMAP4和python从GMail获取加星标的邮件 [英] Get starred messages from GMail using IMAP4 and python

查看:317
本文介绍了使用IMAP4和python从GMail获取加星标的邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现了许多有关使用IMAP的虚拟信息,但我不知道如何将其用于我的目的.我找到了如何从邮箱中获取所有消息和所有已查看消息的方法,但是我应该如何处理星号? 请给我一些python代码示例,这些示例代码用于通过IMAP4从GMail获取已加星标的邮件,检查某些邮件是否已加星标,是否为某个邮件加注星标和取消加星标.

I found many dummy info about working with IMAP, but I didn't understand how to use it for my purposes. I found how I can get ALL messages from mailbox and ALL SEEN messages, but how should I work with stars? Please, give me examples of python code for getting starred messages from GMail through IMAP4, for checking if some message is starred or unstarred, for starring and unstarring some one message.

推荐答案

Gmail的已加星标"状态直接映射到IMAP \Flagged关键字上.因此,您可以通过设置或取消设置邮件上的\Flagged来切换邮件的星号:

Gmail's "Starred" state maps directly onto the IMAP \Flagged keyword. So you can toggle a message's star by setting or unsetting \Flagged on the message:

IMAP4.store(num, '+FLAGS', '\\Flagged')

您可以通过搜索FLAGGED来搜索已加星标的邮件(或通过UNFLAGGED来搜索未加星标的邮件):

You can search for starred messages by searching for FLAGGED (or for unstarred messages via UNFLAGGED):

IMAP4.search(None, 'FLAGGED')

Gmail甚至为您提供了一个包含所有已加星标邮件的虚拟文件夹.如果您SELECT "[Gmail]/Starred",您将获得邮箱中所有已加星标邮件的视图:

Gmail even gives you a virtual folder containing all starred messages. If you SELECT "[Gmail]/Starred", you'll get a view of all the starred messages in the mailbox:

IMAP4.select('[Gmail]/Starred')

这篇关于使用IMAP4和python从GMail获取加星标的邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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