IMAPFILTER_CONFIG(5)

πŸ“¦
version 2.8.3 Β· 3 versions
, in fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, ubuntu resolute, ubuntu stonking

✨ NAME ✨

okay so bestie, this is imapfilter_config(5) β€” the imapfilter configuration file from the File Formats Manual. That's the whole vibe: one Lua script that tells imapfilter(1) what to do. πŸ’–

πŸ¦‹ SYNOPSIS πŸ¦‹

$HOME/.imapfilter/config.lua

πŸ’… DESCRIPTION πŸ’…

imapfilter(1) uses the Lua programming language as a configuration and extension language, so the configuration file is a Lua script. No cap.

Knowledge of Lua isn't required to use imapfilter(1), but it's still recommended, especially if you wanna extend it. For more info on Lua see http://www.lua.org/docs.html. iykyk ✨

🌸 CONVENTIONS 🌸

A brief description of the Lua values and types mentioned hereafter in the manual page follows:

  • nil β€” the type of the value nil; its main property is being different from any other value, and it usually means there's no useful value here. πŸ’€
  • boolean β€” the type of the values true and false. Both nil and false make a condition false; any other value makes it true. βœ…
  • number β€” represents real numbers. πŸ”’
  • string β€” represents a sequence of characters and can be defined using single quotes, double quotes or double square brackets. πŸ“
  • table β€” implements associative arrays, i.e. arrays that can be indexed not only with numbers, but with any value. πŸ—‚οΈ
  • function β€” a first-class value; it can be stored in variables, passed as argument to other functions, and returned as a result. ✨

πŸ‘‘ OPTIONS πŸ‘‘

Program's options are set using an already initialised table named options, like this:

options.timeout = 120
options.namespace = false
options.charset = 'ISO-8859-1'

Available options are:

  • cache β€” okay so when this is on, parts of messages get cached locally in memory so they don't get downloaded more than once. The cache is preserved for the current session only, periodt. This variable takes a boolean as a value. Default is true. πŸ’Ύ
  • certificates β€” turn this on and the server certificate can be accepted and stored, so future connections can validate the authenticity of the server. This variable takes a boolean as a value. Default is true. πŸ”
  • charset β€” tells the server the character set of the strings for the searching methods. This variable takes a string as a value. By default, no character set is set, and thus plain ASCII should be assumed by the server. πŸ”€
  • create β€” IMAP spec says when you try to write a message to a non-existent mailbox, the server must send a hint to the client about whether it should create the mailbox and try again or not. But some IMAP servers are not that girl β€” they don't follow the specification and don't send the correct response code to the client. By enabling this option the client tries to create the mailbox, despite the server's response. This variable takes a boolean as a value. Default is false. πŸ› οΈ
  • close β€” controls whether the currently selected mailbox is implicitly closed at the end of each performed operation, thus removing all messages that are marked deleted. This variable takes a boolean as a value. Default is false. πŸšͺ
  • expunge β€” normally, messages are marked for deletion and are actually deleted when the mailbox is closed. When this option is enabled, messages are expunged immediately after being marked deleted. This variable takes a boolean as a value. Default is true. 🧹
  • hostnames β€” turn this on and the server hostname is validated, in order to verify the client is talking to the correct server. This variable takes a boolean as a value. Default is true. 🏠
  • info β€” turn this on and a summary of the program's actions is printed while processing mailboxes. This variable takes a boolean as a value. Default is true. πŸ“’
  • keepalive β€” the time in minutes before terminating and re-issuing the IDLE command, in order to keep alive the connection, by resetting the inactivity timeout of the server. A standards compliant server must have an inactivity timeout of at least 30 minutes. But some IMAP servers might not respect that, or some intermediary network device has a shorter timeout. By setting this option the above problem can be worked around. This variable takes a number as a value. Default is 29 minutes. πŸ’“
  • limit β€” some servers have problems handling very long requests, but some of the requests that need to be sent can become quite long because they apply an action for many messages at once. When this option is set, the client will try to break up these requests into smaller requests, that each operates on fewer messages at a time. A good value for this would be 50. This variable takes a number as a value. Default is 0. See also the range option which is related. βœ‚οΈ
  • namespace β€” when enabled, the program gets the namespace of the user's personal mailboxes, and applies automatically the prefix and hierarchy delimiter to any mailboxes residing on the mail server; the user must use the / character as the delimiter and "" (i.e. nothing) as the prefix, regardless of the folder format of the mail server. This must be disabled, if the user wants to manually specify mailbox names (e.g. because they are not part of the user's personal namespace mailboxes). This variable takes a boolean as a value. Default is true. 🌌
  • range β€” some servers have problems handling long sequence number ranges, and by setting this option, the number of messages included in each range can be limited. A good value for this would be 50. This variable takes a number as a value. By default, no such limit is imposed. See also the limit option which is related. πŸ“
  • starttls β€” when this option is enabled and the server supports the IMAP STARTTLS extension, a TLS connection will be negotiated with the mail server in the beginning of the session. This variable takes a boolean as value. Default is true. πŸ”’
  • subscribe β€” by enabling this option new mailboxes that were automatically created, get also subscribed; they are set active in order for IMAP clients to recognize them. This variable takes a boolean as a value. Default is false. πŸ“¬
  • timeout β€” the time in seconds for the program to wait for a mail server's response. If set to 0, the client will block indefinitely. This variable takes a number as a value. Default is 60 seconds. ⏳
  • wakeonany β€” by enabling this option, the IDLE command will return on any event that is received from the server, and not just on the RECENT and EXISTS events, that normally indicate the arrival of a new message. Examples of other events are FETCH, which indicates that the details of a message (e.g. its flags) have been modified, or EXPUNGE, which indicates that a message has been deleted. This variable takes a boolean as a value. Default is false. πŸ‘€

✨ ACCOUNTS ✨

okay bestie, so accounts? they get initialized with the IMAP() function, and the whole connection vibe is defined using an account table. like this:

myaccount = IMAP {
    server = 'imap.mail.server',
    username = 'me',
    password = 'secret',
    ssl = 'auto'
}

An account table must have these elements, no skips:

  • server β€” the hostname of the IMAP server you're connecting to. it takes a string as a value. πŸ’»
  • username β€” the user's name. also takes a string as a value. πŸ‘€

An account table can also have these optional elements:

  • password β€” the user's secret keyword. if a password wasn't supplied, the user will be asked to enter one interactively the first time it's needed (unless oauth2 has been set). it takes a string as a value. πŸ”

Passwords can also be extracted during execution time from an encrypted password vault. the samples/extend.lua file contains such an example, periodt.

note that due to Lua using backslash \ as an escape character for its strings, you have to use double backslashes to insert a single backslash. so a backslash character inside a password might require four backslashes. yes really, it's giving escape character trauma 😭
  • oauth2 β€” the OAuth2 string to use to authenticate if the server supports the XOAUTH2 authentication mechanism. if the server does not support it and a password has also been set, authentication will be attempted using the password. it takes a string as a value. πŸ”‘

Note that this requires that an OAuth client ID and client secret have been obtained, an OAuth2 token has been generated and authorized, a new access token has been generated using the refresh token if the last access token has expired, and an OAuth2 string has been generated from the access token. the aforementioned OAuth2 string is a Base64 encoded string that should be set here. for more info, see https://developers.google.com/gmail/xoauth2_protocol.

The samples/extend.lua file contains an example of authentication using OAuth2. slay.

  • port β€” the port to connect to. it takes a number as a value. default is β€œ143” for imap and β€œ993” for imaps. πŸ”Œ
  • ssl β€” forces an imaps connection and specifies the SSL/TLS protocol/version to be used. it takes a string as a value, specifically one of: β€œauto”, β€œtls1.2”, β€œtls1.1”, β€œtls1”, β€œssl3”. πŸ”’
note that the latest versions of the OpenSSL library have deprecated version specific methods, and the actual protocol version used will be negotiated to be the highest version mutually supported by the client and the server. this is also what the β€œauto” value does. so basically auto is the main character. πŸ’…

πŸ“¬ LISTING πŸ“¬

The following methods can be used on an account to list mailboxes in a folder of an account:

  • list_all(folder) β€” lists all the available mailboxes in the folder (string), and returns a table that contains strings, the available mailboxes, and a table that contains strings, the available folders. πŸ—‚οΈ
  • list_subscribed(folder) β€” lists all the subscribed mailboxes in the folder (string), and returns a table that contains strings, the subscribed mailboxes, and a table that contains strings, the subscribed folders. βœ…

The following methods can be used on an account to list mailboxes, using wildcards, in a folder of an account. the β€˜*’ wildcard matches any character and the β€˜%’ matches any character except the folder delimiter, i.e. non-recursively:

  • list_all(folder, mailbox) β€” lists all the available mailboxes in the folder (string) with the name mailbox (string), and returns a table that contains strings, the available mailboxes, and a table that contains strings, the available folders. wildcards may only be used in the mailbox argument. πŸƒ
  • list_subscribed(folder, mailbox) β€” lists all the subscribed mailboxes in the folder (string) with the name mailbox (string), and returns a table that contains strings, the subscribed mailboxes, and a table that contains strings, the subscribed folders. wildcards may only be used in the mailbox argument. πŸƒ

Examples, bestie:

mailboxes, folders = myaccount:list_subscribed('myfolder')
mailboxes, folders = myaccount:list_all('myfolder/mysubfolder', '*')

πŸ› οΈ MANIPULATING πŸ› οΈ

The following methods can be used to manipulate mailboxes in an account:

  • create_mailbox(name) β€” creates the name (string) mailbox. ✨
  • delete_mailbox(name) β€” deletes the name (string) mailbox. πŸ’€
  • rename_mailbox(oldname, newname) β€” renames the oldname (string) mailbox to newname (string). πŸ”
  • subscribe_mailbox(name) β€” subscribes the name (string) mailbox. πŸ””
  • unsubscribe_mailbox(name) β€” unsubscribes the name (string) mailbox. πŸ”•

Examples:

myaccount:create_mailbox('mymailbox')
myaccount:subscribe_mailbox('mymailbox')
myaccount:unsubscribe_mailbox('myfolder/mymailbox')
myaccount:delete_mailbox('myfolder/mymailbox')

πŸ“« MAILBOXES πŸ“«

After an IMAP account has been initialized, mailboxes residing in that account can be accessed simply as elements of the account table:

myaccount.mymailbox

If mailbox names don't only include letters, digits and underscores, or begin with a digit, an alternative form must be used:

myaccount['mymailbox']

A mailbox inside a folder can only be accessed by using the alternative form:

myaccount['myfolder/mymailbox']

The methods that are available for an account (e.g. list_all(), create_mailbox(), etc.) are considered keywords and must not be used as mailbox names, and the same also applies for any string starting with an underscore, as they are considered reserved. so don't try it, bestie, it's giving forbidden. πŸ™ˆ


πŸ” CHECKING πŸ”

The following methods can be used to check the status of a mailbox:

  • check_status()

The check_status() method gets the current status of a mailbox, and returns four values of number type: the total number of messages, the number of recent messages, the number of unseen messages in the mailbox, and the next UID to be assigned to a new message in the mailbox. πŸ”’

  • enter_idle() β€” the enter_idle() method implements the IMAP IDLE (RFC 2177) extension. by using this extension it's not necessary to poll the server for changes to the selected mailbox (i.e. using the check_status() method), but instead the server sends an update when there is a change in the mailbox (e.g. in case of new mail). when the enter_idle() method has been called no more commands in the configuration file are executed until an update is received, at which point the enter_idle() method returns. for enter_idle() to work, the IDLE extension has to be supported by the IMAP server. πŸ“‘

The enter_idle() method returns a value of type boolean: β€œtrue” if the IDLE extension is supported and there was an update in the mailbox, and β€œfalse” if the IDLE extension is not supported, in which case the method returns immediately. when the aforementioned return value was β€œtrue”, an additional second value of type string is also returned, indicating the event received from the server, which is useful when the wakeonany option has been enabled. πŸ‘‘

Apart from an event received by the server, the SIGUSR1 or SIGUSR2 signals can also interrupt the IDLE mode at any time, and the execution of the configuration file will then continue from the next line after the enter_idle(). in this case, only the value β€œtrue” is returned. ⚑

Examples:

exist, unread, unseen, uidnext = myaccount.mymailbox:check_status()
update = myaccount.mymailbox:enter_idle()
update, event = myaccount.mymailbox:enter_idle()

πŸ”Ž SEARCHING πŸ”Ž

The searching methods in this subsection can be applied to any mailbox. they return a special form of table, that contains the messages that match the searching method. this table can be combined with other tables using logic theory. there are three available operations, that implement logical β€œor”, logical β€œand” and logical β€œnot”. 🧠

The logical β€œor” is implemented using the β€˜+’ operator:

results = myaccount.mymailbox:is_unseen() +
          myaccount.mymailbox:is_larger(100000)

The logical β€œand” is implemented using the β€˜*’ operator:

results = myaccount.mymailbox:is_unseen() *
          myaccount.mymailbox:is_larger(100000)

The logical β€œnot” is implemented using the β€˜-’ operator:

results = myaccount.mymailbox:is_unseen() -
          myaccount.mymailbox:is_larger(100000)

The three logical operators can be combined in the same expression. the logical β€œand” has higher precedence than the logical β€œor” and the logical β€œnot”, with the latter two having the same precedence, and parentheses may be used to change this behaviour:

results = myaccount.mymailbox:is_unseen() +
          myaccount.mymailbox:is_larger(100000) *
          myaccount.mymailbox:contain_subject('test')

results = ( myaccount.mymailbox:is_unseen() +
            myaccount.mymailbox:is_larger(100000) ) *
            myaccount.mymailbox:contain_subject('test')

The returned tables of the searching methods can also be stored in variables and then further processed:

unseen = myaccount.mymailbox:is_unseen()
larger = myaccount.mymailbox:is_larger(100000)
subject = myaccount.mymailbox:contain_subject('test')
results = unseen + larger * subject

A composite filter that includes one or more simple rules can be defined:

myfilter = function ()
               return myaccount.mymailbox:is_unseen() +
                      myaccount.mymailbox:is_larger(100000) *
                      myaccount.mymailbox:contain_subject('test')
           end

results = myfilter()

Composite filters can may be more dynamic by adding arguments:

myfilter = function (mailbox, size, subject)
               return mailbox:is_unseen() +
                      mailbox:is_larger(size) *
                      mailbox:contain_subject(subject)
           end

results = myfilter(myaccount.mailbox, 100000, 'test')

It is also possible to combine the searching methods in different mailboxes, either at the same or different accounts, for example when the same actions will be executed on messages residing in different mailboxes or accounts. 🌈

Okay so if you're the kind of person who needs to know exactly what these methods hand back (valid πŸ’…), here's the tea: it's a table. A table full of little tables. Each tiny table has two things in it β€” the mailbox (which is itself a table) that the message lives in, and the message UID (a number) that points at the matching message. Want to loop over these returned tables, or build your own tables in this exact format (spoiler: they're actually metatables that implement sets)? Go peek at the samples/extend.lua file. πŸ¦‹

{
    { <myaccount.mymailbox>, 1 },
    { <myaccount.mymailbox>, 3 },
    { <myaccount.myothermailbox>, 5 },
    { <myothermailbox.myothermailbox>, 7},
    { ... },
    ...
}

Like, for instance, this absolute banger of a query right here:

results = myaccount.mymailbox:is_unseen() +
          myaccount.myothermailbox:is_larger(100000) +
          myotheraccount.myothermailbox:contain_subject('test')

🌈 The Search Methods 🌈

So the next method is the "give me literally everything" one:

  • select_all() β€” All messages. Every single one. No filter, no drama, just vibes. πŸ‘‘

Now the "is it in this specific state" squad β€” these are for hunting down messages by what status they're rocking:

  • is_answered() β€” Messages that have been answered. βœ…
  • is_deleted() β€” Messages that are marked for later removal. πŸ—‘οΈ
  • is_draft() β€” Messages that have not completed composition. πŸ“
  • is_flagged() β€” Messages that are flagged for urgent/special attention. 🚩
  • is_new() β€” Messages that are recently arrived (this session is the first to have been notified about these messages) and have not been read.
  • is_old() β€” Messages that are not recently arrived (this session is not the first to have been notified about these messages) and have not been read.
  • is_recent() β€” Messages that are recently arrived (this session is the first to have been notified about these messages).
  • is_seen() β€” Messages that have been read. πŸ‘€
  • is_unanswered() β€” Messages that have not been answered.
  • is_undeleted() β€” Messages that are not marked for later removal.
  • is_undraft() β€” Messages that have completed composition. ✨
  • is_unflagged() β€” Messages that are not flagged for urgent/special attention.
  • is_unseen() β€” Messages that have not been read. (the unread girlies, we love them 😭)

πŸŽ€ Keyword Vibes πŸŽ€

This one's for when you're looking for messages with a specific keyword flag set:

  • has_keyword(flag) β€” Messages with the specified keyword flag (string) set.
  • has_unkeyword(flag) β€” Messages without the specified keyword flag (string) set.

πŸ“ Size Girlies πŸ“

Searching by how chunky a message is:

  • is_larger(size) β€” Messages that are larger than the size (number) in octets (bytes).
  • is_smaller(size) β€” Messages that are smaller than the size (number) in octets (bytes).

πŸ•°οΈ Age Check πŸ•°οΈ

Searching by how old a message is:

  • is_newer(age) β€” Messages that are newer than the age (number) in days.
  • is_older(age) β€” Messages that are older than the age (number) in days.

πŸ“… Date Girlies πŸ“…

These next ones search by arrival or sent date, all in the β€œday-month-year” form. Quick decoder ring, bestie: day is the day of the month as a decimal number (01-31), month is the abbreviated month (β€œJan”, β€œFeb”, β€œMar”, β€œApr”, β€œMay”, β€œJun”, β€œJul”, β€œAug”, β€œSep”, β€œOct”, β€œNov”, β€œDec”) and year is the year as decimal number including the century (e.g. 2007).

  • arrived_before(date) β€” messages that have arrived earlier than the date (string), where date is in the β€œday-month-year” form.
  • arrived_on(date) β€” Messages that have arrived within the date (string), where date is in the β€œday-month-year” form.
  • arrived_since(date) β€” Messages that have arrived within or later than the date (string), where date is in the β€œday-month-year” form.
  • sent_before(date) β€” Messages that have been sent earlier than the date (string), where date is in the β€œday-month-year” form.
  • sent_on(date) β€” Messages that have been sent within the date (string), where date is in the β€œday-month-year” form.
  • sent_since(date) β€” Messages that have been sent within or later than the date (string), where date is in the β€œday-month-year” form.

πŸ” Case-Insensitive Contain Girlies πŸ”

These ones do case-insensitive searching for messages that contain a specific word or phrase:

  • contain_bcc(string) β€” Messages that contain the string (string) in the β€œBcc” header field.
  • contain_cc(string) β€” Messages that contain the string (string) in the β€œCc” header field.
  • contain_from(string) β€” Messages that contain the string (string) in the β€œFrom” header field.
  • contain_subject(string) β€” Messages that contain the string (string) in the β€œSubject” header field.
  • contain_to(string) β€” Messages that contain the string (string) in the β€œTo” header field.
  • contain_field(field, string) β€” Messages that contain the string (string) in the field (string) header field.
  • contain_body(string) β€” Messages that contain the string (string) in the message body.
  • contain_message(string) β€” Messages that contain the string (string) in the message.

✨ Case-Sensitive Regex Girlies ✨

Now these ones do case-sensitive searching for messages that match a specific regular expression pattern. The matching mechanism that's doing all this work is based on the Perl-compatible regular expressions (PCRE), and if you want the full lore on the patterns and modifiers you can use, it's all in the relevant documentation at http://pcre.org/original/doc/html/. πŸ“š

⚠️ Okay important heads up: this way of searching is not supported by the IMAP protocol, which means what's actually happening under the hood is that the relevant parts of all the messages get downloaded and matched locally. So yeah β€” it is strongly recommended that you use these methods together with meta-searching (see the following section πŸ‘€), so you can narrow down the set of messages that should be searched and thus minimize what will be downloaded. Protect your bandwidth, bestie. 🫢

Also real talk: because Lua uses backslash \ as an escape character for its strings, you have to use double backslashes if you want to insert a single backslash inside a regular expression pattern. Yes, it's giving extra, but that's just how it is. πŸ’…

  • match_bcc(pattern) β€” Messages that match the regular expression pattern (string) in the β€œBcc” header field.
  • match_cc(pattern) β€” Messages that match the regular expression pattern (string) in the β€œCc” header field.
  • match_from(pattern) β€” Messages that match the regular expression pattern (string) in the β€œFrom” header field.
  • match_subject(pattern) β€” Messages that match the regular expression pattern (string) in the β€œSubject” header field.
  • match_to(pattern) β€” Messages that match the regular expression pattern (string) in the β€œTo” header field.
  • match_field(field, pattern) β€” Messages that match the regular expression pattern (string) in the field (string) header field.
  • match_header(pattern) β€” Messages that match the regular expression pattern (string) in the message header.
  • match_body(pattern) β€” Messages that match the regular expression pattern (string) in the message body.
  • match_message(pattern) β€” Messages that match the regular expression pattern (string) in the message.

πŸ“¨ The Raw Query Method πŸ“¨

And here's the one for searching with your own user queries, based on the IMAP specification (RFC 3501 Section 6.4.4):

  • send_query(criteria) β€” Searches messages by sending an IMAP search query as described in the search criteria (string).

🌸 Examples 🌸

Here's the whole girlband in action, copy-paste energy:

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()

And yes, both the dot notation and the bracket notation are out here serving looks β€” pick your fave. πŸ’–

πŸ”Ž RESULTS πŸ”Ž

okay so once you've thrown one or more searching methods at one or more mailboxes, the result is holding literally everything you need β€” like, which messages matched, and in which mailboxes they matched. bestie, that result is your little treasure chest ✨ and from there you can either search even deeper into it, or process those messages in a whole bunch of ways.


πŸ¦‹ META-SEARCHING πŸ¦‹

plot twist: you can search the results of your searches again, using the exact same methods you'd use on a mailbox. the vibe difference? instead of searching the whole mailbox (aka every single message), it only looks at the messages that came back from the previous search. narrowing down the narrowing down, yk? πŸ’…

Examples:

results:match_message('^[Hh]ello world!?$')
myaccount.mymailbox:is_new():match_body('^[Ww]orld, hello!?$')

πŸ’– PROCESSING πŸ’–

processing methods get applied to the results that searching handed you. this is where the main character energy kicks in 😌

the following method can be used to delete messages in a mailbox:

  • delete_messages() β€” deletes the messages that matched. poof, gone 🫢

the following methods can be used to copy and move messages in a mailbox at the same or different accounts. and listen β€” if the destination mailbox lives in a different account than the source mailbox, then the messages get downloaded and then uploaded to the destination:

  • copy_messages(destination) β€” copies the messages to the destination, which is a mailbox at an account.
  • move_messages(destination) β€” moves the messages to the destination, which is a mailbox at an account.

the following methods can be used to mark messages in a mailbox:

  • mark_answered() β€” marks the messages as answered.
  • mark_deleted() β€” marks the messages for later removal.
  • mark_draft() β€” marks the messages as draft.
  • mark_flagged() β€” marks the messages for urgent/special attention.
  • mark_seen() β€” marks the messages as read.
  • unmark_answered() β€” unmarks the messages that have been marked as answered.
  • unmark_deleted() β€” unmarks the messages that have been marked for later removal.
  • unmark_draft() β€” unmarks the messages that have been marked as draft.
  • unmark_flagged() β€” unmarks the messages that have been marked for urgent/special attention.
  • unmark_seen() β€” unmarks the messages that have been marked as read.

the following methods can be used to flag messages in a mailbox. the standard system flags are \Answered, \Deleted, \Draft, \Flagged, \Seen β€” and if the server supports it, brand new user keywords may be defined πŸ‘‘

  • add_flags(flags) β€” adds the flags (table that contains strings) to the messages.
  • remove_flags(flags) β€” removes the flags (table that contains strings) from the messages.
  • replace_flags(flags) β€” replaces the flags (table that contains strings) of the messages.

Examples:

results:delete_messages()
results:copy_messages(myaccount.myothermailbox)
results:move_messages(myotheraccount.mymailbox)
results:mark_seen()
results:unmark_flagged()
results:add_flags({ 'MyFlag', '\\Seen' })
results:remove_flags({ '\\Seen' })

results:move_messages(myotheraccount['myfolder/mymailbox'])

πŸ“¬ MESSAGES πŸ“¬

the messages chilling in any mailbox can also be accessed β€” either as a whole or in parts, your call πŸŽ€ messages are accessed using their unique identifier (UID):

myaccount.mymailbox[22]

and the UIDs of the messages you're interested in? those come straight from the results of searching:

results = account.INBOX:is_unseen()
for _, message in ipairs(results) do
    mailbox, uid = table.unpack(message)
    header = mailbox[uid]:fetch_header()
end

🌸 FETCHING 🌸

the following methods can be used to fetch parts of messages. they return a string. also, the downloaded message parts get cached locally, so you can reuse them inside the same program session β€” no wasteful re-downloading, we love efficiency πŸ’…

  • fetch_message() β€” fetches the header and body of the message.
  • fetch_header() β€” fetches the header of the message.
  • fetch_body() β€” fetches the body of the messages.
  • fetch_field(field) β€” fetches the specified header field (string) of the message.
  • fetch_part(part) β€” fetches the specified part (string) of the message.

the following methods can be used to fetch details about the state of a message:

  • fetch_flags() β€” fetches the flags of the message. returns a table of strings.
  • fetch_date() β€” fetches the internal date of the message. returns a string.
  • fetch_size() β€” fetches the size of the message. returns a number.
  • fetch_structure() β€” fetches the body structure of the message. returns a table that has as keys the parts of the message, and as values a table that has one mandatory element, the type (string) of the part, and three optional elements, the size (number), name (string) and encoding (string) of the part.

πŸŽ€ APPENDING πŸŽ€

the following methods can be used to append a message to a mailbox:

  • append_message(message) β€” appends the message (string) to the mailbox.
  • append_message(message, flags, date) β€” appends the message (string) to the mailbox, setting the specified flags (table of strings), as returned by fetch_flags(), and date (string), as returned by fetch_date().

Examples:

myaccount.mymailbox[2]:fetch_message()
myaccount.mymailbox[3]:fetch_field('subject')
myaccount.mymailbox[5]:fetch_part('1.1')

myaccount['mymailbox'][7]:fetch_message()
myaccount['myfolder/mymailbox'][11]:fetch_message()

myaccount.mymailbox:append_message(message)

✨ FUNCTIONS ✨

these auxiliary functions are also available, just for convenience, because we're nice like that 🫢

  • form_date(days) β€” forms a date in "day-month-year" format that the system had before the number of days (number), and returns it as a string.
  • get_password(prompt) β€” displays the specified prompt (string), and reads a password, while character echoing is turned off. returns that password as a string.
  • become_daemon(interval, commands)
  • become_daemon(interval, commands, nochdir)
  • become_daemon(interval, commands, nochdir, noclose) β€” detaches the program from the controlling terminal and runs it in the background as system daemon. the program will then repeatedly poll at the specified interval (number) in seconds. each time the program wakes up, the commands (function) are executed.

if nochdir (boolean) is "true", the current working directory is not changed to the root directory (/).

if noclose (boolean) is "true", the standard input, standard output and standard error are not redirected to /dev/null.

  • pipe_to(command, data) β€” executes the system's command (string) and sends the data (string) to the standard input channel of the subprocess. returns a number, the exit status of the child process.
  • pipe_from(command) β€” executes the system's command (string) and retrieves the data from the standard output channel of the subprocess. returns a number, the exit status of the child process, and a string, the output of the child process.
  • regex_search(pattern, string) β€” implements Perl-compatible regular expressions (PCRE). the pattern (string) is a PCRE pattern. the string (string) is the subject string in which the pattern is matched against. returns at least a boolean, that denotes if the match was successful, and any captures which are of string type. note that due to Lua using backslash \ as an escape character for its strings, one has to use double backslashes in order to insert a single backslash inside a regular expression pattern. for more information on PCRE see http://pcre.org/original/doc/html/.
  • sleep(interval) β€” delay for the specified interval (number) in seconds.
  • recover(commands)
  • recover(commands, retries) β€” protects the commands (function) executed from raising an error. whenever an error is raised, it sleeps for a few seconds (using exponential backoff up to some upper limit), and then re-executes the commands (function) from start.

if the maximum count of retries (number) is specified, it will retry up to the specified number of times, otherwise it will never give up.

returns the status code of the execution as the first result, "true" if it succeeded or "false" if it failed. if it succeeded, it returns all values the commands (function) returned as additional results. if it failed, it returns the error as an additional result.

Examples:

date = form_date(14)
password = get_password('Enter password: ')
become_daemon(600, myfunction)
status = pipe_to('mycommandline', 'mydata')
status, data = pipe_from('mycommandline')
success, capture = regex_search('^(?i)pcre: (\\w)$', 'mystring')
sleep(300)
recover(myfunction, 5)

for more examples, see the samples/extend.lua file.


🌈 EXAMPLES 🌈

see samples/config.lua and samples/extend.lua in the source code distribution.


πŸ“ ENVIRONMENT πŸ“

  • HOME β€” user's home directory.

πŸ‘‘ SEE ALSO πŸ‘‘

imapfilter(1)


and that's a wrap on the whole page bestie, you're officially an imapfilter config expert πŸ’œ this was the Debian build, version dated Apr 27, 2025, covering IMAPFILTER_CONFIG(5) β€” go forth and filter those emails, periodt πŸŽ€βœ¨πŸ¦‹

πŸ“¦ where this page comes from