File: keyword_criteria_and_custom_flags.py

package info (click to toggle)
imap-tools 1.10.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,624 kB
  • sloc: python: 4,709; makefile: 5
file content (14 lines) | stat: -rw-r--r-- 456 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
"""How to use keyword criteria"""

from imap_tools import A, MailBox

with MailBox('imap.wow.ru').xoauth2('imap.tools', '123') as mailbox:
    uids = ['183']
    # get messages by uid
    for msg in mailbox.fetch(A(uid=uids)):
        print(msg.uid, msg.subject)
    # add custom flag
    mailbox.flag(uids, ['flag1'], True)
    # get messages by custom flag
    for msg in mailbox.fetch(A(keyword='flag1')):
        print(msg.uid, msg.subject, msg.flags)