获取未读邮件的数量
我正在开发一个小软件来检查我的邮件帐户上是否有>0封未读电子邮件(任何免费邮件,imap)。
我正在用 C 编码,但我不是专家...
如何使用 C 的 imap4-api (或只是类似的东西)来检查是否有任何未读电子邮件(不获取它们)?
提前致谢
I am working on a tiny piece of software to check if there are >0 UNread emails on my mail account (any free mail, imap).
I am coding in C, but I'm not an expert...
How can C's imap4-api (or just sth comparable) be used to check if there are any unread emails (without fetching them)?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有几种方法可以做到这一点。我将在协议级别进行解释,我敢打赌您的 C 库将至少公开其中之一...
一般来说,最有效的方法是发出 STATUS 命令并询问文件夹的 UNSEEN 计数:
您可以选择文件夹并检查 [UNSEEN] 响应代码是否返回未标记的 OK:
选择文件夹后,您可以发出 SEARCH 命令并询问 UNSEEN 邮件(如果返回任何内容,则表示您有未读邮件) :
请注意,所有这些都是针对每个文件夹进行操作的。如果您想了解邮箱中的所有文件夹,则必须遍历所有文件夹。要获取完整的文件夹列表,请使用 LIST 命令:
There are several ways to do it. I'll explain at the protocol level, and I'd bet that your C library will expose at least one of these...
In general the most efficient way is to issue the STATUS command and ask for the folder's UNSEEN count:
You can SELECT the folder and check whether the [UNSEEN] response code comes back on an untagged OK:
Once the folder has been selected, you can issue a SEARCH command and ask for UNSEEN messages (if anything comes back, you've got unread mail):
Note that all of these operate on a per-folder basis. If you want to know about all the folders in your mailbox, you'll have to iterate over them all. To get the full folder list, use the LIST command:
鉴于您确实似乎在使用 C API,您可以对 UNSEEN 消息执行 imap4_search。这应该允许您计算未读消息的数量。类似的 PHP 示例可以在这里找到: http://www.electrictoolbox.com/php -imap-未读消息/
Given that you indeed seem to be using the C API, you can do an imap4_search for UNSEEN messages. That should allow you to count the number of unread messages. A similar PHP example can be found here: http://www.electrictoolbox.com/php-imap-unread-messages/