imapfilter_config

Langue: en

Autres versions - même langue

Version: 301626 (debian - 07/07/09)

Section: 5 (Format de fichier)


BSD mandoc

NAME

imapfilter_config - imapfilter configuration file

SYNOPSIS

$HOME/.imapfilter/config.lua

DESCRIPTION

imapfilter(1) uses the Lua programming language (http://www.lua.org) as a configuration and extension language, therefore the configuration file is a Lua script.

Although knowledge of Lua is not required to use imapfilter(1), it is nonetheless recommended, especially if one wants to extend imapfilter(1). The user is advised to have a look at the available Lua documentation at:

http://www.lua.org/docs.html

CONVENTIONS

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

The
Vt nil is the type of the value ``nil'' , whose main property is to be different from any other value; usually it represents the absence of a useful value.
The
Vt boolean is the type of the values ``true'' and ``false''. Both ``nil'' and ``false'' make a condition false; any other value makes it true.
The type
Vt number represents real numbers.
The type
Vt string represents a sequence of characters and can be defined using single quotes, double quotes or double square brackets.
The type
Vt table implements associative arrays, that is, arrays that can be indexed not only with numbers, but with any value.
A
Vt function is 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 Vt table named ``options'' , in the following manner:
 options.timeout = 120
 options.namespace = false
 

Available options are:

create
According to the IMAP specification, when trying to write a message to a non-existent mailbox, the server must send a hint to the client, whether it should create the mailbox and try again or not. However some broken IMAP servers 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 of the server's response. This variable takes a Vt boolean as a value. Default is ``false''.
close
This option 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 Vt boolean as a value. Default is ``false''.
crammd5
When this option is enabled and the server supports the Challenge-Response Authentication Mechanism (specifically CRAM-MD5), this method will be used for user authentication instead of a plaintext password LOGIN. This variable takes a Vt boolean as a value. Default is ``true''.
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 Vt boolean as a value. Default is ``true''.
info
When this options is enabled, a summary of the program's actions is printed, while processing mailboxes. This variable takes a Vt boolean as a value. Default is ``true''.
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 ``'' (ie. 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 (eg. because they are not part of the user's personal namespace mailboxes). This variable takes Vt boolean as a value. Default is ``true''.
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 Vt 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 Vt boolean as a value. Default is ``false''.
timeout
The time in seconds for the program to wait for a mail server's response. If not set, the client will block indefinitely. This variable takes a Vt number as a value.

ACCOUNT

Accounts are initialized using the Fn IMAP function, and the details of the connection are defined using an account Vt table :
 myaccount = IMAP {
     server = 'imap.mail.server',
     username = 'me',
     password = 'secret',
     ssl = 'ssl3'
 }
 

An account Vt table must have the following elements:

server
The hostname of the IMAP server to connect to. It takes a Vt string as a value.
username
User's name. It takes a Vt string as a value.

An account Vt table can also have the following optional elements:

password
User's secret keyword. If a password wasn't supplied the user will be asked to enter one interactively the first time it will be needed. It takes a Vt string as a value.
port
The port to connect to. It takes a Vt number as a value. Default is ``143'' for imap and ``993'' for imaps.
ssl
Forces an imaps connection and specifies the SSL/TLS protocol to be used. It takes a Vt string as a value, specifically one of: ``ssl2'' , ``ssl3'' , ``tls1''.

LISTING

The following methods can be used on an account to list mailboxes in a folder of an account:
Fn list_all folder
Lists all the available mailboxes in the Fa folder (Vt string ) and returns a Vt table that contains Vt strings , the available mailboxes, and a Vt table that contains Vt strings , the available folders.
Fn list_subscribed folder
Lists all the subscribed mailboxes in the Fa folder (Vt string ) and returns a Vt table that contains Vt strings , the subscribed mailboxes, and a Vt table that contains Vt 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, ie. non-recursively:

Fn list_all folder mailbox
Lists all the available mailboxes in the Fa folder (Vt string ) with the name Fa mailbox (Vt string , ) and returns a Vt table that contains Vt strings , the available mailboxes, and a Vt table that contains Vt strings , the available folders. Wildcards may only be used in the Fa mailbox argument.
Fn list_subscribed folder mailbox
Lists all the subscribed mailboxes in the Fa folder (Vt string ) with the name Fa mailbox (Vt string ) and returns a Vt table that contains Vt strings , the subscribed mailboxes, and a Vt table that contains Vt strings , the subscribed folders. Wildcards may only be used in the Fa mailbox argument.

Examples:

 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:
Fn create_mailbox name
Creates the Fa name (Vt string ) mailbox.
Fn delete_mailbox name
Deletes the Fa name (Vt string ) mailbox.
Fn rename_mailbox oldname newname
Renames the Fa oldname (Vt string ) mailbox to Fa newname (Vt string )
Fn subscribe_mailbox name
Subscribes the Fa name (Vt string ) mailbox.
Fn unsubscribe_mailbox name
Unsubscribes the Fa name (Vt string ) mailbox.

Examples:

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

MAILBOX

After an IMAP account has been initialized, mailboxes residing in that account can be accessed simply as elements of the account Vt 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 be only accessed by using the alternative form:

 myaccount['myfolder/mymailbox']
 

The methods that are available for an account (eg. Fn list_all , Fn 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.

CHECKING

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

The Fn check_status method gets the current status of a mailbox, and returns three values of Vt number type: the total number of messages, the number of recent messages and the number of unseen messages in the mailbox.

 exist, unread, unseen = myaccount.mymailbox:check_status()
 

SEARCHING

All the searching methods in this subsection return a special form of Vt table . This Vt table can be combined with other Vt 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:

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

The logical ``and'' is implemented using the `*' operator:

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

The logical ``not'' is implemented using the `-' operator:

 messages = 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:

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

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

 unseen = myaccount.myaccount:is_unseen()
 larger = myaccount.mymailbox:is_larger(100000)
 subject = myaccount.mymailbox:contain_subject('test')
 messages = 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
 
 messages = 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
 
 messages = myfilter(myaccount.mailbox, 100000, 'test')
 

The following methods can be used to search for messages that are in a specific state:

Fn is_answered
Messages that have been answered.
Fn is_deleted
Messages that are marked for later removal.
Fn is_draft
Messages that have not completed composition.
Fn is_flagged
Messages that are flagged for urgent/special attention.
Fn is_new
Messages that are recently arrived (this session is the first to have been notified about these messages) and have not been read.
Fn 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.
Fn is_recent
Messages that are recently arrived (this session is not the first to have been notified about these messages).
Fn is_seen
Messages that have been read.
Fn is_unanswered
Messages that have not been answered.
Fn is_undeleted
Messages that are not marked for later removal.
Fn is_undraft
Messages that have completed composition.
Fn is_unflagged
Messages that are not flagged for urgent/special attention.
Fn is_unseen
Messages that have not been read.

The following method can be used to search for messages that have a specific flag set:

Fn has_flag keyword
Messages with the specified keyword flag (Vt string ) set.

The following methods can be used to search for messages based on their size:

Fn is_larger size
Messages that are larger than the size (Vt number ) in octets (bytes).
Fn is_smaller size
Messages that are smaller than the size (Vt number ) in octets (bytes).

The following methods can be used to search for messages based on their age:

Fn is_newer age
Messages that are newer than the Fa age (Vt number ) in days.
Fn is_older age
Messages that are older than the Fa age (Vt number ) in days.

The following methods can be used to search for messages based on their arrival or sent date, in the ``day-month-year'' form, where 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 (eg. 2007):

Fn arrived_before date
messages that have arrived before the Fa date (Vt string ) where Fa date is in the ``day-month-year'' form.
Fn arrived_on date
Messages that have arrived on the Fa date (Vt string ) where Fa date is in the ``day-month-year'' form.
Fn arrived_since date
Messages that have arrived after the Fa date (Vt string ) where Fa date is in the ``day-month-year'' form.
Fn sent_before date
Messages that have been sent before the Fa date (Vt string ) where Fa date is in the ``day-month-year'' form.
Fn sent_on date
Messages that have been sent on the Fa date (Vt string ) where Fa date is in the ``day-month-year'' form.
Fn sent_since date
Messages that have been sent after the Fa date (Vt string ) where Fa date is in the ``day-month-year'' form.

The following methods can be used to search for messages that contain a specific word or phrase:

Fn contain_bcc string
Messages that contain the Fa string (Vt string ) in the ``Bcc'' header field.
Fn contain_cc string
Messages that contain the Fa string (Vt string ) in the ``Cc'' header field.
Fn contain_from string
Messages that contain the Fa string (Vt string ) in the ``From'' header field.
Fn contain_subject string
Messages that contain the Fa string (Vt string ) in the ``Subject'' header field.
Fn contain_to string
Messages that contain the Fa string (Vt string ) in the ``To'' header field.
Fn contain_field field string
Messages that contain the Fa string (Vt string ) in the Fa field (Vt string ) header field.
Fn contain_header string
Messages that contain the Fa string (Vt string ) in the message header, but not in the message body. Note that due to an IMAP limitation there is no way to search for a string only in the message header, and this oddly behaving method is included only for consistency.
Fn contain_body string
Messages that contain the Fa string (Vt string ) in the message body.
Fn contain_message string
Messages that contain the Fa string (Vt string ) in the message.

The following methods can be used to search for messages that match a specific regular expression pattern. Note that due to Lua using backslash `\' as an escape character for its strings, one has to double backslashes in order to insert a single backslash inside a regular expression pattern:

Fn match_bcc pattern
Messages that match the regular expression Fa pattern (Vt string ) in the ``Bcc'' header field.
Fn match_cc pattern
Messages that match the regular expression Fa pattern (Vt string ) in the ``Cc'' header field.
Fn match_from pattern
Messages that match the regular expression Fa pattern (Vt string ) in the ``From'' header field.
Fn match_subject pattern
Messages that match the regular expression Fa pattern (Vt string ) in the ``Subject'' header field.
Fn match_to pattern
Messages that match the regular expression Fa pattern (Vt string ) in the ``To'' header field.
Fn match_field field pattern
Messages that match the regular expression Fa pattern (Vt string ) in the Fa field (Vt string ) header field.
Fn match_header pattern
Messages that match the regular expression Fa pattern (Vt string ) in the message header.
Fn match_body pattern
Messages that match the regular expression Fa pattern (Vt string ) in the message body.
Fn match_message pattern
Messages that match the regular expression Fa pattern (Vt string ) in the message.

The following method can be used to get all messages in a mailbox:

Fn select_all
All messages.

The following method can be used to search for messages using user queries based on the IMAP specification (RFC 3501 Section 6.4.4):

Fn send_query criteria
Searches messages by sending an IMAP search query as described in the search Fa criteria (Vt string )
Fn send_query criteria charset
Searches messages by sending an IMAP search query as described in the search Fa criteria (Vt string ) while Fa charset (Vt string ) indicates to the server the character set of the strings that appear in the query. Character sets are defined in RFC 2978 and must be supported by the server.

Examples:

 messages = myaccount.mymailbox:is_new()
 messages = myaccount.mymailbox:is_recent()
 messages = myaccount.mymailbox:is_larger(100000)
 messages = myaccount.mymailbox:is_older(10)
 messages = myaccount.mymailbox:has_flag('MyFlag')
 messages = myaccount.mymailbox:arrived_before('01-Jan-2007')
 messages = myaccount.mymailbox:sent_since('01-Jan-2007')
 messages = myaccount.mymailbox:contain_subject('test')
 messages = myaccount.mymailbox:contain_field('Sender', 'user@host')
 messages = myaccount.mymailbox:contain_body('hello world')
 messages = myaccount.mymailbox:match_from('.*(user1|user2)@host')
 messages = myaccount.mymailbox:match_message('^[Hh]ello world!?$')
 messages = myaccount.mymailbox:select_all()
 messages = myaccount.mymailbox:send_query('ALL', 'ISO-8859-1')
 
 messages = myaccount['mymailbox']:is_new()
 messages = myaccount['myfolder/mymailbox']:is_recent()
 

PROCESSING

The following method can be used to delete messages in a mailbox:
Fn delete_messages messages
Deletes the Fa messages (Vt table )

The following methods can be used to copy and move messages in a mailbox at the same or different accounts. If the destination mailbox is in a different account than the source mailbox, then the messages are downloaded and then uploaded to the destination:

Fn copy_messages destination messages
Copies the messages contained in Fa messages (Vt table ) to the Fa destination , which is a mailbox at an account.
Fn move_messages destination messages
Moves the messages contained in Fa messages (Vt table ) to the Fa destination , which is a mailbox at an account.

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

Fn mark_answered messages
Marks Fa messages (Vt table ) as answered.
Fn mark_deleted messages
Marks Fa messages (Vt table ) for later removal.
Fn mark_draft messages
Marks Fa messages (Vt table ) as draft.
Fn mark_flagged messages
Marks Fa messages (Vt table ) for urgent/special attention.
Fn mark_seen messages
Marks Fa messages (Vt table ) as read.
Fn unmark_answered messages
Unmarks Fa messages (Vt table ) that have been marked as answered.
Fn unmark_deleted messages
Unmarks Fa messages (Vt table ) that have been marked for later removal.
Fn unmark_draft messages
Unmarks Fa messages (Vt table ) that have been marked as draft.
Fn unmark_flagged messages
Unmarks Fa messages (Vt table ) that have been marked for urgent/special attention.
Fn unmark_seen messages
Unmarks Fa messages (Vt table ) 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'', while if the server supports it, new user keywords may be defined:

Fn add_flags flags messages
Adds the Fa flags Po Vt table that contains Vt strings Pc to the Fa messages (Vt table )
Fn remove_flags flags messages
Removes the Fa flags Po Vt table that contains Vt strings Pc from the Fa messages (Vt table )
Fn replace_flags flags messages
Replaces the Fa flags Po Vt table that contains Vt strings Pc of the Fa messages (Vt table )

Examples:

 myaccount.mymailbox:delete_messages(messages)
 myaccount.mymailbox:copy_messages(myaccount.othermailbox, messages)
 myaccount.mymailbox:move_messages(otheraccount.mymailbox, messages)
 myaccount.mymailbox:mark_seen(messages)
 myaccount.mymailbox:unmark_flagged(messages)
 myaccount.mymailbox:add_flags({ 'MyFlag', '\\Seen' }, messages)
 myaccount.mymailbox:remove_flags({ '\\Seen' }, messages)
 
 myaccount['mymailbox']:delete_messages(messages)
 myaccount['myfolder/mymailbox']:copy_messages(myaccount.othermailbox,
                                               messages)
 myaccount.mymailbox:move_messages(otheraccount['myfolder/mymailbox'],
                                   messages)
 

FETCHING

The following methods can be used to fetch parts of messages. The methods return a Vt table, which for each message contains a Vt string , the part that has been fetched. The downloaded messages are cached locally, so they can be reused inside the same program session:

Fn fetch_message messages
Fetches the header and body of the Fa messages (Vt table )
Fn fetch_header messages
Fetches the header of the Fa messages (Vt table )
Fn fetch_body messages
Fetches the body of the Fa messages (Vt table )
Fn fetch_fields fields messages
Fetches the header fields of the Fa messages (Vt table )

The following methods can be used to fetch details about the state of messages:

Fn fetch_flags messages
Fetches the flags of the Fa messages (Vt table ) Returns a Vt table , which for each message contains a Vt table of Vt strings .
Fn fetch_date messages
Fetches the internal date of the Fa messages (Vt table ) Returns a Vt table which for each message contains a Vt string .
Fn fetch_size messages
Fetches the size of the Fa messages (Vt table ) Returns a Vt table which for each message contains a Vt number .

Examples:

 myaccount.mymailbox:fetch_message(messages)
 myaccount.mymailbox:fetch_fields({ 'from', 'subject' }, messages)
 
 myaccount['mymailbox']:fetch_message(messages)
 myaccount['myfolder/mymailbox']:fetch_message(messages)
 

FUNCTIONS

The following auxiliary functions are also available for convenience:
Fn form_date days
Forms a date in ``day-month-year'' format that the system had before the number of Fa days (Vt number ) and returns it as a Vt string .
Fn get_password prompt
Displays the specified Fa prompt (Vt string ) and reads a password, while character echoing is turned off. Returns that password as a Vt string .
Fn become_daemon interval commands
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 Fa interval (Vt number ) in seconds. Each time the program wakes up, the Fa commands (Vt function ) are executed.
Fn pipe_to command data
Executes the system's Fa command (Vt string ) and sends the Fa data (Vt string ) to the standard input channel of the subprocess. Returns a Vt number , the exit status of the child process.
Fn pipe_from command
Executes the system's Fa command (Vt string ) and retrieves the data from the standard output channel of the subprocess. Returns a Vt number , the exit status of the child process, and a Vt string , the output of the child process.
Fn regex_search pattern string
Implements Perl-compatible regular expressions (http://www.pcre.org) The Fa pattern (Vt string ) is a PCRE pattern. The Vt string (Vt string ) is the subject string in which the pattern is matched against. Returns at least a Vt boolean , that denotes if the match was successful, and any captures which are of Vt string type. Note that due to Lua using backslash `\' as an escape character for its strings, one has to double backslashes in order to insert a single backslash inside a regular expression pattern:

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('^[PpCcRrEe]: (\\w)$', 'mystring')
 

EXAMPLES

See sample.config.lua and sample.extend.lua

ENVIRONMENT

HOME
User's home directory.

SEE ALSO

imapfilter(1)

AUTHORS

An Lefteris Chatzimparmpas Aq lefcha@hellug.gr