IMAPFILTER_CONFIG(5)
β¨ 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 valuenil; 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 valuestrueandfalse. Bothnilandfalsemake 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 abooleanas a value. Default istrue. πΎ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 abooleanas a value. Default istrue. πcharsetβ tells the server the character set of the strings for the searching methods. This variable takes astringas 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 abooleanas a value. Default isfalse. π οΈ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 abooleanas a value. Default isfalse. πͺ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 abooleanas a value. Default istrue. π§Ή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 abooleanas a value. Default istrue. πinfoβ turn this on and a summary of the program's actions is printed while processing mailboxes. This variable takes abooleanas a value. Default istrue. π’keepaliveβ the time in minutes before terminating and re-issuing theIDLEcommand, 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 least30minutes. 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 anumberas a value. Default is29minutes. π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 be50. This variable takes anumberas a value. Default is0. See also therangeoption 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 abooleanas a value. Default istrue. π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 be50. This variable takes anumberas a value. By default, no such limit is imposed. See also thelimitoption which is related. πstarttlsβ when this option is enabled and the server supports the IMAPSTARTTLSextension, a TLS connection will be negotiated with the mail server in the beginning of the session. This variable takes abooleanas value. Default istrue. π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 abooleanas a value. Default isfalse. π¬timeoutβ the time in seconds for the program to wait for a mail server's response. If set to0, the client will block indefinitely. This variable takes anumberas a value. Default is60seconds. β³wakeonanyβ by enabling this option, theIDLEcommand will return on any event that is received from the server, and not just on theRECENTandEXISTSevents, that normally indicate the arrival of a new message. Examples of other events areFETCH, which indicates that the details of a message (e.g. its flags) have been modified, orEXPUNGE, which indicates that a message has been deleted. This variable takes abooleanas a value. Default isfalse. π
β¨ 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 (unlessoauth2has 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 thename(string) mailbox. β¨delete_mailbox(name)β deletes thename(string) mailbox. πrename_mailbox(oldname, newname)β renames theoldname(string) mailbox tonewname(string). πsubscribe_mailbox(name)β subscribes thename(string) mailbox. πunsubscribe_mailbox(name)β unsubscribes thename(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()β theenter_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 thecheck_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 theenter_idle()method has been called no more commands in the configuration file are executed until an update is received, at which point theenter_idle()method returns. forenter_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 byfetch_flags(), and date (string), as returned byfetch_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 π
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
- fedora 43: imapfilter 2.8.3-2.fc43 Β· MIT
- fedora 44: imapfilter 2.8.3-3.fc44 Β· MIT
- nixos 26.05: imapfilter 2.8.5
- nixpkgs unstable: imapfilter 2.8.6
- ubuntu resolute: imapfilter 1:2.8.3-1 Β· MIT
- ubuntu stonking: imapfilter 1:2.8.3-1ubuntu1 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms