imapfilter cheat sheet

IMAP (SELECT)

Common:

select_all()   send_query(criteria)

Flags:

is_seen()      is_answered()    is_flagged()    is_deleted()    is_draft()
is_unseen()    is_unanswered()  is_unflagged()  is_undeleted()  is_undraft()

Age:

is_recent()
is_new()    is_newer(age)   arrived_before(date)    arrived_on(date)    arrived_since(date)
is_old()    is_older(age)   sent_before(date)       sent_on(date)       sent_since(date)

Misc:

is_larger(size)     has_keyword(flag)
is_smaller(size)    has_unkeyword(flag)

Content (case-insensitive):

contain_from(string)        contain_to(string)      contain_cc(string)      contain_bcc(string)
contain_subject(string)     contain_body(string)    contain_message(string)

contain_field(field, string)

Non-IMAP (FETCH + local PCRE)

Use sparsely!!! These are not supported by IMAP, so they will caise FETCH for each message, resulting in traffic costs. If you ever use them, make sure to do it on smaller sub-selection.

match_from(pattern)         match_to(pattern)   match_cc(pattern)   match_bcc(pattern)
match_subject(pattern)      match_body(pattern) match_message(pattern)
match_field(field, pattern) match_header(pattern)

Logic

Note: Prefer chain selection, and try to keep the first one server-side (no match_*()).

Set operations:

box:contain_from('bob') * box:contain_subject('joke:')   # intersection (OR)
box:contain_from('bob') + box:contain_subject('joke:')   # union (AND)
box:contain_from('bob') - box:contain_subject('joke:')   # difference (NOT, or "remove")

Chain selection:

box:contain_from('bob'):contain_subject('joke:')         # sub-selection (similar to AND)

EXAMPLES

results = myaccount.mymailbox:select_all()
results = myaccount.mymailbox:is_new()
results = myaccount.mymailbox:is_recent()
results = myaccount.mymailbox:is_larger(100000)
results = myaccount.mymailbox:is_older(10)
results = myaccount.mymailbox:has_keyword('MyFlag')
results = myaccount.mymailbox:arrived_before('01-Jan-2007')
results = myaccount.mymailbox:sent_since('01-Jan-2007')
results = myaccount.mymailbox:contain_subject('test')
results = myaccount.mymailbox:contain_field('Sender', 'user@host')
results = myaccount.mymailbox:contain_body('hello world')
results = myaccount.mymailbox:match_from('.*(user1|user2)@host')
results = myaccount.mymailbox:send_query('ALL')

results = myaccount['mymailbox']:is_new()
results = myaccount['myfolder/mymailbox']:is_recent()
Mastodon
published by mdpublish, 2024-07-02