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