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