home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume41 / mailagnt / part04 < prev    next >
Encoding:
Text File  |  1993-12-02  |  54.7 KB  |  1,242 lines

  1. Newsgroups: comp.sources.misc
  2. From: Raphael Manfredi <ram@acri.fr>
  3. Subject: v41i004:  mailagent - Flexible mail filtering and processing package, v3.0, Part04/26
  4. Message-ID: <1993Dec2.133602.18028@sparky.sterling.com>
  5. X-Md4-Signature: c9b4ed00d8c90197ad647fdc4616a24a
  6. Sender: kent@sparky.sterling.com (Kent Landfield)
  7. Organization: Advanced Computer Research Institute, Lyon, France.
  8. Date: Thu, 2 Dec 1993 13:36:02 GMT
  9. Approved: kent@sparky.sterling.com
  10.  
  11. Submitted-by: Raphael Manfredi <ram@acri.fr>
  12. Posting-number: Volume 41, Issue 4
  13. Archive-name: mailagent/part04
  14. Environment: UNIX, Perl
  15. Supersedes: mailagent: Volume 33, Issue 93-109
  16.  
  17. #! /bin/sh
  18. # This is a shell archive.  Remove anything before this line, then feed it
  19. # into a shell via "sh file" or similar.  To overwrite existing files,
  20. # type "sh file -c".
  21. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  22. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  23. # Contents:  agent/filter/README agent/man/mailagent.SH.01
  24. # Wrapped by ram@soft208 on Mon Nov 29 16:49:54 1993
  25. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  26. echo If this archive is complete, you will see the following message:
  27. echo '          "shar: End of archive 4 (of 26)."'
  28. if test -f 'agent/filter/README' -a "${1}" != "-c" ; then 
  29.   echo shar: Will not clobber existing file \"'agent/filter/README'\"
  30. else
  31.   echo shar: Extracting \"'agent/filter/README'\" \(2156 characters\)
  32.   sed "s/^X//" >'agent/filter/README' <<'END_OF_FILE'
  33. XThis is the root directory for the C filter.
  34. X
  35. XUsing the C version of the filter instead of the shell version is up to you.
  36. XThis is not really a filter in the common sense, because it does not actually
  37. Xfilter anything based on the contents of your mails. It only distills your
  38. Xincoming mail into the mailagent's queue, avoiding the spawning of multiple
  39. Xperl processes which are resource consuming.
  40. X
  41. XI had to write a C version for the filter because I was loosing some mail on
  42. Xmy machine when I used the shell script. This occurred seldom, but still...
  43. XThe reason was due to the delivery mode at our site. We get our mail from a
  44. Xuucp feed. Once in a while, 20 or more mails were delivered at the same time,
  45. Xand the shell script was not fast enough, and sendmail + filter were eating
  46. Xall my system's resources.
  47. X
  48. XThis program was written in two days, in self defense, when I decided I could
  49. Xnot afford seeing my precious mail sweeping into /dev/null any longer. It
  50. Xmight not be as portable as I wanted it too.
  51. X
  52. XIf you have an internet connection and receive only a small amount of mail
  53. Xat a time, or if you have NFS mounted mailboxes, then the shell script filter
  54. Xmay well be the winner.
  55. X
  56. XIn case you are lucky enough to have a uucp connection *and* NFS mounted
  57. Xmailboxes where you may receive mail on multiple machines :-), then you may
  58. Xrun into difficulties while setting up your .forward. The best thing to do is
  59. Xto have the filter executable installed at the same location on all the
  60. Xmachines, say in /usr/local/bin/filter.
  61. X
  62. XIf your sendmail does not always set the uid correctly before invoking the
  63. Xmailer specified in the .forward, then you will have to use the C filter and
  64. Xmake a local copy with the setuid bit set. This is yet another reason for me
  65. Xto use this program on my MIPS workstation, grrr...
  66. X
  67. XThe C filter pays attention to more variables in the ~/.mailagent than the
  68. Xshell script one, mainly to ensure a proper PATH variable. Also note that
  69. Xthe algorithms used by the two programs are completely different. Despite the
  70. Xfact it was written in a hurry, I believe it is a little safer than its shell
  71. Xcounterpart. At least it is *much* faster.
  72. X
  73. END_OF_FILE
  74.   if test 2156 -ne `wc -c <'agent/filter/README'`; then
  75.     echo shar: \"'agent/filter/README'\" unpacked with wrong size!
  76.   fi
  77.   # end of 'agent/filter/README'
  78. fi
  79. if test -f 'agent/man/mailagent.SH.01' -a "${1}" != "-c" ; then 
  80.   echo shar: Will not clobber existing file \"'agent/man/mailagent.SH.01'\"
  81. else
  82.   echo shar: Extracting \"'agent/man/mailagent.SH.01'\" \(49974 characters\)
  83.   sed "s/^X//" >'agent/man/mailagent.SH.01' <<'END_OF_FILE'
  84. Xcase $CONFIG in
  85. X'')
  86. X    if test -f config.sh; then TOP=.;
  87. X    elif test -f ../config.sh; then TOP=..;
  88. X    elif test -f ../../config.sh; then TOP=../..;
  89. X    elif test -f ../../../config.sh; then TOP=../../..;
  90. X    elif test -f ../../../../config.sh; then TOP=../../../..;
  91. X    else
  92. X        echo "Can't find config.sh."; exit 1
  93. X    fi
  94. X    . $TOP/config.sh
  95. X    ;;
  96. Xesac
  97. Xcase "$0" in
  98. X*/*) cd `expr X$0 : 'X\(.*\)/'` ;;
  99. Xesac
  100. Xecho "Extracting agent/man/mailagent.$manext (with variable substitutions)"
  101. X$rm -f mailagent.$manext
  102. X$spitshell >mailagent.$manext <<!GROK!THIS!
  103. X.TH MAILAGENT $manext "Version $VERSION PL$PATCHLEVEL"
  104. X''' @(#) Manual page for mailagent's filter -- (c) ram February 1991
  105. X'''
  106. X''' $Id: mailagent.SH,v 3.0 1993/11/29 13:48:27 ram Exp ram $
  107. X'''
  108. X'''  Copyright (c) 1990-1993, Raphael Manfredi
  109. X'''  
  110. X'''  You may redistribute only under the terms of the Artistic License,
  111. X'''  as specified in the README file that comes with the distribution.
  112. X'''  You may reuse parts of this distribution only within the terms of
  113. X'''  that same Artistic License; a copy of which may be found at the root
  114. X'''  of the source tree for mailagent 3.0.
  115. X'''
  116. X''' $Log: mailagent.SH,v $
  117. X''' Revision 3.0  1993/11/29  13:48:27  ram
  118. X''' Baseline for mailagent 3.0 netwide release.
  119. X'''
  120. X.de Ex        \" Start of Example
  121. X.sp
  122. X.in +5
  123. X.nf
  124. X..
  125. X.de Ef        \" End of Example
  126. X.sp
  127. X.in -5
  128. X.fi
  129. X..
  130. X.SH NAME
  131. Xmailagent \- an automatic mail-processing tool
  132. X.SH SYNOPSIS
  133. X\fBmailagent\fR [ \fB\-dhilqtV\fR ] [ \fB\-s{umary}\fR ] [ \fB\-f\fI file\fR ]
  134. X[ \fB\-e\fI rule\fR ] [ \fB\-c\fI config\fR ] [ \fB\-L\fI loglevel\fR ]
  135. X[ \fB\-r\fI rulefile\fR ] [ \fB\-o\fI override\fR ] [ \fImailfile\fR ]
  136. X.SH DESCRIPTION
  137. X.I Mailagent
  138. Xallows you to process your mail automatically. Given a set of \fIlex\fR-like
  139. Xrules, you are able to fill mails to specific folders, forward messages to
  140. Xa third person, pipe a message to a command or even post the message to a
  141. Xnewsgroup. It is also possible to process messages containing some
  142. Xcommands.
  143. XThe \fImailagent\fR is not usually invoked manually but is rather called via
  144. Xthe \fIfilter\fR program, which is in turn invoked by \fIsendmail\fR.
  145. XThat means you must have \fIsendmail\fR on your system to use this.
  146. XYou also must have \fIperl\fR to run the mailagent scripts.
  147. X.PP
  148. XThere is a set of options which may be used when you invoke
  149. X\fImailagent\fR yourself. Please refer to the \fBOPTIONS\fR section for
  150. Xa complete description. You may use the \fB\-h\fR option to get a cryptic
  151. Xusage reminder.
  152. X'''
  153. X.SS Product Overview
  154. X.PP
  155. X.I Mailagent
  156. Xhas actually four distinct set of features, which can be used simultaneously
  157. Xor one at a time. This involves:
  158. X.IP \(bu 5
  159. XAn @SH command processor, to remain compatible with the first implementation.
  160. XIn this simplest usage, all the mail messages are left in your mailbox,
  161. Xwith special processing raised on messages whose subject is \fICommand\fR.
  162. XPlease refer to the section entitled \fBUSING THE DEFAULT RULES\fR if you
  163. Xwish to use this feature.
  164. X.IP \(bu
  165. XA complete mail filter, which helps you sort your mail based on various
  166. Xsorting criteria and actions. Filtering is specified in a rule file and
  167. Xsupersedes the default \fICommand\fR mail processing (which may be turned on
  168. Xagain by explicitly setting up a rule for it). This should be the most
  169. Xcommon use of \fImailagent\fR and is fully documented under the section
  170. Xentitled \fBUSING THE FILTER\fR.
  171. XYou may deliver mail to plain Unix-style folders but also to MMDF and MH ones.
  172. X.IP \(bu
  173. XA replacement for the \fIvacation\fR program, which will automatically
  174. Xanswer your mail while you are not there. You only need to supply a message
  175. Xto be sent back and the frequency at which this will occur. Some simple
  176. Xmacro substitutions allow you to re-use some parts of the mail header into
  177. Xyour vacation message, for a more personalized reply. See the \fBVACATION
  178. XMODE\fR section for more details.
  179. X.IP \(bu
  180. XA generic mail server, which will let you implement a real mail server
  181. Xwithout the hassle of the lower-level concerns like error recovery,
  182. Xlogging or command parsing. The full documentation can be found in the
  183. Xsection \fBGENERIC MAIL SERVER\fR at the end of this manual page.
  184. X.PP
  185. XIt is possible to extend the mailagent filtering commands by implementing
  186. Xthem in \fIperl\fR and then having them automagically loaded when used. Those
  187. Xextended commands will behave exactly like built in ones, as documented
  188. Xin the \fBEXTENDING FILTERING COMMANDS\fR section.
  189. X'''
  190. X.SS Learning From Examples
  191. X.PP
  192. XIt is quite possible that you will find this manual page too complex for you.
  193. XUnfortunately, it is not really meant to be a tutorial but rather a reference
  194. Xmaterial. If you wish, you may start by looking at the examples held in the
  195. Xdistribution source tree under \fIagent/examples\fR. This directory contains
  196. Xtwo examples of rule files (look at the README file first) and are verbosely
  197. Xcommented.
  198. X'''
  199. X''' G e t t i n g   S t a r t e d
  200. X'''
  201. X.SH "GETTING STARTED"
  202. X.PP
  203. XFirst, you need to install a minimum configuration and see how it works. It
  204. Xwould be useless to fully install the program and then discover that it does
  205. Xnot work as advertised...
  206. X.PP
  207. XTo start the installation, you have to set up a \fI~/.mailagent\fR file which is
  208. Xthe main configuration file, and choose the right \fIfilter\fR program.
  209. X'''
  210. X.SS "Choosing The Filter Program"
  211. X.PP
  212. XThe distribution comes with two filter programs. One written in shell and one
  213. Xin C. The shell version might be the one to use if you can receive your mail
  214. Xon many different platforms where your home directory is NFS-mounted (i.e.
  215. Xshared among all those platforms). The C version is safer and much faster,
  216. Xbut you need to install it to a fixed location.
  217. X.PP
  218. XOn some platforms, \fIsendmail\fR does not correctly reset its UID when
  219. Xprocessing mails in its own queue. In that case, you need to get a private
  220. Xcopy of the C filter program and make it setuid to yourself. The filter will
  221. Xthen correctly reset its UID if invoked with an effective UID different from
  222. Xyours (it may also require the setgid bit to reset GID as well).
  223. XIf this is indeed the case on your system, make sure you use the
  224. X\fIpath\fR configuration variable to set a proper PATH, as the filter will
  225. Xspawn a perl process with the '-S' option, looking for a \fImailagent\fR
  226. Xscript.
  227. X.PP
  228. XEven if you do not need to get a setuid copy of the \fIfilter\fR program, it
  229. Xis wise to set up a proper path: someone might break into your account by
  230. Xputting a mailagent Trojan horse in the appropriate location. Also make sure
  231. Xthe mailagent program is protected against writing, as well as the directory
  232. Xwhich holds it, or someone might substitute his own version of the script
  233. Xand break security. I believe the setuid \fIfilter\fR program to be safe, but
  234. Xoverlooking is always possible so please report any security hole to me.
  235. X.PP
  236. XThe \fIfilter\fR script can be found in the \fILib/mailagent\fR directory. It
  237. Xneeds some tailoring so you should copy it into your home directory and edit
  238. Xit to suit your needs. Comments held in it should be
  239. Xself explanatory. There is only a small section at the head of the
  240. Xscript which needs to be edited.  You'll have to delete shell comments
  241. Xin the \fIfilter\fR script by yourself if your shell cannot deal with them.
  242. X'''
  243. X.SS "Configuring The Mailagent"
  244. X.PP
  245. XYou have to copy the \fImailagent.cf\fR file held in the mailagent
  246. Xsub-directory \fI$privlibexp\fR (hereafter named Lib)
  247. Xas a \fI.mailagent\fR in your home directory. Edit it to configure the
  248. Xwhole processing. In particular, you have to choose a spool directory
  249. X(hereafter named Spool) and a log directory (hereafter named Log).
  250. X.PP
  251. XFollowing is a description of each of those fields, followed by a suggested
  252. Xvalue, when applicable. Fields marked as optional may not be present in the
  253. Xconfiguration file. Some fields have a close relationship with others, and
  254. Xthat is given too.
  255. X.sp
  256. X.PD 0
  257. X.TP 10
  258. X.I agemax
  259. XPeriod after which an entry in the database should be removed (suggested: 1y)
  260. XThis field is optional, but needed if \fIautoclean\fR is on.
  261. X.TP
  262. X.I authfile
  263. XRemote sending authorizations (not implemented yet).
  264. X.TP
  265. X.I autoclean
  266. XSet to ON (case insensitively), the mailagent will perform automatic cleaning
  267. Xof the database entries under \fIhash\fR by removing all the items older
  268. Xthan \fIagemax\fR. This is an optional field, omitting it defaults to OFF.
  269. X(suggested: OFF, unless you use ONCE, UNIQUE or RECORD commands, or activate
  270. Xthe vacation mode.)
  271. X.TP
  272. X.I cleanlaps
  273. XCleaning period for database entries. The value of the last clean up is saved
  274. Xinto the context file. This is optional, but needed if \fIautoclean\fR is on.
  275. X(suggested: 1M)
  276. X.TP
  277. X.I comfile
  278. XName of the file containing authorized commands. Needed when PROCESS is used.
  279. X(suggested: \$spool/commands).
  280. X.TP
  281. X.I compress
  282. XName of the file containing the list of compressed folders. See section about
  283. Xfolder compression. This is an optional parameter. (suggested: ~/.compress).
  284. X.TP
  285. X.I comserver
  286. XName of the file containing authorized SERVER commands and their definition.
  287. XThis is an optional parameter if you don't plan to use the generic mail server.
  288. X(suggested: $spool/server).
  289. X.TP
  290. X.I context
  291. XFile holding the mailagent context. The context saves some variables which
  292. Xneed to be kept over the life of the process. Needed if auto cleaning is
  293. Xactivated. (suggested: \$spool/context)
  294. X.TP
  295. X.I distlist
  296. XA list of all the available distributions. See the sample held in
  297. X\fILib/mailagent/distribs\fR. Needed by PROCESS only. (suggested:
  298. X\$spool/distribs)
  299. X.TP
  300. X.I emergdir
  301. XName of the directory which should be used for dumps, preferably. This is
  302. Xoptional. (suggested: ~/tmp/lost+mail)
  303. X.TP
  304. X.I hash
  305. XThe directory used for name hashing by the built-in database used by ONCE,
  306. XUNIQUE and RECORD commands. Optional, unless you make use of those commands
  307. Xor activate auto cleaning. The directory is placed in the spool area.
  308. X(suggested: dbr).
  309. X.TP
  310. X.I helpdir
  311. XDirectory where help files for SERVER commands are kept.
  312. X(suggested: $spool/help)
  313. X.TP
  314. X.I home
  315. XDefines where the home directory is. This must be accurate.
  316. X.TP
  317. X.I level
  318. XLog level, see below for a definition of available levels (suggested: 9).
  319. X.TP
  320. X.I log
  321. XName of the log file, put in Log directory. (suggested: agentlog).
  322. X.TP
  323. X.I logdir
  324. XLogging directory. (suggested: ~/var/log).
  325. X.TP
  326. X.I mailbox
  327. XThe name of the system mailbox file, which by default is the value of the
  328. X\fIuser\fR configuration variable. This is an optional parameter.
  329. X.TP
  330. X.I maildrop
  331. XLocation of the system mail spool directory. If none is provided, then the
  332. Xmailagent will use the value determined by Configure.
  333. X.TP
  334. X.I mailopt
  335. XOptions to be passed to the mailer (see \fIsendmail\fR). (optional, suggested:
  336. X-odq, when using sendmail).
  337. X.TP
  338. X.I maxcmds
  339. XMaximum number of commands that are allowed to be executed by a SERVER command
  340. Xbefore flushing the remaining of the mail message. (suggested: 10).
  341. X.TP
  342. X.I maxerrors
  343. XMaximum number of errors for the SERVER command before flushing the remaining
  344. Xof the mail message. (suggested: 10).
  345. X.TP
  346. X.I maxsize
  347. XMaximum size in bytes of files before using \fIkit\fR for sending files. This
  348. Xis used by PROCESS. (suggested: 150000).
  349. X.TP
  350. X.I mhprofile
  351. XThe name of the MH profile to be used. This is needed only when attempting
  352. Xto save in an MH folder. If this optional parameter is not set, the default
  353. Xvalue \fI~/.mh_profile\fR is used.
  354. X.TP
  355. X.I mmdf
  356. XSet this to ON if you wish to be able to save mail in MMDF-style mailboxes.
  357. X(suggested: OFF, unless you use MMDF or MH).
  358. X.TP
  359. X.I mmdfbox
  360. XThe value of this variable only matters when \fImmdf\fR is on. If set to ON,
  361. Xthen new folders will be created as MMDF ones. This variable is not used when
  362. Xsaving to an existing folder, since in that case the \fImailagent\fR will
  363. Xautomatically determine the type and save the message accordingly.
  364. X(suggested: OFF, unless you use MMDF or wish to use MH's \fImshf\fR).
  365. X.TP
  366. X.I msgprefix
  367. XName of the file to put in directory folders, specifying the message prefix
  368. Xto be used. Optional, defaults to \fI.msg_prefix\fR.
  369. X.TP
  370. X.I name
  371. XFirst name of the user, used by the mailagent when referring to you. This sets
  372. Xthe value of the %U macro.
  373. X.TP
  374. X.I newcmd
  375. XName of the file describing new filtering commands. See section \fIExtending
  376. XFiltering Commands\fR for more details. Leave this optional parameter out
  377. Xunless you are a mailagent expert. (suggested: \$spool/newcmd).
  378. X.TP
  379. X.I newsopt
  380. XOptions to be passed to the news posting program (see \fIsendnews\fR).
  381. X(optional, suggested: leave empty when using inews).
  382. X.TP
  383. X.I nfslock
  384. XSet it to ON to ensure NFS-secure locks. The difference is that the hostname
  385. Xis used in conjunction with the PID to obtain a lock. However, the mailagent
  386. Xhas to fork/exec to obtain that information. This is an optional parameter
  387. Xwhich is set to OFF by default. (suggested: OFF if you deliver
  388. Xmail from only one machine, even though it's via NFS).
  389. X.TP
  390. X.I passwd
  391. XFile where SERVER power passwords are kept -- encrypted usually.
  392. X(suggested: $powers/passwd).
  393. X.TP
  394. X.I path
  395. XMinimum path to be used by C filter program. To set a specific path
  396. Xfor a machine \fIhost\fR, set up a \fIp_host\fR variable. This will
  397. Xbe \fIprepended\fR to the default \fIPATH\fR variable supplied by other
  398. Xprograms. (suggested: /bin:/usr/bin:/usr/ucb). Note that the host name
  399. Xmust be specified without any domain name appended to it (e.g. for
  400. Xan host name of \fIlyon.eiffel.com\fR, use variable \fIp_lyon\fR). If your
  401. Xhost name contains an '-' in it, you must write it as a '_', since '-' is
  402. Xnot a valid character for a \fIperl\fR variable name.
  403. X.TP
  404. X.I perlib
  405. XThis variable may be used to change the perl search path for require'd files.
  406. XDirectories should be separated using a ':' character, just like a shell PATH.
  407. XThis path is prepended to the default perl search path. Any directory not
  408. Xstarting with a '/' (after ~name substitution) is taken relatively to the
  409. Xmailagent private lib directory determined at configuration time.
  410. X.TP
  411. X.I plsave
  412. XName of the file used to save the patchlevels for archived distributions.
  413. XThis is only used by the commands invoked via PROCESS. (suggested:
  414. X\$spool/plsave).
  415. X.TP
  416. X.I powerdir
  417. XDirectory listing user clearances for SERVER powers.
  418. X(suggested: $powers/clearance)
  419. X.TP
  420. X.I powerlist
  421. XName of file containing SERVER power aliases. Since power names can be
  422. Xarbitrary long but some filesystems still have a 14 character limitation
  423. Xon filename length, internal aliases are created and maintained by mailagent.
  424. X(suggested: $powers/aliases).
  425. X.TP
  426. X.I powerlog
  427. XFile where SERVER power requests are logged, in addition to the agentlog. Since
  428. Xthose are a security concern, it is a good idea to log them separately.
  429. XIf not defined, log them only in agentlog. (suggested: $logdir/powerlog).
  430. X.TP
  431. X.I powers
  432. XDirectory for SERVER power administration. (suggested: $spool/powers)
  433. X.TP
  434. X.I proglist
  435. XA small description for the available distributions. See the sample
  436. Xheld in \fILib/mailagent/proglist\fR. This is used by PROCESS only.
  437. X(suggested: \$spool/proglist)
  438. X.TP
  439. X.I queue
  440. XQueue directory (messages waiting to be processed). Required, of course.
  441. X(suggested: \$spool/queue)
  442. X.TP
  443. X.I rulecache
  444. XThe name of the file used to cache the latest compiled rules. Since usually
  445. X\fImailagent\fR works mainly with one same rule file, this saves the overhead
  446. Xof recompiling all the rules each time. (optional, suggested:
  447. X\$spool/rulecache).
  448. X.TP
  449. X.I rules
  450. XThe name of the file holding the filtering rules (optional,
  451. Xsuggested: ~/.rules).
  452. X.TP
  453. X.I scriptcc
  454. XFlag indicating whether a copy of the SERVER session transcript should be
  455. Xsend to the user running mailagent. (suggested: OFF).
  456. X.TP
  457. X.I sendmail
  458. XThe name of the program used to send mail. That program must accept the
  459. Xmail message with headers on its standard input and a list of recipients
  460. Xon the command line. If not specified, will use the mailer chosen at
  461. Xconfiguration time (sendmail usually). The command line used to mail a message
  462. Xwill be \fIsendmail mailopt address(es)\fR.
  463. X(optional, suggested: /usr/lib/sendmail).
  464. X.TP
  465. X.I sendnews
  466. XThe name of the program used to post news. That program must accept the
  467. Xnews article with headers on its standard input. If not specified, will use
  468. Xthe news posting program chosen at configuration time (inews usually).
  469. XThe command line used to post an article will be \fIsendnews -h newsopt\fR.
  470. X(optional, suggested: /usr/local/bin/inews).
  471. X.TP
  472. X.I seq
  473. XFile used to compute job numbers (suggested: .seq).
  474. X.TP
  475. X.I servdir
  476. XThe directory name where shell and perl server commands are stored. This is
  477. Xthe default lookup place. Optional parameter unless SERVER is used.
  478. X(suggested: $spool/cmds).
  479. X.TP
  480. X.I spool
  481. XSpool directory, required (suggested: ~/var/mailagent).
  482. X.TP
  483. X.I statfile
  484. XFile where statistics should be gathered. If no such file exists, no
  485. Xstatistics will be recorded (suggested: mailagent.st).
  486. X.TP
  487. X.I track
  488. XSet to \fIon\fR (case insensitively), this turns on the \fB\-t\fR option
  489. Xwhich tracks all the rule matches and the actions on standard output. This
  490. Xis optional (suggested: OFF).
  491. X.TP
  492. X.I timezone
  493. XThe time zone value for environment variable TZ (optional).
  494. X.TP
  495. X.I tmpdir
  496. XDirectory for temporary files. Required (suggested: /tmp).
  497. X.TP
  498. X.I user
  499. XLogin name of the user who runs the mailagent. This sets the value of the
  500. X%u macro.
  501. X.TP
  502. X.I vacation
  503. XA flag set to ON or OFF to switch the vacation mode accordingly.
  504. X.TP
  505. X.I vacfile
  506. XThe name of the file to be sent back in vacation mode (suggested: ~/.vacation).
  507. X.TP
  508. X.I vacperiod
  509. XThe minimum time elapsed between two vacation messages to a given address
  510. X(suggested: 1d).
  511. X.PD
  512. X'''
  513. X.SS "Available Logging Levels"
  514. X.PP
  515. XThe following log levels can be used while running the mailagent:
  516. X.Ex
  517. X0    No logging
  518. X1    Major problems only
  519. X2    Failed deliveries
  520. X3    Successful deliveries
  521. X4    Deferred messages
  522. X5    Successful filter actions
  523. X6    Unusual but benign incidents
  524. X7    Informative messages
  525. X8    Non-delivery filter actions
  526. X9    Mail reception
  527. X12    Debug
  528. X19    Verbose
  529. X20    Lot more verbose
  530. X.Ef
  531. X'''
  532. X.SS "Setting The Mail Agent"
  533. X.PP
  534. XOnce you have configured the mailagent in a \fI~/.mailagent\fR (where \fI~\fR
  535. Xstands for your home directory), you must tell \fIsendmail\fR how to invoke it.
  536. XThis is done by setting a \fI~/.forward\fR file which looks like this (leading
  537. Xand trailing double quotes are a mandatory part of it):
  538. X.Ex
  539. X"| exec /users/ram/mail/filter >>/users/ram/.bak 2>&1"
  540. X.Ef
  541. XThis will pipe all your mails to the \fIfilter\fR program, redirecting all
  542. Xunusual messages to \fI~/.bak\fR. A sample filter shell script may be found in
  543. X\fILib/mailagent\fR, as well as a C filter program. On some systems, it may
  544. Xbe necessary to move the '|' character before the leading quote, but don't
  545. Xtry this unless you have no other choice (i.e. only as a last resort).
  546. X.PP
  547. XNote that the \fI.forward\fR file only pipes the mail to the \fIfilter\fR
  548. Xprogram and does not leave any copy in the mailbox. It is up to you to decide
  549. Xin the rule file whether you want to trash the mail away or leave it in the
  550. Xmailbox. If you do not have a rule file (i.e. you left a blank entry in your
  551. X\fI~/.mailagent\fR, or you named a non-existent file, or your file is simply
  552. Xempty), don't worry: the default action is to leave the mail in the mailbox.
  553. X'''
  554. X.SS "Allowed Commands"
  555. X.PP
  556. XThe allowed command file (as specified by the \fIcomfile\fR variable in
  557. Xyour \fI~/.mailagent\fR) contains all the recognized and allowed commands.
  558. XThe file \fIcommands\fR held in directory \fILib/mailagent\fR should be
  559. Xcopied as-is into your Spool directory.
  560. X'''
  561. X.SS "Testing Your Installation"
  562. X.PP
  563. XNow, assuming you have set a proper \fI~/.mailagent\fR file and edited the
  564. Xconfiguration section of the \fIfilter\fR, it is time to test your
  565. Xinstallation. Make sure your \fI.forward\fR is world readable and that the
  566. X\fIfilter\fR has the execution bits set (there is no reason to make the
  567. X\fIfilter\fR world readable).
  568. XSet a log-level of 20 and disable vacation mode (the \fIvacation\fR entry in the
  569. X\fI~/.mailagent\fR should be OFF). Set the name of the rule file to
  570. Xan empty file (or a non-existing file for that matter).
  571. XYou are ready to proceed...
  572. X.PP
  573. XSend yourself a mail and give the mailagent time to process your mail. The
  574. Xsubject of the message should be 'test' (in fact, anything but 'Command').
  575. XYou may want to run a "\fItail -f logfile\fR" to see what's happening. At the
  576. Xend of the processing, the logfile should contain something like the following
  577. X(names of temporaries may \-and will\- of course differ; timestamps have been
  578. Xremoved):
  579. X.Ex
  580. Xgot the right to process mail
  581. Xbuilding default rules
  582. Xparsing mail
  583. Xanalyzing mail
  584. Xin mode 'INITIAL' for ALL
  585. Xselector 'All' on '<1,->', pattern '/^Subject: [Cc]ommand/'
  586. Xmatching '/^Subject: [Cc]ommand/' on 'All' (<1,->) was false
  587. XNOTICE no match, leaving in mailbox
  588. XXEQ (LEAVE)
  589. Xstarting LEAVE
  590. Xstarting SAVE /usr/spool/mail/ram
  591. XLEFT [qm7831] in mailbox
  592. XFILTERED [qm7831] from ram (Raphael Manfredi)
  593. Xmailagent continues
  594. Xmailagent exits
  595. X.Ef
  596. X.PP
  597. XIf you do not get that, there is a problem somewhere. Start by looking at
  598. Xthe \fI~/.bak\fR file (or whatever file the \fI.forward\fR uses to redirect
  599. Xoutput of the filter). If you see something like:
  600. X.Ex
  601. XFATAL no valid queue directory
  602. XDUMPED in ~/mbox.filter
  603. X.Ef
  604. Xthen it means the \fIqueue\fR parameter in your \fI~/.mailagent\fR does not
  605. Xpoint to a valid directory. Your mail has been dumped in an emergency
  606. Xmailbox.
  607. X.PP
  608. XThe \fI~/.bak\fR file may also contain error messages stating that \fIperl\fR
  609. Xwas not found. In that case, there should be an error message in the logfile:
  610. X.Ex
  611. XERROR mailagent failed, [qm7886] left in queue
  612. X.Ef
  613. XIn that case, make sure the mail has correctly been queued in a file
  614. X\fIqm7886\fR. The queue will be processed again when another mail arrives
  615. Xor when the \fImailagent\fR is invoked with \fB\-q\fR (however, to avoid
  616. Xrace conditions, only mails which have remained for a while will be processed).
  617. X.PP
  618. XQueuing of mail also happens when another \fImailagent\fR is running. If the
  619. Xlogfile says:
  620. X.Ex
  621. Xdenied right to process mail
  622. X.Ef
  623. Xthen remove the \fIperl.lock\fR file in the Spool directory. Old lock files
  624. Xare automatically discarded by the \fImailagent\fR anyway (after one hour).
  625. X.PP
  626. XIf none of these occurs, then maybe \fIsendmail\fR did not process your
  627. X\fI~/.forward\fR at all or the file has a syntax error.
  628. XCheck your mailbox, and if your mail
  629. Xis in there, your \fI.forward\fR has not been processed. Otherwise, ask your
  630. Xsystem administrator to check \fIsendmail\fR's logfile. A correct entry would
  631. Xappear as (with leading timestamps and syslog stamps removed):
  632. X.Ex
  633. Xmessage-id=<9202041919.AA07882@york.eiffel.com>
  634. Xfrom=ram, size=395, class=0, received from local
  635. Xto="| /york/ram/mail/filter >>/york/ram/.bak 2>&1", delay=00:00:05, stat=Sent
  636. X.Ef
  637. X.PP
  638. XIf you still cannot find why the mail was not correctly processed, you should
  639. Xmake sure you normally receive mail by removing (or renaming) your
  640. X\fI~/.forward\fR and sending yourself another test mail. Also make sure your
  641. Xhome directory is world readable and "executable".
  642. X.PP
  643. XIf you are using the C filter, make sure it is running on the right platform.
  644. XThere may be a low-level routing of all your mail to a \fImailhost\fR machine,
  645. Xresponsible for the final delivery, and the filter program will run on that
  646. Xmachine, which may be a different platform than the one you compiled filter on.
  647. XAlso make sure your home directory is mounted on that machine, or the mail
  648. Xtransport agent will be unable to locate your \fI.forward\fR file, less process
  649. Xit.
  650. X.PP
  651. XThis kind of centralized mail delivery is good only when a few people have
  652. Xmail processing hooks (i.e. \fI.forward\fR files piping mail to a program);
  653. Xotherwise it's better to route mail to each user's workstation or machine,
  654. Xfor local processing, to avoid an excessive workload on the \fImailhost\fR
  655. Xmachine, especially if it is a dedicated NFS server. If you are a system
  656. Xadministrator installing \fImailagent\fR and expect many people to use it,
  657. Xkeep this in mind.
  658. X'''
  659. X''' O p t i o n s
  660. X'''
  661. X.SH OPTIONS
  662. XThere is a limited set of options which may be used when calling the
  663. Xmailagent directly. Only one special option at a time may be specified.
  664. XInvoking the mailagent as \fImailqueue\fR is equivalent to using the
  665. X\fB\-l\fR option.
  666. X.TP 15
  667. X.B \-c\fI file\fR
  668. XSpecify an alternate configuration file (~ substitution occurs). The default
  669. Xis \fI~/.mailagent\fR.
  670. X.TP
  671. X.B \-d
  672. XThe mailagent parses the rule file, compiles the rules and dumps them on the
  673. Xstandard output. This option is mainly used to check the syntax of the
  674. Xrule file and make sure the rules are what the user really thinks they are.
  675. X.TP
  676. X\fB\-e\fI rule\fR
  677. XThis option lets you specify some rules on the command line, which will
  678. Xoverride those specified via the ~/.mailagent, if any. There may be as many
  679. X\fB\-e\fR as necessary, all the rules being concatenated together as one
  680. Xhappy array, which is then parsed the same way a rule file is. If only \fBone\fR
  681. Xrule is given and there is no action specified between {...} braces, then
  682. Xthe whole line is enclosed between braces. Hence saying \fI-e 'SAVE foo'\fR
  683. Xwill be understood as \fI-e '{SAVE foo}'\fR, which will always match and
  684. Xbe executed. Using the \fB\-d\fR option in conjunction with this one is a
  685. Xconvenient way to debug a set of rules.
  686. X.TP
  687. X\fB\-f\fI mailfile\fR
  688. XUsing \fImailfile\fR as a UNIX-style mailbox (i.e. one where each mail is
  689. Xpreceded by a special From line stating the sender and the date the message
  690. Xwas issued), extract all its messages into the queue and process them as if
  691. Xthey were freshly arrived from the mail delivery subsystem.
  692. X.TP
  693. X.B \-h
  694. XPrint out a usage message on the standard error and exit.
  695. X.TP
  696. X.B \-i
  697. XInteractive mode, directs the mailagent to print a copy of all the log messages
  698. Xon \fIstderr\fR.
  699. X.TP
  700. X.B \-l
  701. XList the mailagent queue. Recently queued mails which are waited for by the
  702. X\fIfilter\fR are \fIskipped\fR for about half an hour, to avoid race conditions.
  703. X.TP
  704. X.B \-L\fI level\fR
  705. XOverride the log level specified in the configuration file.
  706. X.TP
  707. X.B \-o\fI override\fR
  708. XThis option lets you override a specific configuration option. The option must
  709. Xbe followed by a valid configuration line, which will be parsed after the
  710. Xconfiguration file itself. For instance, the \fI\-L 4\fR option is completely
  711. Xequivalent to \fI\-o 'level: 4'\fR. Note that any white space must be protected
  712. Xagainst shell interpretation by using the appropriate quoting mechanism. There
  713. Xmay be as many \fB\-o\fR options on the command line as necessary.
  714. X.TP
  715. X.B \-q
  716. XForce processing of the mailagent's queue. Only the mails not tagged as
  717. X\fIskipped\fR by the \fB\-l\fR option will be processed.
  718. X.TP
  719. X.B \-r\fI file\fR
  720. XSpecify an alternate rule file.
  721. X.TP
  722. X.B \-s {umary}
  723. XBuild a summary of all the statistics gathered so far. The output can be
  724. Xcontrolled by appending one or more letters from the set {umary}. Using
  725. X\fB\-summary\fR is a convenient way to get the whole history of the filter
  726. Xactions. The \fBu\fR modifier will print only used rules. The \fBm\fR will
  727. Xmerge all the statistics at the end while \fBa\fR reports the mode the
  728. Xfilter was in when the command was executed. The \fBr\fR asks for rule-based
  729. Xstatistics and the \fBy\fR is pretty useless and is here only to get a nice
  730. Xmnemonic option. Note that specifying an option more than once has no effect
  731. Xwhatsoever on the option itself (i.e. you may put three \fBUu\fR and only
  732. Xone \fBm\fR, but you'll still get the summary!).
  733. X.TP
  734. X.B \-t
  735. XPut the mailagent in a special tracking mode where all the rule matches and
  736. Xexecuted actions are printed on the standard output. This is mostly useful
  737. Xfor debugging a rule file. See also the \fItrack\fR parameter in the
  738. Xconfiguration file.
  739. X.TP
  740. X.B \-V
  741. XPrint version number and exit.
  742. X.PP
  743. XIf you invoke the mailagent without options and without any arguments, the
  744. Xprogram waits for a mail on its standard input. If an argument is provided, it
  745. Xis the name of a file holding one mail to be processed. This is the normal
  746. Xcalling procedure from the filter, the argument being the location of the
  747. Xqueued mail.
  748. X'''
  749. X''' D e f a u l t   R u l e s
  750. X'''
  751. X.SH "USING THE DEFAULT RULES"
  752. XIf you do not want to use the filtering feature of the mailagent, then the
  753. Xdefault built-in rules will be used. Those are really simple: all the mails
  754. Xare left in your mailbox and mails with a line "Subject: Command" anywhere in
  755. Xthe message will be processed. Commands are looked for on lines starting with
  756. X"@SH". The remaining of the line is then given to a shell for execution.
  757. X.PP
  758. XAvailable commands are read from a file (entry \fIcomfile\fR in your
  759. Xconfiguration file), one command name per line. Only those listed there will
  760. Xbe executed, others will produce an error message. The mailagent traps
  761. Xthe exit status and will send an error report if a command fails (provided
  762. Xthat the command does not issue a message by itself, in which case it
  763. Xshould return a zero exit status).
  764. X.PP
  765. XIf you do not want to use the default rules, you may skip the remaining of this
  766. Xsection.
  767. X'''
  768. X.SS "Configuring Help"
  769. X.PP
  770. XThe help text the mailagent will send to people must be copied from
  771. X\fILib/mailagent/agenthelp\fR into your own spool directory, as specified in your
  772. X\fI~/.mailagent\fR. Two macros may be used:
  773. X.TP 10
  774. X.I =DEST=
  775. XThis will be expanded to the sender's address (the one who sent you
  776. Xthe mail currently processed by the mailagent).
  777. X.TP
  778. X.I =MAXSIZE=
  779. XThis stands for the maximum size set before \fIkit\fR is used to send
  780. Xfiles back (parameter \fImaxsize\fR in your \fI~/.mailagent\fR file\fR).
  781. X.PP
  782. XYou may use the default help file or design one that will give even more
  783. Xdetails to the poor user.
  784. X'''
  785. X.SS "Distribution Files"
  786. X.PP
  787. XThe two files \fIproglist\fR and \fIdistribs\fR held in \fILib/mailagent\fR
  788. Xdescribe the distributions your mailagent will be able to distribute.
  789. XThe samples given show the expected syntax. In order to clarify things,
  790. Xhere is what the format should be:
  791. X.PP
  792. XFile \fIproglist\fR contains a small description for programs. The name
  793. Xof the program appears after a single star. It is followed by lines in
  794. Xfree format. An optional three-dashes line separates each program's
  795. Xdescription. Note that a leading tab will be added to each line
  796. Xof description.
  797. X.PP
  798. XThe \fIdistribs\fR file holds lines of the following form:
  799. X.Ex
  800. X\fIprogname version path archived compressed patches\fR
  801. X.Ef
  802. Xwhere:
  803. X.TP 10
  804. X.I progname
  805. Xis the program name (the same as the one mentioned in \fIproglist\fR).
  806. X.TP
  807. X.I version
  808. Xis the current version number. If none, a three-dashed line may be used.
  809. X.TP
  810. X.I path
  811. Xis the path where the distribution is stored. The ~ will be expanded into
  812. Xyour home directory. Note that if the distribution is stored in archived
  813. Xform, the path name is the one of the archive without the ending
  814. Xextension (which may be \fI.cpio.Z\fR or \fI.tar.Z\fR).
  815. X.TP
  816. X.I archived
  817. Xis either \fIy\fR or \fIn\fR depending on whether the distribution is
  818. Xarchived or not.
  819. X.TP
  820. X.I compressed
  821. Xis either \fIy\fR or \fIn\fR depending on whether the distribution is
  822. Xcompressed or not. This could be guessed from the extension's name, but
  823. Xwe must think of file systems with short names.
  824. X.TP
  825. X.I patches
  826. Xis \fIy\fR or \fIn\fR depending on whether the distribution is
  827. Xmaintained or not by you. If you put a \fIp\fR, this means official
  828. Xpatches are available, although you do not maintain the distribution.
  829. XFinally, an \fIo\fR means that this is an old version, where only patches
  830. Xare available, but maildist will not work. In that case, assuming the
  831. Xversion number is \fI1.0\fR, old patches are expected in a \fIbugs-1.0\fR
  832. Xdirectory.
  833. X.PP
  834. XYou may include comments in both files: all lines starting with a leading
  835. X# will be ignored.
  836. X'''
  837. X.SS "Testing Your Mail Agent"
  838. X.PP
  839. XIt is now time to make sure your mailagent works. Send yourself the following
  840. Xmail:
  841. X.Ex
  842. XSubject: Command
  843. X@SH mailhelp
  844. X.Ef
  845. XYou should receive back a mail from yourself with the subject set to:
  846. X"How to use my mailagent". If you don't, check the file \fI~/.bak\fR
  847. X(or whatever file you set in your \fI.forward\fR). If it is empty, look
  848. Xat the log file. If the log file is not empty, then perhaps the mail
  849. Xhas been queued. Check the \fIsendmail\fR queue. Also make sure that
  850. Xyou removed the '#' comments in the \fIfilter\fR script. On some systems,
  851. Xthey cause some trouble. If you are using the C filter, maybe your sendmail
  852. Xis broken and you need to make your own setuid copy (or perl might complain
  853. Xthat you have a kernel bug, etc...).
  854. X.PP
  855. XIf you have done everything right but it still does not work properly,
  856. Xincrease log level to 20 and resend your command mail. Then check the
  857. Xlog file. The diagnosis should be easier.
  858. X.PP
  859. XOnce this works, you should check your \fIdistribs\fR and \fIproglist\fR
  860. Xfiles by sending yourself the following mail:
  861. X.Ex
  862. XSubject: Command
  863. X@SH maillist
  864. X.Ef
  865. XIf the list you have in return is incorrect, then your distribution files
  866. Xare wrongly written. If you do not get the list, there is a problem with
  867. Xyour mailagent's configuration. Retry with a log level set to 20 and look
  868. Xat the issued log messages in your Log directory. Make sure that the file
  869. Xlisted in the \fIplsave\fR entry of your \fI~/.mailagent\fR is correctly
  870. Xupdated after a \fImaillist\fR has been run.
  871. X'''
  872. X''' F i l t e r i n g   R u l e s
  873. X'''
  874. X.SH "USING THE FILTER"
  875. XThe \fImailagent\fR can also be used as a filter: mail is parsed and some
  876. Xactions are taken based on simple \fIlex\fR-like rules. Actions range from
  877. Xa simple saving in a folder, a forwarding to another person, or even spawning
  878. Xof a shell command. Before going further, here is a small example of a valid
  879. Xrule file:
  880. X.Ex
  881. XFrom: root { FORWARD postmaster };
  882. XTo: gue@eiffel.fr { POST mail.gue };
  883. XSubject: /metaconfig/ { SAVE dist };
  884. X.Ef
  885. XThere are three distinct rules. Rules are applied in sequence, until one
  886. Xmatches (so the order is important). Any mail coming from \fIroot\fR will be
  887. Xforwarded to user \fIpostmaster\fR. A mail addressed to \fIgue@eiffel.fr\fR is
  888. Xa mail coming from a mailing list. The mail is posted on a local newsgroup
  889. X\fImail.gue\fR. Mails whose subject contains the word "metaconfig" will be
  890. Xsaved in a folder \fIdist\fR for delayed reading and will not appear in the
  891. Xmain mailbox. If no rule matched, the mail is left in the mailbox.
  892. X'''
  893. X.SS "Rule File Syntax"
  894. X.PP
  895. XHere is a non-formal description of the rule file. Parsing of the file is done
  896. Xlexically, hence the choice of non-ambiguous tokens like '{' or ';' which are
  897. Xeasily parsed. This introduces some limitations which are silently applied:
  898. Xfor instance, no '{' may be used as part of an address.
  899. X.PP
  900. XComments are introduced by a leading '#' , which must be on the left margin.
  901. XUnlike shell comments, a '#' which is not left justified will not be understood
  902. Xas a comment. However, spaces or tabs are allowed in front of '#'.
  903. X.PP
  904. XAll the statements in the rule file must end with a ';'. There are mainly
  905. Xfour parts in each line. A list of comma separated modes, between '<' and '>',
  906. Xwhich give the set of modes in which the rule applies. The special mode
  907. XALL will match everything. The filter begins in the mode INITIAL. Omitting the
  908. Xmode defaults to "<ALL>". It is possible to guard a rule against some
  909. Xspecific mode by negating it, which is done by prefixing the mode with '!'.
  910. XNegated modes take precedence other plain modes, meaning "<!ALL>" will never
  911. Xbe matched, ever, and that "<MODE, !MODE>" is equivalent to "<!MODE>".
  912. X.PP
  913. XThen comes a list of selectors. Those selectors must be space separated and end
  914. Xwith ':'. They represent the names of header fields which must be looked at
  915. Xby the forthcoming pattern. An empty selector list defaults to "Subject:".
  916. XSpecial selectors "All:", "Body:" and "Head:" apply to the whole message,
  917. Xits body or its header. A commonly used selector list is "To Cc:" which tests
  918. Xthe recipient fields of the header. If the selector name is preceded by an
  919. Xexclamation mark '!', then the logical value of the test for that selector is
  920. Xnegated.
  921. X.PP
  922. XThe list of selectors may end with an optional range specification, given as
  923. X\fI<min, max>\fR, before the final ':' character marking the end of the
  924. Xselector list. The minimum or the maximum may be given as '-', in which case
  925. Xit is replaced with the minimal or maximal possible value. Indices for
  926. Xselection begin at 1 (not 0), for instance: \fI<3, 7>\fR. If no range selection
  927. Xis given, then the default \fI<1, ->\fR is used. Ranges normally select lines
  928. Xwithin the matching buffer, unless the selector is expecting a list in which
  929. Xcase it operates on the list items. For instance, \fIBody <3, 5>:\fR would
  930. Xselect lines #3 to #5 (included) from the mail body, whereas \fITo Cc <1,3>:\fR
  931. Xwould focus on the first three addresses on each To: or Cc: header lines.
  932. XNegative values refer to that many lines or addresses back from the end, i.e.
  933. X\fICc <-2,->:\fR selects the last two addresses on the Cc: line.
  934. X.PP
  935. XThe selector is then followed by a pattern within '/' or by a single name.
  936. XIn order to ease the writing of the rules, the semantic of a single name varies
  937. Xdepending on the selector used. For the special selectors "From:", "To:", "Cc:",
  938. X"Sender:", their associated "Resent-" fields, "Reply-To:"
  939. Xand "Apparently-To:", a single name is understood as a match on the \fIlogin
  940. Xname\fR of the address. Note that if no "To:" field is present in the header,
  941. Xone will be forged from the "Apparently-To:" for the purpose of filtering only
  942. X(i.e. no physical modification on the header is done). If the login name of
  943. Xthe address is a full name of the form First.Last, only the last name is
  944. Xkept, and is lower-cased. If only a single name is given, only shell
  945. Xmetacharacters * and ? are allowed, as well as intervals [].
  946. X.PP
  947. XIf the pattern is preceded by a single exclamation mark '!', then the
  948. Xmatching status is negated (i.e. it will succeed if the pattern is not found).
  949. XIf a single word
  950. Xis used for non-special selectors, the same rules apply but the pattern is
  951. Xanchored at the beginning and the end for an exact match. With a pattern
  952. Xstarting with '/', any regular expression understood by \fIperl\fR may be
  953. Xused and your pattern will not be modified in any way. The other special
  954. Xselector "Newsgroups:" works as "To:", excepted that newsgroups names are
  955. Xexpected and a match is attempted on every item in the list. Every pattern
  956. Xmatch on a single name for an address-type field (i.e. "Newsgroups:" excluded),
  957. Xare made in case-insensitive mode.
  958. X.PP
  959. XThere is also a little magic involved when matching on an address field. Namely,
  960. Xif the pattern is not a single word and is \fIanchored at the beginning\fR,
  961. Xthen only the address part of the field will be kept. For instance, if we
  962. Xhave a From: field whose value is \fIRaphael Manfredi <ram@eiffel.com>\fR, then
  963. Xthe pattern \fI/Raphael/\fR would match, but not \fI/^Raphael/\fR. Instead,
  964. X\fI/^ram@.*$/\fR would match, but this is more easily done with a single word
  965. Xpattern \fIram\fR, for it only focuses on the login name of the address and
  966. Xwould also match if the address was written as \fIeiffel.com!ram\fR.
  967. X.PP
  968. XThis may sound a little complex, but this design is meant to make things
  969. Xeasier for the user. Here are some other examples:
  970. X.Ex
  971. X# Match \fIram@eiffel.com\fR as well as \fIram@educ.emse.fr\fR.
  972. XFrom: ram
  973. X
  974. X# Match \fIroot@eiffel.com\fR, \fIram\fR but not \fIribbon@eiffel.com\fR
  975. XFrom: r[oa]*
  976. X
  977. X# Match \fIgue@eiffel.fr\fR but not \fIalgue@eiffel.fr\fR
  978. XTo Cc: gue@eiffel.fr
  979. X
  980. X# This will match \fIgue@eiffel.fr\fR as well as \fIalgue@eiffel.com\fR
  981. XTo Cc: /gue@eiffel/
  982. X
  983. X# Match \fIcomp.lang.perl\fR but not \fIcomp.lang.perl.poetry\fR (?)
  984. XNewsgroups: comp.lang.perl
  985. X
  986. X# Accept anything but messages coming from \fIroot\fR
  987. XFrom: !root
  988. X.Ef
  989. XWhen attempting a match on "To:", "Cc:" or "Apparently-To:", a
  990. Xlist of addresses separated by a comma is expected, whereas only one
  991. Xaddress is expected after "From:". If you omit the pattern, it will be
  992. Xunderstood as * (recall that a single word uses shell meta-characters), which
  993. Xwill match anything.
  994. X.PP
  995. XThen comes the action to be taken when a match occurs. There are only a
  996. Xlimited set of valid actions which will be described soon in detail. The
  997. Xaction is enclosed in curly braces '{' and '}' and actions are separated or
  998. Xterminated (depending on your taste) by a ';'. Action names are spelled in
  999. Xupper-case for readability, but case is irrelevant. If you want to put a ';'
  1000. Xwithin the rule, it must be escaped by preceding it with a backslash.
  1001. XA double backslash is translated into a single one, and any other escape
  1002. Xsequence involving the backslash character is ignored (i.e. \\\\n would
  1003. Xbe kept verbatim).
  1004. X.PP
  1005. XNote that a rule should
  1006. Xbe ended by a single ';' after the last '}'. It is possible to omit this
  1007. Xfinal ';', but that single token is the re-synchronizing point for error
  1008. Xrecovery. One could argue however that there should be no syntax error, and
  1009. Xthus the ';' ought to be safely omitted. Whenever in doubt, check your rule
  1010. Xfile with the \fB\-d\fR option.
  1011. X.PP
  1012. XHere is a prototypical rule (using \fIperl\fR regular expressions; please refer
  1013. Xto the subsection \fBRegular Expressions\fR for more information):
  1014. X.Ex
  1015. X<ROOT> From: /^\\\\w+@eiffel.com$/ { SAVE eiffel };
  1016. X.Ef
  1017. XThat rule will only be taken into account when the filter is in the mode ROOT
  1018. X(recall that the processing starts in mode INITIAL; use BEGIN to change the
  1019. Xmode, as in \fIlex\fR). So in mode ROOT, anything which comes from a user
  1020. Xlocated in the \fIeiffel.com\fR site is saved in folder \fIeiffel\fR for
  1021. Xdeferred reading. The mail will not appear in the mailbox.
  1022. X.PP
  1023. XIt is possible to have more than one selection for a rule. Identical selectors
  1024. Xare logically \fIor\fR'ed while different ones are \fIand\fR'ed. The selections
  1025. Xare comma separated. For instance,
  1026. X.Ex
  1027. XFrom: root, To: ram, From: ram, Subject: /\\\\btest\\\\b/ { DELETE };
  1028. X.Ef
  1029. Xwill delete a mail from \fIroot\fR or \fIram\fR if it is sent to \fIram\fR
  1030. Xand has the word \fItest\fR in its subject. It is also possible to write the
  1031. Xprevious rule as:
  1032. X.Ex
  1033. XFrom: root, ram, To: ram, Subject: /\\\\btest\\\\b/ { DELETE };
  1034. X.Ef
  1035. Xbecause if no selector is given, the previous one is used (with the first
  1036. Xselector being "Subject:" by default).
  1037. X.PP
  1038. XAnywhere in the rule file, it is possible to define some variables. The list
  1039. Xof recognized variables is given later. For now, let's say that \fImaildir\fR
  1040. Xis the default folder directory. This variable is used by the SAVE command
  1041. Xwhen the argument is not an absolute path. Setting
  1042. X.Ex
  1043. Xmaildir = ~/mail;
  1044. X.Ef
  1045. Xwill direct the filter to use \fI~/mail\fR as the folder directory (default is
  1046. X\fI~/Mail\fR). Note the ~ substitution and the final ';'. It is not possible
  1047. X(currently) to modify the environment by setting PATH for instance.
  1048. X.PP
  1049. XFinally, there is a special construct to load patterns from a file. A pattern
  1050. Xenclosed in double quotes means that the patterns to be applied should be
  1051. Xtaken from the specified file. The file is expected to be in the directory
  1052. X\fImailfilter\fR if it is not an absolute path (~ substitution occurs). If
  1053. Xthe variable is not set \fImaildir\fR will be used. If by chance (!)
  1054. X\fImaildir\fR is not set either, the home directory is used. The file should
  1055. Xcontain one pattern per line, shell comments (#) being allowed at the beginning
  1056. Xof each line.
  1057. X.PP
  1058. XAn action may be followed by other rules. Hence the following is perfectly
  1059. Xvalid:
  1060. X.Ex
  1061. XFrom:
  1062. X    ram        { SAVE ram }
  1063. X    /plc/i        { SAVE plc }
  1064. X    root        { SAVE ~/admin }
  1065. X    /xyz/        { DELETE }
  1066. X    "users"        { LEAVE }
  1067. X    ;
  1068. X.Ef
  1069. XNote the use of the file inclusion: all the users listed in file \fIusers\fR
  1070. Xwill have their mail left in the system mailbox. The usual rules apply for
  1071. Xthese loaded patterns.
  1072. X'''
  1073. X.SS "Selector Combination"
  1074. X.PP
  1075. XA single rule may have a various set of selectors. For instance, in the
  1076. Xfollowing rule:
  1077. X.Ex
  1078. XFrom: ram, To Cc: root, !Subject: /test/, From: raphael
  1079. X.Ef
  1080. Xwe have the following set { From, To Cc, !Subject }. The first two selectors
  1081. Xare called \fIdirect\fR selectors, !Subject: is called a \fInegated\fR selector.
  1082. XThe To Cc: selector is a \fIgroup\fR selector decomposing into two \fIdirect\fR
  1083. Xselectors, while From: is an \fIatomic\fR selector. Finally, From: is also
  1084. Xa selector with \fImultiple\fR occurrences. The \fIvalue\fR of a selector is
  1085. Xits matching status logical value.
  1086. X.PP
  1087. XLet \fID\fR be the set of direct selectors and \fIN\fR the set of
  1088. Xnegated selectors, which form a partition of \fIR\fR, the set of all the
  1089. Xselectors in the rule. That is to say, \fIR\fR is the union of \fID\fR
  1090. Xand \fIN\fR, and \fID\fR intersected with \fIN\fR is the empty set
  1091. X(trivial proof: a selector is either direct or negated). If either \fID\fR
  1092. Xor \fIN\fR is empty, then it's not a partition but in that case we have
  1093. Xeither \fID\fR = \fIR\fR or else \fIN\fR = \fIR\fR.
  1094. X.PP
  1095. XLet's define the logical value of a set \fIS\fR as being the logical
  1096. Xvalue the filter would return if those rules were actually written.
  1097. XThen the logical value of \fID\fR is the logical value of each of its item
  1098. Xwith the AND logical operator distributed among them, i.e. the logical
  1099. Xvalue of { a, b, c } is the value of (a AND b AND c). Let's write it
  1100. XAND(\fID\fR). The logical value of each of the items is the logical value of
  1101. Xthe selector itself if it is not multiple, or it is the logical value of
  1102. Xall the occurrences of the multiple selector within the rule, with the
  1103. Xlogical OR operation distributed among them. That is to say, in the
  1104. Xabove example, the value of From is true iff the From: fields contains
  1105. X\fIram\fR OR \fIraphael\fR.  Let's write that OR[From].
  1106. X.PP
  1107. XTo be sound, we have to apply De Morgan's Law on \fIN\fR, hence the following
  1108. Xrules: the logical value of \fIN\fR is OR(\fIN\fR) and given a negated selector
  1109. X\fIs\fR, its logical value is AND[\fIs\fR]. And finally, the logical value of
  1110. X\fIR\fR is that of \fID\fR AND \fIN\fR, with by convention having the logical
  1111. Xvalue of the empty set be \fItrue\fR.
  1112. X.PP
  1113. XFor those who do not know De Morgan's Law, here it is: given two logical
  1114. Xpropositions \fIp\fR and \fIq\fR, then the following identities occur:
  1115. X.Ex
  1116. XNOT (p AND q) <=> (NOT p) OR (NOT q)
  1117. XNOT (p OR q) <=> (NOT p) AND (NOT q)
  1118. X.Ef
  1119. XWhile we are in the logic of the propositions,
  1120. Xnote also that OR and AND are mutually distributive, that is to say, given
  1121. Xthree logical propositions \fIp\fR, \fIq\fR and \fIr\fR, we have:
  1122. X.Ex
  1123. Xp AND (q OR r) <=> (p AND q) OR (p AND r)
  1124. Xp OR (q AND r) <=> (p OR q) AND (p OR r)
  1125. X.Ef
  1126. XTo be complete, OR and AND are associative with themselves and commutative.
  1127. XAnd the \fIB\fR set { 0, 1 } equipped with the set of operations (NOT, OR, AND)
  1128. Xis an \fIalgebra\fR (a Boolean one). I will spare you the definition of an
  1129. Xalgebra, which really has nothing to do in this manual page (which is for a
  1130. Xmail agent, in case you don't remember :-).
  1131. X.PP
  1132. XThe attentive reader will certainly have noted that I have not specified
  1133. Xthe logical value of a group selector. Well, given a group selector \fIG\fR,
  1134. Xwe decompose it into a \fIDG\fR and \fING\fR partition, \fIDG\fR being the
  1135. Xsubset of (atomic) direct selectors of \fIG\fR and \fING\fR being the subset of
  1136. X(atomic) negated selectors.  Then the logical value of \fIDG\fR is
  1137. XOR(\fIDG\fR) and the logical value of \fING\fR is AND(\fING\fR);
  1138. Xthe global logical value of \fIG\fR being that of \fIDG\fR OR \fING\fR.
  1139. XIn case either \fIDG\fR or \fING\fR is empty, then we don't have a partition,
  1140. Xbut by convention the value of the empty set is \fIfalse\fR, and one of the
  1141. Xsets is equal to \fIG\fR.
  1142. XNote that within a group selector, the rules are exactly the dual of the
  1143. Xrules within \fIR\fR.
  1144. X.PP
  1145. XNow the only rule which is not \fIlogical\fR is whether a group selector
  1146. Xbelongs to \fID\fR or \fIN\fR. I've chosen, for analogy reasons, to make the
  1147. Xgroup selector belong to \fID\fR if it does not start by '!' and to \fIN\fR
  1148. Xotherwise. That is, !To Cc: belongs to \fIN\fR whilst Cc !To: belongs to
  1149. X\fID\fR. Apart from that, order within the group selector is irrelevant:
  1150. XTo Cc: is equivalent to Cc To:, so the behavior in the quotient set is sound.
  1151. X.PP
  1152. XHere are some examples:
  1153. X.Ex
  1154. X# Match anything: (not from ram OR not from root) is always true.
  1155. XFrom: !ram, !root
  1156. X
  1157. X# Match anything but reject mails coming from ram OR root
  1158. X!From: ram, root
  1159. X
  1160. X# Reject mails whose headers matching /^Re.*/ contain the word test
  1161. X!^Re.*: /\\\\btest\\\\b/
  1162. X
  1163. X# Keep mails whose subject contains \fItest\fR AND \fIhost\fR
  1164. X!Subject: !/test/, !/host/
  1165. X
  1166. X# Matches if \fIram\fR is listed in the \fITo\fR OR the \fICc\fR line
  1167. XTo Cc: ram
  1168. X.Ef
  1169. X'''
  1170. X.SS "Minimal Header"
  1171. X.PP
  1172. XA minimal set of selectors are guaranteed to be set, regardless of the
  1173. Xactual header of the message. This is for the purpose of filtering only,
  1174. Xno physical alteration is performed.
  1175. X.sp
  1176. X.PD 0
  1177. X.TP 10
  1178. X.I Envelope:
  1179. XThis is the address found in the mail envelope, i.e. the address where the
  1180. Xmail seems to originate from. This can be different from the \fIFrom:\fR
  1181. Xaddress field if the mail originates from a \fItrusted\fR user, in sendmail's
  1182. Xterminology. If you don't know what that is, simply ignore it.
  1183. X.TP
  1184. X.I From:
  1185. XUser who wrote the mail. If this line is missing, uses the address found in
  1186. Xthe first From line.
  1187. X.TP
  1188. X.I To:
  1189. XThe main recipient(s) of the message. If this line is missing but a set of
  1190. X\fIApparently-To:\fR lines is found, then those addresses are used instead. If
  1191. Xno such line exists, then assume the mail was directed to the user (which
  1192. Xseems a reasonable assumption :-).
  1193. X.TP
  1194. X.I Sender:
  1195. XUser who sent the mail. This may differ from the \fIFrom:\fR line. If no
  1196. Xsuch field exists, then the address in the first From line is used (mail
  1197. Xenvelope).
  1198. X.TP
  1199. X.I Reply-To:
  1200. XWhere any reply should be sent. If no \fIReply-To:\fR field is present, then
  1201. Xthe \fIReturn-Path\fR is used (with <> stripped out), or the \fIFrom:\fR
  1202. Xline is parsed to extract the e-mail address of the author.
  1203. X.PD
  1204. X'''
  1205. X.SS "Variables"
  1206. X.PP
  1207. XThe mailagent supports user-defined variables, which are globals. They are
  1208. Xset via the ASSIGN command and referred to with the %# macro. Assuming we
  1209. Xset a variable \fIhost\fR, then %#\fIhost\fR would be replaced by the actual
  1210. Xvalue of the variable. This enables some variable propagation across the rules.
  1211. X.PP
  1212. XFor example, let's say the user receives cron outputs from various machines
  1213. Xand wishes to save them on a per-machine basis, differentiating between
  1214. Xdaily outputs and weekly ones. Here is a solution:
  1215. X.Ex
  1216. XSubject: /output for host (\\\\w+)/    { ASSIGN host %1; REJECT };
  1217. END_OF_FILE
  1218.   if test 49974 -ne `wc -c <'agent/man/mailagent.SH.01'`; then
  1219.     echo shar: \"'agent/man/mailagent.SH.01'\" unpacked with wrong size!
  1220.   fi
  1221.   # end of 'agent/man/mailagent.SH.01'
  1222. fi
  1223. echo shar: End of archive 4 \(of 26\).
  1224. cp /dev/null ark4isdone
  1225. MISSING=""
  1226. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 ; do
  1227.     if test ! -f ark${I}isdone ; then
  1228.     MISSING="${MISSING} ${I}"
  1229.     fi
  1230. done
  1231. if test "${MISSING}" = "" ; then
  1232.     echo You have unpacked all 26 archives.
  1233.     echo "Now run 'sh PACKNOTES', then read README and type Configure.'"
  1234.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1235. else
  1236.     echo You still must unpack the following archives:
  1237.     echo "        " ${MISSING}
  1238. fi
  1239. exit 0
  1240.  
  1241. exit 0 # Just in case...
  1242.