home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume33 / mailagnt / part01 < prev    next >
Encoding:
Text File  |  1992-11-19  |  54.2 KB  |  1,363 lines

  1. Newsgroups: comp.sources.misc
  2. From: ram@eiffel.com (Raphael Manfredi)
  3. Subject:  v33i093:  mailagent - Rule Based Mail Filtering, Part01/17
  4. Message-ID: <csm-v33i093=mailagent.230117@sparky.IMD.Sterling.COM>
  5. X-Md4-Signature: 7986fd5a3479b449302a99ec909a364b
  6. Date: Fri, 20 Nov 1992 05:01:51 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: ram@eiffel.com (Raphael Manfredi)
  10. Posting-number: Volume 33, Issue 93
  11. Archive-name: mailagent/part01
  12. Environment: Perl, Sendmail, UNIX
  13.  
  14. The mailagent is yet another mail filter, written in perl, which will let
  15. you do anything with your mail. It has all the features you may expect from
  16. a filter: mailing lists sorting, forwarding to MTA or to inews, pre-processing
  17. of message before saving into folder, vacation mode, etc... It was initially
  18. written as an ELM-filter replacement, but has now enough power to also
  19. supplant MMDF's .maildelivery. There is also a support for @SH mail hooks,
  20. which allows you to automatically distribute patches or software via command
  21. mails.
  22.  
  23. The mailagent was designed to make mail filtering as easy as it can be. It
  24. is highly configurable and fairly complete. Rules are specified in a lex-like
  25. style, with the full power of perl's regular expressions. The automaton
  26. supports the notion of mode, and header selection has many magic features
  27. built-in, to ease the rule writing process.
  28.  
  29. The distribution comes with a set of examples, an exhaustive test suite,
  30. and naturally a detailed manual page. It should be noted that the mailagent
  31. will work even if your system administrator forbids "| programs" hooks in
  32. the ~/.forward, provided you have access to some sort of cron daemon.
  33.  
  34. Raphael Manfredi <ram@eiffel.com>
  35. Santa Barbara, November 17th 1992
  36. --------------------------------------
  37. #! /bin/sh
  38. # This is a shell archive.  Remove anything before this line, then feed it
  39. # into a shell via "sh file" or similar.  To overwrite existing files,
  40. # type "sh file -c".
  41. # Contents:  README agent agent/examples agent/files agent/filter
  42. #   agent/man agent/man/mailagent.SH.a agent/pl agent/test
  43. #   agent/test/basic agent/test/cmd agent/test/filter
  44. #   agent/test/filter/hook.t agent/test/option agent/test/pl bin
  45. # Wrapped by kent@sparky on Wed Nov 18 22:42:19 1992
  46. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
  47. echo If this archive is complete, you will see the following message:
  48. echo '          "shar: End of archive 1 (of 17)."'
  49. if test -f 'README' -a "${1}" != "-c" ; then 
  50.   echo shar: Will not clobber existing file \"'README'\"
  51. else
  52.   echo shar: Extracting \"'README'\" \(5291 characters\)
  53.   sed "s/^X//" >'README' <<'END_OF_FILE'
  54. X                           mailagent 2.9
  55. X
  56. X              Copyright (c) 1990-1992, Raphael Manfredi
  57. X
  58. X------------------------------------------------------------------------
  59. X    This program is free software; you can redistribute it and/or modify
  60. X    it under the terms of the GNU General Public License as published by
  61. X    the Free Software Foundation.
  62. X
  63. X    This program is distributed in the hope that it will be useful,
  64. X    but WITHOUT ANY WARRANTY; without even the implied warranty of
  65. X    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  66. X    GNU General Public License for more details.
  67. X
  68. X    You should have received a copy of the GNU General Public License
  69. X    along with this program; if not, write to the Free Software
  70. X    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  71. X------------------------------------------------------------------------
  72. X
  73. XPlease read all the directions below before you proceed any further, and
  74. Xthen follow them carefully.
  75. X
  76. XAfter you have unpacked your kit, you should have all the files listed
  77. Xin MANIFEST.
  78. X========================================================================
  79. X
  80. XThis is a mailagent program, and it will take care of all your incoming
  81. Xmail by applying a set of rules and trying to figure out what to do with
  82. Xit. A message can be saved in a folder, left in the main mailbox, posted
  83. Xto a newsgroup, forwarded to other people, split if it is a digest,
  84. Xetc... You may even delete all those mails you do not wish to see, ever.
  85. X
  86. XFiltering rules are specified using lex-style rules, i.e. they have
  87. Xa set of patterns in the left handside (lhs) and a set of actions within
  88. X{} braces on the right handside (rhs). Pattern on the lhs are applied
  89. Xin sequence until one match occurs, at which time the rhs is executed.
  90. XNormally the first match stops the processing, but that may be changed.
  91. X
  92. XAs in lex, the filtering automaton supports the notion of modes, each
  93. Xrule belonging to a set of modes and being applied only when the current
  94. Xworking mode matches one of the modes associated with the rule.
  95. X
  96. XIf you do not install any filtering rules, then some default hardwired
  97. Xrules apply. Those simply leave all the messages in your mailbox, but
  98. Xprocess mails whose Subject line is Command (@SH hooks). You may
  99. Xoverride this default behaviour by writing your own set of rules,
  100. Xand maybe disable this processing entirely.
  101. X
  102. XI have included in the subdirectory 'examples' a set of files which are
  103. Xpart of my own mail environment, in the hope that they will be useful.
  104. XIn particular, there is a heavily documented rule file, which is a copy
  105. Xof the one I am currently using, comments excepted...
  106. X
  107. X(The following only matters if you decide to use the PROCESS command.)
  108. XThe mailhelp, maillist, mailpatch and maillist programs are *old* and
  109. Xwould need some clean up. They require you to have the kit program
  110. Xand cshar; those two programs have been posted to comp.sources.unix.
  111. X
  112. XAny feedback on this program will be appreciated. However, please make
  113. Xsure to introduce the word 'mailagent' in the subject of your message,
  114. Xso that the new rule I am about to add to my ~/.rules may correctly
  115. Xredirect your message into a high priority folder :-)
  116. X
  117. X    Raphael Manfredi <ram@eiffel.com>
  118. X    Santa Barbara, July 14th 1992
  119. X
  120. X========================================================================
  121. X
  122. XINSTALLATION
  123. X
  124. X1) Run Configure. This will figure out various things about your
  125. Xsystem. After it has completed, it will produce config.h and config.sh.
  126. X
  127. XYou might possibly have to trim # comments from the front of Configure
  128. Xif your shell doesn't handle them, but all other comments will be taken
  129. Xcare of.
  130. X
  131. X2) Run make.
  132. X
  133. X3) If make succeeded, you may wish to do "make install install.man". Be
  134. Xsure your rights are correct (if you install manual pages, you may need
  135. Xsuper-user privileges). By not running "make install.man", you avoid the
  136. Xinstallation of the manual pages.
  137. X
  138. X4) Read the manual entry before running.
  139. X
  140. X5) IMPORTANT!  Communicate any problem and suggested patches to me,
  141. Xram@eiffel.com (Raphael Manfredi), so we can keep this distribution in
  142. Xsync.  If you have a problem, there will be someone else who had it or
  143. Xwill have it too...
  144. X
  145. XIf possible, send me patches such that the patch program will apply
  146. Xthem.  Context diffs are the best, then normal diffs.  Do not send ed
  147. Xscripts, I have probably changed my copy since the version you got.
  148. X
  149. X6) After everything is installed, you can do make clobber. This will
  150. Xclean up everything and let you re-distribute this kit, without
  151. Xcarrying useless files. You should keep this distribution intact, so
  152. Xthat future patches will be applyable.
  153. X
  154. X7) I have an automatic patch sender. Send me the following mail:
  155. X
  156. X    Subject: Command
  157. X    @SH mailhelp PATH
  158. X
  159. Xand you'll get instructions (PATH stands for YOUR e-mail address, either
  160. Xin INTERNET or in bang notation). I would recommend you to get all the
  161. Xissued patches before you start making some modifications on this
  162. Xpackage.
  163. X
  164. X8) If you wish to deinstall the package, you may run "make deinstall".
  165. XA separate "make deinstall.man" will remove the manual pages. Be sure
  166. Xthe makefiles are correctly set before running any deinstall target.
  167. XOn USG systems, some executable have a chance to remain despite the
  168. Xdeinstall (text file busy...).
  169. X
  170. X    Raphael Manfredi <ram@eiffel.com>
  171. X
  172. END_OF_FILE
  173.   if test 5291 -ne `wc -c <'README'`; then
  174.     echo shar: \"'README'\" unpacked with wrong size!
  175.   fi
  176.   # end of 'README'
  177. fi
  178. if test ! -d 'agent' ; then
  179.     echo shar: Creating directory \"'agent'\"
  180.     mkdir 'agent'
  181. fi
  182. if test ! -d 'agent/examples' ; then
  183.     echo shar: Creating directory \"'agent/examples'\"
  184.     mkdir 'agent/examples'
  185. fi
  186. if test ! -d 'agent/files' ; then
  187.     echo shar: Creating directory \"'agent/files'\"
  188.     mkdir 'agent/files'
  189. fi
  190. if test ! -d 'agent/filter' ; then
  191.     echo shar: Creating directory \"'agent/filter'\"
  192.     mkdir 'agent/filter'
  193. fi
  194. if test ! -d 'agent/man' ; then
  195.     echo shar: Creating directory \"'agent/man'\"
  196.     mkdir 'agent/man'
  197. fi
  198. if test -f 'agent/man/mailagent.SH.a' -a "${1}" != "-c" ; then 
  199.   echo shar: Will not clobber existing file \"'agent/man/mailagent.SH.a'\"
  200. else
  201.   echo shar: Extracting \"'agent/man/mailagent.SH.a'\" \(40771 characters\)
  202.   sed "s/^X//" >'agent/man/mailagent.SH.a' <<'END_OF_FILE'
  203. Xcase $CONFIG in
  204. X'')
  205. X    if test ! -f config.sh; then
  206. X        ln ../config.sh . || \
  207. X        ln ../../config.sh . || \
  208. X        ln ../../../config.sh . || \
  209. X        (echo "Can't find config.sh."; exit 1)
  210. X    fi
  211. X    . config.sh
  212. X    ;;
  213. Xesac
  214. Xcase "$0" in
  215. X*/*) cd `expr X$0 : 'X\(.*\)/'` ;;
  216. Xesac
  217. Xecho "Extracting agent/man/mailagent.$manext (with variable substitutions)"
  218. X$rm -f mailagent.$manext
  219. X$spitshell >mailagent.$manext <<!GROK!THIS!
  220. X.TH MAILAGENT $manext "Version $VERSION PL$PATCHLEVEL"
  221. X''' @(#) Manual page for mailagent's filter -- (c) ram February 1991
  222. X'''
  223. X''' $Id: mailagent.SH,v 2.9.1.6 92/11/10 10:12:13 ram Exp $
  224. X'''
  225. X'''  Copyright (c) 1991, 1992, Raphael Manfredi
  226. X'''
  227. X'''  You may redistribute only under the terms of the GNU General Public
  228. X'''  License as specified in the README file that comes with dist.
  229. X'''
  230. X''' $Log:    mailagent.SH,v $
  231. X''' Revision 2.9.1.6  92/11/10  10:12:13  ram
  232. X''' patch12: perl interface functions now return 1 for success
  233. X''' 
  234. X''' Revision 2.9.1.5  92/11/01  15:42:53  ram
  235. X''' patch11: documents @ARGV setting by PERL command
  236. X''' 
  237. X''' Revision 2.9.1.4  92/08/26  12:43:58  ram
  238. X''' patch8: documents persistent variables
  239. X''' patch8: new section about mail hooks
  240. X''' patch8: added subsection to explain the PERL escape mechanism
  241. X''' patch8: environment set-up for children is now documented
  242. X''' patch8: mentions that argument of ASSIGN is evaluated through perl
  243. X''' 
  244. X''' Revision 2.9.1.3  92/08/12  21:32:20  ram
  245. X''' patch6: documents security checks performed by filter and mailagent
  246. X''' patch6: added description of mbox.<username>
  247. X''' 
  248. X''' Revision 2.9.1.2  92/08/02  15:59:13  ram
  249. X''' patch2: documents new mailbox configuration parameter
  250. X''' patch2: added NOTA BENE section
  251. X''' patch2: documented exit status for each command
  252. X''' patch2: explains the selector combination rules
  253. X''' patch2: shows an application of optimized OR selector combination
  254. X''' patch2: added flags and argument to ABORT, REJECT and RESTART
  255. X''' patch2: added new flags and arguments to RECORD and UNIQUE
  256. X''' 
  257. X''' Revision 2.9.1.1  92/07/25  12:35:51  ram
  258. X''' patch1: now respects English uppercased title conventions
  259. X''' patch1: a bulk or junk Precendence header voids vacation message
  260. X''' patch1: documents the minimal set of header selectors available
  261. X''' patch1: host name in p_host config variable cannot have domain name
  262. X''' 
  263. X''' Revision 2.9  92/07/14  16:49:11  ram
  264. X''' 3.0 beta baseline.
  265. X''' 
  266. X.SH NAME
  267. Xmailagent \- an automatic mail-processing tool
  268. X.SH SYNOPSIS
  269. X\fBmailagent\fR [ \fB\-dhilqtV\fR ] [ \fB\-s{umary}\fR ] [ \fB\-f\fI file\fR ]
  270. X[ \fB\-e\fI rule\fR ] [ \fB\-c\fI config\fR ] [ \fB\-L\fI loglevel\fR ]
  271. X[ \fB\-r\fI rulefile\fR ] [ \fB\-o\fI override\fR ] [ \fImailfile\fR ]
  272. X.SH DESCRIPTION
  273. X.I Mailagent
  274. Xallows you to process your mail automatically. Given a set of \fIlex\fR-like
  275. Xrules, you are able to fill mails to specific folders, forward messages to
  276. Xa third person, pipe a message to a command or even post the message to a
  277. Xnewsgroup. It is also possible to process messages containing some shell
  278. Xcommands.
  279. XThe \fImailagent\fR is not usually invoked manually but is rather called via
  280. Xthe \fIfilter\fR program, which is in turn invoked by \fIsendmail\fR.
  281. XThat means you must have \fIsendmail\fR on your system to use this.
  282. XYou also must have \fIperl\fR to run the mailagent scripts.
  283. X.PP
  284. XThere is a limited set of options which may be used when you invoke
  285. X\fImailagent\fR yourself. You may only specify one special option at a time.
  286. XA quick overview of the special options follows, and a complete description
  287. Xof all the options may be found under the \fBOPTIONS\fR section.
  288. X.PP
  289. XThe \fB\-h\fR option will give you a cryptic usage while \fB\-V\fR prints out
  290. Xthe version number.
  291. XMore intersting is the \fB\-\q\fR option, which raises a queue processing.
  292. XYou may also invoke \fImailagent\fR with the \fB\-d\fR option to process
  293. Xthe rule file and see how it is understood. The \fB\-s\fR option, possibly
  294. Xfollowed by one or more letters from the {umary} set, will report filtering
  295. Xstatistics, provided this feature was enabled.
  296. X.PP
  297. XOne possible usage of the mailagent is to send patches or whole distributions
  298. Xto people. You also have a useful feature that will acknowledge the mails
  299. Xif the sender asks so. This is activated by default rules hardwired in the
  300. Xprogram, as explained later on. Providing your own rule file will override
  301. Xthis default behaviour.
  302. X'''
  303. X''' G e t t i n g   S t a r t e d
  304. X'''
  305. X.SH "GETTING STARTED"
  306. X.PP
  307. XFirst, you need to install a minimum configuration and see how it works. It
  308. Xwould be useless to fully install the program and then discover that it does
  309. Xnot work as advertised...
  310. X.PP
  311. XTo start the installation, you have to set up a \fI~/.mailagent\fR file which is
  312. Xthe main configuration file, and choose the right \fIfilter\fR program.
  313. X'''
  314. X.SS "Choosing The Filter Program"
  315. X.PP
  316. XThe distribution comes with two filter programs. One written in shell and one
  317. Xin C. The shell version might be the one to use if you can receive your mail
  318. Xon many different platforms where your home directory is NFS-mounted (i.e.
  319. Xshared among all those platforms). The C version is safer and much faster,
  320. Xbut you need to install it to a fixed loaction.
  321. X.PP
  322. XOn some platforms, \fIsendmail\fR does not correctly reset its UID when
  323. Xprocessing mails in its own queue. In that case, you need to get a private
  324. Xcopy of the C filter program and make it setuid on yourself. The filter will
  325. Xthen corretly reset its UID if invoked with an effective UID different from
  326. Xyours (it may also require the setgid bit to reset GID as well).
  327. XIf this is indeed the case on your system, make sure you use the
  328. X\fIpath\fR configuration variable to set a proper PATH, as the filter will
  329. Xspawn a perl process with the '-S' option, looking for a \fImailagent\fR
  330. Xscript.
  331. X.PP
  332. XEven if you do not need to get a setuid copy of the \fIfilter\fR program, it
  333. Xis wise to set up a proper path: someone might break into your account by
  334. Xputting a mailagent trojan horse in the appropriate location. Also make sure
  335. Xthe mailagent program is protected against writing, as well as the directory
  336. Xwhich holds it, or someone might substitute his own version of the script
  337. Xand break security. I believe the setuid \fIfilter\fR program is safe, but
  338. Xoverlooking is always possible so please report any security hole to me.
  339. X.PP
  340. XThe \fIfilter\fR script can be found in the \fILib/mailagent\fR directory. It
  341. Xneeds some tailoring so you should copy it into your home directory and edit
  342. Xit to suit your needs. Comments held in it should be
  343. Xself explanatory. There is only a small section at the head of the
  344. Xscript which needs to be edited.  You'll have to delete shell comments
  345. Xin the \fIfilter\fR script by yourself if your shell cannot deal with them.
  346. X'''
  347. X.SS "Configuring The Mailagent"
  348. X.PP
  349. XYou have to copy the \fImailagent.cf\fR file held in the mailagent
  350. Xsub-directory \fI$privlib\fR (hereafter named Lib)
  351. Xas a \fI.mailagent\fR in your home directory. Edit it to configure the
  352. Xwhole processing. In particular, you have to choose a spool directory
  353. X(hereafter named Spool) and a log directory (hereafter named Log).
  354. X.PP
  355. XFollowing is a description of each of those fields, followed by a suggested
  356. Xvalue, when applicable. Fields marked as optional may not be present in the
  357. Xconfiguration file. Some fields have a close relationship with others, and
  358. Xthat is given too.
  359. X.sp
  360. X.PD 0
  361. X.TP 10
  362. X.I agemax
  363. XPeriod after which an entry in the database should be removed (suggested: 1y)
  364. XThis field is optional, but needed if \fIautoclean\fR is on.
  365. X.TP
  366. X.I authfile
  367. XRemote sending authorizations (not implemented yet).
  368. X.TP
  369. X.I autoclean
  370. XSet to ON (case insensitively), the mailagent will perform automatic cleaning
  371. Xof the database entries under \fIhash\fR by removing all the items older
  372. Xthan \fIagemax\fR. This is an optional field, omitting it defaults to OFF.
  373. X(suggested: OFF, unless you use ONCE, UNIQUE or RECORD commands, or activate
  374. Xthe vacation mode.)
  375. X.TP
  376. X.I cleanlaps
  377. XCleaning period for database entries. The value of the last clean up is saved
  378. Xinto the context file. This is optional, but needed if \fIautoclean\fR is on.
  379. X(suggested: 1M)
  380. X.TP
  381. X.I comfile
  382. XName of the file containing authorized commands. Needed when PROCESS is used.
  383. X(suggested: \$spool/commands).
  384. X.TP
  385. X.I context
  386. XFile holding the mailagent context. The context saves some variables which
  387. Xneed to be kept over the life of the process. Needed if auto cleaning is
  388. Xactivated. (suggested: \$spool/context)
  389. X.TP
  390. X.I distlist
  391. XA list of all the available distributions. See the sample held in
  392. X\fILib/mailagent/distribs\fR. Needed by PROCESS only. (suggested:
  393. X\$spool/distribs)
  394. X.TP
  395. X.I emergdir
  396. XName of the directory which should be used for dumps, preferably. This is
  397. Xoptional. (suggested: ~/tmp/lost+mail)
  398. X.TP
  399. X.I hash
  400. XThe directory used for name hashing by the built-in database used by ONCE,
  401. XUNIQUE and RECORD commands. Optional, unless you make use of those commands
  402. Xor activate auto cleaning. The directory is placed in the spool area.
  403. X(suggested: dbr).
  404. X.TP
  405. X.I home
  406. XDefines where the home directory is. This must be accurate.
  407. X.TP
  408. X.I level
  409. XLog level, see below for a definition of available levels (suggested: 9).
  410. X.TP
  411. X.I log
  412. XName of the log file, put in Log directory. (suggested: agentlog).
  413. X.TP
  414. X.I logdir
  415. XLogging directory. (suggested: ~/var/log).
  416. X.TP
  417. X.I mailbox
  418. XThe name of the system mailbox file, which by default is the value of the
  419. X\fIuser\fR configuration variable. This is an optional parameter.
  420. X.TP
  421. X.I maildrop
  422. XLocation of the system mail spool directory. If none is provided, then the
  423. Xmailagent will use the value determined by Configure.
  424. X.TP
  425. X.I maxsize
  426. XMaximum size in bytes of files before using \fIkit\fR for sending files. This
  427. Xis used by PROCESS. (suggested: 150000).
  428. X.TP
  429. X.I name
  430. XFirst name of the user, used by the mailagent when referring to you. This sets
  431. Xthe value of the %U macro.
  432. X.TP
  433. X.I path
  434. XMinimum path to be used by C filter program. To set a specific path
  435. Xfor a machine \fIhost\fR, set up a \fIp_host\fR variable. This will
  436. Xbe \fIprepended\fR to the default \fIPATH\fR variable supplied by other
  437. Xprograms. (suggested: /bin:/usr/bin:/usr/ucb). Note that the host name
  438. Xmust be specified without any domain name appended to it (e.g. for
  439. Xan host name of \fIlyon.eiffel.com\fR, use variable \fIp_lyon\fR).
  440. X.TP
  441. X.I plsave
  442. XName of the file used to save the patchlevels for archived distributions.
  443. XThis is only used by the commands invoked via PROCESS. (suggested:
  444. X\$spool/plsave.
  445. X.TP
  446. X.I proglist
  447. XA small description for the available distributions. See the sample
  448. Xheld in \fILib/mailagent/proglist\fR. This is used by PROCESS only.
  449. X(suggested: \$spool/proglist)
  450. X.TP
  451. X.I queue
  452. XQueue directory (messages waiting to be processed). Required, of course.
  453. X(suggested: \$spool/queue)
  454. X.TP
  455. X.I rules
  456. XThe name of the file holding the filtering rules (optional,
  457. Xsuggested: ~/.rules).
  458. X.TP
  459. X.I seq
  460. XFile used to compute job numbers (suggested: .seq).
  461. X.TP
  462. X.I spool
  463. XSpool directory, required (suggested: ~/var/mailagent).
  464. X.TP
  465. X.I statfile
  466. XFile where statistics should be gathered. If no such file exists, no
  467. Xstatistics will be recorded (suggested: mailagent.st).
  468. X.TP
  469. X.I track
  470. XSet to \fIon\fR (case insensitively), this turns on the \fB\-t\fR option
  471. Xwhich tracks all the rule matches and the actions on standard output. This
  472. Xis optional (suggested: OFF).
  473. X.TP
  474. X.I timezone
  475. XThe time zone value for environment variable TZ (optional).
  476. X.TP
  477. X.I tmpdir
  478. XDirectory for temporary files. Required (suggested: /tmp).
  479. X.TP
  480. X.I user
  481. XLogin name of the user who runs the mailagent. This sets the value of the
  482. X%u macro.
  483. X.TP
  484. X.I vacation
  485. XA flag set to ON or OFF to switch the vacation mode accordingly.
  486. X.TP
  487. X.I vacfile
  488. XThe name of the file to be sent back in vacation mode (suggested: ~/.vacation).
  489. X.TP
  490. X.I vacperiod
  491. XThe minimum time elapsed between two vacation messages to a given address
  492. X(suggested: 1d).
  493. X.PD
  494. X'''
  495. X.SS "Available Logging Levels"
  496. X.PP
  497. XThe following log levels can be used while running the mailagent:
  498. X.sp
  499. X.in +5
  500. X.nf
  501. X0    No logging
  502. X1    Major problems only
  503. X2    Failed deliveries
  504. X3    Successful deliveries
  505. X4    Deferred messages
  506. X5    Successful filter actions
  507. X6    Unusual but benign incidents
  508. X7    Informative messages
  509. X8    Non-delivery filter actions
  510. X9    Mail reception
  511. X12    Debug
  512. X19    Verbose
  513. X20    Lot more verbose
  514. X.fi
  515. X.in -5
  516. X.sp
  517. X'''
  518. X.SS "Setting The Mail Agent"
  519. X.PP
  520. XOnce you have configured the mailagent in a \fI~/.mailagent\fR (where \fI~\fR
  521. Xstands for your home directory), you must tell \fIsendmail\fR how to invoke it.
  522. XThis is done by setting a \fI~/.forward\fR file which looks like this:
  523. X.sp
  524. X.in +5
  525. X"| exec /users/ram/mail/filter >>/users/ram/.bak 2>&1"
  526. X.in -5
  527. X.sp
  528. XThis will pipe all your mails to the \fIfilter\fR program, redirecting all
  529. Xunusual messages to \fI~/.bak\fR. A sample filter shell script may be found in
  530. X\fILib/mailagent\fR, as well as a C filter program.
  531. X.PP
  532. XNote that the \fI.forward\fR file only pipes the mail to the \fIfilter\fR
  533. Xprogram and does not leave any copy in the mailbox. It is up to you to decide
  534. Xin the rule file whether you want to trash the mail away or leave it in the
  535. Xmailbox. If you do not have a rule file (i.e. you left a blank entry in your
  536. X\fI~/.mailagent\fR, or you named a non-existent file, or your file is simply
  537. Xempty), don't worry: the default action is to leave the mail in the mailbox.
  538. X'''
  539. X.SS "Allowed Commands"
  540. X.PP
  541. XThe allowed command file (as specified by the \fIcomfile\fR variable in
  542. Xyour \fI~/.mailagent\fR) contains all the recognized and allowed commands.
  543. XThe file \fIcommands\fR held in directory \fILib/mailagent\fR should be
  544. Xcopied as-is into your Spool directory.
  545. X'''
  546. X.SS "Testing Your Installation"
  547. X.PP
  548. XNow, assuming you have set a proper \fI~/.mailagent\fR file and edited the
  549. Xconfiguration section of the \fIfilter\fR, it is time to test your
  550. Xinstallation. Make sure your \fI.forward\fR is world readable and that the
  551. X\fIfilter\fR has the execution bits set (there is no reason to make the
  552. X\fIfilter\fR world readable).
  553. XSet a log-level of 20 and disable vacation mode (the \fIvacation\fR entry in the
  554. X\fI~/.mailagent\fR should be OFF). Set the name of the rule file to
  555. X\fI/dev/null\fR. You are ready to proceed...
  556. X.PP
  557. XSend yourself a mail and give the mailagent time to process your mail. The
  558. Xsubject of the message should be 'test' (in fact, anything but 'Command').
  559. XYou may want to run a "\fItail -f logfile\fR" to see what's happening. At the
  560. Xend of the processing, the logfile should contain something like the following
  561. X(names of temporaries may \-and will\- of course differ; timestamps have been
  562. Xremoved):
  563. X.sp
  564. X.in +5
  565. X.nf
  566. Xgot the right to process mail
  567. Xbuilding default rules
  568. Xparsing mail
  569. Xanalyzing mail
  570. Xin mode 'INITIAL' for ALL
  571. Xselector 'All', pattern '/^Subject: [Cc]ommand/'
  572. Xmatching '/^Subject: [Cc]ommand/' on 'All' was false
  573. XNOTICE no match, leaving in mailbox
  574. XXEQ (LEAVE)
  575. Xstarting LEAVE
  576. Xstarting SAVE /usr/spool/mail/ram
  577. XLEFT [qm7831] in mailbox
  578. XFILTERED [qm7831] from ram (Raphael Manfredi)
  579. Xmailagent continues
  580. Xmailagent exits
  581. X.fi
  582. X.in -5
  583. X.sp
  584. X.PP
  585. XIf you do not get that, there is a problem somewhere. Start by looking at
  586. Xthe \fI~/.bak\fR file (or whatever file the \fI.forward\fR uses to redirect
  587. Xoutput of the filter). If you see something like:
  588. X.sp
  589. X.in +5
  590. X.nf
  591. XFATAL no valid queue directory
  592. XDUMPED in ~/mbox.filter
  593. X.in -5
  594. X.fi
  595. X.sp
  596. Xthen it means the \fIqueue\fR parameter in your \fI~/.mailagent\fR does not
  597. Xpoint to a valid directory. Your mail has been dumped in an emergency
  598. Xmailbox.
  599. X.PP
  600. XThe \fI~/.bak\fR file may also contain error messages stating that \fIperl\fR
  601. Xwas not found. In that case, there should be an error message in the logfile:
  602. X.sp
  603. X.in +5
  604. XERROR mailagent failed, [qm7886] left in queue
  605. X.in -5
  606. X.sp
  607. XIn that case, make sure the mail has correctly been queued in a file
  608. X\fIqm7886\fR. The queue will be processed again when another mail arrives
  609. Xor when the \fImailagent\fR is invoked with \fB\-q\fR (however, to avoid
  610. Xrace conditions, only mails which have remained for a while will be processed).
  611. X.PP
  612. XQueuing of mail also happens when another \fImailagent\fR is running. If the
  613. Xlogfile says:
  614. X.sp
  615. X.in +5
  616. Xdenied right to process mail
  617. X.in -5
  618. X.sp
  619. Xthen remove the \fIperl.lock\fR file in the Spool directory. Old lock files
  620. Xare automatically discarded by the \fImailagent\fR anyway (after one hour).
  621. X.PP
  622. XIf none of these occurs, then maybe \fIsendmail\fR did not process your
  623. X\fI~/.forward\fR at all or the file has a syntax error.
  624. XCheck your mailbox, and if your mail
  625. Xis in there, your \fI.forward\fR has not been processed. Otherwise, ask your
  626. Xsystem administrator to check \fIsendmail\fR's logfile. A correct entry would
  627. Xappear as (with leading timestamps and syslog stamps removed):
  628. X.sp
  629. X.in +5
  630. X.nf
  631. Xmessage-id=<9202041919.AA07882@york.eiffel.com>
  632. Xfrom=ram, size=395, class=0, received from local
  633. Xto="| /york/ram/mail/filter >>/york/ram/.bak 2>&1", delay=00:00:05, stat=Sent
  634. X.in -5
  635. X.fi
  636. X.sp
  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'''
  643. X''' O p t i o n s
  644. X'''
  645. X.SH OPTIONS
  646. XThere is a limited set of options which may be used when calling the
  647. Xmailagent directly. Only one special option at a time may be specified.
  648. XInvoking the mailagent as \fImailqueue\fR is equivalent to using the
  649. X\fB\-l\fR option.
  650. X.TP 15
  651. X.B \-c\fI file\fR
  652. XSpecify an alternate configuration file (~ substitution occurs). The default
  653. Xis \fI~/.mailagent\fR.
  654. X.TP
  655. X.B \-d
  656. XThe mailagent parses the rule file, compiles the rules and dumps them on the
  657. Xstandard output. This option is mainly used to check the syntax of the
  658. Xrule file and make sure the rules are what the user really thinks they are.
  659. X.TP
  660. X\fB\-e\fI rule\fR
  661. XThis option lets you specify some rules on the command line, which will
  662. Xoverride those specified via the ~/.mailagent, if any. There may be as many
  663. X\fB\-e\fR as necessary, all the rules being concatenated together as one
  664. Xhappy array, which is then parsed the same way a rule file is. If only \fBone\fR
  665. Xrule is given and there is no action specified between {...} braces, then
  666. Xthe whole line is enclosed between braces. Hence saying \fI-e 'SAVE foo'\fR
  667. Xwill be understood as \fI-e '{SAVE foo}'\fR, which will always match and
  668. Xbe exectuted. Using the \fB\-d\fR option in conjunction with this one is a
  669. Xconvenient way to debug a set of rules.
  670. X.TP
  671. X\fB\-f\fI mailfile\fR
  672. XUsing \fImailfile\fR as a UNIX-style mailbox (i.e. one where each mail is
  673. Xpreceded by a special From line stating the sender and the date the message
  674. Xwas issued), extract all its messages into the queue and process them as if
  675. Xthey were freshly arrived from the mail delivery subsystem.
  676. X.TP
  677. X.B \-h
  678. XPrint out a usage message on the standard error and exit.
  679. X.TP
  680. X.B \-i
  681. XInteractive mode, directs the mailagent to print a copy of all the log messages
  682. Xon \fIstderr\fR.
  683. X.TP
  684. X.B \-l
  685. XList the mailagent queue. Recently queued mails which are waited for by the
  686. X\fIfilter\fR are \fIskipped\fR for about half an hour, to avoid race conditions.
  687. X.TP
  688. X.B \-L\fI level\fR
  689. XOverride the log level specified in the configuration file.
  690. X.TP
  691. X.B \-o\fI overrride\fR
  692. XThis option lets you override a specific configuration option. The option must
  693. Xbe followed by a valid configuration line, which will be parsed after the
  694. Xconfiguration file itself. For instance, the \fI\-L 4\fR option is completely
  695. Xequivalent to \fI\-o 'level: 4'\fR. Note that any white space must be protected
  696. Xagainst shell interpretation by using the appropriate quoting mechanism. There
  697. Xmay be as many \fB\-o\fR options on the command line as necessary.
  698. X.TP
  699. X.B \-q
  700. XForce processing of the mailagent's queue. Only the mails not tagged as
  701. X\fIskipped\fR by the \fB\-l\fR option will be processed.
  702. X.TP
  703. X.B \-r\fI file\fR
  704. XSpecify an alternate rule file.
  705. X.TP
  706. X.B \-s {umary}
  707. XBuild a summary of all the statistics gathered so far. The output can be
  708. Xcontrolled by appending one or more letters from the set {umary}. Using
  709. X\fB\-summary\fR is a convenient way to get the whole history of the filter
  710. Xactions. The \fBu\fR modifier will print only used rules. The \fBm\fR will
  711. Xmerge all the statistics at the end while \fBa\fR reports the mode the
  712. Xfilter was in when the command was executed. The \fBr\fR asks for rule-based
  713. Xstatistics and the \fBy\fR is pretty useless and is here only to get a nice
  714. Xmnemonic option. Note that specifying an option more than once has no effect
  715. Xwhatsoever on the option itself (i.e. you may put three \fbUu\fR and only
  716. Xone \fBm\fR, but you'll still get the summary!).
  717. X.TP
  718. X.B \-t
  719. XPut the mailagent in a special tracking mode where all the rule matches and
  720. Xexecuted actions are printed on the standard output. This is mostly useful
  721. Xfor debugging a rule file. See also the \fItrack\fR parameter in the
  722. Xconfiguration file.
  723. X.TP
  724. X.B \-V
  725. XPrint version number and exit.
  726. X.PP
  727. XIf you invoke the mailagent without options and without any arguments, the
  728. Xprogram waits for a mail on its standard input. If an argument is provided, it
  729. Xis the name of a file holding one mail to be processed. This is the normal
  730. Xcalling procedure from the filter, the argument being the location of the
  731. Xqueued mail.
  732. X'''
  733. X''' D e f a u l t   R u l e s
  734. X'''
  735. X.SH "USING THE DEFAULT RULES"
  736. XIf you do not want to use the filtering feature of the mailagent, then the
  737. Xdefault built-in rules will be used. Those are really simple: all the mails
  738. Xare left in your mailbox and mails with a line "Subject: Command" anywhere in
  739. Xthe message will be processed. Commands are looked for on lines starting with
  740. X"@SH". The remaining of the line is then given to a shell for execution.
  741. X.PP
  742. XAvailable commands are read from a file (entry \fIcomfile\fR in your
  743. Xconfiguration file), one command name per line. Only those listed there will
  744. Xbe executed, others will produce an error message. The mailagent traps
  745. Xthe exit status and will send an error report if a command fails (provided
  746. Xthat the command does not issue a message by itself, in which case it
  747. Xshould return a zero exit status).
  748. X.PP
  749. XIf you do not want to use the default rules, you may skip the remaining of this
  750. Xsection.
  751. X'''
  752. X.SS "Configuring Help"
  753. X.PP
  754. XThe help text the mailagent will send to people must be copied from
  755. X\fILib/mailagent/agenthelp\fR into your own spool directory, as specified in your
  756. X\fI~/.mailagent\fR. Two macros may be used:
  757. X.TP 10
  758. X.I =DEST=
  759. XThis will be expanded to the sender's address (the one who sent you
  760. Xthe mail currently processed by the mailagent).
  761. X.TP
  762. X.I =MAXSIZE=
  763. XThis stands for the maximum size set before \fIkit\fR is used to send
  764. Xfiles back (parameter \fImaxsize\fR in your \fI~/.mailagent\fR file\fR).
  765. X.PP
  766. XYou may use the default help file or design one that will give even more
  767. Xdetails to the poor user.
  768. X'''
  769. X.SS "Distribution Files"
  770. X.PP
  771. XThe two files \fIproglist\fR and \fIdistribs\fR held in \fILib/mailagent\fR
  772. Xdescribe the distributions your mailagent will be able to distribute.
  773. XThe samples given show the expected syntax. In order to clarify things,
  774. Xhere is what the format should be:
  775. X.PP
  776. XFile \fIproglist\fR contains a small description for programs. The name
  777. Xof the program appears after a single star. It is followed by lines in
  778. Xfree format. An optional three-dashes line separates each program's
  779. Xdescription. Note that a leading tab will be added to each line
  780. Xof description.
  781. X.PP
  782. XThe \fIdistribs\fR file holds lines of the following form:
  783. X.sp
  784. X.in +5
  785. X\fIprogname version path archived compressed patches\fR
  786. X.in -5
  787. X.sp
  788. Xwhere:
  789. X.TP 10
  790. X.I progname
  791. Xis the program name (the same as the one mentioned in \fIproglist\fR).
  792. X.TP
  793. X.I version
  794. Xis the current version number. If none, a three-dashed line may be used.
  795. X.TP
  796. X.I path
  797. Xis the path where the distribution is stored. The ~ will be expanded into
  798. Xyour home directory. Note that if the distribution is stored in archived
  799. Xform, the path name is the one of the archive without the ending
  800. Xextension (which may be \fI.cpio.Z\fR or \fI.tar.Z\fR).
  801. X.TP
  802. X.I archived
  803. Xis either \fIy\fR or \fIn\fR depending on whether the distribution is
  804. Xarchived or not.
  805. X.TP
  806. X.I compressed
  807. Xis either \fIy\fR or \fIn\fR depending on whether the distribution is
  808. Xcompressed or not. This could be guessed from the extension's name, but
  809. Xwe must think of file systems with short names.
  810. X.TP
  811. X.I patches
  812. Xis \fIy\fR or \fIn\fR depending on whether the distribution is
  813. Xmaintained or not by you. If you put a \fIp\fR, this means official
  814. Xpatches are available, although you do not maintain the distribution.
  815. XFinally, an \fIo\fR means that this is an old version, where only patches
  816. Xare available, but maildist will not work. In that case, assuming the
  817. Xversion number is \fI1.0\fR, old patches are expected in a \fIbugs-1.0\fR
  818. Xdirectory.
  819. X.PP
  820. XYou may include comments in both files: all lines starting with a leading
  821. X# will be ignored.
  822. X'''
  823. X.SS "Testing Your Mail Agent"
  824. X.PP
  825. XIt is now time to make sure your mailagent works. Send yourself the following
  826. Xmail:
  827. X.sp
  828. X.in +5
  829. X.nf
  830. XSubject: Command
  831. X@SH mailhelp
  832. X.fi
  833. X.in -5
  834. X.sp
  835. XYou should receive back a mail from yourself with the subject set to:
  836. X"How to use my mailagent". If you don't, check the file \fI~/.bak\fR
  837. X(or whatever file you set in your \fI.forward\fR). If it is empty, look
  838. Xat the log file. If the log file is not empty, then perhaps the mail
  839. Xhas been queued. Check the \fIsendmail\fR queue. Also make sure that
  840. Xyou removed the '#' comments in the \fIfilter\fR script. On some systems,
  841. Xthey cause some trouble. If you are using the C filter, maybe your sendmail
  842. Xis broken and you need to make your own setuid copy (or perl might complain
  843. Xthat you have a kernel bug, etc...).
  844. X.PP
  845. XIf you have done everything right but it still does not work properly,
  846. Xincrease log level to 20 and resend your command mail. Then check the
  847. Xlog file. The diagnosis should be easier.
  848. X.PP
  849. XOnce this works, you should check your \fIdistribs\fR and \fIproglist\fR
  850. Xfiles by sending yourself the following mail:
  851. X.sp
  852. X.in +5
  853. X.nf
  854. XSubject: Command
  855. X@SH maillist
  856. X.fi
  857. X.in -5
  858. X.sp
  859. XIf the list you have in return is incorrect, then your distribution files
  860. Xare wrongly written. If you do not get the list, there is a problem with
  861. Xyour mailagent's configuration. Retry with a log level set to 20 and look
  862. Xat the issued log messages in your Log directory. Make sure that the file
  863. Xlisted in the \fIplsave\fR entry of your \fI~/.mailagent\fR is correctly
  864. Xupdated after a \fImaillist\fR has been run.
  865. X'''
  866. X''' F i l t e r i n g   R u l e s
  867. X'''
  868. X.SH "USING THE FILTER"
  869. XThe \fImailagent\fR can also be used as a filter: mail is parsed and some
  870. Xactions are taken based on simple \fIlex\fR-like rules. Actions range from
  871. Xa simple saving in a folder, a forwarding to another person, or even spawning
  872. Xof a shell command. Before going further, here is a small example of a valid
  873. Xrule file:
  874. X.sp
  875. X.in +5
  876. X.nf
  877. XFrom: root { FORWARD postmaster };
  878. XTo: gue@eiffel.fr { POST mail.gue };
  879. XSubject: /metaconfig/ { SAVE dist };
  880. X.fi
  881. X.in -5
  882. X.sp
  883. XThere are three distinct rules. Rules are applied in sequence, until one
  884. Xmatches (so the order is important). Any mail coming from \fIroot\fR will be
  885. Xforwarded to user \fIpostmaster\fR. A mail addressed to \fIgue@eiffel.fr\fR is
  886. Xa mail coming from a mailing list. The mail is posted on a local newsgroup
  887. X\fImail.gue\fR. Mails whose subject contains the word "metaconfig" will be
  888. Xsaved in a folder \fIdist\fR for delayed reading and will not appear in the
  889. Xmain mailbox. If no rule matched, the mail is left in the mailbox.
  890. X'''
  891. X.SS "Syntax Of The Rule File"
  892. X.PP
  893. XHere is a non-formal description of the rule file. Parsing of the file is done
  894. Xlexically, hence the choice of non-ambiguous tokens like '{' or ';' which are
  895. Xeasily parsed. This introduces some limitations which are silently applied:
  896. Xfor instance, no '{' may be used as part of an address.
  897. X.PP
  898. XComments are introduced by a leading '#' , which must be on the left margin.
  899. XUnlike shell comments, a '#' which is not left justified will not be understood
  900. Xas a comment. However, spaces or tabs are allowed in front of '#'.
  901. X.PP
  902. XAll the statements in the rule file must end with a ';'. There are mainly
  903. Xfour parts in each line. A list of comma separated modes, between '<' and '>',
  904. Xwhich give the set of modes in which the rule applies. The special mode
  905. XALL will match everything. The filter begins in the mode INITIAL. Omitting the
  906. Xmode defaults to "<ALL>".
  907. X.PP
  908. XThen comes a list of selectors. Those selectors must be space separated and end
  909. Xwith ':'. They represent the names of header fields which must be looked at
  910. Xby the forthcoming pattern. An empty selector list defaults to "Subject:".
  911. XSpecial selectors "All:", "Body:" and "Head:" apply to the whole message,
  912. Xits body or its header. A commonly used selector list is "To Cc:" which tests
  913. Xthe recipient fields of the header. If the selector name is preceded by an
  914. Xexclamation mark '!', then the logical value of the test for that selector is
  915. Xnegated.
  916. X.PP
  917. XThe selector is then followed by a pattern within '/' or by a single name.
  918. XIn order to ease the writing of the rules, the semantic of a single name varies
  919. Xdepending on the selector used. For the special selector "From:", "To:", "Cc:"
  920. Xand "Apparently-To:", a single name is understood as a match on the \fIlogin
  921. Xname\fR of the address. Note that if no "To:" field is present in the header,
  922. Xone will be forged from the "Apparently-To:" for the purpose of filtering only
  923. X(i.e. no physical modification on the header is done). If the login name of
  924. Xthe address is a full name of the form First.Last, only the last name is
  925. Xkept, and is lower-cased. If only a single name is given, only shell
  926. Xmetacharacters * and ? are allowed, as well as intervals [].
  927. X.PP
  928. XIf the pattern is preceded by a single exclamation mark '!', then the
  929. Xmatching status is negated (i.e. it will succeed if the pattern is not found).
  930. XIf a single word
  931. Xis used for non-special selectors, the same rules apply but the pattern is
  932. Xanchored at the beginning and the end for an exact match. With a pattern
  933. Xstarting with '/', any regular expression understood by \fIperl\fR may be
  934. Xused and your pattern will not be modified in any way. The other special
  935. Xselector "Newsgroups:" works as "To:", excepted that newsgroups names are
  936. Xexpected and a match is attempted on every item in the list. Every pattern
  937. Xmatch on a single name for an address-type field (i.e. "Newsgroups:" excluded),
  938. Xare made in case-insensitive mode.
  939. X.PP
  940. XThere is also a little magic involved when matching on an address field. Namely,
  941. Xif the pattern is not a single word and is \fIanchored at the beginning\fR,
  942. Xthen only the address part of the field will be kept. For instance, if we
  943. Xhave a From: field whose value is \fIRaphael Manfredi <ram@eiffel.com>\fR, then
  944. Xthe pattern \fI/Raphael/\fR would match, but not \fI/^Raphael/\fR. Instead,
  945. X\fI/^ram@.*$/\fR would match, but this is more easily done with a single word
  946. Xpattern \fIram\fR, for it only focuses on the login name of the address and
  947. Xwould also match if the address was written as \fIeiffel.com!ram\fR.
  948. X.PP
  949. XThis may sound a little complex, but this design is meant to make things
  950. Xeasier for the user. Here are some other examples:
  951. X.sp
  952. X.in +5
  953. X.nf
  954. X# Match \fIram@eiffel.com\fR as well as \fIram@educ.emse.fr\fR.
  955. XFrom: ram
  956. X
  957. X# Match \fIroot@eiffel.com\fR, \fIram\fR but not \fIribbon@eiffel.com\fR
  958. XFrom: r[oa]*
  959. X
  960. X# Match \fIgue@eiffel.fr\fR but not \fIalgue@eiffel.fr\fR
  961. XTo Cc: gue@eiffel.fr
  962. X
  963. X# This will match \fIgue@eiffel.fr\fR as well as \fIalgue@eiffel.com\fR
  964. XTo Cc: /gue@eiffel/
  965. X
  966. X# Match \fIcomp.lang.perl\fR but not \fIcomp.lang.perl.poetry\fR (?)
  967. XNewsgroups: comp.lang.perl
  968. X
  969. X# Accept anything but messages coming from \fIroot\fR
  970. XFrom: !root
  971. X.fi
  972. X.in -5
  973. X.sp
  974. XWhen attempting a match on "To:", "Cc:" or "Apparently-To:", a
  975. Xlist of addresses separated by a comma is expected, whereas only one
  976. Xaddress is expected after "From:". If you omit the pattern, it will be
  977. Xunderstood as * (recall that a single word uses shell meta-characters), which
  978. Xwill match anything.
  979. X.PP
  980. XThen comes the action to be taken when a match occurs. There are only a
  981. Xlimited set of valid actions which will be described soon in detail. The
  982. Xaction is enclosed in curly braces '{' and '}' and actions are separated or
  983. Xterminated (depending on your taste) by a ';'. Action names are spelled in
  984. Xupper-case for readability, but case is irrelevant. If you want to put a ';'
  985. Xwithin the rule, it must be escaped by preceding it with a backslash.
  986. XA double backslash is translated into a single one, and any other escape
  987. Xsequence involving the backslash character is ignored (i.e. \\\\n would
  988. Xbe kept verbatim).
  989. X.PP
  990. XNote that a rule should
  991. Xbe ended by a single ';' after the last '}'. It is possible to omit this
  992. Xfinal ';', but that single token is the resynchronizing point for error
  993. Xrecovery. One could argue however that there should be no syntax error, and
  994. Xthus the ';' ought to be safely omitted. Whenever in doubt, check your rule
  995. Xfile with the \fB\-d\fR option.
  996. X.PP
  997. XHere is a prototypical rule:
  998. X.sp
  999. X.in +5
  1000. X.nf
  1001. X<ROOT> From: /^\\\\w+@eiffel.com$/ { SAVE eiffel };
  1002. X.fi
  1003. X.in -5
  1004. X.sp
  1005. XThat rule will only be taken into account when the filter is in the mode ROOT
  1006. X(recall that the processing starts in mode INITIAL; use BEGIN to change the
  1007. Xmode, as in \fIlex\fR). So in mode ROOT, anything which comes from a user
  1008. Xlocated in the \fIeiffel.com\fR site is saved in folder \fIeiffel\fR for
  1009. Xdeferred reading. The mail will not appear in the mailbox.
  1010. X.PP
  1011. XIt is possible to have more than one selection for a rule. Identical selectors
  1012. Xare logically \fIor\fR'ed while different ones are \fIand\fR'ed. The selections
  1013. Xare comma separated. For instance,
  1014. X.sp
  1015. X.in +5
  1016. X.nf
  1017. XFrom: root, To: ram, From: ram, Subject: /\\\\btest\\\\b/ { DELETE };
  1018. X.fi
  1019. X.in -5
  1020. X.sp
  1021. Xwill delete a mail from \fIroot\fR or \fIram\fR if it is sent to \fIram\fR
  1022. Xand has the word \fItest\fR in its subject. It is also possible to write the
  1023. Xprevious rule as:
  1024. X.sp
  1025. X.in +5
  1026. X.nf
  1027. XFrom: root, ram, To: ram, Subject: /\\\\btest\\\\b/ { DELETE };
  1028. X.fi
  1029. X.in -5
  1030. X.sp
  1031. Xbecause if no selector is given, the previous one is used (with the first
  1032. Xselector being "Subject:" by default).
  1033. X.PP
  1034. XAnywhere in the rule file, it is possible to define some variables. The list
  1035. Xof recognized variables is given later. For now, let's say that \fImaildir\fR
  1036. Xis the default folder directory. This variable is used by the SAVE command
  1037. Xwhen the argument is not an absolute path. Setting
  1038. X.sp
  1039. X.in +5
  1040. Xmaildir = ~/mail;
  1041. X.in -5
  1042. X.sp
  1043. Xwill direct the filter to use \fI~/mail\fR as the folder directory (default is
  1044. X\fI~/Mail\fR). Note the ~ substitution and the final ';'. It is not possible
  1045. X(currently) to modify the environment by setting PATH for instance.
  1046. X.PP
  1047. XFinally, there is a special construct to load patterns from a file. A pattern
  1048. Xenclosed in double quotes means that the patterns to be applied should be
  1049. Xtaken from the specified file. The file is expected to be in the directory
  1050. X\fImailfilter\fR if it is not an absolute path (~ substitution occurs). If
  1051. Xthe variable is not set \fImaildir\fR will be used. If by chance (!)
  1052. X\fImaildir\fR is not set either, the home directory is used. The file should
  1053. Xcontain one pattern per line, shell comments (#) being allowed at the beginning
  1054. Xof each line.
  1055. X.PP
  1056. XAn action may be followed by other rules. Hence the following is perfectly
  1057. Xvalid:
  1058. X.sp
  1059. X.in +5
  1060. X.nf
  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.fi
  1069. X.in -5
  1070. X.sp
  1071. XNote the use of the file inclusion: all the users listed in file \fIusers\fR
  1072. Xwill have their mail left in the system mailbox. The usual rules apply for
  1073. Xthese loaded patterns.
  1074. X'''
  1075. X.SS "Selector Combination"
  1076. X.PP
  1077. XA single rule may have a various set of selectors. For instance, in the
  1078. Xfollowing rule:
  1079. X.sp
  1080. X.in +5
  1081. X.nf
  1082. XFrom: ram, To Cc: root, !Subject: /test/, From: raphael
  1083. X.fi
  1084. X.in -5
  1085. X.sp
  1086. Xwe have the following set { From, To Cc, !Subject }. The first tow selectors
  1087. Xare called \fIdirect\fR selectors, !Subject: is called a \fInegated\fR selector.
  1088. XThe To Cc: selector is a \fIgroup\fR selector decomposing into two \fIdirect\fR
  1089. Xselectors, while From: is an \fIatomic\fR selector. Finally, From: is also
  1090. Xa selector with \fImultiple\fR occurences. The \fIvalue\fR of a selector is
  1091. Xits matching status logical value.
  1092. X.PP
  1093. XLet \fID\fR be the set of of direct selectors and \fIN\fR the set of
  1094. Xnegated selectors, which form a partition of \fIR\fR, the set of all the
  1095. Xselectors in the rule. That is to say, \fIR\fR is the union of \fID\fR
  1096. Xand \fIN\fR, and \fID\fR intersected with \fIN\fR is the empty set
  1097. X(trivial proof: a selector is either direct or negated). If either \fID\fR
  1098. Xor \fIN\fR is empty, then it's not a partition but in that case we have
  1099. Xeither \fID\fR = \fIR\fR or else \fIN\fR = \fIR\fR.
  1100. X.PP
  1101. XLet's define the logical value of a set \fIS\fR as being the logical
  1102. Xvalue the filter would return if those rules were actually written.
  1103. XThen the logical value of \fID\fR is the logical value of each of its item
  1104. Xwith the AND logical operator distributed among them, i.e. the logical
  1105. Xvalue of { a, b, c } is the value of (a AND b AND c). Let's write it
  1106. XAND(\fID\fR). The logical value of each of the items is the logical value of
  1107. Xthe selector itself if it is not multiple, or it is the logical value of
  1108. Xall the occurences of the multiple selector within the rule, with the
  1109. Xlogical OR operation distributed among them. That is to say, in the
  1110. Xabove example, the value of From is true iff the From: fields contains
  1111. X\fIram\fR OR \fIraphael\fR.  Let's write that OR[From].
  1112. X.PP
  1113. XTo be sound, we have to apply De Morgan's Law on \fIN\fR, hence the following
  1114. Xrules: the logical value of \fIN\fR is OR(\fIN\fR) and given a negated selector
  1115. X\fIs\fR, its logical value is AND[\fIs\fR]. And finally, the logical value of
  1116. X\fIR\fR is that of \fID\fR AND \fIN\fR, with by convention having the logical
  1117. Xvalue of the empty set be \fItrue\fR.
  1118. X.PP
  1119. XFor those who do not know De Morgan's Law, here it is: given two logical
  1120. Xpropositions \fIp\fR and \fIq\fR, then the following identities occur:
  1121. X.sp
  1122. X.in +5
  1123. X.nf
  1124. XNOT (p AND q) <=> (NOT p) OR (NOT q)
  1125. XNOT (p OR q) <=> (NOT p) AND (NOT q)
  1126. X.fi
  1127. X.in -5
  1128. X.sp
  1129. XWhile we are in the logic of the propositions,
  1130. Xnote also that OR and AND are mutually distributive, that is to say, given
  1131. Xthree logical propositions \fIp\fR, \fIq\fR and \fIr\fR, we have:
  1132. X.sp
  1133. X.in +5
  1134. X.nf
  1135. Xp AND (q OR r) <=> (p AND q) OR (p AND r)
  1136. Xp OR (q AND r) <=> (p OR q) AND (p OR r)
  1137. X.fi
  1138. X.in -5
  1139. X.sp
  1140. XTo be complete, OR and AND are associative with themseleves and commutative.
  1141. XAnd the \fIB\fR set { 0, 1 } equiped with the set of operations (NOT, OR, AND)
  1142. Xis an \fIalgebra\fR (a Boolean one). I will spare you the definition of an
  1143. Xalgebra, which really has nothing to do in this manual page (which is for a
  1144. Xmail agent, in case you don't remember :-).
  1145. X.PP
  1146. XThe attentive reader will certainly have noted that I have not specified
  1147. Xthe logical value of a group selector. Well, given a group selector \fIG\fR,
  1148. Xwe decompose it into a \fIDG\fR and \fING\fR partition, \fIDG\fR being the
  1149. Xsubset of (atomic) direct selectors of \fIG\fR and \fING\fR being the subset of
  1150. X(atomic) negated selectors.  Then the logical value of \fIDG\fR is
  1151. XOR(\fIDG\fR) and the logical value of \fING\fR is AND(\fING\fR);
  1152. Xthe global logical value of \fIG\fR being that of \fIDG\fR OR \fING\fR.
  1153. XIn case either \fIDG\fR or \fING\fR is empty, then we don't have a partition,
  1154. Xbut by convention the value of the empty set is \fIfalse\fR, and one of the
  1155. Xsets is equal to \fIG\fR.
  1156. XNote that within a group selector, the rules are exactly the dual of the
  1157. Xrules within \fIR\fR.
  1158. X.PP
  1159. XNow the only rule which is not \fIlogical\fR is whether a group selector
  1160. Xbelongs to \fID\fR or \fIN\fR. I've chosen, for analogy reasons, to make the
  1161. Xgroup selector belong to \fID\fR if it does not start by '!' and to \fIN\fR
  1162. Xotherwise. That is, !To Cc: belongs to \fIN\fR whilst Cc !To: belongs to
  1163. X\fID\fR. Appart from that, order within the group selector is irrelevant:
  1164. XTo Cc: is equivalent to Cc To:, so the behaviour in the quotient set is sound.
  1165. X.PP
  1166. XHere are some examples:
  1167. X.sp
  1168. X.in +5
  1169. X.nf
  1170. X# Match anything: (not from ram OR not from root) is always true.
  1171. XFrom: !ram, !root
  1172. X
  1173. X# Match anything but reject mails coming from ram OR root
  1174. X!From: ram, root
  1175. X
  1176. X# Reject mails whose headers matching /^Re.*/ contain the word test
  1177. X!^Re.*: /\\\\btest\\\\b/
  1178. X
  1179. X# Keep mails whose subject contains \fItest\fR AND \fIhost\fR
  1180. X!Subject: !/test/, !/host/
  1181. X
  1182. X# Matches if \fIram\fR is listed in the \fITo\fR OR the \fICc\fR line
  1183. XTo Cc: ram
  1184. X.fi
  1185. X.in -5
  1186. X.sp
  1187. X'''
  1188. X.SS "Minimal Header"
  1189. X.PP
  1190. XA minimal set of selectors are guaranteed to be set, regardless of the
  1191. Xactual header of the message. This is for the purpose of filtering only,
  1192. Xno physical alteration is performed.
  1193. X.sp
  1194. X.PD 0
  1195. X.TP 10
  1196. X.I From:
  1197. XUser who wrote the mail. If this line is missing, uses the address found in
  1198. Xthe first From line.
  1199. X.TP
  1200. X.I To:
  1201. XThe main recipient(s) of the message. If this line is missing but a set of
  1202. X\fIApparently-To:\fR lines is found, then those addresses are used instead. If
  1203. END_OF_FILE
  1204.  if test 40771 -ne `wc -c <'agent/man/mailagent.SH.a'`; then
  1205.     echo shar: \"'agent/man/mailagent.SH.a'\" unpacked with wrong size!
  1206.  elif test -f 'agent/man/mailagent.SH.b'; then
  1207.     echo shar: Combining  \"'agent/man/mailagent.SH'\" \(91668 characters\)
  1208.     cat 'agent/man/mailagent.SH.a' 'agent/man/mailagent.SH.b' > 'agent/man/mailagent.SH'
  1209.     if test 91668 -ne `wc -c <'agent/man/mailagent.SH'`; then
  1210.       echo shar: \"'agent/man/mailagent.SH'\" combined with wrong size!
  1211.     else
  1212.       chmod u+x agent/man/mailagent.SH
  1213.       rm agent/man/mailagent.SH.a agent/man/mailagent.SH.b
  1214.     fi
  1215.   fi
  1216.   # end of 'agent/man/mailagent.SH.a'
  1217. fi
  1218. if test ! -d 'agent/pl' ; then
  1219.     echo shar: Creating directory \"'agent/pl'\"
  1220.     mkdir 'agent/pl'
  1221. fi
  1222. if test ! -d 'agent/test' ; then
  1223.     echo shar: Creating directory \"'agent/test'\"
  1224.     mkdir 'agent/test'
  1225. fi
  1226. if test ! -d 'agent/test/basic' ; then
  1227.     echo shar: Creating directory \"'agent/test/basic'\"
  1228.     mkdir 'agent/test/basic'
  1229. fi
  1230. if test ! -d 'agent/test/cmd' ; then
  1231.     echo shar: Creating directory \"'agent/test/cmd'\"
  1232.     mkdir 'agent/test/cmd'
  1233. fi
  1234. if test ! -d 'agent/test/filter' ; then
  1235.     echo shar: Creating directory \"'agent/test/filter'\"
  1236.     mkdir 'agent/test/filter'
  1237. fi
  1238. if test -f 'agent/test/filter/hook.t' -a "${1}" != "-c" ; then 
  1239.   echo shar: Will not clobber existing file \"'agent/test/filter/hook.t'\"
  1240. else
  1241.   echo shar: Extracting \"'agent/test/filter/hook.t'\" \(2086 characters\)
  1242.   sed "s/^X//" >'agent/test/filter/hook.t' <<'END_OF_FILE'
  1243. X# Test hooking facilities
  1244. Xdo '../pl/filter.pl';
  1245. Xdo '../pl/logfile.pl';
  1246. Xunlink 'never', 'always', 'always.2', 'always.3';
  1247. Xunlink 'hook.1', 'hook.2', 'hook.3', 'hook.4';
  1248. X
  1249. Xopen(HOOK, '>hook.1') || print "1\n";
  1250. Xprint HOOK <<'EOH';
  1251. X#! /bin/sh
  1252. Xcat > always
  1253. Xexit 0
  1254. XEOH
  1255. Xclose HOOK;
  1256. X
  1257. Xopen(HOOK, '>hook.2') || print "2\n";
  1258. Xprint HOOK <<'EOH';
  1259. X#: deliver
  1260. Xopen(OUT, '>always.2') || exit 1;
  1261. Xprint OUT "$login\n";
  1262. Xclose OUT;
  1263. Xprint "SAVE ~/always; RUN /bin/echo hi! > always.3";
  1264. XEOH
  1265. Xclose HOOK;
  1266. X
  1267. Xopen(HOOK, '>hook.3') || print "3\n";
  1268. Xprint HOOK <<'EOH';
  1269. X#: rules
  1270. X!To: ram { SAVE never };
  1271. X{ SAVE ~/always; RUN /bin/echo hi! > always.3 };
  1272. XEOH
  1273. Xclose HOOK;
  1274. X
  1275. Xopen(HOOK, '>hook.4') || print "29\n";
  1276. Xprint HOOK <<'EOH';
  1277. X#: perl
  1278. X&save("~/always");
  1279. X&run("/bin/echo hi! > always.3");
  1280. XEOH
  1281. Xclose HOOK;
  1282. Xchmod 0544, 'hook.1', 'hook.2', 'hook.3', 'hook.4';
  1283. X
  1284. X&add_header('X-Tag: hook #1');
  1285. X`$cmd`;
  1286. X$? == 0 || print "4\n";
  1287. X-f 'never' && print "5\n";
  1288. X&get_log(6, 'always');
  1289. X&check_log('^To: ram', 7) == 1 || print "8\n";
  1290. X&get_log(9, 'hook.1');
  1291. X¬_log('^To: ram', 10);
  1292. Xunlink 'never', 'always', 'always.2', 'always.3';
  1293. X
  1294. X&replace_header('X-Tag: hook #2');
  1295. X`$cmd`;
  1296. X$? == 0 || print "11\n";
  1297. X-f 'never' && print "12\n";
  1298. X&get_log(13, 'always');
  1299. X&check_log('^To: ram', 14) == 1 || print "15\n";
  1300. X&get_log(16, 'always.3');
  1301. X&check_log('^hi!', 17) == 1 || print "18\n";
  1302. X&get_log(19, 'always.2');
  1303. X&check_log('^compilers-request$', 20);
  1304. Xunlink 'never', 'always', 'always.2', 'always.3';
  1305. X
  1306. X&replace_header('X-Tag: hook #3');
  1307. X`$cmd`;
  1308. X$? == 0 || print "21\n";
  1309. X-f 'never' && print "22\n";
  1310. X&get_log(23, 'always');
  1311. X&check_log('^To: ram', 24) == 1 || print "25\n";
  1312. X&get_log(26, 'always.3');
  1313. X&check_log('^hi!', 27) == 1 || print "28\n";
  1314. Xunlink 'never', 'always', 'always.2', 'always.3';
  1315. X
  1316. X&replace_header('X-Tag: hook #4');
  1317. X`$cmd`;
  1318. X$? == 0 || print "30\n";
  1319. X-f 'never' && print "31\n";
  1320. X&get_log(32, 'always');
  1321. X&check_log('^To: ram', 33) == 1 || print "34\n";
  1322. X&get_log(35, 'always.3');
  1323. X&check_log('^hi!', 36) == 1 || print "37\n";
  1324. X
  1325. Xunlink 'hook.1', 'hook.2', 'hook.3', 'hook.4';
  1326. Xunlink 'never', 'always', 'always.2', 'always.3';
  1327. Xprint "0\n";
  1328. END_OF_FILE
  1329.   if test 2086 -ne `wc -c <'agent/test/filter/hook.t'`; then
  1330.     echo shar: \"'agent/test/filter/hook.t'\" unpacked with wrong size!
  1331.   fi
  1332.   # end of 'agent/test/filter/hook.t'
  1333. fi
  1334. if test ! -d 'agent/test/option' ; then
  1335.     echo shar: Creating directory \"'agent/test/option'\"
  1336.     mkdir 'agent/test/option'
  1337. fi
  1338. if test ! -d 'agent/test/pl' ; then
  1339.     echo shar: Creating directory \"'agent/test/pl'\"
  1340.     mkdir 'agent/test/pl'
  1341. fi
  1342. if test ! -d 'bin' ; then
  1343.     echo shar: Creating directory \"'bin'\"
  1344.     mkdir 'bin'
  1345. fi
  1346. echo shar: End of archive 1 \(of 17\).
  1347. cp /dev/null ark1isdone
  1348. MISSING=""
  1349. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ; do
  1350.     if test ! -f ark${I}isdone ; then
  1351.     MISSING="${MISSING} ${I}"
  1352.     fi
  1353. done
  1354. if test "${MISSING}" = "" ; then
  1355.     echo You have unpacked all 17 archives.
  1356.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1357. else
  1358.     echo You still must unpack the following archives:
  1359.     echo "        " ${MISSING}
  1360. fi
  1361. exit 0
  1362. exit 0 # Just in case...
  1363.