Debian Codegraph @

MANUAL

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 fdm ============================================================================
2
3 *** Introduction
4
5 fdm is a program to fetch mail and deliver it in various ways depending on a
6 user-supplied ruleset. Mail may be fetched from stdin, IMAP or POP3 servers, or
7 from local maildirs, and filtered based on whether it matches a regexp, its
8 size or age, or the output of a shell command. It can be rewritten by an
9 external process, dropped, left on the server or delivered into maildirs,
10 mboxes, to a file or pipe, or any combination.
11
12 fdm is designed to be lightweight but powerful, with a compact but clear
13 configuration syntax. It is primarily designed for single-user uses but may
14 also be configured to deliver mail in a multi-user setup. In this case, it uses
15 privilege separation to minimise the amount of code running as the root user.
16
17 *** Table of contents
18
19 ## Installation
20 ## Quick start
21 ## The configuration file
22 %% Including other files
23 %% Macros
24 %% Testing macros
25 %% Shell commands
26 ## Invoking fdm
27 %% Temporary files
28 %% Command line arguments
29 %% Running from cron
30 %% The lock file
31 %% Testing and debugging
32 ## Fetching mail
33 %% Mail tags
34 %% POP3 and POP3S
35 %% SSL certificate verification
36 %% The .netrc file
37 %% IMAP and IMAPS
38 %% IMAP or POP3 over a pipe or ssh
39 %% stdin and local mail
40 %% From maildirs and mboxes
41 %% Using NNTP and NNTPS
42 %% New or old mail only
43 ## Defining actions
44 %% Drop and keep
45 %% Maildirs
46 %% Mboxes
47 %% IMAP and IMAPS
48 %% SMTP
49 %% LMTP
50 %% Write, pipe, exec and append
51 %% stdout
52 %% Rewriting mail
53 %% Adding or removing headers
54 %% Tagging
55 %% Compound actions
56 %% Chained actions
57 ## Filtering mail
58 %% Nesting rules
59 %% Lambda actions
60 %% The all condition
61 %% Matched and unmatched
62 %% Matching by account
63 %% Matching a regexp
64 %% Matching bracket expressions
65 %% Matching by age or size
66 %% Using a shell command
67 %% Attachments
68 %% Matching tags
69 %% Using caches
70 %% Cache commands
71 ## Setting options
72 ## Archiving and searching mail
73 ## Using fdm behind a proxy
74 ## Bug reports and queries
75 ## Frequently asked questions
76
77 ### Installation
78
79 fdm depends on the Trivial Database library (TDB), available at:
80
81 https://tdb.samba.org
82
83 Ensure it is installed, then download the source tarball and build fdm with:
84
85 $ tar -zxvf fdm-?.?.tar.gz
86 $ cd fdm-?.?
87 $ ./configure && make
88
89 Then run 'make install' to install fdm to the default location under
90 /usr/local. The --prefix argument may be set to specify an alternative
91 installation location:
92
93 $ ./configure --prefix=/opt/fdm && make
94 $ sudo make install
95
96 If being run as root, fdm requires a user named "debianfdm" to exist. It will drop
97 privileges to this user and its primary group. The user may be added on
98 OpenBSD with, for example:
99
100 # useradd -u 999 -s /bin/nologin -d /var/empty -g=uid debianfdm
101
102 It is not necessary to add a user if fdm is always started by a non-root user.
103
104 fdm can be built to use PCRE rather than standard regexps. To do so, add -DPCRE
105 to the make command:
106
107 $ make -DPCRE
108
109 Or PCRE=1 if using GNU make:
110
111 $ make PCRE=1
112
113 ### Quick start
114
115 A simple ~/.fdm.conf file for a single user fetching from POP3, POP3S and IMAP
116 accounts and delivering to one maildir may look similar to:
117
118 # Set the maximum size of mail.
119 set maximum-size 128M
120
121 # An action to save to the maildir ~/mail/inbox.
122 action "inbox" maildir "%h/mail/inbox"
123
124 # Accounts: POP3, POP3S and IMAP. Note the double escaping of the '\'
125 # character in the password. If the port is omitted, the default
126 # ("pop3", "pop3s", "imap" or "imaps" in the services(5) db) is used.
127 account "pop3" pop3 server "my.pop3.server"
128 user "my-username" pass "my-password-with-a-\\-in-it"
129 account "pop3s" pop3s server "pop.googlemail.com" port 995
130 user "[email protected]" pass "my-password"
131 # If the 'folder "my-folder"' argument is omitted, fdm will fetch mail
132 # from the inbox.
133 account "imap" imap server "my.imap.server"
134 user "my-username" pass "my-password" folder "my-folder"
135
136 # Discard mail from Bob Idiot. Note that the regexp is an extended
137 # regexp, and case-insensitive by default. This action is a "lambda" or
138 # unnamed action, it is defined inline as part of the match rule.
139 match "^From:.*bob@idiot\\.net" in headers action drop
140
141 # Match all other mail and deliver using the 'inbox' action.
142 match all action "inbox"
143
144 A simple initial configuration file without filtering, perhaps to replace
145 fetchmail or getmail delivering to maildrop, may look similar to:
146
147 # Set the maximum size of mail.
148 set maximum-size 128M
149
150 # Action to pipe directly to maildrop.
151 action "maildrop" pipe "/usr/local/bin/maildrop"
152
153 # Account definitions.
154 account ....
155
156 # Send all mail to maildrop.
157 match all action "maildrop"
158
159 To run fdm every half hour from cron, add something like this:
160
161 */30 * * * * /usr/local/bin/fdm -l fetch
162
163 See the fdm.conf(5) man page or the rest of this manual for more detail of the
164 configuration file format.
165
166 ### The configuration file
167
168 fdm is controlled by its configuration file. It first searches for a .fdm.conf
169 file in the invoking user's home directory. If that fails, fdm attempts to use
170 /etc/fdm.conf. The configuration file may also be specified using the '-f'
171 command line option, see the section on that subject below.
172
173 This section gives an overview of the configuration file syntax. Further
174 details of syntax, and specific keywords, are covered in later sections.
175
176 The configuration file has the following general rules:
177
178 - Keywords are specified as unadorned lowercase words: match, action, all.
179 - Strings are enclosed in double quotes (") or single quotes ('). In double
180 quoted strings, double quotes may be included by escaping them using the
181 backslash character (\). Backslashes must also be escaped ("\\") - this
182 applies to all such strings, including regexps and passwords. The special
183 sequence '\t' is replaced by a tab character. In single quoted strings no
184 escaping is necessary, but it is not possible to include a literal ' or a
185 tab character.
186 - Comments are prefixed by the hash character (#) and continue to the end of
187 the line.
188 - Whitespace is largely ignored. Lines may generally be split, concatenated
189 or indented as preferred.
190 - Lists are usually specified as 'singular item' or 'plural { item item }', for
191 example: 'user "nicholas"', 'users { "nicholas" "bob" }'. The singular/plural
192 distinction is not required, it is recommended only to aid readability:
193 'user { "nicholas "bob" }' is also accepted.
194 - Regexps are specified as normal strings without additional adornment other
195 than the "s (not wrapped in /s). All regexps are extended regexps. They are
196 case insensitive by default but may be prefixed with the 'case' keyword to
197 indicate case sensitivity is required.
198 - Strings may be concatenated using plus: "a" + "b" is the same as "ab". This
199 is most useful to wrap strings across multiple lines.
200
201 Definition/option lines generally follow the following basic form:
202
203 <keyword> <name or command> <parameters>
204
205 Example lines that may appear in a configuration file are:
206
207 # This is a comment.
208
209 set lock-types flock
210
211 account "stdin" disabled stdin
212
213 action "strip-full-disclosure"
214 rewrite "sed 's/^\\(Subject:.*\\)\\[Full-disclosure\\] /\\1/'"
215
216 match "^X-Mailing-List:.*[email protected]" in headers
217 or "^(To:|Cc:):.*@vger.kernel.org" in headers
218 action "linux-kernel"
219
220 %%% Including other files
221
222 The fdm configuration may be split into several files. Additional files may
223 be referenced using the 'include' keyword:
224
225 include "my-include-file.conf"
226
227 include "/etc/fdm.d/shared-conf-1.conf"
228
229 %%% Macros
230
231 Macros may be defined and used in the configuration file. fdm makes a
232 distinction between macros which may hold a number (numeric macros) and
233 those that hold a string (string macros). Numeric macros are prefixed with
234 the percentage sign (%) and string by the dollar sign ($). Macros are
235 defined using the equals operator (=):
236
237 %nummacro = 123
238
239 $strmacro = "a string"
240
241 Macros may then be referenced in either a standalone fashion anywhere a string
242 or number is expected, depending on the type of macro:
243
244 $myfile = "a-file"
245 include $myfile
246
247 %theage = 12
248 match age < %theage action "old-mail"
249
250 Or embedded in a string by enclosing the macro name in {}s:
251
252 $myfile2 = "a-file2"
253 include "/etc/${myfile2}"
254
255 %anum = 57
256 include "/etc/file-number-%{anum}"
257
258 Macros are not substituted in strings specified using single-quotes.
259
260 %%% Testing macros
261
262 The 'ifdef', 'ifndef' and 'endif' keywords may be used to include or omit
263 sections of the configuration file depending on whether a macro is defined. An
264 'ifdef' is followed by a macro name (including $ or % type specifier) and if
265 that macro exists, all following statements up until the next endif are
266 evaluated (accounts created, rules added, and so on), otherwise they are
267 skipped. 'ifndef' is the inverse: if the macro exists, the statements are
268 skipped, otherwise they are included. An example is:
269
270 ifdef $dropeverything
271 match all action drop
272 endif
273
274 These keywords are particularly useful in conjunction with the '-D' command line
275 option. Any statements between 'ifdef'/'ifndef' and 'endif' must still be valid
276 syntax.
277
278 %%% Shell commands
279
280 The value of a shell command may be used at any point in the configuration file
281 where fdm expects a string or number. Shell commands are invoked by enclosing
282 them in $() or %(). They are executed when the configuration file is parsed
283 and if $() is used, any output to stdout is treated as a literal string (as
284 if the output was inserted directly in the file enclosed in double quotes); %()
285 attempts to convert the output to a number. For example:
286
287 $mytz = $(date +%Z)
288
289 %two = %(expr 1 + 1)
290
291 $astring = "abc" + $(echo def)
292
293 Parts of the command within double quotes (") are subject to tag and macro
294 replacement as normal (so it is necessary to use %% if a literal % is required,
295 see the section on tags below); parts outside double quotes or inside single
296 quotes are not.
297
298 ### Invoking fdm
299
300 fdm accepts a number of command line arguments and may be invoked as needed
301 from the command line or by a mail transfer agent, such as sendmail, or at
302 regular times using a program such as cron(8).
303
304 %%% Temporary files
305
306 As each mail is being processed, it is stored in a temporary file in /tmp, or
307 if the TMPDIR environment variable exists in the directory it points to.
308
309 fdm tries to queue a number of mails simultaneously, so that older can be
310 delivered while waiting for the server to provide the next. The maximum length
311 of the queue for each account is set by the 'queue-high' option (the default is
312 two) and the maximum mail size accepted by the 'maximum-size' option (the
313 default is 32 MB). In addition, the 'rewrite' action requires an additional
314 temporary mail. Although fdm will fail rather than dropping mail if the disk
315 becomes full, users should bear in mind the possibility and set the size of the
316 temporary directory and the fdm options according to their needs.
317
318 %%% Command line arguments
319
320 The fdm command has the following synopsis:
321
322 fdm [-klmnqv] [-f conffile] [-u user] [-a account] [-x account]
323 [-D name=value] [fetch | poll | cache ...]
324
325 The meaning of the flags are covered in the fdm(1) man page, but a brief
326 description is given below. The flags are also mentioned at relevant points
327 in the rest of this document.
328
329 Flag Meaning
330 -k Keep all mail (do not delete it from the server). This is useful for
331 testing delivery rules without risking mail ending up permanently
332 in the wrong place.
333 -l Log to syslog(3) using the 'mail' facility rather than outputting to
334 stderr.
335 -m Ignore the lock file.
336 -n Run a syntax check on the configuration file and exit without fetching
337 any mail.
338 -q Quiet mode. Don't print anything except errors.
339 -v Print verbose debugging output. This option may be specified multiple
340 times for increasing levels of verbosity. Useful levels are -vv to
341 display the result of parsing the configuration file, and -vvvv to copy
342 all traffic to and from POP3 or IMAP servers to stdout (note that -l
343 disables this behaviour).
344 -f conffile
345 Specify the path of the configuration file.
346 -u user
347 Use 'user' as the default user for delivering mail when started as
348 root.
349 -a account
350 Process only accounts with a name matching the given pattern. Note that
351 fnmatch(3) wildcards may be used to match multiple accounts with one
352 option, and that the option may be specified multiple times.
353 -x account
354 Process all accounts except those that match the given pattern. Again,
355 fnmatch(3) wildcards may be used, and the -x option may be specified
356 multiple times.
357 -D name=value
358 Define a macro. The macro name must be prefixed with '$' or '%' to
359 indicate if it is a string or numeric macro. Macros defined on the
360 command line override any macros with the same name defined in the
361 configuration file.
362
363 If -n is not specified, the flags must be followed by one of the keywords
364 'fetch' or 'poll' or 'cache'. The 'fetch' keyword will fetch and deliver mail,
365 the 'poll' keyword print an indication of how many mails are present in each
366 account, and the 'cache' keyword is followed by one of a set of cache commands
367 used to manipulate caches from the command-line (see the sections on caches
368 below). 'fetch' or 'poll' or 'cache' may be abbreviated.
369
370 Examples:
371
372 $ fdm -v poll
373
374 $ fdm -vvnf /etc/my-fdm.conf
375
376 $ fdm -lm -a pop3\* fetch
377
378 $ fdm -x stdinacct fetch
379
380 # fdm -u nicholas -vv f
381
382 %%% Running from cron
383
384 To fetch mail regularly, fdm must be run from cron. This line in a crontab(5)
385 will run fdm every 30 minutes:
386
387 */30 * * * * /usr/local/bin/fdm -l fetch
388
389 The '-l' option sends fdm's output to syslog(3) rather than having cron mail
390 it. To keep a closer eye, adding '-v' options and removing '-l' will have
391 debugging output mailed by cron, or, using a line such as:
392
393 */30 * * * * fdm -vvvv fetch >>/home/user/.fdm.log 2>&1
394
395 Will append extremely verbose fdm output to the ~/.fdm.log file. Note that this
396 log file can become pretty large, so another cronjob may be required to remove
397 it occasionally!
398
399 %%% The lock file
400
401 fdm makes use of a lock file to prevent two instances running simultaneously.
402 By default, this lock file is .fdm.lock in the home directory of the user who
403 runs fdm, or /var/db/fdm.lock for root. This default may be overridden in
404 the configuration file with the 'set lock-file' command:
405
406 set lock-file "/path/to/my/lock-file"
407
408 Or disabled altogether by being set to the empty string:
409
410 set lock-file ""
411
412 The '-m' command line option may be used to force fdm to ignore the lock file
413 and run regardless of its existence and without attempting to create it.
414
415 %%% Testing and debugging
416
417 fdm has some features to assist with testing and debugging a ruleset:
418
419 The '-n' command line option. This is particularly useful in conjunction with
420 '-vv', for example:
421
422 $ cat test.conf
423 account "pop3" pop3 server "s" user "u" pass "p"
424 action "rw" rewrite "sed 's/\\(Subject:.*\\)\\[XYZ\\]/\1/'"
425 action "mbox" mbox "%h/INBOX"
426 match all actions { "rw" "mbox" }
427 $ fdm -vvnf test.conf
428 version is: fdm 0.6 (20061204-1433)
429 starting at: Tue Dec 5 15:45:41 2006
430 user is: nicholas, home is: /home2/nicholas
431 loading configuration from test.conf
432 added account: name=pop3 fetch=pop3 server "s" port pop3 user "u"
433 added action: name=rw deliver=rewrite "sed 's/\(Subject:.*\)\[XYZ\]/1/'"
434 added action: name=mbox deliver=mbox "%h/INBOX"
435 finished file test.conf
436 added rule: actions="rw" "mbox" matches=all
437 configuration loaded
438 locking using: flock
439 headers are: "to" "cc"
440 domains are: "yelena"
441 using tmp directory: /tmp
442
443 Looking at the output, the parsed strings used by fdm can be seen, and it is
444 possible to spot that an escape character has been missed in the command.
445
446 If '-vvvv' is used, fdm will print all data sent to and received from remote
447 servers to stdout. Note that this is disabled if the '-l' option is given, and
448 includes passwords, usernames and hostnames unmodified. The 'fdm-sanitize'
449 script provided with fdm may be used to remove passwords and usernames from
450 this output, either while it is being collected:
451
452 fdm -vvvv -a testacct f 2>&1|./fdm-sanitize|tee my-output
453
454 Or afterwards:
455
456 ./fdm-sanitize <vvvv-output >my-output
457
458 Since fdm fetches multiple accounts simultaneously, which may intersperse
459 debugging output, it is recommended to fetch each account seperately if running
460 the output through fdm-sanitize. If this is not done, it may not be able to
461 detect all usernames or passwords.
462
463 The '-k' command line option (and the 'keep' keywords on actions and accounts,
464 covered later) prevent fdm from deleting any mail after delivery. This may be
465 used to perform any number of test deliveries without risk of losing mail.
466
467 ### Fetching mail
468
469 fdm fetches mail from a set of 'accounts', defined using the 'account'
470 keyword. Each account has a name, a type, a number of account specific
471 parameters and a couple of optional flags. The general form is:
472
473 account <name> [<users>] [disabled] <type> [<parameters>] [keep]
474
475 The <name> item is a string by which the account is referred in filtering
476 rules, log output and for the '-a' and '-x' command line options.
477
478 The <users> portion specifies the default users to use when delivering mail
479 fetched from this account as root. It has the same syntax as discussed in
480 detail in the section below on defining actions.
481
482 If the optional 'disabled' keyword is present, fdm ignores the account unless
483 it is specified on the command line using the '-a' flag.
484
485 The optional 'keep' keyword instructs fdm to keep all mail from this account
486 (not delete it from the server) regardless of the result of the filtering
487 rules.
488
489 The <type> item may be one of: 'pop3', 'pop3s', 'imap', 'imaps', 'stdin',
490 'maildir' or 'maildirs'.
491
492 %%% Mail tags
493
494 As mail is processed by fdm, it is tagged with a number of name/value pairs.
495 Some tags are added automatically, and mail may also be tagged explicitly by
496 the user (see the later tagging section). Tags may be inserted in strings in a
497 similar manner to macros, except tags are processed when the string is used
498 rather than always as the configuration file is parsed. A tag's value is
499 inserted by wrapping its name in %[], for example:
500
501 match string "%[account]" to "myacct" action "myacctact"
502
503 Most of the default tags have a single-letter shorthand which removes the needs
504 for the []s:
505
506 match string "%a" to "myacct" action "myacctact"
507
508 Including a nonexistent tag in a string is equivalent to including a tag with
509 an empty value, so "abc%[nonexistent]def" will be translated to "abcdef".
510
511 The automatically added tags are:
512
513 Name Shorthand Replaced with
514 account %a The name of the account from which the mail was
515 fetched.
516 home %h The delivery user's home directory.
517 uid %n The delivery user's uid.
518 action %t The name of the action the mail has matched.
519 user %u The delivery user's username.
520 hour %H The current hour (00-23).
521 minute %M The current minute (00-59).
522 second %S The current second (00-59).
523 day %d The current day of the month (00-31).
524 month %m The current month (01-12).
525 year %y The current year as four digits.
526 year2 The current year as two digits.
527 dayofweek %W The current day of the week (0-6, Sunday is 0).
528 dayofyear %Y The current day of the year (000-365).
529 quarter %Q The current quarter (1-4).
530 rfc822date The current time in RFC822 date format.
531 mail_hour The hour from the mail's date header, converted
532 to local time, if it exists and is valid,
533 otherwise the current time.
534 mail_minute The minute from the mail's date header.
535 mail_second The second from the mail's date header.
536 mail_day The day from the mail's date header.
537 mail_month The month from the mail's date header.
538 mail_year The year from the mail's date header as four
539 digits.
540 mail_year2 The same as two digits.
541 mail_rfc822date The mail date in RFC822 format.
542 hostname The local hostname.
543 folder The name of the IMAP folder that the mail
544 originated from.
545
546 In addition, the shorthand %% is replaced with a literal %, and %1 to %9 are
547 replaced with the result of any bracket expressions in the last regexp (see
548 later section on regexps). A leading ~ or ~user is expanded in strings where a
549 path or command is expected.
550
551 Some accounts add additional tags, discussed below.
552
553 Tags are replaced in almost all strings (including those in single-quotes!),
554 some when the configuration file is parsed and some when the string is used.
555
556 %%% POP3 and POP3S
557
558 Mail may be fetched from a POP3 account. A POP3 account is defined by
559 specifying the following parameters: the server host and optionally port, and
560 optionally the user name and password. If the port is not specified, the
561 default port ('pop3' in the services(5) database) is used. If the user name,
562 password, or both is omitted, fdm attempts to look it up the .netrc file, see
563 the next section for details. Optionally fdm can read the password from a
564 command line program, see below for details.
565
566 Examples of a POP3 account definition are:
567
568 account "pop3acct" pop3 server "pop.isp.com" user "bob" pass "pass"
569
570 account "gmx" pop3 server "pop.gmx.net" port 110 user "jim" pass "pass"
571
572 account "acct" pop3 server "10.0.0.1" port "pop3"
573 user "nicholas" keep
574
575 account "lycos" disabled pop3 server $localserver port 10110
576 pass "password"
577
578 Note that the server string is enclosed in double quotes even if it is an IP,
579 and don't forget to escape any " and \ characters in passwords!
580
581 fdm will attempt to use APOP to obscure the password, if the server offers it.
582 If the server advertises itself as supporting APOP but subsequently refuses
583 to accept it, fdm will not retry with a cleartext password. Use of APOP can be
584 disabled for an account using the 'no-apop' flag, for example:
585
586 account "acct" pop3 server "server" user "bob" pass "pass" no-apop
587
588 The 'starttls' keyword may be added to a POP3 account to attemp STARTTLS after
589 connection.
590
591 POP3S is specified in exactly the same way, except using the 'pop3s' keyword
592 for the type, and the default port is 'pop3s' rather than 'pop3':
593
594 account "pop3sacct" pop3s server "pop.isp.com" user "bob" pass "pass"
595
596 POP3 accounts automatically tag mail with 'server' and 'port' tags, with the
597 value of the server and port attributes exactly as specified in the account
598 definition. A 'server_uid' tag is also added with the server unique id (UIDL).
599
600 POP3 adds 'lines', 'body_lines' and 'header_lines' tags with the number of
601 lines in the complete mail and its body and header. These tags are not updated
602 to reflect any changes made to the mail by fdm rules.
603
604 %%% SSL certificate verification
605
606 fdm can verify SSL certificates before collecting mail from an SSL server. This
607 is enabled globally with the 'verify-certificates' option:
608
609 set verify-certificates
610
611 And may be disabled per-account using the 'no-verify' keyword (this applies to
612 both POP3S and IMAPS accounts):
613
614 account "pop3sacct" pop3s server "pop.isp.com" no-verify
615
616 For an introduction to SSL, see:
617
618 http://httpd.apache.org/docs/2.0/ssl/ssl_intro.html
619
620 A cert bundle is required to verify SSL certificate chains. For more information
621 see:
622
623 http://lynx.isc.org/current/README.sslcerts
624
625 A pregenerated bundle is available courtesy of the MirOS project:
626
627 http://cvs.mirbsd.de/src/etc/ssl.certs.shar
628
629 %%% The .netrc file
630
631 If the user name or password is omitted in POP3 or IMAP account definitions,
632 fdm will attempt to look it up in the .netrc file in the invoking user's home
633 directory.
634
635 The .netrc file format is shared with ftp(1) and some other programs. It
636 consists of a number of 'machine' sections and optionally one 'default' section
637 containing a username ('login') and password for that host. fdm accepts entries
638 only if the machine name matches the POP3 or IMAP server string exactly. If no
639 matches are found and a 'default' section exists, it is used.
640
641 An example .netrc file is:
642
643 machine "my.mail-server.com"
644 login "nicholas"
645 password "abcdef"
646
647 machine "pop.googlemail.com"
648 password "pass1"
649
650 default
651 login "bob"
652 password "moo"
653
654 fdm will abort if the .netrc file is world-writable or world-readable.
655
656 %%% Passwords from a command
657
658 fdm can read the password from a command by using command substitution
659 with $(). For example:
660
661 user "[email protected]" pass $(gpg --quiet --decrypt ~/.password.gpg)
662
663 %%% IMAP and IMAPS
664
665 IMAP and IMAPS accounts are defined using exactly the same syntax as for POP3
666 and POP3S, aside from using the 'imap' or 'imaps' keywords and that the default
667 port is 'imap' or 'imaps'. There is also an additional, optional 'folders'
668 option to specify the folders from which mail should be fetched. If omitted,
669 fdm defaults to the inbox. When the 'folders' tag is used the recieved mail
670 will have a 'folder' tag with the origin folder name.
671
672 Note that with IMAP and IMAPS, mail is still removed from the server unless the
673 'keep' option is given, or the '-k' command line option used.
674
675 Examples of IMAP and IMAPS accounts include:
676
677 account "imapacct" imap server "imap.server.ca" user "bob" pass "pass"
678
679 account "oldimap" disabled imaps server "192.168.0.1" port 10993
680 user "nicholas" pass "pass" folders { "Saved" "MyStuff" }
681
682 account "workspam" disabled imap server "my-work.ath.cx"
683 user "Nicholas" folder "Junk"
684
685 By default, fdm prefers the CRAM-MD5 authentication method, since no passwords
686 are sent in the clear. If the server does not advertise CRAM-MD5 capability,
687 and 'oauthbearer' option is not passed the older LOGIN method is used. For
688 IMAPS connections (which use SSL), the LOGIN method is just as secure. Either
689 of these methods may be disabled with the 'no-cram-md5' and 'no-login' options.
690 If the server advertises OAUTHBEARER capability, the 'oauthbearer' option will
691 use OAuth 2.0 bearer tokens - passed via the 'pass' keyword - as authentication
692 method.
693
694 The 'starttls' keyword may be added to an IMAP account to attemp STARTTLS after
695 connection.
696
697 As with POP3, IMAP adds the 'server', 'port', 'server_uid' and the three line
698 count tags to mail.
699
700 %%% IMAP or POP3 over a pipe or ssh
701
702 Mail may be fetched using IMAP or POP3 via a pipe. This is particularly useful
703 for fetching mail over ssh using public keys.
704
705 For IMAP, a user and password may be supplied, but fdm will only use them if
706 the server asks. If the connection is preauthenticated, the user and password
707 are unnecessary. For POP3, a user and password must be supplied as usual: due
708 to the lack of server name, it cannot be read from the .netrc file.
709
710 Communication takes place via the pipe program's stdin and stdout. If any
711 output is found on stderr, fdm will print it (or log it with '-l').
712
713 Examples are:
714
715 account "imapssh" imap pipe "ssh jim@myhost /usr/local/libexec/imapd"
716
717 account "imapssh2" imap pipe "/usr/bin/whatever" user "bob" pass "bah"
718
719 account "pop3local" pop3
720 pipe "/usr/local/bin/ipop3d" user "me" pass "foo"
721
722 %%% stdin and local mail
723
724 fdm may be configured to fetch mail from stdin, by specifying an account of
725 type 'stdin', for example:
726
727 account "stdin" disabled stdin
728
729 This is most useful to have fdm behave as a mail delivery agent. To configure
730 it for single-user use with sendmail, the simplest method it to add:
731
732 "|/usr/local/bin/fdm -m -a stdin fetch"
733
734 To the user's ~/.forward file (including the double quotes). Note the use of
735 '-m' to prevent stdin delivery from interfering with any normal cronjob, and
736 '-a' to specify that only the disabled "stdin" account should be fetched.
737
738 stdin accounts add the three line count tags described in the POP3 section.
739
740 %%% From maildirs and mboxes
741
742 Fetching from maildirs allows fdm to be used to filter mail on the local
743 machine. This is covered more detail in the later section on archiving and
744 searching.
745
746 Maildir accounts are specified as follows:
747
748 account "mymaildir" maildir "/path/to/dir"
749
750 account "mymaildirs" maildirs { "/path/to/dir1" "/path/to/dir2" }
751
752 Shell glob wildcards may be included in the path names to match multiple
753 maildirs, but every directory found must be a valid maildir.
754
755 Maildir accounts tag mail with a 'maildir' tag which is the basename of the
756 maildir.
757
758 Fetching from mboxes is similar:
759
760 account "mybox" mbox "/path/to/mbox"
761
762 account "mymboxes" mboxes { "/path/to/mbox1" "/path/to/mbox2" }
763
764 Note that if an mbox is modified (mail is dropped from it), sufficient disk
765 space is required to create a temporary copy of the entire mbox.
766
767 %%% Using NNTP and NNTPS
768
769 fdm can fetch news messages from a news server using NNTP or NNTPS. News
770 accounts are specified like so:
771
772 account "news1" nntp server "news.server.sk" port 119
773 group "comp.unix.bsd.openbsd.misc"
774 cache "%h/.fdm.cache/%[group]"
775
776 account "mynews" nntps server "ssl.news.server" port "nntps"
777 user "myuser" pass "mypass"
778 groups { "alt.test" "alt.humor.best-of-usenet" }
779 cache "%h/.fdm.cache"
780
781 The cache is a file used to store details of the last article fetched. If only
782 one group is supplied in the account definition, %[group] tags are replaced by
783 the name of the group in the cache path. If multiple groups are provided,
784 %[group] is removed.
785
786 Note that whether a message is kept or deleted is irrelevent to NNTP, articles
787 are always left on the server. The index and message-id of the last article
788 is recorded in the cache file so that older articles are skipped when the a
789 newsgroup is again fetched. This happens regardless of any 'keep' keywords or
790 the '-k' command line option.
791
792 As with POP3 and IMAP, NNTP accounts add the 'server' and 'port' tags to mail.
793 In addition, a 'group' tag is added with the group name. This can ensure
794 articles are matched purely on the group they are fetched from (trying to do
795 this using headers is unreliable with cross-posted articles). For example:
796
797 match account "news" {
798 match string "%[group]" to "comp.lang.c" action "news-%[group]"
799 match string "%[group]" to "comp.std.c" action "news-%[group]"
800 match all action drop
801 }
802
803 %%% New or old mail only
804
805 With POP3 and IMAP, fdm can be set up to fetch only new or old mail. For POP3
806 this is achieved by recording the current state of the server in a cache file,
807 which is updated as each mail is fetched. For IMAP it makes use of the 'seen'
808 server flag which is updated by the server after each mail is fetched.
809
810 These options are specified as in the following examples. For POP3:
811
812 account "name" pop3 server "blah" new-only cache "~/.fdm-pop3-cache"
813
814 account "acct" pop3s server "my-server" user "bob"
815 new-only cache "my-server-pop3-cache" no-apop
816
817 And for IMAP:
818
819 account "imap" imap server "blah" new-only
820
821 account "sslimap" imaps server "imaps.somewhere"
822 user "user" pass "pass" old-only no-verify
823
824 Note that currently, when using this with IMAP, the server is permitted to flag
825 the mail as 'seen' before fdm has successfully delivered it, so there is no
826 guarantee that mail so marked has been delivered, only that it has been
827 fetched.
828
829 ### Defining actions
830
831 An action is a particular command to execute on a mail when it matches a
832 filtering rule (see the next section on filtering mail). Actions are named,
833 similar to accounts, and have a similar form:
834
835 action <name> [<users>] <type> <parameters>
836
837 The <users> item may be either:
838
839 - the keyword 'user' followed by a single username string or uid, such as:
840
841 user "nicholas"
842
843 user "1000"
844
845 - the keyword 'users' followed by a list of users in {}s, for example:
846
847 users { "1001" "nicholas" }
848
849 If users are specified, the action will be run once for each user, with fdm
850 changing to that user before executing the action. Note that fdm will execute
851 the action once for each user even when not started as root, but will not be
852 able to change to the user. The user keyword is primarily of use in multiuser
853 configurations. If users are present on an action, they override any specified
854 by the account definition.
855
856 If running as root and no user is specified on either the action or on the
857 filtering rule (see the section on filtering below), the default user is
858 used, see the '-u' command line option and the 'default-user' option in the
859 setting options section
860
861 %%% Drop and keep
862
863 The simplest actions are the 'drop' and 'keep' actions. They have no parameters
864 and are specified like this:
865
866 action "mydropaction" drop
867
868 action "mykeepaction" keep
869
870 The 'drop' action arranges for mail to be dropped when rule evaluation is
871 complete. Note that using 'drop' does not stop further evaluation if the
872 filtering rule contains a 'continue' keyword, and it may be overridden by a
873 'keep' option on the account or by the '-k' flag on the command line.
874
875 The 'keep' action is similar to 'drop', but it arranges for the mail to be
876 kept once rule evaluation is complete, rather than dropped.
877
878 %%% Maildirs
879
880 Mails may be saved to a maildir through a 'maildir' action, defined like so:
881
882 action "mymaildiraction" maildir "/path/to/maildir"
883
884 If any component of the maildir path does not exist, it is created, unless the
885 no-create option is specified. Mails saved to a maildir are tagged with a
886 'mail_file' tag containing the full path to the file in which they were saved.
887
888 %%% Mboxes
889
890 An action to deliver to an mbox is defined in the same way as for a maildir:
891
892 action "mymboxaction" mbox "/path/to/mbox"
893
894 The same % tokens are replaced in the path. If the mbox does not exist, it
895 is created. Mboxes may optionally be gzip compressed by adding the 'compress'
896 keyword:
897
898 action "mymboxaction" mbox "/path/to/mbox" compress
899
900 fdm will append .gz to the mbox path (if it is not already present) and append
901 compressed data. If the mbox exists but is not already compressed, uncompressed
902 data will be appended.
903
904 As with maildirs, if any component of the mbox path does not exist, it is
905 created, unless the no-create option is set. Mails saved to an mbox are tagged
906 with an 'mbox_file' tag with the path of the mbox.
907
908 %%% IMAP and IMAPS
909
910 An action may be defined to store mail in an IMAP folder. The specification is
911 similar to the IMAP account definition. A server host and optionally port
912 (default 'imap' or 'imaps') must be specified. A username and password may be
913 supplied; if they are omitted, fdm will attempt to find a .netrc
914 entry. Examples include:
915
916 action "myimapaction" imap server "imap.server"
917
918 action "myimapaction" imaps server "imap.server"
919 port "8993" user "user" pass "pass" folder "folder"
920
921 action "myimapaction" imaps server "imap.server"
922 user "user" pass "pass" no-verify no-login
923
924 %%% SMTP
925
926 An action may be defined to pass mail on over SMTP. The server host must be
927 specified and optionally the port and string to pass to the server with the
928 RCPT TO and MAIL FROM commands. If the port is not specified it defaults to
929 "smtp". Examples include:
930
931 action "mysmtpaction" smtp server "smtp.server"
932
933 action "mysmtpaction" smtp server "smtp.server" port 587
934
935 action "mysmtpaction" smtp
936 server "smtp.server" port "submission" from "[email protected]"
937
938 action "mysmtpaction" smtp server "smtp.server" to "me@somewhere"
939
940 %%% LMTP
941
942 An action may be defined to store mail in a LMTP server. UNIX and TCP sockets
943 are supported. Examples include:
944
945 action "mylmtpaction" lmtp server "/path/to/socket" to "user@domain"
946
947 action "mylmtpaction" lmtp server "hostname" port 24 to "user@domain"
948
949 action "mylmtpaction" lmtp server "10.1.1.7" port 24 to "user@domain"
950
951 %%% Write, pipe, exec and append
952
953 Actions may be defined to write or append a mail to a file, to pipe it to a
954 shell command, or merely to execute a shell command. The append action appends
955 to and write overwrites the file. % tokens are replaced in the file or command
956 as for maildir and mbox actions.
957
958 Examples are:
959
960 action "mywriteaction" write "/tmp/file"
961
962 action "myappendaction" append "/tmp/file"
963
964 action "mypipeaction" pipe "cat > /dev/null"
965
966 action "domaildirexec" exec "~/.fdm.d/my-special-script %[mail_file]"
967
968 Pipe and exec commands are run as the command user (by default the user who
969 invoked fdm).
970
971 %%% stdout
972
973 fdm can write mails directly to stdout, using the 'stdout' action:
974
975 action "so" stdout
976
977 %%% Rewriting mail
978
979 Mail may be altered by passing it to a rewrite action. This is similar to
980 the pipe action, but the output of the shell command to stdout is reread by fdm
981 and saved as a new mail. This is useful for such things as passing mail
982 through a spam filter or removing or altering headers with sed. Note that
983 rewrite only makes sense on filtering rules where the continue keyword is
984 specified, or where multiple actions are used (see the next section for details
985 of this). Possible rewrite action definitions are:
986
987 action "myspamaction" rewrite "bmf -p"
988
989 action "mysedaction" rewrite "sed 's/x/y/'"
990
991 %%% Adding or removing headers
992
993 Simple actions are provided to add a header to a mail:
994
995 action "lines" add-header "Lines" value "%[lines]"
996
997 Or to remove all instances of a header from mail:
998
999 action "del-ua" remove-header "user-agent"
1000
1001 action "rmhdr" remove-header "x-stupid-header"
1002
1003 action "remove-headers" remove-headers { "X-*" "Another-Header" }
1004
1005 %%% Tagging
1006
1007 Mails may be assigned one of more tags manually using the tag action type. For
1008 example,
1009
1010 match account "my*" action tag "myaccts"
1011
1012 match "^User-Agent:[ \t]*(.*)" action tag "user-agent" value "%1"
1013
1014 The tag is attached to the mail with the specified value, or no value if none
1015 is provided.
1016
1017 %%% Compound actions
1018
1019 Compound actions may be defined which perform multiple single actions. They
1020 are similar to standard single actions but multiple actions are provided using
1021 {}. For example,
1022
1023 action "multiple" {
1024 add-header "X-My-Header" value "Yay!"
1025 mbox "mbox2"
1026 }
1027
1028 action "myaction" users { "bob" "jim" } {
1029 rewrite "rev"
1030 maildir "%h/%u's maildir"
1031 }
1032
1033 Compound action are executed from top-to-bottom, once for each user. Note that
1034 the effects are cumulative: the second example above would deliver a mail
1035 rewritten once to 'bob' and rewritten again (ie, twice) to 'jim'. If this is
1036 not desired, seperate actions must be used.
1037
1038 %%% Chained actions
1039
1040 An action may call other named actions by reusing the 'action' keyword:
1041
1042 action "abc" action "def"
1043
1044 action "an_action" {
1045 rewrite "rev"
1046 action "another_action"
1047 action "yet_more_actions"
1048 }
1049
1050 There is a hard limit of five chained actions in a sequence to prevent infinite
1051 loops.
1052
1053 ### Filtering mail
1054
1055 Mail is filtered by defining a set of filtering rules. These rules tie together
1056 mail fetched from an account and passed to one or more actions. Rules are
1057 evaluated from top-to-bottom of the file, and evaluation stops at the first
1058 matching rule (unless the continue keyword is specified).
1059
1060 The general form of a filtering rule is:
1061
1062 match <conditions> [<users>] <actions> [continue]
1063
1064 The optional <users> item is specified as for an action definition. If users
1065 are specified on a filtering (match) rule, they override any specified on the
1066 action or account.
1067
1068 The <conditions> item is set of conditions against which the match may be
1069 specified, each condition returns true or false. Conditions are described in
1070 the next few sections. Aside from the 'all' condition, which is a special case,
1071 conditions may be chained as an expression using 'and' and 'or', in which case
1072 they are evaluated from left to right at the same precedence, or prepended with
1073 'not' to invert their outcome.
1074
1075 The <actions> item is a list of actions to execute when this rule matches.
1076 It is in the same list format: 'action "name"' or 'actions { "name1" "name2" }'.
1077 It may also be a lambda (inline) action, see the section below.
1078
1079 If a rule with the 'continue' keyword matches, evaluation does not stop after
1080 the actions are executed, instead subsequent rules are matched.
1081
1082 %%% Nesting rules
1083
1084 Filtering rules may be nested by using the special form:
1085
1086 match <conditions> [<accounts>] {
1087 match ...
1088 }
1089
1090 If the conditions on the outer rule match, the inner rules are evaluated. If
1091 none of the inner rules match (or they all specify the 'continue' keyword)
1092 evaluation continues outside to rules following the nested rule, otherwise it
1093 stops.
1094
1095 %%% Lambda actions
1096
1097 Lambda actions are unnamed actions included inline as part of the filtering
1098 rule. This can be convenient for actions which do not need to be used multiple
1099 times. Lambda actions are specified as a combination of the rule and an action
1100 definition. For example:
1101
1102 match all action maildir "mymaildir"
1103
1104 match all actions {
1105 rewrite "rev"
1106 tag "reversed"
1107 } continue
1108
1109 %%% The all condition
1110
1111 The all condition matches all mail.
1112
1113 Examples include:
1114
1115 match all action "default"
1116
1117 match all rewrite "rewaction" continue
1118
1119 %%% Matched and unmatched
1120
1121 The matched and unmatched conditions are used to match mail that has matched
1122 or has not matched previous rules and been passed on with the 'continue'
1123 keyword. For example,
1124
1125 match "myregexp" action "act1" continue
1126 # This rule will match only mails that also matched the first.
1127 match matched action "act2"
1128 # This rule will match only mails that matched neither of the first two.
1129 match unmatched action "act3"
1130
1131 %%% Matching by account
1132
1133 The account condition matches a list of accounts from which the mail was
1134 fetched. It is specified as either a single account ('account "name"') or a list
1135 of accounts ('accounts { "name1" "name2" }'). fnmatch(3) wildcards may also be
1136 used. Examples include:
1137
1138 match "blah" accounts { "pop3" "imap" } action "go!"
1139
1140 match matched and account "myacc" action drop
1141
1142 %%% Matching a regexp
1143
1144 Matching against a regexp is the most common form of condition. It takes the
1145 following syntax:
1146
1147 [case] <regexp> [in headers|in body]
1148
1149 The 'case' keyword instructs fdm to match the regexp case sensitively rather
1150 than the default of case insensitivity. The 'in headers' or 'in body' keywords
1151 make fdm search only the headers or body of each mail, the default is to match
1152 the regexp against the entire mail. Any multiline headers are unwrapped onto
1153 a single line before matching takes place and the process reversed afterwards.
1154 The regexp itself is an extended regexp specified as a simple string, but care
1155 must be taken to escape \s and "s properly.
1156
1157 Examples include:
1158
1159 match "^From:.*bob@bobland\\.bob" in headers and
1160 account "pop3" action "act"
1161
1162 match ".*YAHOO.*BOOTER.*" in body action "junk"
1163
1164 %%% Matching bracket expressions
1165
1166 The results of any bracket expressions within the last regexp match are
1167 remembered, and may be made use of using the 'string' condition, or used to
1168 construct an action name, maildir or mbox path, etc. The bracket expressions
1169 may be substituted using the %0 to %9 tokens. For example,
1170
1171 match "^From:.*[ \t]([a-z]*)@domain" in headers action "all" continue
1172 match string "%1" to "bob.*" action "bobmail"
1173
1174 match "^From:.*[ \t]([a-z]*)@domain" in headers action "all" continue
1175 match all action "%1mail"
1176
1177 This is particularly useful in combination with nested rules (see later):
1178 bracket expressions in a regexp on the outer rule may be compared on inner
1179 rules.
1180
1181 Note that %0 to %9 are used only for 'regexp' rules. Regexps that are part of
1182 'command' rules use the 'command0' to 'command9' tags.
1183
1184 %%% Matching by age or size
1185
1186 Mail may be matched based on its age or size. An age condition is specified as
1187 follows:
1188
1189 age [<|>] <age> [hours|minutes|seconds|days|months|years]
1190
1191 If '<' is used, mail is matched if it is younger than the specified age. If '>',
1192 if it is older. The <age> item may be a simple number of seconds, or suffixed
1193 with a unit. Examples are:
1194
1195 match age < 3 months actions { "act1" "act2" }
1196
1197 match age > 100 hours action "tooold"
1198
1199 The age is extracted from the 'Date' header, if possible. To match mails for
1200 which the header was invalid, the following form may be used:
1201
1202 match age invalid action "baddate"
1203
1204 The size condition is similar:
1205
1206 size [<|>] <size> [K|KB|kilobytes...]
1207
1208 Where <size> is a simple number in bytes, or suffixed with 'K', 'M' or 'G' to
1209 specify a size in kilobytes, megabytes or gigabytes, such as:
1210
1211 match size < 1K action "small"
1212
1213 match size > 2G action "whoa"
1214
1215 %%% Using a shell command
1216
1217 Mail may be matched using the result of a shell command. This condition follows
1218 the form:
1219
1220 [exec|pipe] <command> returns (<return code>, [case] <stdout regexp>)
1221
1222 If 'exec' is used, the command is executed. If 'pipe', the mail is piped to the
1223 command's stdin. The <command> is a simple string. % tokens are replaced as
1224 normal.
1225
1226 Any of the <return code> or <stdout regexp> or both may be specified. The
1227 <return code> is a simple number which is compared against the return code from
1228 the command, the <stdout regexp> is a regexp that is matched case insensitively
1229 against each line output by the command on stdout. The result of any bracket
1230 expressions in the stdout regexp are saved as 'command0' to 'command9' tags on
1231 the mail.
1232
1233 Any output on stderr is logged by fdm, so 2>&1 must be included in the command
1234 in order to apply the regexp to it.
1235
1236 Examples:
1237
1238 match exec "true" (0, ) action "act"
1239
1240 match not pipe "grep Bob" (1, ) action "act"
1241
1242 match pipe "myprogram" (, "failed") actions { "act1" "act2" }
1243
1244 match exec "blah" (12, "^Out") action "meep"
1245
1246 %%% Attachments
1247
1248 There are five conditions available to filter based on the size, quantity, type
1249 and name of attachments. They are all prefixed with the 'attachment'
1250 keyword. Two compare the overall number of attachments:
1251
1252 The 'attachment count' conditions matches if the number of attachments is
1253 equal to, not equal to, less than or greater than the specified number:
1254
1255 match attachment count == 0 action "action"
1256
1257 match attachment count != 10 action "action"
1258
1259 match attachment count < 2 action "action"
1260
1261 match attachment count > 7 action "action"
1262
1263 The 'attachment total-size' condition is similar, but compares the total
1264 size of all the attachments in a mail:
1265
1266 match attachment total-size < 4096 kilobytes action "action"
1267
1268 match attachment total-size > 1M action "action"
1269
1270 There are also three conditions which matches if any individual attachment
1271 fulfils the condition: 'any-size' to match if any attachment is less than or
1272 greater than the given size, and 'any-type' and 'any-name' which compare the
1273 attachment MIME type and name attribute (if any) using fnmatch(3):
1274
1275 match attachment any-size < 2K action "action"
1276
1277 match attachment any-type "*/pdf" action "action"
1278
1279 match attachment any-name "*.doc" action "action"
1280
1281 %%% Matching tags
1282
1283 The existence of a tag may be tested for using the 'tagged' condition:
1284
1285 match tagged "mytag" action "a"
1286
1287 match tagged "ohno" and size >1K action drop
1288
1289 Or the tags value matched using the 'string' match type (in a similar way to
1290 matching bracket expressions):
1291
1292 match string "%[group]" to "comp.lang.c" action "clc"
1293
1294 match string "%u" to "bob" action "bob"
1295
1296 %%% Using caches
1297
1298 fdm has builtin support for maintaining a cache of string keys, including
1299 appending to a cache, checking if a key is present in a cache, and expiring
1300 keys from a cache once they reach a certain age.
1301
1302 These caches should not be confused with the NNTP cache file. Key caches are
1303 referenced by filename and must be declared before use:
1304
1305 cache "%h/path/to/cache"
1306
1307 cache "~/.fdm.db" expire 1 month
1308
1309 If the expiry time is not specified, items are never expired from the cache.
1310
1311 Once declared, keys may be added to the cache with the 'add-to-cache' action:
1312
1313 match all action add-to-cache "~/my-cache" key "%[message_id]"
1314
1315 Or removed with the 'remove-from-cache' action:
1316
1317 match all action remove-from-cache "~/my-cache" key "%[message_id]"
1318
1319 And the existence of a key in the cache may be tested for using the 'in-cache'
1320 condition:
1321
1322 match in-cache "~/my-cache" key "%[message_id]" action "foundincache"
1323
1324 Any string may be used as key, but the message-id is most often useful. Note
1325 that the key may not be empty, so care must be taken with messages without
1326 message-id (such as news posts fetched with NNTP).
1327
1328 Caches may be used to elimate duplicate messages using rules similar to those
1329 above:
1330
1331 $db = "~/.fdm-duplicates.db"
1332 $key = "%[message_id]"
1333 cache $db expire 2 weeks
1334
1335 match not string $key to "" {
1336 match in-cache $db key $key action maildir "%h/mail/duplicates"
1337 match all action add-to-cache $db key $key continue
1338 }
1339
1340 %%% Cache commands
1341
1342 fdm includes a number of commands to manipulate caches from the command-line.
1343 These are invoked with the 'cache' keyword followed by a command. The
1344 following commands are supported:
1345
1346 cache add <path> <string>
1347 cache remove <path> <string>
1348 These add or remove <string> as a key in the cache <path>.
1349
1350 cache list [<path>]
1351 This lists the number of keys in a cache, or in all caches declared
1352 in the configuration file if <path> is omitted.
1353
1354 cache dump <path>
1355 This dumps the contents of the cache <path> to stdout. Each key is
1356 printed followed by a space and the timestamp as Unix time.
1357
1358 cache clear <path>
1359 Delete all keys from a cache.
1360
1361 Examples:
1362
1363 $ fdm cache list
1364 /export/home/nicholas/.fdm.d/duplicates: 4206 keys
1365
1366 $ touch my-cache
1367 $ fdm cache dump my-cache
1368 $ fdm cache add my-cache test
1369 $ fdm cache dump my-cache
1370 test 1195072403
1371
1372 ### Setting options
1373
1374 fdm has a number of options that control its behaviour. These are defined
1375 using the set command:
1376
1377 set <option> [<value>]
1378
1379 In addition to the options below, some environment variables may be used to
1380 control fdm. If TMPDIR is present, its value will be used instead of /tmp for
1381 saving temporary files.
1382
1383 The possible options are:
1384
1385 - maximum-size <size>
1386
1387 This specifies the maximum size of mail that fdm will accept. The default is 32
1388 MB. Note that fdm may be storing a number of mails simultaneously, up to the
1389 'queue-high' setting (doubled if rewrite is used) for each account, so care
1390 should be taken when increasing this option.
1391
1392 If mail over the maximum size is encountered, fdm will abort with an error,
1393 without deleting the mail from the server (unless 'delete-oversized' is set).
1394
1395 - delete-oversized
1396
1397 If this option is set, fdm will delete oversized mail from the server rather
1398 than leaving it for the user to sort out.
1399
1400 - queue-high <number>
1401
1402 This sets the number of mails fdm will queue simultaneously. The default is
1403 two. Once this limit is reached, fdm will cease fetching mail until the number
1404 queued drops to the value of the 'queue-low' setting.
1405
1406 fdm queues mails so that they may be processed while waiting for data from the
1407 server. Changing this option can increase (or decrease) performance, it's
1408 usefulness varies wildly with the ruleset, speed of connection and remote host,
1409 and the local hardware.
1410
1411 The maximum possible value is currently 50. To ensure fdm fetches and delivers
1412 mail sequentially, set this option to one.
1413
1414 - queue-low <number>
1415
1416 This sets the number of mails fdm will wait for the queue to drop to before
1417 restarting fetching after the 'queue-high' limit has been reached. The default
1418 is three-quarters of the 'queue-high' setting.
1419
1420 - allow-multiple
1421
1422 This option makes fdm ignore the lock file, similar to the '-m' command line
1423 option.
1424
1425 - lock-file <path>
1426
1427 This option specifies a string to use as the path of the lock file. For example:
1428
1429 set lock-file "/tmp/my-lock-file"
1430
1431 - command-user <user>
1432
1433 This specifies the user used to run exec and pipe actions. By default it is
1434 the user who invoked fdm.
1435
1436 - default-user <user>
1437
1438 This specifies the default user to use if run as root and no users are specified
1439 on the action or filtering rule. This option may be overriden with the '-u'
1440 flag on the command line.
1441
1442 - lock-types [fcntl] [flock] [dotlock]
1443
1444 These specify the type of locking to use when writing to mboxes. fcntl and
1445 flock locking are mutually exclusive, but dotlock may be used with either.
1446 Some NFS servers do not support fcntl. The default is flock only. Example:
1447
1448 set lock-types fcntl dotlock
1449
1450 - proxy <url>
1451
1452 This specifies a URL to proxy outgoing connections through. See the section
1453 on proxying below.
1454
1455 - unmatched-mail [drop|keep]
1456
1457 This option controls how fdm should deal with mail that reaches the end of
1458 the ruleset (doesn't match any rules, or only rules with the 'continue'
1459 keyword). If 'drop' is specified, such mail is dropped. If 'keep', it is
1460 kept. The default is to keep the mail, and issue a warning.
1461
1462 - purge-after <message count>
1463
1464 The 'purge-after' option instructs fdm to attempt to purge deleted mail after
1465 the specified number of mails has been fetched. This is useful to limit the
1466 number of mails refetched on the next run if the connection fails. It can have
1467 a large effect on performance, particularly if the message count is set to a
1468 low number.
1469
1470 Note that for POP3, purging deleted mail involves disconnecting and
1471 reconnecting from the server; some POP3 servers refuse reconnections if too
1472 many are made too quickly, so this option should be used with care.
1473
1474 - no-received
1475
1476 If this option is present, fdm will not insert a 'Received' header into fetched
1477 mail.
1478
1479 - no-create
1480
1481 When this option is specified, fdm will not attempt to create maildir and
1482 mboxes or directories above them.
1483
1484 - file-umask [user|<umask>]
1485
1486 This specifies the umask to use when creating files. 'user' means to use the
1487 umask set when fdm is started, or it may be specified as a three-digit octal
1488 number. The default is 077.
1489
1490 - file-group [user|<group>]
1491
1492 This option allows the default group ownership of files and directories created
1493 by fdm to be specified. 'group' may be a group name string or a numeric gid. If
1494 'user' is used, or if this option is not set in the configuration file, fdm
1495 does not attempt to set the group of new files and directories.
1496
1497 - timeout <time>
1498
1499 This controls the maximum time to wait for a server to send data before closing
1500 a connection. The default is 900 seconds.
1501
1502 - verify-certificates
1503
1504 This instructs fdm to verify SSL certificates for all SSL connections, see the
1505 previous section on SSL certificate verification.
1506
1507 - ignore-errors
1508
1509 By default, fdm will stop processing mail and exit if any delivery fails; if
1510 this option is set, it will instead continue and try the next mail when
1511 delivery of one fails.
1512
1513 ### Archiving and searching mail
1514
1515 As fdm can fetch from maildirs, it can be used to filter mail from one maildir
1516 into another, for example to archive older mail (with drop) or to search for
1517 mail matching a particular pattern (with keep). The 'age' condition, and the
1518 %[maildir] and time/date tags are particularly useful for archiving. For
1519 example, to archive all mail older than 30 days by quarter, something like this
1520 may suffice (the account restriction can be dropped if being used in a
1521 single-purpose configuration file):
1522
1523 account "archive" disabled maildir "source-maildir"
1524 match account "archive" and age > 30 days action mbox "%[maildir]q%Q"
1525 match account "archive" action keep
1526
1527 Then, fdm may be run to move the mail:
1528
1529 fdm -vaarchive fetch
1530
1531 To search mail, similar rules may be used, but all mail should be kept, in this
1532 example by marking the account with 'keep' so that mail is kept no matter what
1533 rules it matches:
1534
1535 account "search" disabled maildir "source-maildir" keep
1536 action "found" mbox "search-results"
1537 match "^From.*Bob" in headers account "search" action "found"
1538 match account "search" action keep
1539
1540 All mail matching the regexp will be copied to the target mbox. There are
1541 several other ways to write this ruleset.
1542
1543 ### Using fdm behind a proxy
1544
1545 fdm may be used behind a proxy by specifying the proxy URL using the 'proxy'
1546 option. HTTP and SOCKS5 proxies are supported:
1547
1548 set proxy "http://proxy.server/"
1549
1550 set proxy "http://proxy.server:port/"
1551
1552 set proxy "socks5://proxy.server/"
1553
1554 set proxy "socks5://proxy.server:port/"
1555
1556 set proxy "socks5://[email protected]/"
1557
1558 set proxy "socks5://user:[email protected]/"
1559
1560 Authentication is not supported for HTTP proxies.
1561
1562 ### Bug reports and queries
1563
1564 Bug reports, queries, suggestions and code are best sent by email to:
1565
1566 [email protected]
1567
1568 Bug reports may also be registered on GitHub.
1569
1570 ### Frequently asked questions
1571
1572 %%% Why?
1573
1574 Two main reasons:
1575
1576 1. I didn't like the existing tools. That is not to say that other tools are
1577 bad or aren't useful, merely that fdm meets my needs better.
1578
1579 And more importantly:
1580
1581 2. I disliked the fact that as a home user with a relatively simple setup I
1582 had to have five programs to deal with mail: sendmail, fetchmail, procmail,
1583 archivemail, mutt; all with different, variously broken configuration file
1584 syntaxes, and weird quirks. I now have three programs: sendmail, fdm and
1585 mutt, and fewer weird configurations to learn and potential problems. I can
1586 also do some quite complex things without reaching for additional tools like
1587 formail and reformail.
1588
1589 %%% How do I write regexps?
1590
1591 See the re_format(7) man page. It is online here (for OpenBSD):
1592
1593 http://www.openbsd.org/cgi-bin/man.cgi?re_format
1594
1595 There are also a number of books and probably websites on the subject.
1596
1597 %%% Keep doesn't work with GMail!
1598
1599 This is because GMail is broken, see:
1600
1601 http://pyropus.ca/software/getmail/faq.html#faq-notabug-gmail-bug
1602
1603 In addition, GMail IMAP doesn't set the \Seen flag when mail is fetched with
1604 the UID FETCH BODY[] command (RFC3501 says that the "\Seen flag is implicitly
1605 set"). fdm works around this bug by setting the flag explicitly when mail is
1606 kept.
1607
1608 %%% Why doesn't fdm run as a daemon?
1609
1610 Because that is what cron is for: it comes as standard with all sensible
1611 operating systems, and by using it I avoid a lot of code to deal with signals,
1612 configuration reload, extra configuration options and general other crap
1613 related to running all the time. Daemonising is for servers, for stuff that
1614 needs to run periodically, use cron.
1615
1616 %%% Why does fdm fork child processes when not running as root?
1617
1618 Because one design is much cleaner and easier to work with than two. And it
1619 has a negligible practical effect on performance in any case.
1620
1621 %%% Can fdm get rid of that crap in []s some mailing lists add to subjects?
1622
1623 Yes! Rewrite the mail using sed to remove the crap, for example:
1624
1625 action "full-disclosure" {
1626 rewrite "sed 's/^\\(Subject:.*\\)\\[Full-disclosure\\] /\\1/'"
1627 maildir "%h/mail/full-disclosure"
1628 }
1629 match "^List-Id:.*<full-disclosure\\.lists\\.grok\\.org\\.uk>" in headers
1630 action "full-disclosure"
1631
1632 %%% I'm building on Linux and it complains about REG_STARTEND.
1633
1634 Older versions (pre-2005) of glibc don't support the REG_STARTEND flag to
1635 regexec(3). Either upgrade to a later version of glibc, or use PCRE.
1636
1637 %%% Should I use PCRE or standard POSIX regexps? What's the difference?
1638
1639 PCRE is a library providing "perl-compatible" regexps. These are broadly
1640 compatible with POSIX extended regexps, but with a number of extensions based
1641 on perl regexps.
1642
1643 Unless you want or need some of the extensions, there is generally no
1644 compelling reason to choose one over the other. PCRE is faster than some
1645 POSIX regexp implementations, but few rulesets will include sufficient
1646 regexps for this to make any difference. PCRE has had some security
1647 problems, but most regexp implementations pose a similar risk for their
1648 complexity if nothing else; fdm performs regexp matching as non-root in
1649 any case.
1650
1651 The Debian package and FreeBSD port both use PCRE by default.
1652
1653 Because I hate maintaining and testing two sets of code, there is a strong
1654 possibility that PCRE may become the fdm default at some point.
1655
1656 ================================================================================
1657 $Id$
1658