]> Pileus Git - ~andy/fetchmail/blob - fetchmail.man
45fc6ffb0cedb38ca85c333d312b031487e44b90
[~andy/fetchmail] / fetchmail.man
1 '\" t
2 .\" ** The above line should force tbl to be used as a preprocessor **
3 .\"
4 .\" Man page for fetchmail
5 .\"
6 .\" For license terms, see the file COPYING in this directory.
7 .TH fetchmail 1
8 .SH NAME
9 fetchmail \- fetch mail from a POP, IMAP, or ETRN-capable server
10
11 .SH SYNOPSIS
12 \fBfetchmail\fR [\fIoptions\fR] [\fImailserver...\fR]
13
14 .SH DESCRIPTION
15 .I fetchmail
16 is a mail-retrieval and forwarding utility; it fetches
17 mail from remote mailservers and forwards it to your local (client)
18 machine's delivery system.  You can then handle the retrieved mail
19 using normal mail user agents such as \fIelm\fR(1) or \fIMail\fR(1).
20 The \fBfetchmail\fR utility can be run in a daemon mode to repeatedly
21 poll one or more systems at a specified interval.
22 .PP
23 The
24 .I fetchmail
25 program can gather mail from servers supporting any of the common
26 mail-retrieval protocols: POP2, POP3, IMAP2bis, and IMAP4.  It can
27 also use the ESMTP ETRN extension.  (The RFCs describing all these
28 protocols are listed at the end of this document.)
29 .PP
30 While
31 .I fetchmail
32 is primarily intended to be used over on-demand TCP/IP links (such as
33 SLIP or PPP connections), it may also be useful as a message transfer
34 agent for sites which refuse for security reasons to permit
35 (sender-initiated) SMTP transactions with sendmail.
36 .PP
37 As each message is retrieved \fIfetchmail\fR normally delivers it via SMTP to
38 port 25 on the machine it is running on (localhost), just as though it
39 were being passed in over a normal TCP/IP link.  The mail will then be
40 delivered locally via your system's MDA (Mail Delivery Agent, usually
41 \fIsendmail\fR(8) but your system may use a different one such
42 as \fIsmail\fR, \fImmdf\fR, or \fIqmail\fR).  All the delivery-control
43 mechanisms (such as \fI.forward\fR files) normally available through
44 your system MDA and local delivery agents will therefore work.
45 .PP
46 The behavior of
47 .I fetchmail
48 is controlled by command-line options and a run control file,
49 \fI~/.fetchmailrc\fR, the syntax of which we describe below.  Command-line
50 options override
51 .I ~/.fetchmailrc
52 declarations.
53 .PP
54 Each server name that you specify following the options on the
55 command line will be queried.  If you don't specify any servers
56 on the command line, each server in your 
57 .I ~/.fetchmailrc
58 file will be queried.
59 .PP
60 To facilitate the use of
61 .I fetchmail
62 In scripts, pipelines, etc., it returns an appropriate exit code upon 
63 termination -- see EXIT CODES below.
64
65 .SH OPTIONS
66 The following options modify the behavior of \fIfetchmail\fR.  It is
67 seldom necessary to specify any of these once you have a
68 working \fI.fetchmailrc\fR file set up.
69 .PP
70 Almost all options have a corresponding keyword which can be used to
71 declare them in a 
72 .I fetchmailrc
73 file.
74 .PP
75 Some special options are not covered here, but are documented insttead
76 in sections on AUTHENTICATION and DAEMON MODE which follows.
77 .SS General Options
78 .TP
79 .B \-V, --version
80 Displays the version information for your copy of 
81 .I fetchmail.
82 No mail fetch is performed.
83 Instead, for each server specified, all option information
84 that would be computed if
85 .I fetchmail.
86 were connecting to that server is displayed.  Any non-printables in
87 passwords or other string names are shown as backslashed C-like
88 escape sequences.  This option is useful for verifying that your
89 options are set the way you want them.
90 .TP
91 .B \-c, --check
92 Return a status code to indicate whether there is mail waiting,
93 without actually fetching or deleting mail (see EXIT CODES below).
94 This option turns off daemon mode (in which it would be useless).  It
95 doesn't play well with queries to multiple sites, and doesn't work
96 with ETRN.  It will return a false positive if you leave read but
97 undeleted mail in your server mailbox and your fetch protocol can't
98 tell kept messages from new ones.  This means it will work with IMAP,
99 not work with POP2, and may occasionally flake out under POP3.
100 .TP
101 .B \-s, --silent
102 Silent mode.  Suppresses all progress/status messages that are normally
103 echoed to standard error during a fetch.  The --verbose option
104 overrides this.
105 .TP
106 .B \-v, --verbose
107 Verbose mode.  All control messages passed between 
108 .I fetchmail
109 and the mailserver are echoed to stderr.  Overrides --silent.
110 .SS Disposal Options
111 .TP
112 .B \-a, --all
113 (Keyword: fetchall)
114 Retrieve both old (seen) and new messages from the mailserver.  The
115 default is to fetch only messages the server has not marked seen.
116 Note that POP2 retrieval behaves as though --all is always on (see
117 RETRIEVAL FAILURE MODES below) and this option does not work with ETRN.
118 This option has the side effect or forcing POP3 retrieval to use RETR
119 rather than TOP for retrieval, working around buggy implementations
120 of the latter in some POP3 servers.
121 .TP
122 .B \-k, --keep
123 (Keyword: keep)
124 Keep retrieved messages on the remote mailserver.  Normally, messages 
125 are deleted from the folder on the mailserver after they have been retrieved.
126 Specifying the 
127 .B keep 
128 option causes retrieved messages to remain in your folder on the
129 mailserver.  This option does not work with ETRN.
130 .TP
131 .B \-K, --nokeep
132 (Keyword: nokeep)
133 Delete retrieved messages from the remote mailserver.  This
134 option forces retrieved mail to be deleted.  It may be useful if
135 you have specified a default of \fBkeep\fR in your
136 \&\fI.fetchmailrc\fR.  This option is forced on with ETRN.
137 .TP
138 .B \-F, --flush
139 POP3/IMAP only.  Delete old (previously retrieved) messages from the mailserver
140 before retrieving new messages. This option does not work with ETRN.
141 Warning: if your local MTA hangs and fetchmail is aborted, the next
142 time you run fetchmail, it will delete mail that was never delivered to you.
143 What you probably want is the default setting: if you don't specify `-k', then
144 fetchmail will automatically delete messages after successful delivery.
145 .SS Protocol and Query Options
146 .TP
147 .B \-p, \--protocol proto
148 (Keyword: proto[col])
149 Specify the protocol to used when communicating with the remote 
150 mailserver.  If no protocol is specified,
151 .I fetchmail
152 will try each of the supported protocols in turn, terminating after
153 any successful attempt.
154 .I proto 
155 may be one of the following:
156 .RS
157 .IP POP2
158 Post Office Protocol 2
159 .IP POP3
160 Post Office Protocol 3
161 .IP APOP
162 Use POP3 with MD5 authentication.
163 .IP RPOP
164 Use POP3 with RPOP authentication.
165 .IP KPOP
166 Use POP3 with Kerberos V4 authentication on port 1109.
167 .IP IMAP
168 IMAP2bis, IMAP4, or IMAP4rev1 (\fIfetchmail\fR autodetects their capabilities).
169 .IP IMAP-K4
170 IMAP4, or IMAP4rev1 (\fIfetchmail\fR autodetects their capabilities)
171 with RFC 1731 Kerberos v4 authentication.
172 .IP IMAP-GSS
173 IMAP4, or IMAP4rev1 (\fIfetchmail\fR autodetects their capabilities)
174 with RFC 1731 GSSAPI authentication.
175 .IP ETRN
176 Use the ESMTP ETRN option.
177 .RE
178 All these alternatives work in basically the same way (communicating
179 with standard server daemons to fetch mail already delivered to a
180 mailbox on the server) except ETRN.  The ETRN mode allows you to ask a
181 compliant ESMTP server (such as BSD sendmail at release 8.8.0 or
182 higher) to immediately open a sender-SMTP connection to your
183 client machine and begin forwarding any items addressed to your client
184 machine in the server's queue of undelivered mail.
185 .TP
186 .B \-U, --uidl
187 (Keyword: uidl)
188 Force UIDL use (effective only with POP3).  Force client-side tracking
189 of `newness' of messages (UIDL stands for ``unique ID listing'' and is
190 described in RFC1725).  Use with `keep' to use a mailbox as a baby
191 news drop for a group of users.
192 .TP
193 .B \-P, --port
194 (Keyword: port)
195 The  option permits you to specify a TCP/IP port to connect on. 
196 This option will seldom be necessary as all the supported protocols have
197 well-established default port numbers.
198 .TP
199 .B \-r folder, --folder folder
200 (Keyword: folder[s])
201 Causes a specified non-default mail folder on the mailserver (or
202 comma-separated list of folders) to be retrieved.  The syntax of the
203 folder name is server-dependent.  This option is not available under
204 POP3 or ETRN.
205 .SS Delivery Control Options
206 .TP
207 .B \-S host, --smtphost host
208 (Keyword: smtp[host])
209 Specify a hunt list of hosts to forward mail to (one or more
210 hostnames, comma-separated).  In ETRN mode, set the host that the
211 mailserver is asked to ship mail to.  Hosts are tried in list order;
212 the first one that is up becomes the forwarding or ETRN target for the
213 current run.  Each hostname may have a '/'-delimited suffix specifying
214 a port or service to forward to; the default is 25 (or "smtp" under
215 IPv6). 
216 .TP
217 .B \-D domain, --smtpaddress domain
218 (Keyword: smtpaddress) 
219 Specify the domain to be put in RCPT TO lines shipped to SMTP. The
220 name of the SMTP server (as specified by --smtphost, or defaulted to
221 "localhost") is used when this is not specified.
222 .TP
223 .B \-Z nnn, --antispam nnn
224 (Keyword: antispam) 
225 Specifies the numeric SMTP error that is to be interpreted as a
226 spam-block response from the listener.  A value of -1 disables
227 this option.
228 .TP
229 .B \-m, \--mda
230 (Keyword: mda)
231 You can force mail to be passed to an MDA directly (rather than
232 forwarded to port 25) with the -mda or -m option.  If \fIfetchmail\fR
233 is running as root, it sets its userid to that of the target user
234 while delivering mail through an MDA.  Some possible MDAs are
235 "/usr/sbin/sendmail -oem", "/usr/lib/sendmail -oem",
236 "/usr/bin/formail", and "/usr/bin/deliver".  Local delivery addresses
237 will be inserted into the MDA command wherever you place a %T; the
238 mail message's From address will be inserted where you place an %F.  Do
239 \fInot\fR use an MDA invocation like
240 "sendmail -oem -t" that dispatches on the contents of To/Cc/Bcc, it
241 will create mail loops and bring the just wrath of many postmasters
242 down upon your head.
243 .SS Resource Limit Control Options
244 .TP
245 .B \-l, --limit
246 (Keyword: limit)
247 Takes a maximum octet size argument.  Messages larger than this size
248 will not be fetched, not be marked seen, and will be left on the
249 server (in foreground sessions, the progress messages will note that
250 they are "oversized").  An explicit --limit of 0 overrides any limits set
251 in your run control file. This option is intended for those needing to
252 strictly control fetch time in interactive mode.  It may not be used
253 with daemon mode, as users would never receive a notification that
254 messages were waiting.  This option does not work with ETRN.
255 .TP
256 .B -b, --batchlimit
257 (Keyword: batchlimit)
258 Specify the maximum number of messages that will be shipped to an SMTP
259 listener before the connection is deliberately torn down and rebuilt
260 (defaults to 0, meaning no limit).  An explicit --batchlimit of 0
261 overrides any limits set in your run control file.  While
262 \fBsendmail\fR(8) normally initiates delivery of a message immediately
263 after receiving the message terminator, some SMTP listeners are not so
264 prompt.  MTAs like \fIqmail\fR(8) and \fIsmail\fR(8) may wait till the
265 delivery socket is shut down to deliver.  This may produce annoying
266 delays when
267 .IR fetchmail (8)
268 is processing very large batches.  Setting the batch limit to some
269 nonzero size will prevent these delays.
270 This option does not work with ETRN.
271 .TP
272 .B -B, --fetchlimit
273 (Keyword: fetchlimit)
274 Limit the number of messages accepted from a given server in a single
275 poll.  By default there is no limit. An explicit --fetchlimit of 0
276 overrides any limits set in your run control file.
277 This option does not work with ETRN.
278 .TP
279 .B -e, --expunge
280 (keyword: expunge)
281 When talking to an IMAP server, 
282 .I fetchmail
283 normally issues an EXPUNGE command after each deletion in order to
284 force the deletion to be done immediately.  This is safest when your
285 connection to the server is flaky and expensive, as it avoids
286 resending duplicate mail after a line hit.  However, on large
287 mailboxes the overhead of re-indexing after every message can slam the
288 server pretty hard, so if your connection is reliable it is good to do
289 expunges less frequently.  If you specify this option to an integer N,
290 it tells
291 .I fetchmail
292 to only issue expunges on every Nth delete.  An argument
293 of zero suppresses expunges entirely (so no expunges at all will be
294 done until the end of run). 
295 This option does not work with ETRN, POP2, or POP3.
296 .SS Authentication Options
297 .TP
298 .B \-u name, --username name
299 (Keyword: user[name])
300 Specifies the user identification to be used when logging in to the mailserver.
301 The appropriate user identification is both server and user-dependent.  
302 The default is your login name on the client machine that is running 
303 .I fetchmail.
304 See USER AUTHENTICATION below for a complete description.
305 .TP
306 .B \-I specification, --interface specification
307 (Keyword: interface)
308 Require that a specific interface device be up and have a specific local
309 IP address (or range) before polling.  Frequently
310 .I fetchmail
311 is used over a transient point-to-point TCP/IP link established directly
312 to a mailserver via SLIP or PPP.  That is a relatively secure channel.
313 But when other TCP/IP routes to the mailserver exist (e.g. when the link
314 is connected to an alternate ISP), your username and password may be
315 vulnerable to snooping (especially when daemon mode automatically polls
316 for mail, shipping a clear password over the net at predictable
317 intervals).  The --interface option may be used to prevent this.  When
318 the specified link is not up or is not connected to a matching IP
319 address, polling will be skipped.  The format is:
320 .sp
321         interface/iii.iii.iii.iii/mmm.mmm.mmm.mmm
322 .sp
323 The field before the first slash is the interface name (i.e. sl0, ppp0
324 etc.).  The field before the second slash is the acceptable IP address.
325 The field after the second slash is a mask which specifies a range of
326 IP addresses to accept.  If no mask is present 255.255.255.255 is
327 assumed (i.e. an exact match).  This option is currently only supported
328 under Linux.
329 .TP
330 .B \-M interface, --monitor interface
331 (Keyword: monitor)
332 Daemon mode can cause transient links which are automatically taken down
333 after a period of inactivity (e.g. PPP links) to remain up
334 indefinitely.  This option identifies a system TCP/IP interface to be
335 monitored for activity.  After each poll interval, if the link is up but
336 no other activity has occurred on the link, then the poll will be
337 skipped.  This option is currently only supported under Linux.
338 .TP
339 .B \-A, --auth
340 (Keyword: auth[enticate]) 
341 This option permits you to specify a preauthentication type (see USER
342 AUTHENTICATION below for details).  The possible values are
343 \&`\fBpassword\fR', `\fBkerberos_v5\fR' and `\fBkerberos\fR' (or, for
344 excruciating exactness, `\fBkerberos_v4\fR').  This option is provided
345 primarily for developers; choosing KPOP protocol automatically selects
346 Kerberos preauthentication, and all other alternatives use password
347 authentication (though APOP uses a generated one-time key as the
348 password and IMAP-K4 uses RFC1731 Kerberos v4 authentication).  This
349 option does not work with ETRN.
350 .SS Miscellaneous Options
351 .TP
352 .B \-f pathname, --fetchmailrc pathname
353 Specify a non-default name for the 
354 .I .fetchmailrc
355 run control file.  Unless the --version option is also on, the file must have
356 permissions no more open than  0600 (u=rw,g=,o=) or else be /dev/null.
357 .TP
358 .B \-i pathname, --idfile pathname
359 (Keyword: idfile)
360 Specify an alternate name for the .fetchids file used to save POP3
361 UIDs. 
362 .TP
363 .B \-n, --norewrite
364 (Keyword: no rewrite)
365 Normally,
366 .I fetchmail
367 edits RFC-822 address headers (To, From, Cc, Bcc, and Reply-To) in
368 fetched mail so that any mail IDs local to the server are expanded to
369 full addresses (@ and the mailserver hostname are appended).  This enables 
370 replies on the client to get addressed correctly (otherwise your
371 mailer might think they should be addressed to local users on the
372 client machine!).  This option disables the rewrite.  (This option is
373 provided to pacify people who are paranoid about having an MTA edit
374 mail headers and want to know they can prevent it, but it is generally
375 not a good idea to actually turn off rewrite.)
376 When using ETRN, the rewrite option is ineffective.
377 .TP
378 .B -E, --envelope
379 (Keyword: envelope)
380 This option changes the header 
381 .I fetchmail
382 assumes will carry a copy of the mail's envelope address.  Normally
383 this is `X-Envelope-To' but as this header is not standard, practice
384 varies. See the discussion of multidrop address handling below.  As a
385 special case, `envelope "Received"' enables parsing of sendmail-style
386 Received lines.  This is the default, and it should not be necessary
387 unless you have globally disabled Received parsing with `no envelope'
388 in the \fI.fetchmailrc\fR file.
389 .TP
390 .B -Q, --qvirtual
391 (Keyword: qvirtual)
392 The string prefix assigned to this option will be removed from the user
393 name found in the header specified with the \fIenvelope\fR option
394 (\fIbefore\fR doing multidrop name mapping or localdomain checking,
395 if either is applicable). This option is useful if you are using  
396 .I fetchmail
397 to collect the mail for an entire domain and your ISP (or your mail
398 redirection provider) is using qmail.
399 One of the basic features of qmail is the
400 .sp
401 \&`Delivered-To:'
402 .sp
403 message header.  Whenever qmail delivers a message to a local mailbox
404 it puts the username and hostname of the envelope recipient on this
405 line.  The major reason for this is to prevent mail loops.  To set up
406 qmail to batch mail for a disconnected site the ISP-mailhost will have
407 normally put that site in its `Virtualhosts' control file so it will
408 add a prefix to all mail addresses for this site. This results in mail
409 sent to 'username@userhost.userdom.dom.com' having a
410 \&`Delivered-To:' line of the form:
411 .sp
412 Delivered-To: mbox-userstr-username@userhost.userdom.dom.com
413 .sp
414 The ISP can make the 'mbox-userstr-' prefix anything they choose
415 but a string matching the user host name is likely.
416 By using the option `envelope Delivered-To:' you can make fetchmail reliably
417 identify the original envelope recipient, but you have to strip the
418 `mbox-userstr-' prefix to deliver to the correct user.
419 This is what this option is for.
420
421 .SH USER AUTHENTICATION AND ENCRYPTION
422 Every mode except ETRN requires authentication of the client.
423 Normal user authentication in 
424 .I fetchmail
425 is very much like the authentication mechanism of 
426 .IR ftp (1).
427 The correct user-id and password depend upon the underlying security
428 system at the mailserver.  
429 .PP
430 If the mailserver is a Unix machine on which you have an ordinary user 
431 account, your regular login name and password are used with 
432 .I fetchmail.
433 If you use the same login name on both the server and the client machines,
434 you needn't worry about specifying a user-id with the 
435 .B \-u
436 option \-\- 
437 the default behavior is to use your login name on the client machine as the 
438 user-id on the server machine.  If you use a different login name
439 on the server machine, specify that login name with the
440 .B \-u
441 option.  e.g. if your login name is 'jsmith' on a machine named 'mailgrunt',
442 you would start 
443 .I fetchmail 
444 as follows:
445 .IP
446 fetchmail -u jsmith mailgrunt
447 .PP
448 The default behavior of 
449 .I fetchmail
450 is to prompt you for your mailserver password before the connection is
451 established.  This is the safest way to use 
452 .I fetchmail
453 and ensures that your password will not be compromised.  You may also specify
454 your password in your
455 .I ~/.fetchmailrc
456 file.  This is convenient when using 
457 .I fetchmail
458 in daemon mode or with scripts.
459 .PP
460 If you do not specify a password, and
461 .I fetchmail
462 cannot extract one from your
463 .I .fetchmailrc
464 file, it will look for a 
465 .I .netrc
466 file in your home directory before requesting one interactively; if an
467 entry matching the mailserver is found in that file, the password will
468 be used.  See the
469 .IR ftp (1)
470 man page for details of the syntax of the
471 .I .netrc
472 file.  (This feature may allow you to avoid duplicating password
473 information in more than one file.)
474 .PP
475 On mailservers that do not provide ordinary user accounts, your user-id and 
476 password are usually assigned by the server administrator when you apply for 
477 a mailbox on the server.  Contact your server administrator if you don't know 
478 the correct user-id and password for your mailbox account.
479 .PP
480 Early versions of POP3 (RFC1081, RFC1225) supported a crude form of
481 independent authentication using the
482 .I rhosts
483 file on the mailserver side.  Under this RPOP variant, a fixed
484 per-user ID equivalent to a password was sent in clear over a link to
485 a reserved port, with the command RPOP rather than PASS to alert the
486 server that it should do special checking.  RPOP is supported
487 by
488 .I fetchmail
489 (you can specify `protocol RPOP' to have the program send `RPOP'
490 rather than `PASS') but its use is strongly discouraged.  This
491 facility was vulnerable to spoofing and was withdrawn in RFC1460.
492 .PP
493 RFC1460 introduced APOP authentication.  In this variant of POP3,
494 you register an APOP password on your server host (the program
495 to do this with on the server is probably called \fIpopauth\fR(8)).  You
496 put the same password in your 
497 .I .fetchmailrc
498 file.  Each time 
499 .I fetchmail
500 logs in, it sends a cryptographically secure hash of your password and
501 the server greeting time to the server, which can verify it by
502 checking its authorization database. 
503 .PP
504 If your \fIfetchmail\fR was built with Kerberos support and you specify 
505 Kerberos preauthentication (either with --auth or the \fI.fetchmailrc\fR
506 option \fBauthenticate kerberos_v4\fR) it will try to get a Kerberos
507 ticket from the mailserver at the start of each query. 
508 .PP
509 If you use IMAP-K4, \fIfetchmail\fR will expect the IMAP server to have
510 RFC1731-conformant AUTHENTICATE KERBEROS_V4 capability, and will use it.
511 .PP
512 If you use IMAP-GSS, \fIfetchmail\fR will expect the IMAP server to have
513 RFC1731-conformant AUTHENTICATE GSSAPI capability, and will use it. 
514 Currently this has only been tested over Kerberos V, so you're expected
515 to already have a ticket-granting ticket. You may pass a username different
516 from your principal name using the standard \fB--user\fR command or by
517 the \fI.fetchmailrc\fR option \fBuser\fR.
518 .PP
519 If you are using POP3, and the server issues a one-time-password
520 challenge conforming to RFC1938, \fIfetchmail\fR will use your
521 password as a pass phrase to generate the required response. This
522 avoids sending secrets over the net unencrypted.
523 .PP
524 Compuserve's RPA authentication (similar to APOP) is supported.  If
525 you are using POP3, and the RPA code has been compiled into your
526 binary, and you query a server in the Compuserve csi.com domain,
527 \fIfetchmail\fR will try to perform an RPA pass-phrase authentication
528 instead of sending over the password en clair.
529 .PP
530 If you are using IPsec, the -T (--netsec) option can be used to pass
531 an IP security request to be used when outgoing IP connections are
532 initialized.  You can also do this using the `netsec' server option
533 in the .fetchmailrc file.  In either case, the option value is a
534 string in the format accepted by the net_security_strtorequest() 
535 function of the inet6_apps library.
536
537 .SH DAEMON MODE
538 The 
539 .B --daemon
540 or
541 .B -d 
542 option runs 
543 .I fetchmail
544 in daemon mode.  You must specify a numeric argument which is a
545 polling interval in seconds.
546 .PP
547 In daemon mode, 
548 .I fetchmail
549 puts itself in background and runs forever, querying each specified
550 host and then sleeping for the given polling interval.
551 .PP
552 Simply invoking
553 .IP
554 fetchmail -d 900
555 .PP
556 will, therefore, poll all the hosts described in your 
557 .I ~/.fetchmailrc
558 file (except those explicitly excluded with the `skip' verb) once
559 every fifteen minutes.
560 .PP
561 It is possible to set a polling interval 
562 in your
563 .I ~/.fetchmailrc
564 file by saying `set daemon <interval>', where <interval> is an
565 integer number of seconds.  If you do this, fetchmail will always
566 start in daemon mode unless you override it with the command-line
567 option --daemon 0 or -d0.
568 .PP
569 Only one daemon process is permitted per user; in daemon mode,
570 .I fetchmail
571 makes a per-user lockfile to guarantee this.
572 .PP
573 Normally, calling fetchmail with a daemon in the background sends a
574 wakeup signal to the daemon, forcing it to poll mailservers
575 immediately.  (The wakeup signal is SIGHUP if fetchmail is running as
576 root, SIGUSR1 otherwise.)
577 .PP
578 The option
579 .B --quit
580 will kill a running daemon process instead of waking it up (if there
581 is no such option, 
582 .I fetchmail
583 notifies you).  If the --quit option is the only command-line option,
584 that's all there is to it.
585 .PP
586 The quit option may also be mixed with other command-line options; its
587 effect is to kill any running daemon before doing what the other
588 options specify in combination with the rc file.
589 .PP
590 The 
591 .B -t
592 or
593 .B --timeout
594 option (keyword: timeout) allows you to set a server-nonresponse
595 timeout in seconds.  If a mailserver does not send a greeting message
596 or respond to commands for the given number of seconds,
597 \fIfetchmail\fR will hang up on it.  Without such a timeout
598 \fIfetchmail\fR might hang up indefinitely trying to fetch mail from a
599 down host.  This would be particularly annoying for a \fIfetchmail\fR
600 running in background.  There is a default timeout which fetchmail -V
601 will report.
602 .PP
603 The
604 .B -L
605 or
606 .B --logfile
607 option (keyword: set logfile) allows you to redirect status messages
608 emitted while detached into a specified logfile (follow the
609 option with the logfile name).  The logfile is opened for append, so
610 previous messages aren't deleted.  This is primarily useful for
611 debugging configurations.
612 .PP
613 The
614 .B --syslog
615 option (keyword: syslog) allows you to redirect status and error
616 messages emitted to the
617 .IR syslog (3)
618 system daemon if available.
619 Messages are logged with an id of \fBfetchmail\fR, the facility \fBLOG_MAIL\fR,
620 and priorities \fBLOG_ERR\fR, \fBLOG_ALERT\fR or \fBLOG_INFO\fR.
621 This option is intended for logging status and error messages which
622 indicate the status of the daemon and the results while fetching mail
623 from the server(s).
624 Error messages for command line options and parsing the \fI.fetchmailrc\fR
625 file are still written to stderr, or the specified log file if the
626 .B -L
627 or
628 .B --logfile
629 option was used.
630 .PP
631 The 
632 .B --invisible
633 option tries to make fetchmail invisible.  Normally, fetchmail behaves
634 like any other MTA would -- it generates a Received header into each
635 message describing its place in the chain of transmission, and tells
636 the MTA it forwards to that the mail came from the machine fetchmail
637 itself is running on.  If the invisible option is on, the Received
638 header is suppressed and fetchmail tries to spoof the MTA it forwards
639 to into thinking it came directly from the mailserver host.
640 .PP
641 The 
642 .B \-N
643 or --nodetach option suppresses backgrounding and detachment of the
644 daemon process from its control terminal.  This is primarily useful
645 for debugging.  Note that this also causes the logfile option to be
646 ignored (though perhaps it shouldn't).
647 .PP
648 Note that while running in daemon mode polling a POP2 or IMAP2bis server,
649 transient errors (such as DNS failures or sendmail delivery refusals)
650 may force the fetchall option on for the duration of the next polling
651 cycle.  This is a robustness feature.  It means that if a message is
652 fetched (and thus marked seen by the mailserver) but not delivered
653 locally due to some transient error, it will be re-fetched during the
654 next poll cycle.  (The IMAP logic doesn't delete messages until
655 they're delivered, so this problem does not arise.)
656
657 .SH RETRIEVAL FAILURE MODES
658 The protocols \fIfetchmail\fR uses to talk to mailservers are next to
659 bulletproof.  In normal operation forwarding to port 25, no message is
660 ever deleted (or even marked for deletion) on the host until the SMTP
661 listener on the client has acknowledged to \fIfetchmail\fR that the
662 message has been accepted for delivery.  When forwarding to an MDA,
663 however, there is more possibility of error (because there's no way
664 for fetchmail to get a reliable positive acknowledgement from the MDA).
665 .PP
666 The normal mode of \fIfetchmail\fR is to try to download only `new'
667 messages, leaving untouched (and undeleted) messages you have already
668 read directly on the server (or fetched with a previous \fIfetchmail
669 --keep\fR).  But you may find that messages you've already read on the
670 server are being fetched (and deleted) even when you don't specify
671 --all.  There are several reasons this can happen.
672 .PP
673 One could be that you're using POP2.  The POP2 protocol includes no
674 representation of `new' or `old' state in messages, so \fIfetchmail\fR
675 must treat all messages as new all the time.  But POP2 is obsolete, so
676 this is unlikely.
677 .PP
678 Under POP3, blame RFC1725.  That version of the POP3 protocol
679 specification removed the LAST command, and some POP servers follow it
680 (you can verify this by invoking \fIfetchmail -v\fR to the mailserver
681 and watching the response to LAST early in the query).  The
682 \fIfetchmail\fR code tries to compensate by using POP3's UID feature,
683 storing the identifiers of messages seen in each session until the
684 next session, in the \fI.fetchids\fR file.  But this doesn't track
685 messages seen with other clients, or read directly with a mailer on
686 the host but not deleted afterward.  A better solution would be to
687 switch to IMAP.
688 .PP
689 Another potential POP3 problem might be servers that insert messages
690 in the middle of mailboxes (some VMS implementations of mail are
691 rumored to do this).  The \fIfetchmail\fR code assumes that new
692 messages are appended to the end of the mailbox; when this is not true
693 it may treat some old messages as new and vice versa.  The only 
694 real fix for this problem is to  switch to IMAP.
695 .PP
696 The IMAP code uses the presence or absence of the server flag \eSeen
697 to decide whether or not a message is new.  Under Unix, it counts on
698 your IMAP server to notice the BSD-style Status flags set by mail user
699 agents and set the \eSeen flag from them when appropriate.  All Unix
700 IMAP servers we know of do this, though it's not specified by the IMAP
701 RFCs.  If you ever trip over a server that doesn't, the symptom will
702 be that messages you have already read on your host will look new to
703 the server.  In this (unlikely) case, only messages you fetched with
704 \fIfetchmail --keep\fR will be both undeleted and marked old.
705 .PP
706 In ETRN mode, \fIfetchmail\fR does not actually retrieve messages;
707 instead, it asks the server's SMTP listener to start a queue flush
708 to the client via SMTP.  Therefore it sends only undelivered messages.
709
710 .SH SPAM FILTERING
711 Many SMTP listeners allow administrators to set up `spam filters' that
712 block unsolicited email from specified domains.  A MAIL FROM line that
713 triggers this feature will elicit an SMTP response which
714 (unfortunately) varies according to the listener.
715 .PP
716 Newer versions of 
717 .I sendmail
718 return an error code of 571.  This return value
719 is blessed by RFC1893 as "Delivery not authorized, message refused".
720 .PP
721 According to current drafts of the replacement for RFC821, the correct
722 thing to return in this situation is 550 "Requested action not taken:
723 mailbox unavailable" (the draft adds "[E.g., mailbox not found, no
724 access, or command rejected for policy reasons].").
725 .PP
726 The
727 .I exim
728 MTA returns 501 "Syntax error in parameters or arguments" , but will
729 move to 550 soon.
730 .PP
731 The
732 .I fetchmail
733 code recognizes and discards the message on a code that defaults to
734 sendmail's 571 but can be set with the `antispam' option.  This is the
735 .I only
736 circumstance under which fetchmail ever discards mail.
737 .P
738 If
739 .I fetchmail
740 is fetching from an IMAP server, the antispam response will be detected and
741 the message rejected immediately after the headers have been fetched,
742 without reading the message body.  Thus, you won't pay for downloading 
743 spam message bodies.
744
745 .SH THE RUN CONTROL FILE
746 The preferred way to set up fetchmail is to write a
747 \&\fI.fetchmailrc\fR file in your home directory.  When there is a
748 conflict between the command-line arguments and the arguments in this
749 file, the command-line arguments take precedence.
750 .PP
751 To protect the security of your passwords, when --version is not on
752 your \fI~/.fetchmailrc\fR may not have more than 0600 (u=rw,g=,o=) permissions;
753 .I fetchmail
754 will complain and exit otherwise.
755 .PP
756 You may read the \fI.fetchmailrc\fR file as a list of commands to 
757 be executed when 
758 .I fetchmail
759 is called with no arguments.
760 .SS Run Control Syntax
761 .PP
762 Comments begin with a '#' and extend through the end of the line.
763 Otherwise the file consists of a series of server entries or global
764 option statements in a free-format, token-oriented syntax.
765 .PP
766 There are four kinds of tokens: grammar keywords, numbers
767 (i.e. decimal digit sequences), unquoted strings, and quoted strings.
768 A quoted string is bounded by double quotes and may contain
769 whitespace (and quoted digits are treated as a string).  An unquoted
770 string is any whitespace-delimited token that is neither numeric, string
771 quoted nor contains the special characters `,', `;', `:', or `='.
772 .PP
773 Any amount of whitespace separates tokens in server entries, but is
774 otherwise ignored. You may use standard C-style escapes (\en, \et,
775 \eb, octal, and hex) to embed non-printable characters or string
776 delimiters in strings.
777 .PP
778 Each server entry consists of one of the keywords `poll' or `skip',
779 followed by a server name, followed by server options, followed by any
780 number of user descriptions.  Note: the most common cause of syntax
781 errors is mixing up user and server options.
782 .PP
783 For backward compatibility, the word `server' is a synonym for `poll'.
784 .PP
785 You can use the noise keywords `and', `with',
786 \&`has', `wants', and `options' anywhere in an entry to make
787 it resemble English.  They're ignored, but but can make entries much
788 easier to read at a glance.  The punctuation characters ':', ';' and
789 \&',' are also ignored.
790 .PP
791 .SS Poll vs. Skip
792 The `poll' verb tells fetchmail to query this host when it is run with
793 no arguments.  The `skip' verb tells
794 .I fetchmail 
795 not to poll this host unless it is explicitly named on the command
796 line.  (The `skip' verb allows you to experiment with test entries
797 safely, or easily disable entries for hosts that are temporarily down.)
798 .PP
799 .SS Keyword/Option Summary
800 Here are the legal server options.  Keyword suffixes enclosed in
801 square brackets are optional.  Those corresponding to command-line
802 options are followed by `-' and the appropriate option letter.
803
804 .TS
805 l l lw34.
806 Keyword         Opt     Function
807 _
808 via             \&      T{
809 Specify DNS name of mailserver, overriding poll name
810 T}
811 proto[col]      -p      T{
812 Specify protocol (case insensitive):
813 POP2, POP3, IMAP, IMAP-K4, IMAP-GSS, APOP, KPOP
814 T}
815 port            -P      T{
816 Specify TCP/IP service port
817 T}
818 auth[enticate]  -A      T{
819 Set preauthentication type (default `password')
820 T}
821 timeout         -t      T{
822 Server inactivity timout in seconds (default 300)
823 T}
824 envelope        -E      T{
825 Specify envelope-address header name
826 T}
827 no envelope     \&      T{
828 Disable looking for envelope address
829 T}
830 qvirtual        -Q      T{
831 Qmail virtual domain prefix to remove from user name
832 T}
833 aka             \&      T{
834 Specify alternate DNS names of mailserver
835 T}
836 interface       -I      T{
837 specify IP interface(s) that must be up for server poll to take place
838 T}
839 monitor         -M      T{
840 Specify IP address to monitor for activity
841 T}
842 dns             \&      T{
843 Enable DNS lookup for multidrop (default)
844 T}
845 no dns          \&      T{
846 Disable DNS lookup for multidrop
847 T}
848 uidl            -U      T{
849 Force POP3 to use client-side UIDLs
850 T}
851 no uidl         \&      T{
852 Turn off POP3 use of client-side UIDLs (default)
853 T}
854 .TE
855
856 Here are the legal user options:
857
858 .TS
859 l l lw34.
860 Keyword         Opt     Function
861 _
862 user[name]      -u      T{
863 Set remote user name 
864 (local user name if name followed by `here') 
865 T}
866 is              \&      T{
867 Connect local and remote user names
868 T}
869 to              \&      T{
870 Connect local and remote user names
871 T}
872 pass[word]      \&      T{
873 Specify remote account password
874 T}
875 folder          -r      T{
876 Specify remote folder to query
877 T}
878 smtphost        -S      T{
879 Specify smtp host(s) to forward to
880 T}
881 smtpaddress     -D      T{
882 Specify the domain to be put in RCPT TO lines
883 T}
884 antispam        -Z      T{
885 Specify what SMTP return is interpreted as a spam-policy block
886 T}
887 mda             -m      T{
888 Specify MDA for local delivery
889 T}
890 preconnect      \&      T{
891 Command to be executed before each connection
892 T}
893 postconnect     \&      T{
894 Command to be executed after each connection
895 T}
896 keep            -k      T{
897 Don't delete seen messages from server
898 T}
899 flush           -F      T{
900 Flush all seen messages before querying
901 T}
902 fetchall        -a      T{
903 Fetch all messages whether seen or not
904 T}
905 rewrite         \&      T{
906 Rewrite destination addresses for reply (default)
907 T}
908 stripcr         \&      T{
909 Strip carriage returns from ends of lines
910 T}
911 forcecr         \&      T{
912 Force carriage returns at ends of lines
913 T}
914 pass8bits       \&      T{
915 Force BODY=8BITMIME to ESMTP listener
916 T}
917 dropstatus      \&      T{
918 Strip Status and X-Mozilla-Status lines out of incoming mail
919 T}
920 mimedecode      \&      T{
921 Convert quoted-printable to 8-bit in MIME messages
922 T}
923 no keep         -K      T{
924 Delete seen messages from server (default)
925 T}
926 no flush        \&      T{
927 Don't flush all seen messages before querying (default)
928 T}
929 no fetchall     \&      T{
930 Retrieve only new messages (default)
931 T}
932 no rewrite      \&      T{
933 Don't rewrite headers
934 T}
935 no stripcr      \&      T{
936 Don't strip carriage returns (default)
937 T}
938 no forcecr      \&      T{
939 Don't force carriage returns at EOL (default)
940 T}
941 no pass8bits    \&      T{
942 Don't force BODY=8BITMIME to ESMTP listener (default)
943 T}
944 no dropstatus   \&      T{
945 Don't drop Status headers (default)
946 T}
947 no mimedecode   \&      T{
948 Don't convert quoted-printable to 8-bit in MIME messages (default)
949 T}
950 limit           -l      T{
951 Set message size limit
952 T}
953 batchlimit      -b      T{
954 Max # messages to fetch in single connect
955 T}
956 fetchlimit      -B      T{
957 Max # messages to forward in single connect
958 T}
959 expunge         -e      T{
960 Perform an expunge on every #th message (IMAP only)
961 T}
962 syslog          \&      T{
963 Do error logging through syslog(3).
964 T}
965 .TE
966 .PP
967 Remember that all user options must \fIfollow\fR all server options.
968 .PP
969 In the .fetchmailrc file, the `envelope' string argument may be
970 preceded by a whitespace-separated number.  This number, if specified,
971 is the number of such headers to skip (that is, an argument of 1
972 selects the second header of the given type).  This is sometime useful
973 for ignoring bogus Received headers created by an ISP's local delivery
974 agent.
975 .SS Keywords Not Corresponding To Option Switches
976 .PP
977 The `folder' and `smtphost' options (unlike their command-line
978 equivalents) can take a space- or comma-separated list of names
979 following them.
980 .PP
981 All options correspond to the obvious command-line arguments, except
982 the following: `via', `interval', `aka', `is', `to', `dns'/`no dns',
983 \&`password', \&`preconnect', \&`postconnect', `localdomains',
984 \&`stripcr'/`no stripcr', \&`forcecr'/`no forcecr', `pass8bits'/`no
985 pass8bits' `dropstatus/no dropstatus', `mimedecode/no mimedecode',
986 and `no envelope'.
987 .PP
988 The `via' option is for use with ssh, or if you want to have more
989 than one configuration pointing at the same site.  If it is present,
990 the string argument will be taken as the actual DNS name of the 
991 mailserver host to query.
992 This will override the argument of poll, which can then simply be a
993 distinct label for the configuration (e.g. what you would give on the
994 command line to explicitly query this host).
995 If the `via' name is `localhost', the poll name will also still be
996 used as a possible match in multidrop mode; otherwise the `via' name
997 will be used instead and the poll name will be purely a label.
998 .PP
999 The `interval' option (which takes a numeric argument) allows you to poll a
1000 server less frequently than the basic poll interval.  If you say
1001 \&`interval N' the server this option is attached to will only be
1002 queried every N poll intervals. 
1003 .PP
1004 The `is' or `to' keywords associate the following local (client)
1005 name(s) (or server-name to client-name mappings separated by =) with
1006 the mailserver user name in the entry.  If an is/to list has `*' as
1007 its last name, unrecognized names are simply passed through.
1008 .PP
1009 A single local name can be used to support redirecting your mail when
1010 your username on the client machine is different from your name on the
1011 mailserver.  When there is only a single local name, mail is forwarded
1012 to that local username regardless of the message's Received, To, Cc,
1013 and Bcc headers.  In this case 
1014 .I fetchmail
1015 never does DNS lookups.
1016 .PP
1017 When there is more than one local name (or name mapping) the
1018 \fIfetchmail\fR code does look at the Received, To, Cc, and Bcc
1019 headers of retrieved mail (this is `multidrop mode').  It looks for
1020 addresses with hostname parts that match your poll name or your `via',
1021 `aka' or `localdomains' options, and usually also for hostname parts
1022 which DNS tells it are aliases of the mailserver.  See the discussion
1023 of `dns', `localdomains', and `aka' for details on how matching
1024 addresses are handled.  If \fIfetchmail\fR cannot match any mailserver
1025 usernames or localdomain addresses, the default recipient is the
1026 calling user (as set by the USER or LOGNAME variable in the
1027 environment; you could use this to redirect to an alias like postmaster).
1028 .PP
1029 The `dns' option (normally on) controls the way addresses from
1030 multidrop mailboxes are checked.  On, it enables logic to check each
1031 host address that doesn't match an `aka' or `localdomains' declaration
1032 by looking it up with DNS.  When a mailserver username is recognized
1033 attached to a matching hostname part, its local mapping is added to
1034 the list of local recipients.
1035 .PP
1036 The `aka' option is for use with multidrop mailboxes.  It allows you
1037 to pre-declare a list of DNS aliases for a server.  This is an
1038 optimization hack that allows you to trade space for speed.  When
1039 .IR fetchmail ,
1040 while processing a multidrop mailbox, grovels through message headers
1041 looking for names of the mailserver, pre-declaring common ones can
1042 save it from having to do DNS lookups.
1043 .PP
1044 The `localdomains' option allows you to declare a list of domains
1045 which fetchmail should consider local.  When fetchmail is parsing
1046 address lines in multidrop modes, and a trailing segment of a host
1047 name matches a declared local domain, that address is passed through
1048 to the listener or MDA unaltered (local-name mappings are \fInot\fR
1049 applied).
1050 .PP
1051 If you are using `localdomains', you may also need to specify \&`no
1052 envelope', which disables \fIfetchmail\fR's normal attempt to deduce
1053 an envelope address from the Received line or X-Envelope-To header or
1054 whatever header has been previously set by `envelope'.  If you set `no
1055 envelope' in the defaults entry it is possible to undo that in
1056 individual entries by using `envelope <string>'.  As a special case,
1057 \&`envelope "Received"' restores the default parsing of
1058 Received lines.
1059 .PP
1060 The \fBpassword\fR option requires a string argument, which is the password
1061 to be used with the entry's server.
1062 .PP
1063 The `preconnect' keyword allows you to specify a shell command to be
1064 executed just before each time
1065 .I fetchmail
1066 establishes a mailserver connection.  This may be useful if you are 
1067 attempting to set up secure POP connections with the aid of
1068 .IR ssh (1).
1069 If the command returns a nonzero status, the poll of that mailserver
1070 will be aborted.
1071 .PP
1072 Similarly, the `postconnect' keyword similarly allows you to specify a
1073 shell command to be executed just after each time a mailserver
1074 connection is taken down.
1075 .PP
1076 The `forcecr' option controls whether lines terminated by LF only are
1077 given CRLF termination before forwarding.  Strictly speaking RFC821
1078 requires this, but few MTAs enforce the requirement it so this option
1079 is normally off (only one such MTA, qmail, is in significant use at
1080 time of writing).  
1081 .PP
1082 The `stripcr' option controls whether carriage returns are stripped
1083 out of retrieved mail before it is forwarded.  It is normally not
1084 necessary to set this, because it defaults to `on' (CR stripping
1085 enabled) when there is an MDA declared but `off' (CR stripping
1086 disabled) when forwarding is via SMTP.  If `stripcr' and `forcecr' are
1087 both on, `stripcr' will override.
1088 .PP
1089 The `pass8bits' option exists to cope with Microsoft mail programs that
1090 stupidly slap a "Content-Transfer-Encoding: 7bit" on everything.  With
1091 this option off (the default) and such a header present, 
1092 .I fetchmail
1093 declares BODY=7BIT to an ESMTP-capable listener; this causes problems for
1094 messages actually using 8-bit ISO or KOI-8 character sets, which will
1095 be garbled by having the high bits of all characters stripped.  If
1096 \&`pass8bits' is on, 
1097 .I fetchmail
1098 is forced to declare BODY=8BITMIME to any ESMTP-capable listener.  If
1099 the listener is 8-bit-clean (as all the major ones now are) the right
1100 thing will probably result.
1101 .PP
1102 The `dropstatus' option controls whether nonempty Status and
1103 X-Mozilla-Status lines are retained in fetched mail (the default) or
1104 discarded.  Retaining them allows your MUA to see what messages (if
1105 any) were marked seen on the server.  On the other hand, it can
1106 confuse some new-mail notifiers, which assume that anything with a
1107 Status line in it has been seen.  (Note: the empty Status lines
1108 inserted by some buggy POP servers are unconditionally discarded.)
1109 .PP
1110 The `mimedecode' option controls whether MIME messages using the
1111 quoted-printable encoding are automatically converted into pure
1112 8-bit data. If you are delivering mail to an ESMTP-capable,
1113 8-bit-clean listener (that includes all of the major programs
1114 like sendmail), then this will automatically convert quoted-printable
1115 message headers and data into 8-bit data, making it easier to
1116 understand when reading mail. If your e-mail programs know how to
1117 deal with MIME messages, then this option is not needed.
1118 .PP
1119 .SS Miscellaneous Run Control Options
1120 The words `here' and `there' have useful English-like
1121 significance.  Normally `user eric is esr' would mean that 
1122 mail for the remote user `eric' is to be delivered to `esr',
1123 but you can make this clearer by saying `user eric there is esr here',
1124 or reverse it by saying `user esr here is eric there'
1125 .PP
1126 Legal protocol identifiers for use with the `protocol' keyword are:
1127
1128     auto (or AUTO)
1129     pop2 (or POP2)
1130     pop3 (or POP3)
1131     imap (or IMAP)
1132     imap-k4 (or IMAP-K4)
1133     imap-gss (or IMAP-GSS)
1134     apop (or APOP)
1135     kpop (or KPOP)
1136
1137 .PP
1138 Legal authentication types are `password' or `kerberos'.  The former
1139 specifies authentication by normal transmission of a password (the
1140 password may be plaintext or subject to protocol-specific encryption
1141 as in APOP); the second tells \fIfetchmail\fR to try to get a Kerberos
1142 ticket at the start of each query instead, and send an arbitrary
1143 string as the password.
1144 .PP
1145 Specifying `kpop' sets POP3 protocol over port 1109 with Kerberos V4
1146 preauthentication.  These defaults may be overridden by later options.
1147 .PP
1148 There are currently three global option statements; `set logfile'
1149 followed by a string sets the same global specified by --logfile.  A
1150 command-line --logfile option will override this.  Also, `set daemon'
1151 sets the poll interval as --daemon does.  This can be overridden by
1152 a command-line --daemon option; in particular --daemon 0 can be used 
1153 to force foreground operation. Finally, `set syslog' sends log
1154 messages to syslogd(8).
1155
1156 .SH INTERACTION WITH RFC 822
1157 When trying to detertmine the originating address of a message,
1158 fetchmail looks through headers in the following order: 
1159
1160         Return-Path:
1161         Resent-Sender:
1162         Sender:
1163         Resent-From:
1164         From:
1165         Reply-To:
1166         Apparently-From:
1167
1168 The originating address is used for logging, and to set the MAIL FROM
1169 address when forwarding to SMTP.  This order is intended to cope
1170 gracefully with receiving mailing list messages in multidrop mode. The
1171 intent is that if a local address doesn't exist, the bounce message
1172 won't be returned blindly to the author or to the list itself, but
1173 rather to the list manager (which is less annoying).
1174
1175 In multidrop mode, destination headers are processed as follows:
1176 First, fetchmail looks for the Received: header (or whichever one is
1177 specified by the `envelope' option) to determine the local
1178 recipient adress. If the mail is addressed to more than one recipient,
1179 the Received line won't contain any information regarding recipient adresses.
1180
1181 Then fetchmail looks for the Resent-To:, Resent-Cc:, and Resent-Bcc:
1182 lines.  If they exists, they should contain the final recipients and
1183 have precedence over their To:/Cc:/Bcc: counterparts.  If the Resent-*
1184 lines doesn't exist, the To:, Cc:, Bcc: and Apparently-To: lines are
1185 looked for. (The presence of a Resent-To: is taken to impluy that the
1186 person referred by the To: address has already received the original
1187 copy of the mail).
1188
1189 .SH CONFIGURATION EXAMPLES
1190 Basic format is:
1191
1192 .nf
1193   poll SERVERNAME protocol PROTOCOL username NAME password PASSWORD 
1194 .fi
1195 .PP
1196 Example:
1197
1198 .nf
1199   poll pop.provider.net protocol pop3 username jsmith password secret1
1200 .fi
1201 .PP
1202 Or, using some abbreviations:
1203
1204 .nf
1205   poll pop.provider.net proto pop3 user jsmith password secret1
1206 .fi
1207 .PP
1208 Multiple servers may be listed:
1209
1210 .nf
1211   poll pop.provider.net proto pop3 user jsmith pass secret1
1212   poll other.provider.net proto pop2 user John.Smith pass My^Hat
1213 .fi
1214
1215 Here's a version of those two with more whitespace and some noise words: 
1216
1217 .nf
1218   poll pop.provider.net proto pop3
1219       user jsmith, with password secret1, is jsmith here;
1220   poll other.provider.net proto pop2:
1221       user John.Smith, with password My^Hat, is John.Smith here;
1222 .fi
1223
1224 This version is much easier to read and doesn't cost significantly
1225 more (parsing is done only once, at startup time).
1226
1227 .PP
1228 If you need to include whitespace in a parameter string, enclose the
1229 string in double quotes.  Thus:
1230
1231 .nf
1232   poll mail.provider.net with proto pop3:
1233         user jsmith there has password "u can't krak this"
1234                     is jws here and wants mda "/bin/mail"
1235 .fi
1236
1237 You may have an initial server description headed by the keyword
1238 `defaults' instead of `poll' followed by a name.  Such a record
1239 is interpreted as defaults for all queries to use. It may be overwritten
1240 by individual server descriptions.  So, you could write:
1241
1242 .nf
1243   defaults proto pop3
1244         user jsmith
1245   poll pop.provider.net
1246         pass secret1
1247   poll mail.provider.net
1248         user jjsmith there has password secret2
1249 .fi
1250
1251 It's possible to specify more than one user per server (this is only
1252 likely to be useful when running fetchmail in daemon mode as root).
1253 The `user' keyword leads off a user description, and every user specification
1254 in a multi-user entry must include it.  Here's an example:
1255
1256 .nf
1257   poll pop.provider.net proto pop3 port 3111
1258         user jsmith with pass secret1 is smith here
1259         user jones with pass secret2 is jjones here
1260 .fi
1261
1262 This associates the local username `smith' with the pop.provider.net
1263 username `jsmith' and the local username `jjones' with the
1264 pop.provider.net username `jones'.
1265 .PP
1266 Here's what a simple retrieval configuration for a multi-drop mailbox
1267 looks like:
1268
1269 .nf
1270   poll pop.provider.net:
1271         user maildrop with pass secret1 to golux hurkle=happy snark here
1272 .fi
1273
1274 This says that the mailbox of account `maildrop' on the server is a
1275 multi-drop box, and that messages in it should be parsed for the
1276 server user names `golux', `hurkle', and `snark'.  It further
1277 specifies that `golux' and `snark' have the same name on the
1278 client as on the server, but mail for server user `hurkle' should be
1279 delivered to client user `happy'.
1280 .PP
1281 Here's an example of another kind of multidrop connection:
1282
1283 .nf
1284   poll pop.provider.net localdomains loonytoons.org:
1285         user maildrop with pass secret1 to esr * here
1286 .fi
1287
1288 This also says that the mailbox of account `maildrop' on the server is
1289 a multi-drop box.  It tells fetchmail that any address in the
1290 loonytoons.org domain (including subdomain addresses like
1291 `joe@daffy.loonytoons.org') should be passed through to the local SMTP
1292 listener without modification.  Be careful of mail loops if you do this!
1293 .PP
1294 Here's an example configuration using ssh.  The queries go through an
1295 ssh connecting local port 1234 to port 110 on mailhost.net; the
1296 preconnect command sets up the ssh.
1297
1298 .nf
1299 poll mailhost.net via localhost port 1234 with proto pop3:
1300         preconnect "ssh -f -L 1234:mailhost.net:110
1301                 mailhost.net sleep 20 </dev/null >/dev/null";
1302 .fi
1303
1304 .SH THE USE AND ABUSE OF MULTIDROP MAILBOXES
1305 Use the multiple-local-recipients feature with caution -- it can bite.
1306 Also note that all multidrop features are ineffective in ETRN mode.
1307
1308 .SS Header vs. Envelope addresses 
1309 The fundamental problem is that by having your mailserver toss several
1310 peoples' mail in a single maildrop box, you may have thrown away
1311 potentially vital information about who each piece of mail was
1312 actually addressed to (the `envelope address', as opposed to the
1313 header addresses in the RFC822 To/Cc/Bcc headers).  This `envelope
1314 address' is the address you need in order to reroute mail properly.
1315 .PP
1316 Sometimes 
1317 .I fetchmail
1318 can deduce the envelope address.  If the mailserver MTA is
1319 .I sendmail
1320 and the item of mail had just one recipient, the MTA will have written
1321 a `by/for' clause that gives the envelope addressee into its Received
1322 header. But this doesn't work reliably for other MTAs, nor if there is
1323 more than one recipient.  By default, \fIfetchmail\fR looks for
1324 envelope addresses in these lines; you can restore this default with
1325 -E "Received" or \&`envelope Received'.
1326 .PP
1327 Alternatively, some SMTP listeners and/or mail servers insert a header
1328 in each message containing a copy of the envelope addresses.  This
1329 header (when it exists) is often `X-Envelope-To'.  Fetchmail's
1330 assumption about this can be changed with the -E or `envelope' option.
1331 Note that writing an envelope header of this kind exposes the names of
1332 recipients (including blind-copy recopients) to all receivers of the
1333 messages; it is therefore regarded by some administrators as a
1334 security/privacy problem.
1335 .PP
1336 A slight variation of the `X-Envelope-To' header is the `Delivered-To' put
1337 by qmail to avoid mail loops. It will probably prefix the user name with a
1338 string that normally matches the user's domain. To remove this prefix you
1339 can use the -Q or `qvirtual' option.
1340 .PP
1341 Sometimes, unfortunately, neither of these methods works.  When they
1342 all fail, fetchmail must fall back on the contents of To/Cc/Bcc
1343 headers to try to determine recipient addressees -- and these are not
1344 reliable.  In particular, mailing-list software often ships mail with
1345 only the list broadcast address in the To header.
1346 .PP
1347 When
1348 .I fetchmail
1349 cannot deduce a recipient address that is local, and the intended
1350 recipient address was anyone other than fetchmail's invoking user,
1351 mail will get lost.  This is what makes the multidrop feature risky.
1352 .PP
1353 A related problem is that when you blind-copy a mail message, the Bcc
1354 information is carried \fIonly\fR as envelope address (it's not put
1355 in the headers fetchmail can see unless there is an X-Envelope
1356 header).  Thus, blind-copying to someone who gets mail over a
1357 fetchmail link will fail unless the the mailserver host routinely
1358 writes X-Envelope or an equivalent header into messages in your maildrop.
1359
1360 .SS Good Ways To Use Multidrop Mailboxes
1361 Multiple local names can be used to administer a mailing list from the
1362 client side of a \fIfetchmail\fR collection.  Suppose your name is
1363 \&`esr', and you want to both pick up your own mail and maintain a mailing
1364 list called (say) "fetchmail-friends", and you want to keep the alias
1365 list on your client machine.
1366 .PP
1367 On your server, you can alias \&`fetchmail-friends' to `esr'; then, in
1368 your \fI.fetchmailrc\fR, declare \&`to esr fetchmail-friends here'.
1369 Then, when mail including `fetchmail-friends' as a local address
1370 gets fetched, the list name will be appended to the list of
1371 recipients your SMTP listener sees.  Therefore it will undergo alias
1372 expansion locally.  Be sure to include `esr' in the local alias
1373 expansion of fetchmail-friends, or you'll never see mail sent only to
1374 the list.  Also be sure that your listener has the "me-too" option set
1375 (sendmail's -oXm command-line option or OXm declaration) so your name
1376 isn't removed from alias expansions in messages you send.
1377 .PP
1378 This trick is not without its problems, however.  You'll begin to see
1379 this when a message comes in that is addressed only to a mailing list
1380 you do \fInot\fR have declared as a local name.  Each such message
1381 will feature an `X-Fetchmail-Warning' header which is generated
1382 because fetchmail cannot find a valid local name in the recipient
1383 addresses.  Such messages default (as was described above) to being
1384 sent to the local user running
1385 .IR fetchmail ,
1386 but the program has no way to know that that's actually the right thing.
1387
1388 .SS Bad Ways To Abuse Multidrop Mailboxes
1389 Multidrop mailboxes and 
1390 .I fetchmail
1391 serving multiple users in daemon mode do not mix.  The problem, again, is
1392 mail from mailing lists, which typically does not have an individual
1393 recipient address on it.   Unless 
1394 .I fetchmail
1395 can deduce an envelope address, such mail will only go to the account
1396 running fetchmail (probably root).  Also, blind-copied users are very
1397 likely never to see their mail at all.
1398 .PP
1399 If you're tempted to use 
1400 .I fetchmail 
1401 to retrieve mail for multiple users from a single mail drop via POP or
1402 IMAP, think again (and reread the section on header and envelope
1403 addresses above).  It would be smarter to just let the mail sit in the
1404 mailserver's queue and use fetchmail's ETRN mode to trigger SMTP sends
1405 periodically (of course, this means you have to poll more frequently
1406 than the mailserver's expiry period).  If you can't arrange this, try
1407 setting up a UUCP feed.
1408 .PP
1409 If you absolutely \fImust\fR use multidrop for this purpose, make sure
1410 your mailserver writes an envelope-address header that fetchmail can
1411 see.  Otherwise you \fIwill\fR lose mail and it \fIwill\fR come back
1412 to haunt you.
1413
1414 .SS Speeding Up Multidrop Checking
1415 Normally, when multiple user are declared 
1416 .I fetchmail
1417 extracts recipient addresses as described above and checks each host
1418 part with DNS to see if it's an alias of the mailserver.  If so, the
1419 name mappings described in the to ... here declaration are done and
1420 the mail locally delivered.
1421 .PP
1422 This is the safest but also slowest method.  To speed it up,
1423 pre-declare mailserver aliases with `aka'; these are checked before
1424 DNS lookups are done.  If you're certain your aka list contains
1425 .B all
1426 DNS aliases of the mailserver (and all MX names pointing at it) 
1427 you can declare `no dns' to suppress DNS lookups entirely and
1428 \fIonly\fR match against the aka list.
1429
1430 .SH EXIT CODES
1431 To facilitate the use of 
1432 .I fetchmail
1433 in shell scripts, an exit code is returned to give an indication
1434 of what occurred during a given connection.
1435 .PP
1436 The exit codes returned by 
1437 .I fetchmail
1438 are as follows:
1439 .IP 0
1440 One or more messages were successfully retrieved.
1441 .IP 1
1442 There was no mail awaiting retrieval.  (There may have been old mail still
1443 on the server but not selected for retrieval.)
1444 .IP 2
1445 An error was encountered when attempting to open a socket for the POP 
1446 connection.  If you don't know what a socket is, don't worry about it --
1447 just treat this as an 'unrecoverable error'.
1448 .IP 3
1449 The user authentication step failed.  This usually means that a bad 
1450 user-id, password, or APOP id was specified.
1451 .IP 4
1452 Some sort of fatal protocol error was detected.
1453 .IP 5
1454 There was a syntax error in the arguments to 
1455 .I fetchmail.
1456 .IP 6
1457 The run control file had bad permissions.
1458 .IP 7
1459 There was an error condition reported by the server.  Can also
1460 fire if
1461 .I fetchmail
1462 timed out while waiting for the server.
1463 .IP 8
1464 Client-side exclusion error.  This means 
1465 .I fetchmail
1466 either found another copy of itself already running, or failed in such
1467 a way that it isn't sure whether another copy is running.
1468 .IP 9
1469 The user authentication step failed because the server responded "lock
1470 busy".  Try again after a brief pause!  This error is not implemented
1471 for all protocols, nor for all servers.  If not implemented for your
1472 server, "3" will be returned instead, see above.  May be returned when
1473 talking to qpopper or other servers that can respond with "lock busy"
1474 or some similar text containing the word "lock".
1475 .IP 10
1476 The 
1477 .I fetchmail.
1478 run failed while trying to do an SMTP port open or transaction.
1479 .IP 11
1480 Fatal DNS error.  Fetchmail encountered an error while performing
1481 a DNS lookup at startup and could not proceed.
1482 .IP 11
1483 Internal error.  You should see a message on standard error with
1484 details.
1485 .PP
1486 When
1487 .I fetchmail
1488 queries more than one host, return status is 0 if \fIany\fR query
1489 successfully retrieved mail. Otherwise the returned error status is
1490 that of the last host queried.
1491
1492 .SH AUTHOR
1493 Eric S. Raymond <esr@snark.thyrsus.com>.  
1494 This program is descended from and replaces 
1495 .IR popclient , 
1496 by Carl Harris <ceharris@mal.com>; the internals are quite different, 
1497 but some of its interface design is directly traceable to that
1498 ancestral program.
1499
1500 .SH FILES
1501 .TP 5
1502 ~/.fetchmailrc
1503 default run control file
1504 .TP 5
1505 ~/.fetchids
1506 default location of file associating hosts with last message IDs seen
1507 (used only with newer RFC1725-compliant POP3 servers supporting the
1508 UIDL command).
1509 .TP 5
1510 ~/.netrc 
1511 your FTP run control file, which (if present) will be searched for
1512 passwords as a last resort before prompting for one interactively.
1513 .TP 5
1514 ~/.fetchmail.pid
1515 lock file to help prevent concurrent runs (non-root mode).
1516 .TP 5
1517 /var/run/fetchmail.pid
1518 lock file to help prevent concurrent runs (root mode, Linux systems).
1519 .TP 5
1520 /etc/fetchmail.pid
1521 lock file to help prevent concurrent runs (root mode, systems without /var/run).
1522
1523 .SH ENVIRONMENT
1524 For correct initialization, 
1525 .I fetchmail
1526 requires either that both the USER and HOME environment variables are
1527 correctly set, or that \fBgetpwuid\fR(3) be able to retrieve a password
1528 entry from your user ID.
1529
1530 .SH SIGNALS
1531 If a
1532 .I fetchmail
1533 daemon is running as root, SIGHUP wakes it up from its sleep phase and
1534 forces a poll of all non-skipped servers (this is in accordance with
1535 the usual conventions for system daemons).
1536 .PP
1537 If
1538 .I fetchmail
1539 is running in daemon mode as non-root, use SIGUSR1 to wake it (this is
1540 so SIGHUP due to logout can retain the default action of killing it).
1541 .PP
1542 Running
1543 .I fetchmail
1544 in foreground while a background fetchmail is running will do
1545 whichever of these is appropriate to wake it up.
1546
1547 .SH BUGS AND KNOWN PROBLEMS
1548 The RFC822 address parser used in multidrop mode chokes on some
1549 @-addresses that are technically legal but bizarre.  Strange uses of
1550 quoting and embedded comments are likely to confuse it.
1551 .PP
1552 Use of any of the supported protocols other than POP3 with OTP or RPA, APOP,
1553 KPOP, IMAP-K4, IMAP-GSS, or ETRN requires that the program send unencrypted
1554 passwords over the TCP/IP connection to the mailserver.  This creates
1555 a risk that name/password pairs might be snaffled with a packet
1556 sniffer or more sophisticated monitoring software.  Under Linux, the
1557 --interface option can be used to restrict polling to availability of
1558 a specific interface device with a specific local IP address, but
1559 snooping is still possible if (a) either host has a network device
1560 that can be opened in promiscuous mode, or (b) the intervening network
1561 link can be tapped.
1562 .PP
1563 Use of the %F or %T escapes in an mda option could open a security
1564 hole, because they pass text manipulable by an attacker to a shell
1565 command.  The hole is reduced by the fact that fetchmail temporarily
1566 discards any suid privileges it may have while running the MDA.  To
1567 avoid potential problems, (1) enclose the %F and %T escapes in single
1568 quotes within the option, and (2) never use an mda command containing
1569 %F or %T when fetchmail is run from the root account itself.
1570 .PP
1571 Send comments, bug reports, gripes, and the like to Eric S. Raymond
1572 <esr@thyrsus.com>.  An HTML FAQ is available at the fetchmail home
1573 page; surf to http://www.tuxedo.org/~esr/fetchmail or do a WWW search
1574 for pages with `fetchmail' in their titles.
1575
1576 .SH SEE ALSO
1577 elm(1), mail(1), sendmail(8), popd(8), imapd(8)
1578 .SH APPLICABLE STANDARDS
1579 .TP 5
1580 SMTP/ESMTP:
1581 RFC 821, RFC 1869, RFC 1652, RFC 1870, RFC1983, RFC 1985
1582 .TP 5
1583 mail:
1584 RFC 822
1585 .TP 5
1586 POP2:
1587 RFC 937
1588 .TP 5
1589 POP3:
1590 RFC 1081, RFC 1225, RFC 1460, RFC 1725, RFC 1939
1591 .TP 5
1592 APOP:
1593 RFC 1460, RFC 1725, RFC 1939
1594 .TP 5
1595 RPOP:
1596 RFC 1081, RFC 1225
1597 .TP 5
1598 IMAP2/IMAP2BIS:
1599 RFC 1176, RFC 1732
1600 .TP 5
1601 IMAP4:
1602 RFC 1730, RFC 1731, RFC 1732, RFC 2060, RFC 2061
1603 .TP 5
1604 ETRN:
1605 RFC 1985
1606 .TP 5
1607 OTP:
1608 RFC 1938