Mailutils filter

From Mailutils

Jump to: navigation, search

The mailutils filter command applies a chain of filters to the input. The filters to apply and their arguments are given in the command line. The full invocation syntax is:

 mailutils filter [option] filter-chain

The syntax for filter-chain in Backus-Naur form follows:

 <filter-chain> ::= <filter> | <filter-chain> "+" <filter>
 <filter> ::= <filter-spec> <ARG>* 
 <filter-spec> ::= <WORD> | "~" <WORD>

where <WORD> stands for the filter name and <ARG> represents filter arguments. To obtain a list of known filter names, run:

 mailutils filter --list

Filters are applied in the order of their appearence, from left to right and operate in encode mode. The plus sign has the same meaning as pipe in shell. The default mode can be changed using the --decode (-d) and --encode (-e) options. Whatever the default mode is, a ~ before filter name reverts the mode for that filter alone.

For example, to encode the contents of file file.txt in Base64 run:

 mailutils filter base64 < file.txt

To convert it to base64 and use CRLF as line delimiters, run:

 mailutils filter base64 + crlf < file.txt

The following command will decode the produced output:

 mailutils filter --decode crlf + base64

It can also be written as

 mailutils filter ~crlf + ~base64

The following example converts the input from ISO-8859-2 to UTF-8, quotes eventual From occurring at the beginning of a line, encodes the result in Base64 and changes line delimiters to CRLF:

 mailutils filter iconv iso-8859-2 utf-8 + from + base64 + crlf

This final example removes UNIX-style comments from the input and joins continuation lines:

 mailutils filter --decode inline-comment -S '#' + linecon 

Such invocation can be useful in shell scripts to facilitate configuration file processing.

See also

Personal tools