home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / sources / misc / 4098 < prev    next >
Encoding:
Text File  |  1992-11-19  |  54.4 KB  |  1,370 lines

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