Python imapclient 搜索使用多个操作数
Python imapclient search using multiple operands
我正在使用 Python 的 imapclient
,我需要能够搜索多个操作数。例如,假设我想查看 2018 年 1 月 6 日或 2018 年 1 月 13 日发送的消息。我查看了 IMAP criteria with multiple ORs and at https://www.limilabs.com/blog/imap-search-requires-parentheses。
使用上次参考中的技巧,我尝试过:
*r_data = M.search(['OR SENTON "6-Jan-2018" SENTON "13-Jan-2018"'])
r_data = M.search('OR SENTON "6-Jan-2018" SENTON "13-Jan-2018"')
r_data = M.search('SENTON "6-Jan-2018" OR SENTON "13-Jan-2018"')*
和其他几个人。每次我得到:
*imaplib.error: UID command error: BAD ['Command Argument Error. 11']*
我真的不想深入研究 imapclient
代码来弄清楚如何构造此请求。有人有什么建议吗?
我遇到了同样的问题。找到的解决方案是(基于 comments in the source code):
r_data = M.search(['OR', 'SENTON', '6-Jan-2018', 'SENTON', '13-Jan-2018'])
甚至更好:
r_data = M.search(['OR', 'SENTON', date(2018, 1, 6), 'SENTON', date(2018, 1, 13)])
也适用于更复杂的查询,例如:
M.search(['OR', 'OR', 'FROM', 'a', 'FROM', 'b', 'FROM', 'c'])
尝试使用查询生成器:
import datetime as dt
from imap_tools import AND, OR, NOT, Q, H
# date not in the date list (NOT(date=date1 OR date=date3 OR date=date2))
q2 = NOT(OR(date=[dt.date(2019, 10, 1), dt.date(2019, 10, 10), dt.date(2019, 10, 15)]))
# "NOT ((OR OR ON 1-Oct-2019 ON 10-Oct-2019 ON 15-Oct-2019))"
我正在使用 Python 的 imapclient
,我需要能够搜索多个操作数。例如,假设我想查看 2018 年 1 月 6 日或 2018 年 1 月 13 日发送的消息。我查看了 IMAP criteria with multiple ORs and at https://www.limilabs.com/blog/imap-search-requires-parentheses。
使用上次参考中的技巧,我尝试过:
*r_data = M.search(['OR SENTON "6-Jan-2018" SENTON "13-Jan-2018"'])
r_data = M.search('OR SENTON "6-Jan-2018" SENTON "13-Jan-2018"')
r_data = M.search('SENTON "6-Jan-2018" OR SENTON "13-Jan-2018"')*
和其他几个人。每次我得到:
*imaplib.error: UID command error: BAD ['Command Argument Error. 11']*
我真的不想深入研究 imapclient
代码来弄清楚如何构造此请求。有人有什么建议吗?
我遇到了同样的问题。找到的解决方案是(基于 comments in the source code):
r_data = M.search(['OR', 'SENTON', '6-Jan-2018', 'SENTON', '13-Jan-2018'])
甚至更好:
r_data = M.search(['OR', 'SENTON', date(2018, 1, 6), 'SENTON', date(2018, 1, 13)])
也适用于更复杂的查询,例如:
M.search(['OR', 'OR', 'FROM', 'a', 'FROM', 'b', 'FROM', 'c'])
尝试使用查询生成器:
import datetime as dt
from imap_tools import AND, OR, NOT, Q, H
# date not in the date list (NOT(date=date1 OR date=date3 OR date=date2))
q2 = NOT(OR(date=[dt.date(2019, 10, 1), dt.date(2019, 10, 10), dt.date(2019, 10, 15)]))
# "NOT ((OR OR ON 1-Oct-2019 ON 10-Oct-2019 ON 15-Oct-2019))"