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