简体   繁体   English

python imap邮件搜索分钟

[英]python imap mail search with minutes

I am trying to search "10 minutes older" emails via python imaplib I can search emails with any strings, but not date.我正在尝试通过 python imaplib 搜索“10 分钟前”的电子邮件我可以搜索带有任何字符串的电子邮件,但不能搜索日期。

result, data = mail.uid('search', None, '(HEADER Subject "SEARCH_TERM")')

How can I make a search by minutes?如何按分钟进行搜索?

The SEARCH command (SENTSINCE, SINCE, SENTBEFORE, SENTON, BEFORE) works only with with a date, not a date + timestamp. SEARCH 命令(SENTSINCE、SINCE、SENTBEFORE、SENTON、BEFORE)仅适用于日期,而不是日期 + 时间戳。 That means the search criteria is limited to DD-MMM-YYYY.这意味着搜索条件仅限于 DD-MMM-YYYY。 You can't include hours or minutes or seconds, just the date.您不能包括小时、分钟或秒,只能包括日期。

YES: a1 search since "01-mar-2014"是:a1 搜索自“01-mar-2014”

NO: a1 search since "01-mar-2014 00:00:00"否:自“01-mar-2014 00:00:00”以来的 a1 搜索

1 search since "01-mar-2014"自“2014 年 3 月 1 日”以来搜索了 1 次

  • SEARCH 498 499 500搜索 498 499 500

1 search since "01-mar-2014 00:00:00"自“01-mar-2014 00:00:00”以来搜索了 1 次

1 BAD Error in IMAP command SEARCH: Invalid search date parameter 1 IMAP 命令 SEARCH 中的 BAD 错误:无效的搜索日期参数

You'll have to look at each message whose message number is returned by the search and apply timestamp filtering in your code.您必须查看搜索返回其消息编号的每条消息,并在代码中应用时间戳过滤。 For example:例如:

1 fetch 498:500 internaldate 1 取 498:500 内部日期

  • 498 FETCH (INTERNALDATE "04-Mar-2014 13:07:29 -0600") 498 FETCH(国际“2014 年 3 月 4 日 13:07:29 -0600”)

  • 499 FETCH (INTERNALDATE "05-Mar-2014 07:16:43 -0600") 499 FETCH(国际“2014 年 3 月 5 日 07:16:43 -0600”)

  • 500 FETCH (INTERNALDATE "05-Mar-2014 07:44:36 -0600") 500 FETCH(INTERNALDATE“2014 年 3 月 5 日 07:44:36 -0600”)

Or fetch 498:500 (body.peek[header.fields (Date)]) if you prefer to use that date.或者 fetch 498:500 (body.peek[header.fields (Date)]) 如果你更喜欢使用那个日期。

-Rick -瑞克

Base IMAP doesn't allow that.基本 IMAP 不允许这样做。 There is an extension, WITHIN , to do it, but it's spottily implemented.有一个扩展, WITHIN ,可以做到这一点,但它被巧妙地实现。 See if your server supports WITHIN.查看您的服务器是否支持 WITHIN。 If not you'll just have to search for today's mail, retrieve the date fields or INTERNALDATE, and do the fine-tuning yourself.如果没有,您只需搜索今天的邮件,检索日期字段或 INTERNALDATE,然后自己进行微调。

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

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