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