SYNOPSIS formating to prevent filling
[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 If your MTA is
124 .BR sendmail ,
125 you should include the line
126 .PP
127 .RS 5
128 \*(lq|\ %libdir%/slocal\ \-user\ username\*(rq
129 .RE
130 .PP
131 in your \&.forward file in your home directory.  This will cause
132 .B sendmail
133 to invoke
134 .B slocal
135 on your behalf when a message arrives.
136 .PP
137 If your MTA is
138 .BR MMDF-I ,
139 you should (symbolically) link
140 .B %libdir%/slocal
141 to the file
142 .B bin/rcvmail
143 in your home directory.  This will
144 cause
145 .B MMDF-I
146 to invoke
147 .B slocal
148 on your behalf with the correct
149 .RI \*(lq "address\ info\ sender" \*(rq
150 arguments.
151 .PP
152 If your MTA is
153 .BR MMDF-II ,
154 then you should not use
155 .B slocal.
156 An equivalent functionality is already provided by
157 .BR MMDF-II ;
158 see
159 .BR maildelivery (5)
160 for details.
161
162 .SS "The Maildelivery File"
163 The
164 .RI \*(lq \&.maildelivery \*(rq
165 file controls how
166 .B slocal
167 filters and delivers
168 incoming mail.  Each line of this file consists of five fields, separated
169 by white-space or comma.  Since double-quotes are honored, these
170 characters may be included in a single argument by enclosing the entire
171 argument in double-quotes.  A double-quote can be included by preceding it
172 with a backslash.  Lines beginning with `#' and blank lines are ignored.
173 .PP
174 The format of each line in the
175 .RI \*(lq \&.maildelivery \*(rq
176 file is:
177 .PP
178 .RS 5
179 .B header       pattern action  result  string
180 .RE
181 .PP
182 .BR header :
183 .RS 5
184 The name of a header field (such as To, Cc,  or From) that is to
185 be searched for a pattern.  This is any field in the headers of
186 the message that might be present.
187 .PP
188 The following special fields are also defined:
189 .TP \w'defaultrrr'u
190 .I source
191 the out-of-band sender information
192 .TP \w'defaultrrr'u
193 .I addr
194 the address that was used to cause delivery to the recipient
195 .TP \w'defaultrrr'u
196 .I default
197 this matches
198 .B only
199 if the message hasn't been delivered yet
200 .TP \w'defaultrrr'u
201 .I *
202 this always matches
203 .RE
204 .PP
205 .BR pattern :
206 .RS 5
207 The sequence of characters to match in the specified header field.
208 Matching is case-insensitive, but does not use regular expressions.
209 .RE
210 .PP
211 .BR action :
212 .RS 5
213 The action to take to deliver the message.  When a message is delivered,
214 a \*(lqDelivery\-Date:\ date\*(rq header is added which indicates the date
215 and time that message was delivered.
216 .TP \w'qpipezorztzzz'u
217 .I destroy
218 This action always succeeds.
219 .IR file ", " mbox ", or " >
220 Append the message to the file named by
221 .IR string .
222 The message is
223 appended to the file in mbox (uucp) format.  This is the format used by most
224 other mail clients (such as mailx, elm).  If the message can be appended to
225 the file, then this action succeeds.
226 .TP \w'qpipezorztzzz'u
227 .I mmdf
228 Identical to
229 .IR file ,
230 but always appends the message using the MMDF mailbox format.
231 .TP \w'qpipezorztzzz'u
232 .IR pipe " or " |
233 Pipe the message as the standard input to the command named by
234 .IR string ,
235 using the Bourne shell
236 .B sh
237 to interpret the string.
238 Prior to giving the string to the shell, it is expanded with the following
239 built-in variables:
240 .RS \w'qpipezorztzzz'u
241 .TP \w'zzreplyztozaaa'u
242 $(sender)
243 the out-of-band sender information
244 .TP \w'zzreplyztozaaa'u
245 $(address)
246 the address that was used to cause delivery to the recipient
247 .TP \w'zzreplyztozaaa'u
248 $(size)
249 the size of the message in bytes
250 .TP \w'zzreplyztozaaa'u
251 $(reply\-to)
252 either the \*(lqReply\-To:\*(rq or \*(lqFrom:\*(rq field of the message
253 .TP \w'zzreplyztozaaa'u
254 $(info)
255 the out-of-band information specified
256 .RE
257 .PP
258 .TP \w'qpipezorztzzz'u
259 .IR qpipe " or " ^
260 Similar to
261 .IR pipe ,
262 but executes the command
263 directly, after built-in variable expansion, without assistance from
264 the shell.  This action can be used to avoid quoting special characters
265 which your shell might interpret.
266 .TP \w'qpipezorztzzz'u
267 .IR folder " or " +
268 Store the message in the
269 .B nmh
270 folder named by
271 .IR string .
272 Currently this is handled by piping the message to the
273 .B nmh
274 program
275 .BR rcvstore ,
276 although this may change in the future.
277 .RE
278 .PP
279 .BR result :
280 .RS 5
281 Indicates how the action should be performed:
282 .TP \w'Azzz'u
283 .I A
284 Perform the action.  If the action succeeds, then the message
285 is considered delivered.
286 .TP \w'Azzz'u
287 .I R
288 Perform the action. Regardless of the outcome of the action,
289 the message is not considered delivered.
290 .TP \w'Azzz'u
291 .I ?
292 Perform the action only if the message has not been delivered.
293 If the action succeeds, then the message is considered delivered.
294 .TP \w'Azzz'u
295 .I N
296 Perform the action only if the message has not been delivered
297 and the previous action succeeded.  If this action succeeds, then the
298 message is considered delivered.
299 .PP
300 The delivery file is always read completely, so that several matches
301 can be made and several actions can be taken.
302 .RE
303
304 .SS "Security of Delivery Files"
305 In order to prevent security problems, the
306 .RI \*(lq \&.maildelivery \*(rq
307 file must be owned either by the user or by root, and must be
308 writable only by the owner.  If this is not the case, the file is
309 not read.
310 .PP
311 If the
312 .RI \*(lq \&.maildelivery \*(rq
313 file cannot be found, or does not
314 perform an action which delivers the message, then
315 .B slocal
316 will check for a global delivery file at
317 .IR %etcdir%/maildelivery .
318 This file is read according to the same rules.  This file must be
319 owned by the root and must be writable only by the root.
320 .PP
321 If a global delivery file cannot be found or does not perform an
322 action which delivers the message, then standard delivery to the
323 user's maildrop is performed.
324
325 .SS "Example Delivery File"
326 To summarize, here's an example delivery file:
327 .PP
328 .nf
329 .ta \w'default  'u +\w'mh-workersxx 'uC +\w'destroy 'uC +\w'result 'u
330 #
331 # .maildelivery file for nmh's slocal
332 #
333 # Blank lines and lines beginning with a '#' are ignored
334 #
335 # FIELD   PATTERN   ACTION  RESULT  STRING
336 #
337
338 # File mail with foobar in the \*(lqTo:\*(rq line into file foobar.log
339 To        foobar    file    A       foobar.log
340
341 # Pipe messages from coleman to the program message-archive
342 From      coleman   pipe    A       /bin/message-archive
343
344 # Anything to the \*(lqnmh-workers\*(rq mailing list is put in
345 # its own folder, if not filed already
346 To        nmh-workers  folder ?     nmh-workers
347
348 # Anything with Unix in the subject is put into
349 # the file unix-mail
350 Subject   unix      file    A       unix-mail
351
352 # I don't want to read mail from Steve, so destroy it
353 From      steve     destroy A       \-
354
355 # Put anything not matched yet into mailbox
356 default   \-        file    ?       mailbox
357
358 # always run rcvtty
359 *         \-        pipe    R       /nmh/lib/rcvtty
360 .fi
361
362 .SS "Sub-process environment"
363 When a process is invoked, its environment is: the user/group-ids are
364 set to recipient's ids; the working directory is the recipient's home
365 directory; the umask is 0077; the process has no /dev/tty; the standard
366 input is set to the message; the standard output and diagnostic output are
367 set to /dev/null; all other file-descriptors are closed; the environment
368 variables
369 .BR $USER ,
370 .BR $HOME ,
371 .B $SHELL
372 are set appropriately, and no other environment variables exist.
373 .PP
374 The process is given a certain amount of time to execute.  If the process
375 does not exit within this limit, the process will be terminated with
376 extreme prejudice.  The amount of time is calculated as ((size / 60) +
377 300) seconds, where size is the number of bytes in the message (with
378 30 minutes the maximum time allowed).
379 .PP
380 The exit status of the process is consulted in determining the success
381 of the action.  An exit status of zero means that the action succeeded.
382 Any other exit status (or abnormal termination) means that the action
383 failed.
384 .PP
385 In order to avoid any time limitations, you might implement a process
386 that began by
387 .BR fork ()-ing.
388 The parent would return the appropriate
389 value immediately, and the child could continue on, doing whatever it
390 wanted for as long as it wanted.  This approach is somewhat risky if
391 the parent is going to return an exit status of zero.  If the parent is
392 going to return a non-zero exit status, then this approach can lead to
393 quicker delivery into your maildrop.
394
395 .SH FILES
396 .fc ^ ~
397 .nf
398 .ta \w'/usr/local/nmh/etc/ExtraBigFileName  'u
399 ^%etcdir%/mts.conf~^nmh mts configuration file
400 ^$HOME/\&.maildelivery~^The file controlling local delivery
401 ^%etcdir%/maildelivery~^Rather than the standard file
402 ^%mailspool%/$USER~^The default maildrop
403 .fi
404
405 .SH "SEE ALSO"
406 rcvdist(1), rcvpack(1), rcvstore(1), rcvtty(1), mh\-format(5)
407
408 .SH DEFAULTS
409 .nf
410 .RB ` \-noverbose '
411 .RB ` \-nosuppressdup '
412 .RB ` \-maildelivery "' defaults to $HOME/\&.maildelivery"
413 .RB ` \-mailbox "' deaults to %mailspool%/$USER"
414 .RB ` \-file "' defaults to stdin"
415 .RB ` \-user "' defaults to the current user"
416 .fi
417
418 .SH CONTEXT
419 None
420
421 .SH HISTORY
422 .B Slocal
423 was originally designed to be backward-compatible with
424 the
425 .B maildelivery
426 facility provided by
427 .BR MMDF-II .
428 Thus, the
429 .RI \*(lq \&.maildelivery \*(rq
430 file syntax is somewhat limited.  But
431 .B slocal
432 has been modified and extended, so that is it no longer compatible with
433 .BR MMDF-II .
434 .PP
435 In addition to an exit status of zero, the
436 .B MMDF
437 values
438 .B RP_MOK
439 (32) and
440 .B RP_OK
441 (9) mean that the message has been fully delivered.
442 Any other non-zero exit status, including abnormal termination, is
443 interpreted as the
444 .B MMDF
445 value
446 .B RP_MECH
447 (200), which means
448 \*(lquse an alternate route\*(rq (deliver the message to the maildrop).
449
450 .SH BUGS
451 Only two return codes are meaningful, others should be.
452 .PP
453 .B Slocal
454 was originally designed to be backwards-compatible with the
455 .B maildelivery
456 functionality provided by
457 .BR MMDF-II .