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