擅长:python、mysql、java
<p>您可以使用imap_工具包:
<a href="https://pypi.org/project/imap-tools/" rel="nofollow noreferrer">https://pypi.org/project/imap-tools/</a></p>
<p>实现了rfc3501中描述的搜索逻辑。</p>
<pre><code>from imap_tools import Q, AND, OR, NOT
# base
mailbox.fetch('TEXT "hello"') # str
mailbox.fetch(b'TEXT "\xd1\x8f"') # bytes
mailbox.fetch(Q(subject='weather')) # query, the str-like object
# AND
Q(text='hello', new=True) # 'TEXT "hello" NEW'
# OR
OR(text='hello', date=datetime.date(2000, 3, 15)) # '(OR TEXT "hello" ON 15-Mar-2000)'
# NOT
NOT(text='hello', new=True) # '(NOT TEXT "hello" NEW)'
# complex:
# 'TO "to@ya.ru" (OR FROM "from@ya.ru" TEXT "\\"the text\\"") (NOT (OR UNANSWERED NEW))')
Q(OR(from_='from@ya.ru', text='"the text"'), NOT(OR(Q(answered=False), Q(new=True))), to='to@ya.ru')
# encoding
mailbox.fetch(Q(subject='привет'), charset='utf8') # 'привет' will be encoded by MailBox._criteria_encoder
</code></pre>
<p>更多信息请参见文档。</p>