* man/mhbuild.man: wrapped one appearance of "Content-Disposition"
[mmh] / man / slocal.man
1 .\"
2 .\" %nmhwarning%
3 .\" $Id$
4 .\"
5 .TH SLOCAL %manext1% "%nmhdate%" MH.6.8 [%nmhversion%]
6 .SH NAME
7 slocal \- asynchronously filter and deliver new mail
8 .SH SYNOPSIS
9 .HP 5
10 .na
11 .B %libdir%/slocal
12 [address\ info\ sender]
13 .RB [ \-addr
14 .IR address ]
15 .RB [ \-info
16 .IR data ]
17 .RB [ \-sender
18 .IR sender ]
19 .RB [ \-user
20 .IR username ]
21 .RB [ \-mailbox
22 .IR mbox ]
23 .\" \%[\-home\ homedir]
24 .RB [ \-file
25 .IR file ]
26 .RB [ \-maildelivery
27 .IR deliveryfile ]
28 .RB [ \-verbose " | " \-noverbose ]
29 .RB [ \-suppressdup " | " \-nosuppressdup ]
30 .RB [ \-debug ]
31 .RB [ \-version ]
32 .RB [ \-help ]
33 .ad
34 .SH DESCRIPTION
35 .B Slocal
36 is a program designed to allow you to have your inbound
37 mail processed according to a complex set of selection criteria.
38 You do not normally invoke
39 .B slocal
40 yourself, rather
41 .B slocal
42 is invoked on your behalf by your system's Message Transfer Agent
43 (such as
44 .BR sendmail )
45 when the message arrives.
46 .PP
47 The message selection criteria used by
48 .B slocal is specified
49 in the file
50 .RI \*(lq \&.maildelivery \*(rq
51 in the user's home directory.
52 You can specify an alternate file with the
53 .B \-maildelivery
54 .I file
55 option.  The syntax of this file is specified below.
56 .PP
57 The message delivery address and message sender are determined from
58 the Message Transfer Agent envelope information, if possible.
59 Under
60 .BR sendmail ,
61 the sender will obtained from the UUCP
62 \*(lqFrom:\*(rq line, if present.  The user may override these
63 values with command line arguments, or arguments to the
64 .B \-addr
65 and
66 .B \-sender
67 switches.
68 .PP
69 The message is normally read from the standard input.  The
70 .B \-file
71 switch sets the name of the file from which the message should be
72 read, instead of reading stdin.  This is useful when debugging a
73 .RI \*(lq \&.maildelivery \*(rq
74 file.
75 .PP
76 The
77 .B \-user
78 switch tells
79 .B slocal
80 the name of the user for
81 whom it is delivering mail.  The
82 .B \-mailbox
83 switch tells
84 .B slocal
85 the name of the user's maildrop file.
86 .PP
87 .B slocal
88 is able to detect and suppress duplicate messages.
89 To enable this, use the option
90 .BR \-suppressdup .
91 .B slocal
92 will
93 keep a database containing the Message-ID's of incoming messages,
94 in order to detect duplicates.  Depending on your configuration,
95 this database will be in either ndbm or Berkeley db format.
96 .PP
97 The
98 .B \-info
99 switch may be used to pass an arbitrary argument to
100 sub-processes which
101 .B slocal
102 may invoke on your behalf.
103 .PP
104 The
105 .B \-verbose
106 switch causes
107 .B slocal
108 to give information on
109 stdout about its progress.  The
110 .B \-debug
111 switch produces more
112 verbose debugging output on stderr.  These flags are useful when
113 creating and debugging your
114 .RI \*(lq \&.maildelivery \*(rq
115 file, as they
116 allow you to see the decisions and actions that
117 .B slocal
118 is taking, as well as check for syntax errors in your
119 .RI \*(lq \&.maildelivery \*(rq
120 file.
121
122 .SS "Message Transfer Agents"
123 Most modern MTAs including
124 .BR sendmail ,
125 .BR postfix
126 and
127 .BR exim
128 support a \&.forward file for directing incoming mail.
129 You should include the line
130 .PP
131 .RS 5
132 \*(lq|\ %libdir%/slocal\ \-user\ username\*(rq
133 .RE
134 .PP
135 in your \&.forward file in your home directory.  This will cause
136 your MTA to invoke
137 .B slocal
138 on your behalf when a message arrives.
139
140 .SS "The Maildelivery File"
141 The
142 .RI \*(lq \&.maildelivery \*(rq
143 file controls how
144 .B slocal
145 filters and delivers
146 incoming mail.  Each line of this file consists of five fields, separated
147 by white-space or comma.  Since double-quotes are honored, these
148 characters may be included in a single argument by enclosing the entire
149 argument in double-quotes.  A double-quote can be included by preceding it
150 with a backslash.  Lines beginning with `#' and blank lines are ignored.
151 .PP
152 The format of each line in the
153 .RI \*(lq \&.maildelivery \*(rq
154 file is:
155 .PP
156 .RS 5
157 .B header       pattern action  result  string
158 .RE
159 .PP
160 .BR header :
161 .RS 5
162 The name of a header field (such as To, Cc,  or From) that is to
163 be searched for a pattern.  This is any field in the headers of
164 the message that might be present.
165 .PP
166 The following special fields are also defined:
167 .TP \w'defaultrrr'u
168 .I source
169 the out-of-band sender information
170 .TP \w'defaultrrr'u
171 .I addr
172 the address that was used to cause delivery to the recipient
173 .TP \w'defaultrrr'u
174 .I default
175 this matches
176 .B only
177 if the message hasn't been delivered yet
178 .TP \w'defaultrrr'u
179 .I *
180 this always matches
181 .RE
182 .PP
183 .BR pattern :
184 .RS 5
185 The sequence of characters to match in the specified header field.
186 Matching is case-insensitive, but does not use regular expressions.
187 .RE
188 .PP
189 .BR action :
190 .RS 5
191 The action to take to deliver the message.  When a message is delivered,
192 a \*(lqDelivery\-Date:\ date\*(rq header is added which indicates the date
193 and time that message was delivered.
194 .TP \w'qpipezorztzzz'u
195 .I destroy
196 This action always succeeds.
197 .IR file ", " mbox ", or " >
198 Append the message to the file named by
199 .IR string .
200 The message is
201 appended to the file in mbox (uucp) format.  This is the format used by most
202 other mail clients (such as mailx, elm).  If the message can be appended to
203 the file, then this action succeeds.
204 .TP \w'qpipezorztzzz'u
205 .I mmdf
206 Identical to
207 .IR file ,
208 but always appends the message using the MMDF mailbox format.
209 .TP \w'qpipezorztzzz'u
210 .IR pipe " or " |
211 Pipe the message as the standard input to the command named by
212 .IR string ,
213 using the Bourne shell
214 .B sh
215 to interpret the string.
216 Prior to giving the string to the shell, it is expanded with the following
217 built-in variables:
218 .RS \w'qpipezorztzzz'u
219 .TP \w'zzreplyztozaaa'u
220 $(sender)
221 the out-of-band sender information
222 .TP \w'zzreplyztozaaa'u
223 $(address)
224 the address that was used to cause delivery to the recipient
225 .TP \w'zzreplyztozaaa'u
226 $(size)
227 the size of the message in bytes
228 .TP \w'zzreplyztozaaa'u
229 $(reply\-to)
230 either the \*(lqReply\-To:\*(rq or \*(lqFrom:\*(rq field of the message
231 .TP \w'zzreplyztozaaa'u
232 $(info)
233 the out-of-band information specified
234 .RE
235 .PP
236 .TP \w'qpipezorztzzz'u
237 .IR qpipe " or " ^
238 Similar to
239 .IR pipe ,
240 but executes the command
241 directly, after built-in variable expansion, without assistance from
242 the shell.  This action can be used to avoid quoting special characters
243 which your shell might interpret.
244 .TP \w'qpipezorztzzz'u
245 .IR folder " or " +
246 Store the message in the
247 .B nmh
248 folder named by
249 .IR string .
250 Currently this is handled by piping the message to the
251 .B nmh
252 program
253 .BR rcvstore ,
254 although this may change in the future.
255 .RE
256 .PP
257 .BR result :
258 .RS 5
259 Indicates how the action should be performed:
260 .TP \w'Azzz'u
261 .I A
262 Perform the action.  If the action succeeds, then the message
263 is considered delivered.
264 .TP \w'Azzz'u
265 .I R
266 Perform the action. Regardless of the outcome of the action,
267 the message is not considered delivered.
268 .TP \w'Azzz'u
269 .I ?
270 Perform the action only if the message has not been delivered.
271 If the action succeeds, then the message is considered delivered.
272 .TP \w'Azzz'u
273 .I N
274 Perform the action only if the message has not been delivered
275 and the previous action succeeded.  If this action succeeds, then the
276 message is considered delivered.
277 .PP
278 The delivery file is always read completely, so that several matches
279 can be made and several actions can be taken.
280 .RE
281
282 .SS "Security of Delivery Files"
283 In order to prevent security problems, the
284 .RI \*(lq \&.maildelivery \*(rq
285 file must be owned either by the user or by root, and must be
286 writable only by the owner.  If this is not the case, the file is
287 not read.
288 .PP
289 If the
290 .RI \*(lq \&.maildelivery \*(rq
291 file cannot be found, or does not
292 perform an action which delivers the message, then
293 .B slocal
294 will check for a global delivery file at
295 .IR %etcdir%/maildelivery .
296 This file is read according to the same rules.  This file must be
297 owned by the root and must be writable only by the root.
298 .PP
299 If a global delivery file cannot be found or does not perform an
300 action which delivers the message, then standard delivery to the
301 user's maildrop is performed.
302
303 .SS "Example Delivery File"
304 To summarize, here's an example delivery file:
305 .PP
306 .nf
307 .ta \w'default  'u +\w'mh-workersxx 'uC +\w'destroy 'uC +\w'result 'u
308 #
309 # .maildelivery file for nmh's slocal
310 #
311 # Blank lines and lines beginning with a '#' are ignored
312 #
313 # FIELD   PATTERN   ACTION  RESULT  STRING
314 #
315
316 # File mail with foobar in the \*(lqTo:\*(rq line into file foobar.log
317 To        foobar    file    A       foobar.log
318
319 # Pipe messages from coleman to the program message-archive
320 From      coleman   pipe    A       /bin/message-archive
321
322 # Anything to the \*(lqnmh-workers\*(rq mailing list is put in
323 # its own folder, if not filed already
324 To        nmh-workers  folder ?     nmh-workers
325
326 # Anything with Unix in the subject is put into
327 # the file unix-mail
328 Subject   unix      file    A       unix-mail
329
330 # I don't want to read mail from Steve, so destroy it
331 From      steve     destroy A       \-
332
333 # Put anything not matched yet into mailbox
334 default   \-        file    ?       mailbox
335
336 # always run rcvtty
337 *         \-        pipe    R       %libdir%/rcvtty
338 .fi
339
340 .SS "Sub-process environment"
341 When a process is invoked, its environment is: the user/group-ids are
342 set to recipient's ids; the working directory is the recipient's home
343 directory; the umask is 0077; the process has no /dev/tty; the standard
344 input is set to the message; the standard output and diagnostic output are
345 set to /dev/null; all other file-descriptors are closed; the environment
346 variables
347 .BR $USER ,
348 .BR $HOME ,
349 .B $SHELL
350 are set appropriately, and no other environment variables exist.
351 .PP
352 The process is given a certain amount of time to execute.  If the process
353 does not exit within this limit, the process will be terminated with
354 extreme prejudice.  The amount of time is calculated as ((size / 60) +
355 300) seconds, where size is the number of bytes in the message (with
356 30 minutes the maximum time allowed).
357 .PP
358 The exit status of the process is consulted in determining the success
359 of the action.  An exit status of zero means that the action succeeded.
360 Any other exit status (or abnormal termination) means that the action
361 failed.
362 .PP
363 In order to avoid any time limitations, you might implement a process
364 that began by
365 .BR fork ()-ing.
366 The parent would return the appropriate
367 value immediately, and the child could continue on, doing whatever it
368 wanted for as long as it wanted.  This approach is somewhat risky if
369 the parent is going to return an exit status of zero.  If the parent is
370 going to return a non-zero exit status, then this approach can lead to
371 quicker delivery into your maildrop.
372
373 .SH FILES
374 .fc ^ ~
375 .nf
376 .ta \w'%etcdir%/ExtraBigFileName  'u
377 ^%etcdir%/mts.conf~^nmh mts configuration file
378 ^$HOME/\&.maildelivery~^The file controlling local delivery
379 ^%etcdir%/maildelivery~^Rather than the standard file
380 ^%mailspool%/$USER~^The default maildrop
381 .fi
382
383 .SH "SEE ALSO"
384 rcvdist(1), rcvpack(1), rcvstore(1), rcvtty(1), mh\-format(5)
385
386 .SH DEFAULTS
387 .nf
388 .RB ` \-noverbose '
389 .RB ` \-nosuppressdup '
390 .RB ` \-maildelivery "' defaults to $HOME/\&.maildelivery"
391 .RB ` \-mailbox "' deaults to %mailspool%/$USER"
392 .RB ` \-file "' defaults to stdin"
393 .RB ` \-user "' defaults to the current user"
394 .fi
395
396 .SH CONTEXT
397 None
398
399 .SH HISTORY
400 .B Slocal
401 was originally designed to be backward-compatible with
402 the
403 .B maildelivery
404 facility provided by
405 .BR MMDF-II .
406 Thus, the
407 .RI \*(lq \&.maildelivery \*(rq
408 file syntax is somewhat limited.  But
409 .B slocal
410 has been modified and extended, so that is it no longer compatible with
411 .BR MMDF-II .
412 .PP
413 In addition to an exit status of zero, the
414 .B MMDF
415 values
416 .B RP_MOK
417 (32) and
418 .B RP_OK
419 (9) mean that the message has been fully delivered.
420 Any other non-zero exit status, including abnormal termination, is
421 interpreted as the
422 .B MMDF
423 value
424 .B RP_MECH
425 (200), which means
426 \*(lquse an alternate route\*(rq (deliver the message to the maildrop).
427
428 .SH BUGS
429 Only two return codes are meaningful, others should be.
430 .PP
431 .B Slocal
432 was originally designed to be backwards-compatible with the
433 .B maildelivery
434 functionality provided by
435 .BR MMDF-II .