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

  1. Newsgroups: comp.sources.misc
  2. From: Raphael Manfredi <ram@acri.fr>
  3. Subject: v41i003:  mailagent - Flexible mail filtering and processing package, v3.0, Part03/26
  4. Message-ID: <1993Dec2.133530.17946@sparky.sterling.com>
  5. X-Md4-Signature: 4a3517124d4c3cd0fdefa3611e0589b8
  6. Sender: kent@sparky.sterling.com (Kent Landfield)
  7. Organization: Advanced Computer Research Institute, Lyon, France.
  8. Date: Thu, 2 Dec 1993 13:35:30 GMT
  9. Approved: kent@sparky.sterling.com
  10.  
  11. Submitted-by: Raphael Manfredi <ram@acri.fr>
  12. Posting-number: Volume 41, Issue 3
  13. Archive-name: mailagent/part03
  14. Environment: UNIX, Perl
  15. Supersedes: mailagent: Volume 33, Issue 93-109
  16.  
  17. #! /bin/sh
  18. # This is a shell archive.  Remove anything before this line, then feed it
  19. # into a shell via "sh file" or similar.  To overwrite existing files,
  20. # type "sh file -c".
  21. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  22. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  23. # Contents:  agent/files/proglist agent/man/mailagent.SH.03
  24. # Wrapped by ram@soft208 on Mon Nov 29 16:49:54 1993
  25. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  26. echo If this archive is complete, you will see the following message:
  27. echo '          "shar: End of archive 3 (of 26)."'
  28. if test -f 'agent/files/proglist' -a "${1}" != "-c" ; then 
  29.   echo shar: Will not clobber existing file \"'agent/files/proglist'\"
  30. else
  31.   echo shar: Extracting \"'agent/files/proglist'\" \(2060 characters\)
  32.   sed "s/^X//" >'agent/files/proglist' <<'END_OF_FILE'
  33. X# Small descriptions for programs
  34. X
  35. X* cshar
  36. XThe useful shell-archive maker. I modified the original
  37. Xslightly to add a Configure script.
  38. X---
  39. X
  40. X* kit
  41. XA simple binary tarmailer. This is used by the mail agent when
  42. Xmailing big sets of files. You presently need cshar (from
  43. XRich Salz) to use kit.
  44. X---
  45. X
  46. X* dist
  47. XLarry Wall's dist package, modified. It contains:
  48. X    - metaconfig, a Configure script generator
  49. X    - a patch generator
  50. X    - a distribution maker
  51. XIt comes from version Larry's dist 2.0 PL 2 package, but has
  52. Xquite a few extensions (I worked especially on the patch
  53. Xgenerating tools and metaconfig itself). The units used by
  54. Xmetaconfig have been manually ripped off from some recently
  55. Xposted Configure scripts (elm 2.3, perl 3.0).
  56. X---
  57. X
  58. X* matrix
  59. XAn object-oriented matrix library. It is a beta-test release.
  60. X---
  61. X
  62. X* file
  63. XThe file(1) command with lots of /etc/magic entries. Useful
  64. Xwhen you work with NFS on different architectures as you
  65. Xcan have your own magic file.
  66. X---
  67. X
  68. X* rcs
  69. XGNU Revision Control System. You need RCS to use Larry's
  70. Xdist package (patch generating tools).
  71. X---
  72. X
  73. X* cops
  74. XSecurity analysis tools. May be useful to find holes in
  75. Xyour system.
  76. X---
  77. X
  78. X* xfmt
  79. XSimple text formatter. You need flex to compile it.
  80. XIt looks like SUN-OS fmt program.
  81. X---
  82. X
  83. X* less
  84. XThe pager that is more than more(1).
  85. X---
  86. X
  87. X* flex
  88. XFast lex. Needed for the xfmt package, because lex is not
  89. Xpowerful enough.
  90. X---
  91. X
  92. X* et
  93. XError table compiler (from MIT).
  94. X---
  95. X
  96. X* undel
  97. XReplacement for rm(1). Marks files for deletion instead of
  98. Xremoving them. You need the et package for version 2.0 to
  99. Xcompile.
  100. X---
  101. X
  102. X* dither
  103. XDisplays a color image on a two-level display (White and black).
  104. XUses a non-standard picture format in input and output
  105. X(that's mine ! :-)).
  106. X---
  107. X
  108. X* perl
  109. XLarry Wall's Practical Extraction and Report Language. It
  110. Xcombines the best features of C, awk, sed and sh.
  111. XYou need it to use the dist package.
  112. X---
  113. X
  114. X* patch
  115. XThe useful utility to apply diff files on a distribution. You could
  116. Xof course apply them by hand, but it may well be a long procedure !
  117. XWritten by Larry Wall.
  118. X---
  119. END_OF_FILE
  120.   if test 2060 -ne `wc -c <'agent/files/proglist'`; then
  121.     echo shar: \"'agent/files/proglist'\" unpacked with wrong size!
  122.   fi
  123.   # end of 'agent/files/proglist'
  124. fi
  125. if test -f 'agent/man/mailagent.SH.03' -a "${1}" != "-c" ; then 
  126.   echo shar: Will not clobber existing file \"'agent/man/mailagent.SH.03'\"
  127. else
  128.   echo shar: Extracting \"'agent/man/mailagent.SH.03'\" \(49980 characters\)
  129.   sed "s/^X//" >'agent/man/mailagent.SH.03' <<'END_OF_FILE'
  130. Xsee who runs my mailagent program and who doesn't...
  131. X.PP
  132. XThe \fIsendmail\fR program usually implements such a feature via a
  133. XReturn-Receipt-To: header line, which sends the whole header back upon
  134. Xsuccessful delivery. However, this is not implemented on all mail transport
  135. Xagents, and @RR is a good alternative :-).
  136. X.SH "NOTA BENE"
  137. XThroughout this manual page, I have always written header fields with the first
  138. Xletter of each word uppercased, as in \fIReturn-Receipt-To\fR. But RFC-822 does
  139. Xnot impose this spelling convention, and a mailer could legally rewrite the
  140. Xprevious field as \fIreturn-receipt-to\fR (and in fact so does \fIsendmail\fR
  141. Xin its own private mail queue files).
  142. X.PP
  143. XHowever, you must always specify the headers in what could be called a
  144. X\fInormalized\fR case (for headers anyway). The mailagent will correctly
  145. Xrecognize \fIcc:\fR, \fICC:\fR or \fICc:\fR in a mail message and will allow
  146. Xyou to select those fields via the normalized \fICc:\fR selector. In fact, it
  147. Xoperates the normalization for you, and a \fIcc:\fR selector would not be
  148. Xrecognized as such. Of course, no physical alteration is ever made on the
  149. Xheader itself.
  150. X.PP
  151. XThis is also true for headers specified in the STRIP or KEEP command. If you
  152. Xwrite \fISTRIP Cc\fR, it will correctly remove any \fIcc:\fR line. Likewise,
  153. Xif you use regular expressions to specify a selector, \fIRe.*:\fR would match
  154. Xboth original \fIreceived:\fR and \fIReturn-path:\fR fields, internally known
  155. Xthrough their normalized representation.
  156. X.SH "MAIL HOOKS"
  157. XThe mail hooks allow the mailagent to transparently invoke some scripts or
  158. Xperform further processing on the message. Those hooks are activated via
  159. Xthe SAVE, STORE or LEAVE commands. Namely, saving in a folder whose executable
  160. Xbit is set will raise a special processing. By default, the folder is taken
  161. Xas a program where the mail should be piped to. If the "folder" program
  162. Xreturns a zero status, then the message is considered \fIsaved\fR by the
  163. Xmailagent. Otherwise, all the processing attached to failed save commands is
  164. Xstarted (including emergency saving attempts). Executable folders provide a
  165. Xtransparent way (from the rule file point of view) to deal with special
  166. Xkind of messages.
  167. X.PP
  168. XIn fact, five different types of hooks are available. The first one is the
  169. Xplain executable folder we have just spoken about. But in fact, here is what
  170. Xreally happens when a saving command detects an executable folder: the
  171. Xmailagent scans the first line of the
  172. Xfolder (in fact, the first 128 bytes) and looks for something starting with
  173. X#: and followed by a single word, describing a special kind of hook. This is
  174. Xsimilar in the way the kernel deals with the #! hook in executable programs.
  175. XIf no #: is found or #: is followed by some garbage, then \fImailagent\fR
  176. Xdecides
  177. Xit is a simple program and feeds the mail message to this program. End of the
  178. Xstory.
  179. X.PP
  180. XBut if the #: token is followed (spaces allowed, case is irrelevant) by one of
  181. Xthe following words, then special actions are taken:
  182. X.PD
  183. X.TP 10
  184. X.I rules
  185. XThe file holds a set of mailagent rules which are to be applied. A new mailagent
  186. Xprocess is created to actually deal with those and the exit status is
  187. Xpropagated back to the original mailagent.
  188. X.TP
  189. X.I audit
  190. XThis is similar in spirit to what Martin Streicher's audit.pl package does,
  191. Xhence the name of this hook. The special variables which are set up by the
  192. XPERL filter commands are initialized and the script is loaded in the special
  193. X\fImailhook\fR package name space, which also gives you an interface to the
  194. Xmailagent's own routines.
  195. XYou may safely use the \fIexit\fR function here, since
  196. Xan extra \fIfork\fR is done. This is the only difference between an \fIaudit\fR
  197. Xand a \fIperl\fR hook.
  198. X.TP
  199. X.I deliver
  200. XSame thing as for the \fIaudit\fR hook, but the standard output of your script
  201. Xis monitored by \fImailagent\fR and understood as mailagent filtering commands.
  202. XUpon successful return, a mailagent process will be invoked to actually execute
  203. Xthose commands on the message. Again, this is similar in spirit to Chip
  204. XSalzenberg's \fIdeliver\fR package and gave the name of this hook.
  205. X.TP
  206. X.I perl
  207. XThis hook is the same as \fIaudit\fR but it is executed without forking a
  208. Xnew mailagent, and
  209. Xyou have the perl interface to the mailagent's filtering commands. There is
  210. Xno difference with the PERL command, because it is implemented that way, by
  211. Xcalling a mailagent and forcing the PERL command to be executed. This is
  212. Xsimilar in spirit to Larry Wall's famous \fIperl\fR language and it is
  213. Xresponsible for the name of this hook :-).
  214. X.PP
  215. XAs mentioned earlier in this manual page, the hook is invoked from with the
  216. X\fIhome\fR directory specified in your ~/.mailagent (which may differ from
  217. Xyour real home directory, as far as \fImailagent\fR or \fImailhook\fR are
  218. Xconcerned).
  219. X.PP
  220. XFor those hooks which are finally ran by perl, the special @INC array has
  221. Xthe mailagent's own private library path prepended to it, so that \fIrequire\fR
  222. Xfirst looks in this place.
  223. X.SH "FOLDERS"
  224. XA folder is a file or a directory which can be the target of a delivery by the
  225. Xmailagent, that is to say the argument of SAVE-like commands.
  226. X'''
  227. X.SS "Folder Format"
  228. X.PP
  229. XBy default, mails are written into folders according to the standard UNIX-style
  230. Xmailbox format: each mail starts with a leading \fIFrom\fR line bearing the
  231. Xsender's address and the date. However, by setting the \fImmdf\fR parameter
  232. Xfrom the \fI~/.mailagent\fR to ON, the \fImailagent\fR will be able to save
  233. Xmessages in MMDF format: each message is sandwiched between two lines of four
  234. Xctrl-A characters (ASCII code 1) and the leading \fIFrom\fR line is removed.
  235. X.PP
  236. XWhen MMDF mode is activated, each folder will be scanned to see if it is a
  237. XUNIX-style or MMDF-style mailbox and the message will be saved accordingly.
  238. XWhen saving to a new folder, the default is to create a UNIX-style mailbox,
  239. Xunless the \fImmdfbox\fR configuration variable was set to ON, in which case
  240. Xthe MMDF format prevails.
  241. X.PP
  242. XNote that the MMDF format is also the standard for MH packed folders, so by
  243. Xenabling the MMDF mode, you can actually deliver directly to those packed
  244. Xfolders. The MH command \fIinc\fR is able to incorporate mail from either
  245. Xform anyway, i.e. it does not matter whether the folder is in UNIX format
  246. X(also called UUCP-style) or in MMDF format.
  247. X.PP
  248. XMH-style folders are also supported. It is mainly a directory in which messages
  249. Xare stored in individual files. To save directly into an MH folder, simply
  250. Xprefix the folder name with '+', just as you would do with MH commands.
  251. XThe unseen sequences specified in your MH profile (the \fImhprofile\fR
  252. Xparameter in your \fI~/.mailagent\fR, default is \fI~/.mh_profile\fR)
  253. Xwill be correctly updated, as \fIrcvstore\fR would.
  254. X.PP
  255. XWhen the target folder is a directory, mailagent attempts the delivery in
  256. Xan individual numbered file. If a prefix file is present
  257. X(config parameter \fImsgprefix\fR, default is \fI.msg_prefix\fR), its first
  258. Xline is used to specify the base name of the message, then a number is
  259. Xappended to give the name of the message file to use. That is, if there is
  260. Xno such file, the folder will look like an MH one, without any MH sequence
  261. Xfile though.
  262. X'''
  263. X.SS "Folder Compression"
  264. X.PP
  265. XIf you have \fIcompress\fR in your PATH (as set up by \fI~/.mailagent\fR), then
  266. Xyou may wish to use folder compression to save some disk space, especially when
  267. Xyou are away for some time and do not want to see your mail fill-up the
  268. Xfilesystem.
  269. X.PP
  270. XTo achieve folder compression, you have to set up a file, referred to by the
  271. X\fIcompress\fR configuration variable. This file must list folder names, one
  272. Xper line, with blank lines ignored and shell-style (#) comments allowed. You
  273. Xmay use shell-style patterns to specify the folders, and the match will be
  274. Xattempted on the full pathname of the folder (~ substitution occurs). If you
  275. Xdo not specify a pattern starting with a leading '/' character, then the match
  276. Xwill be attempted on the basename of the folder (i.e. the last component of
  277. Xthe folder path). If you want to compress all your folders, then simply put
  278. Xa single '*' inside this file.
  279. X.PP
  280. XWhen attempting delivery, the mailagent will check the folder name against
  281. Xthe list of patterns in the compress file. If there is a match, the folder is
  282. Xflagged as compressed. Then the mailagent attempts decompression if there
  283. Xis already a compressed form (a .Z file) and if no uncompressed form is present.
  284. XDelivery is then made to the uncompressed folder. However, re-compression is not
  285. Xdone immediately, since it is still possible to get messages to that folder in
  286. Xa single batch delivery. Should disk space become so tight that decompression
  287. Xof other folders is impossible, the mailagent will re-compress the folders
  288. Xit has already uncompressed. Otherwise, it waits until the last moment.
  289. X.PP
  290. XIf for some reason there is a .Z compressed folder which cannot be decompressed,
  291. Xthe mailagent will deliver the mail to the plain folder. Further delivery
  292. Xto that folder will be faced with both a compressed and a plain version of the
  293. Xfolder, and that will get you a warning in the log file, but delivery will be
  294. Xmade automatically to the plain file.
  295. X'''
  296. X''' E x t e n d i n g   F i l t e r i n g   C o m m a n d s
  297. X'''
  298. X.SH EXTENDING FILTERING COMMANDS
  299. XOnce you've reached the \fIexpert\fR level, and provided you have a fair
  300. Xknowledge of \fIperl\fR, you may feel the need for more advanced commands
  301. Xwhich are not part of the standard set. This section explains how you
  302. Xcan achieve this dynamically, without the need of diving deep inside the
  303. Xsource code.
  304. X.PP
  305. XOnce you have extended the filtering command set, you may use those commands
  306. Xinside the rule file as if they were built-in. You may even choose to redefine
  307. Xthe standard commands if they do not suit you (however, if you wish to do
  308. Xthat, you should know exactly what you are doing, or you may start loosing
  309. Xsome mail or get an unexpected behavior -- this also voids your warranty :-).
  310. X.PP
  311. XThe ability to provide external commands without actually modifying the main
  312. Xsource code is, I believe, a strong point in favor of having a program written
  313. Xin an interpreted language like \fIperl\fR. This of course once you have
  314. Xconvinced yourself that it is a Good Thing to customize and extend a program
  315. Xin the same language as the one used for the core, meaning usually a fairly
  316. Xlow-level language with fewer user-friendly hooks.
  317. X'''
  318. X.SS Overview
  319. X.PP
  320. XIn order to implement a new command, say FOLD, you will need to do the
  321. Xfollowing:
  322. X.IP \(bu 5
  323. XWrite a perl subroutine to implement the FOLD action and put that into
  324. Xan external file. Say we write the subroutine \fIfold\fR and we store
  325. Xthat in a \fIfold.pl\fR file. This is naturally the difficult part, where
  326. Xyou need to know some basic things about the mailagent internals.
  327. X.IP \(bu
  328. XChoose where you want to store your \fIfold.pl\fR file. Then check the
  329. Xsyntax with \fIperl \-c\fR, just to be sure...
  330. X.IP \(bu
  331. XEdit the \fInewcmd\fR file (as given by the configuration file) to record
  332. Xyour new command. Then make sure this file is tightly protected. You must
  333. Xown it, and it should not be writable by any other individual but you.
  334. X.IP \(bu
  335. XAdditionally, you may want to specify whether FOLD is to modify the existing
  336. Xexecution status and whether or not it will be allowed within the special
  337. X_SEEN_ mode.
  338. X.IP \(bu
  339. XWrite some rules using the new FOLD command. This is the \fIeasy\fR part!
  340. XNote that your command may also be used within perl hooks as if it were
  341. Xa builtin command (this means there is an interface function built for
  342. Xyou within the \fImailhook\fR package).
  343. X.PP
  344. XIn the following sections, we're going to describe the syntax of the
  345. X\fInewcmd\fR file, and we'll then present some low-level internal variables
  346. Xwhich may be used when implementing new commands.
  347. X'''
  348. X.SS New Command File Format
  349. X.PP
  350. XThe \fInewcmd\fR file consists of a series of lines, each line describing
  351. Xone command. Blank lines are ignored and shell-style comments introduced by
  352. Xthe sharp (#) character are allowed.
  353. X.PP
  354. XEach line is formed by 3 principal fields and 2 optional ones; fields are
  355. Xseparated by spaces or tabs. Here is a skeleton:
  356. X.Ex
  357. X<cmd_name> <path> <function> <status_flag> <seen_flag>
  358. X.Ef
  359. XThe \fIcmd_name\fR is the name of the command you wish to add. In our
  360. Xprevious example, it would be FOLD. The next field, \fIpath\fR, tells
  361. Xthe mailagent where the file containing the command implementation is
  362. Xlocated. Say we store it in \fI~/mail/cmds/fold.pl\fR. The \fIfunction\fR
  363. Xfield is the name of the \fIperl\fR function implementing FOLD, which may
  364. Xbe found in \fIfold.pl\fR. Here, we named our function \fIfold\fR. Note that
  365. Xif your function has its name within the \fInewcmd\fR package, which is the
  366. Xdefault behavior if you do not specify any, then there is no need to prefix
  367. Xthe function name with the package. Otherwise, you must use a fully qualified
  368. Xname.
  369. X.PP
  370. XThe last two fields are optional, and are boolean values which may be
  371. Xspecified by \fItrue\fR or \fIyes\fR to express truth, and \fIfalse\fR
  372. Xor \fIno\fR to express falsehood. If \fIstatus_flag\fR is set to
  373. Xtrue, then the command will modify the last execution status variable.
  374. XIf \fIseen_flag\fR is true, then the command may be used when the filter
  375. Xis in _SEEN_ mode. The default values are respectively \fItrue\fR and
  376. X\fIfalse\fR.
  377. X.PP
  378. XSo in our example, we would have written:
  379. X.Ex
  380. XFOLD  ~/mail/cmds/fold.pl  fold  no  yes
  381. X.Ef
  382. Xto allow FOLD even in _SEEN_ mode and have it executed without modifying
  383. Xthe current value of the \fIlast-command-status\fR variable.
  384. X'''
  385. X.SS Writing An Implementation
  386. X.PP
  387. XYour perl function will be loaded when needed into the special package
  388. X\fInewcmd\fR, so that its own name-space is protected and does not accidentally
  389. Xconflict with other mailagent routines or variables. When you need to call the
  390. Xperl interface of some common mailagent functions, you will have to remember
  391. Xto use the fully qualified routine name, for instance \fI&mailhook'leave\fR
  392. Xto actually execute the LEAVE command.
  393. X.PP
  394. X(Normally, in PERL hooks, there is no need for this prefixing since the perl
  395. Xscript is loaded in the \fImailhook\fR package. When you are extending your
  396. Xmailagent, you should be extra careful however, and it does not really hurt
  397. Xto use this prefixing. You are free to use the perl \fIpackage\fR directive
  398. Xwithin your function, hence switching to the \fImailhook\fR package in
  399. Xthe body of the routine but leaving its name in the \fInewcmd\fR package.)
  400. X.PP
  401. XSince the mailagent will dynamically load the implementation of your command
  402. Xthe first time it is run, by loading the specified perl script into memory
  403. Xand evaluating it, I suggest you put each command implementation in a separate
  404. Xfile, to avoid storing potentially unneeded code in memory.
  405. X.PP
  406. XEach command is called with one argument, namely the full command string as
  407. Xread from the filter rules. Additionally, the special \fI@ARGV\fR array is
  408. Xset by performing a shell-style parsing of the command line (which will fail
  409. Xif quotes are mismatched, but then you can do the parsing by yourself since you
  410. Xget the command line).
  411. XAt the end of your routine, you must return a failure status, i.e.
  412. X\fB0\fR for success and \fB1\fR to signal failure.
  413. X.PP
  414. XThose are your only requirements. You are free to do whatever you want inside
  415. Xthe routine. To ease your task however, some variables are pre-computed for
  416. Xyou, the same ones that are made available within mail hooks, only they are
  417. Xdefined within the \fInewcmd\fR package this time. There are also a few
  418. Xspecial variables which you need to know about, and a set of standard routines
  419. Xyou may want to call. Please avoid calling something which is not documented
  420. Xhere, since it may change without prior notice. If you would like to use one
  421. Xroutine and it is not documented in this manual page, please let me know.
  422. X.PP
  423. XEach command is called from within an \fIeval\fR construct, so you may
  424. Xsafely use \fIdie\fR or call external library routines that use \fIdie\fR.
  425. XIf you use \fIrequire\fR, be aware that the mailagent is setting up a special
  426. X\fI@INC\fR array by putting its private library path first, so you may place
  427. Xall your \fImailagent\fR-related library files in this place.
  428. X'''
  429. X.SS Special Variables
  430. X.PP
  431. XThe following special variables (some of them marked read-only, meaning you
  432. Xshouldn't modify them, and indeed you can't) made available directly
  433. Xwithin the \fInewcmd\fR package, are pre-set by the filter
  434. Xautomaton, and are used to control the filtering process:
  435. X.sp
  436. X.TP 15
  437. X.I \$mfile
  438. XThe base name of the mail file being processed. This variable is read-only.
  439. XIt is mainly used in log messages, as in [\$mfile] to tag each log, since a
  440. Xsingle mailagent process may deal with multiple messages.
  441. X.TP
  442. X.I \$ever_saved
  443. XThis is a boolean, which should be \fIset\fR to \fB1\fR once a successful
  444. Xsaving operation has been completed. If at the end of the filtering, this
  445. Xvariable is still \fB0\fR, then the default LEAVE will be executed.
  446. X.TP
  447. X.I \$vacation
  448. XThis is a boolean, which when \fIset\fR to \fB1\fR will allow vacation messages.
  449. XIt is mainly used by the VACATION command, but if you wish to re-implement that
  450. Xcommand you will need access to this variable.
  451. X.TP
  452. X.I \$cont
  453. XThis is the continuation status, a variable of the utmost importance when
  454. Xdealing with the control flow. Four constants from the \fImain\fR package
  455. Xcan be used to specify whether we should continue with the current rule
  456. X(\$FT_CONT), abandon current rule (\$FT_REJECT), restart filtering from the
  457. Xbeginning (\$FT_RESTART) or simply abort processing (\$FT_ABORT). More on
  458. Xthis later.
  459. X.TP
  460. X.I \$lastcmd
  461. XThe last failure status recorded by the last command (among those which do
  462. Xmodify the execution status). You should not have to update this by yourself
  463. Xunless you are implementing some encapsulation for other commands, like BACK
  464. Xor ONCE, since by default \fI\$lastcmd\fR will be set to the value you return
  465. Xat the end of the command.
  466. X.TP
  467. X.I \$wmode
  468. XThis records the current state of the filter automaton (working mode), in a
  469. Xliteral string form, typically modified by the BEGIN command or as a side
  470. Xeffect, as in REJECT for instance.
  471. X.PP
  472. XOther variables you might have a need for are configuration parameters, held
  473. Xin the \fI~/.mailagent\fR configuration file. Well, the rule is simple. The
  474. Xvalue of each parameter \fIparam\fR from the configuration file is held in
  475. Xvariable \fI\$cf'param\fR. Variable \fI\$main'loglvl\fR is the copy of
  476. X\fI\$cf'level\fR, since it's always shorter to type in \fI\$'loglvl\fR after
  477. Xeach call to the logging routine \fI&add_log\fR.
  478. X.PP
  479. XThere is one more variable worth knowing about: \$main'FILTER, which is the
  480. Xsuitable X-Filter line that should be appended in \fBall\fR the mails you
  481. Xsend via the mailagent, in order to avoid loops. Also when you save mails
  482. Xto a folder, it's wise adding this line in case a problem arises: you may
  483. Xthen identify the culprit.
  484. X'''
  485. X.SS Altering Control Flow
  486. X.PP
  487. XWhen you want to alter control flow to perform a REJECT, a RESTART or an
  488. XABORT, you have three choices. If you wish to control that action via an
  489. Xoption, the same way the standard UNIQUE does (with \fB\-c\fR, \fB\-r\fR or
  490. X\fB\-a\fR), you may call \fI&main'alter_execution(option, mode)\fR giving it
  491. Xtwo parameters: the option letter and the mode you wish to change to before
  492. Xaltering the control flow.
  493. X.PP
  494. XYou may also want to directly alter the \fI\$wmode\fR and \fI\$cont\fR variables,
  495. Xbut then you'll have to do your own logging if you want some. Or you may
  496. Xcall low-level routines \fI&main'do_reject\fR, \fI&main'do_restart\fR and
  497. X\fI&main'do_abort\fR to perform the corresponding operation (with logging).
  498. X.PP
  499. XRemember that the mode _SEEN_ is special and directly handled at the
  500. Xfilter level, and the the filter begins in the INITIAL mode. The default
  501. Xaction is to continue with the current rule, which is why there is no
  502. Xroutine to perform this task.
  503. X.PP
  504. XThe preferred way is to invoke the \fImailhook\fR interface functions,
  505. X\fI&mailhook'begin\fR, \fI&mailhook'reject\fR, etc..., and that will work
  506. Xeven if you redefine those functions yourself. Besides, that's the only
  507. Xinterface which is likely not to be changed by new versions.
  508. X'''
  509. X.SS General Purpose Routines
  510. X.PP
  511. XThe following is a list of all the general routines you may wish to call when
  512. Xperforming some low-level tasks. Note that this information is
  513. Xversion-dependent. Since I document them, I'll try to keep them in new
  514. Xversions, but I cannot guarantee I will not have to slightly change some
  515. Xof their semantics. There is a good chance you will never have to worry about
  516. Xthat anyway.
  517. X.sp
  518. X.TP 10
  519. X.I &header'format(rfc822-field)
  520. XReturn a formatted RFC822 field to fit in 78 columns, with proper
  521. Xcontinuations introduced by eight spaces.
  522. X.TP
  523. X.I &header'normalize(rfc822-header-name)
  524. XNormalize case in RFC822 header and return the new header name with every
  525. Xfirst letter uppercased.
  526. X.TP
  527. X.I &header'reset
  528. XThis is part of an RFC822 header validation, mainly used when splitting a
  529. Xdigest. This resets the recognition automaton (see &header'valid).
  530. X.TP
  531. X.I &header'valid(line)
  532. XReturns a boolean status, indicating if all the lines given so far to this
  533. Xfunction since the last &header'reset are part of a valid RFC822 header.
  534. XThe function understands the first From line which is part of UNIX mails.
  535. XAt any time, the variable \fI\$header'maybe\fR may be checked to see if
  536. Xso far we have found at least one essential mail header field.
  537. X.TP
  538. X.I &main'acs_rqst(file)
  539. XPerform a .lock locking on the file, returning 0 on success and -1 on failure.
  540. XIf an old lock was present, it is removed (time limit set to one hour). Use
  541. X\fI&main'free_file\fR to release the lock.
  542. X.TP
  543. X.I &main'add_log(string)
  544. XAdd the \fIstring\fR to the logfile. The usual idiom is to postfix that call
  545. Xwith the \fIif \$'loglvl > value\fR, where \fIvalue\fR is the logging
  546. Xlevel you wish to have before emitting that kind of log (\fI$'loglvl\fR is
  547. Xa short form for \fI\$main'loglvl\fR).
  548. X.TP
  549. X.I &main'free_file(file)
  550. XRemove a .lock on a file, obtained by \fI&main'acs_rqst\fR. It returns 0 if
  551. Xthe lock was successfully removed, -1 if it was a stale lock (obtained by someone
  552. Xelse).
  553. X.TP
  554. X.I &main'header_found(file)
  555. XScan the head of a file and try to determine whether there is a mail header
  556. Xat the beginning or not. Return true if a header was found.
  557. X.TP
  558. X.I &main'history_record
  559. XRecord the message ID of the current message and return 0 if the message had
  560. Xnot been previously seen, 1 if it is a duplicate.
  561. X.TP
  562. X.I &main'hostname
  563. XReturn the value of the hostname, lowercased, with possible domain name
  564. Xappended to it.
  565. XThe hostname is cached, since its value must initially be obtained by forking.
  566. X(see also \fI&main'myhostname\fR)
  567. X.TP
  568. X.I &main'internet_info(email-address)
  569. XParse an e-mail internet address and return a three-element array containing
  570. Xthe host, the domain and the country part of the internet host. For instance,
  571. Xif the address is \fIuser@d.c.b.a\fR, it will return \fI(c, b, a)\fR.
  572. X.TP
  573. X.I &main'login_name(email-address)
  574. XParse the e-mail internet address and return the login name.
  575. X.TP
  576. X.I &main'macros_subst(*line)
  577. XPerform in-place macro substitution (line passed as a type glob) using
  578. Xthe information currently held in the \fI%main'Header\fR array. Do \fInot\fR
  579. Xpass \fI*_\fR as a parameter, since internally \fImacros_subst\fR uses a local
  580. Xvariable bearing that name to perform the substitutions and you would end up
  581. Xwith an unmodified version. If you really want to pass \fI*_\fR, then you must
  582. Xuse the returned value from \fImacros_subst\fR which is the substituted text,
  583. Xbut that's less efficient than having it modified in place.
  584. X.TP
  585. X.I &main'makedir(pathname, mode)
  586. XMake directory, creating all the intermediate directories needed to make
  587. X\fIpathname\fR a valid directory. Has no effect if the directory already
  588. Xexists. The mode parameter is optional, 0700 is used (octal number) if not
  589. Xspecified.
  590. X.TP
  591. X.I &main'myhostname
  592. XReturns the hostname of the current machine, without any domain name.
  593. XThe hostname is cached, since its value must initially be obtained by forking.
  594. X.TP
  595. X.I &main'run_command(filter-command)
  596. XExecute the single filter command specified and return the continuation
  597. Xstatus, which should normally be affected to the \fI\$cont\fR variable. You
  598. Xwill need this routine when trying to implement commands which encapsulate
  599. Xother commands, like ONCE or SELECT.
  600. X.TP
  601. X.I &main'seconds_in_period(period)
  602. XReturn the number of seconds in the period specified. See section \fISpecifying
  603. XA Period\fR to get valid period strings.
  604. X.TP
  605. X.I &main'shell_command(program, input, feedback)
  606. XRun a shell command and return a failure status (0 for OK). The input parameter
  607. Xmay be one of the following constants (defined in the \fImain\fR package):
  608. X\$NO_INPUT to close standard input, \$BODY_INPUT to pipe the body of the
  609. Xcurrent message, \$MAIL_INPUT to pipe the whole mail and \$HEADER_INPUT to
  610. Xpipe the message header. The feedback parameter may be one of \$FEEDBACK or
  611. X\$NO_FEEDBACK depending whether or not you wish to use the standard output
  612. Xto alter the corresponding part of the message. If no feedback is wanted, the
  613. Xoutput of the command is mailed back to the user.
  614. X.TP
  615. X.I &main'parse_address(rfc822-address)
  616. XParse an RFC822 e-mail address and return a two-elements array containing the
  617. Xinternet address and the comment part of that address.
  618. X.TP
  619. X.I &main'xeqte(filter-actions)
  620. XExecute a series of actions separated by the ';' character, calling
  621. X\fIrun_command\fR to actually perform the job. Return the continuation status.
  622. XNote that \$FT_ABORT will \fInever\fR be returned, since the mailagent
  623. Xusually stops after having executed one set of actions, only continuing
  624. Xif it saw an RESTART or a REJECT. What ABORT does is skipping the remaining
  625. Xcommands on the line and exiting as if all the commands had been run. You
  626. Xcould say \fIxeqte\fR is the equivalent of the \fIeval\fR function in perl,
  627. Xsince it interprets a little filter script and returns control to the caller
  628. Xonce finished, and ABORT is perl's \fIdie\fR.
  629. X.PP
  630. XYou may also use the three functions from the \fIextern\fR package which
  631. Xmanipulate persistent variables (already documented in the section dealing
  632. Xwith variables) as well as the user-defined macro routines.
  633. X'''
  634. X.SS Example
  635. X.PP
  636. XWriting your own commands is not easy, since it requires some basic knowledge
  637. Xregarding the mailagent internals. However, once you are familiar with that,
  638. Xit should be relatively straightforward.
  639. X.PP
  640. XHere is a small example. We want to write a command to bounce back a mail
  641. Xmessage to the original sender, the way sendmail does, with some leading
  642. Xtext to explain what happened. The command would have the following syntax:
  643. X.Ex
  644. XSENDBACK \fIreason\fR
  645. X.Ef
  646. Xand we would like that command to modify the existing status, returning
  647. Xa failure if the mail cannot be bounced back. Since this command actually
  648. Xsends something back, we do not want it to be executed in _SEEN_ mode.
  649. XHere is my implementation (untested):
  650. X.Ex
  651. Xsub sendback {
  652. X    local(\$cmd_line) = @_;
  653. X    local(\$reason) = join(' ', @ARGV[1..\$#ARGV]);
  654. X    unless (open(MAILER, "|/usr/lib/sendmail -odq -t")) {
  655. X        &'add_log("ERROR cannot run sendmail to send message")
  656. X            if \$'loglvl;
  657. X        return 1;
  658. X    }
  659. X    print MAILER <<EOF;
  660. XFrom: mailagent
  661. XTo: \$header{'Sender'}
  662. XSubject: Returned mail: Mailagent failure
  663. X\$main'FILTER
  664. X
  665. X  --- Transcript Of Session
  666. X
  667. X\$reason
  668. X
  669. X  --- Unsent Message Follows
  670. X
  671. X\$header{'All'}
  672. XEOF
  673. X    close MAILER;
  674. X    \$ever_saved = 1;    # Don't want it in mailbox
  675. X    \$? == 0 ? 0 : 1;    # Failure status
  676. X}
  677. X.Ef
  678. XAssuming this command is put into ~/mail/cmds/sendback.pl, the line
  679. Xdescribing it in the \fInewcmd\fR file would be:
  680. X.Ex
  681. XSENDBACK  ~/mail/cmds/sendback.pl  sendback  yes  no
  682. X.Ef
  683. XNow this command may be used freely in any rule, and will be logged
  684. Xas a user-defined command by the command dispatcher. Who said it was
  685. Xnot easy to do? :-)
  686. X.PP
  687. XNote the use of the \$ever_saved variable to mark the mail as saved once
  688. Xit has been bounced. Indeed, should the SENDBACK action be the only one
  689. Xaction to be run, we do not want the mailagent to LEAVE the mail in the
  690. Xmailbox because it has never been saved (this default behavior being
  691. Xa precaution only -- better safe than sorry).
  692. X'''
  693. X.SS Conclusion
  694. X.PP
  695. XIf along the way you imagine some useful commands which could be made
  696. Xpart of the standard command set, please e-mail them to me and I'll
  697. Xconsider integrating them. In the future, I would also like to provide
  698. Xa standard library of perl scripts to implement some weird commands which
  699. Xcould be needed in special cases.
  700. X.PP
  701. XNote that you may also use the information presented here inside the
  702. Xperl escape scripts. Via the \fIrequire\fR operator, it is easy to get
  703. Xthe new command implementation into your script and perform the same task.
  704. XYou will maybe need to set up @ARGV by yourself if you rely on that
  705. Xfeature in your command implementation.
  706. X.PP
  707. XCommand extension can also be viewed as a way to reuse some other perl
  708. Xcode, the mailagent providing a fixed and reliable frame and the external
  709. Xprogram providing the service. One immediate extension would be mailing
  710. Xlist handling, using this mechanism to interface with some mailing list
  711. Xmanagement software written in perl.
  712. X'''
  713. X''' G e n e r i c   M a i l   S e r v e r
  714. X'''
  715. X.SH GENERIC MAIL SERVER
  716. X.PP
  717. XOne nice thing about mailagent is that it provides you with the basic tools to
  718. Ximplement a generic mail server. Indeed, via the SERVER command, you can
  719. Xprocess a mail message, extract and then execute some predefined commands.
  720. XFor instance, you may implement an archive server, or a mailing list
  721. Xmanager, etc...
  722. X.PP
  723. XThe major limitation currently is that only plain commands are accepted,
  724. Xor commands taking some additional info as \fIstandard input\fR or
  725. Xequivalent. There is no notion of modes, with separate command sets for
  726. Xeach mode or limited name-space visibility, at least for now, so it is not
  727. Xeasy (albeit possible) to implement an ftpmail server, for instance, since
  728. Xthis implies the notion of mode.
  729. X'''
  730. X.SS Overview
  731. XIn order to implement a mail server command (say send \fIfile\fR, which
  732. Xwould send an arbitrary file from the file system in a separate mail message),
  733. Xyou need to do the following:
  734. X.IP \(bu 5
  735. XThink about the command from a security point of view. Here, the command we
  736. Xwant to implement is a potentially dangerous one since it can give access
  737. Xto any file on the machine the individual running \fImailagent\fR has access to.
  738. XSo we want to restrict that command to a limited number of trusted people,
  739. Xwho will be granted the \fIpower\fR to run this command. More on this later.
  740. X.IP \(bu
  741. XChoose whether you want to implement the command in perl or in another
  742. Xprogramming language. If you do the latter, your command will be known as
  743. Xa \fIshell\fR command (i.e. a command runnable directly from a shell), while
  744. Xin the former case, you have the choice of making it appear as a \fIshell\fR
  745. Xcommand, or have it hooked to the \fImailagent\fR in which case it is known
  746. Xas a \fIperl\fR command. In that last case, your command will be dynamically
  747. Xloaded into mailagent with all the advantages that brings you. Here, we are
  748. Xgoing to write our command as a shell script.
  749. X.IP \(bu
  750. XWrite the command itself. That's the most difficult part in this scheme.
  751. XLater on, we will see a straightforward implementation of the \fIsend\fR
  752. Xcommand.
  753. X.IP \(bu
  754. XEdit the \fIcomserver\fR file (defined in your \fI~/.mailagent\fR) to
  755. Xrecord your new command. Then make sure this file is tightly protected.
  756. XYou must own it, and be the only one allowed to modify it.
  757. X.IP \(bu
  758. XAdditionally, you may want to hide some of the arguments in the session
  759. Xtranscript (more on this later), allow the command to take a flow of
  760. Xdata as its \fIstandard input\fR, assign a path to the command, etc...
  761. XAll those parameters take place in your \fIcomserver\fR file.
  762. X.IP \(bu
  763. XStart using the command... which of course is the nicest part in this scheme!
  764. X.PP
  765. XIn the following sections, we'll learn about the syntax of the \fIcomserver\fR
  766. Xfile, what \fIpowers\fR are, how the session transcript is built, what the
  767. Xcommand environment is, etc...
  768. X'''
  769. X.SS Builtin Commands Overview
  770. X.PP
  771. XThe mail server has a limited set of builtin commands, dealing with user
  772. Xauthentication and command environment settings. User authentication
  773. Xis password based and is not extremely strong since passwords are specified
  774. Xin clear within the mail message itself, which could be easily intercepted.
  775. X.PP
  776. XThe server maintains the notion of \fIpowers\fR. One user may have more
  777. Xthan one power at a time, each power granting only a limited access to
  778. Xsome sensitive area. A few powers are hardwired in the server, but the
  779. Xuser may create new ones when necessary. Those powers are software-enforced,
  780. Xmeaning the command must check for itself whether is has the necessary
  781. Xpower(s) to perform correctly.
  782. X.PP
  783. XPowers are protected by a password and a clearance file. Having the good
  784. Xpassword is not enough, you have to be cleared in order to (ab)use it. The
  785. Xclearance file is a list of e-mail address patterns, using the shell
  786. Xmetacharacters scheme, someone being cleared
  787. Xif and only if his e-mail address matches at least one of the patterns from
  788. Xthe clearance file. The more use you will make of metacharacters, the weaker
  789. Xthis clearance scheme will be, so be careful.
  790. X.PP
  791. XYour commands and the output resulting from their execution is normally
  792. Xmailed back to you as a session transcript. For security reasons, passwords
  793. Xare hidden from the command line. Likewise, failure to get a power will not
  794. Xindicate whether you lacked authorization or whether your password was bad.
  795. X.PP
  796. XA user with the \fIsystem\fR power is allowed to create new powers, delete
  797. Xother powers, change power passwords, and list, remove or change power
  798. Xclearances. This is somehow an important power which should be detained by
  799. Xa small number of users with very strict clearance (no meta-characters in
  800. Xthe address, if possible). A good password should also protect that power.
  801. X.PP
  802. XHowever, a user with the \fIsystem\fR power is not allowed to directly get
  803. Xanother power without specifying its password and being allowed to do so by the
  804. Xassociated clearance file. But it would be possible to achieve that indirectly
  805. Xby removing the power and creating a new one bearing the same name. In order
  806. Xto control people with the \fIsystem\fR power and also for some tricky
  807. Xsituation, there is another more god-like power: the \fIroot\fR power.
  808. X.PP
  809. XA user with the \fIroot\fR power can do virtually anything, since it
  810. Xinstantly grants that individual \fIall\fR the powers available on the
  811. Xserver (but \fIsecurity\fR). The only limitation is that \fIroot\fR
  812. Xcannot remove the \fIroot\fR
  813. Xpower alone. One needs to specify the \fIsecurity\fR password (another
  814. Xhardwired power) in order to proceed. Needless to say, only \fBone\fR
  815. Xindividual should have both \fIroot\fR and \fIsecurity\fR clearance, and
  816. Xonly one individual should know the \fIsecurity\fR password and be listed
  817. Xin the clearance file. The \fIsystem\fR power cannot harm any of those
  818. Xtwo powers. Eventually, more than one user could have the \fIroot\fR power,
  819. Xbut do not grant that lightly...
  820. X.PP
  821. XGetting the \fIroot\fR power is necessary when \fIsystem\fR has messed with
  822. Xthe system configuration in an hopeless way, or when a long atomic sequence
  823. Xof commands has to be issued: \fIroot\fR is not subject to the maximum
  824. Xnumber of command that can be issued in one single message.
  825. X.PP
  826. XIn case you think this \fImailagent\fR feature is dangerous for your account,
  827. Xdo not create the \fIroot\fR and \fIsecurity\fR powers, and do not write
  828. Xany sensitive commands.
  829. X'''
  830. X.SS Builtin Commands Definition
  831. X.PP
  832. XNow let's have a look at those builtin commands. Passwords of sensitive
  833. Xcommands will be concealed in the session transcript. Some commands accept
  834. Xinput by reading the mail message up to the \fIEOF\fR marker, which is a
  835. Xsimple EOF string on a line by itself (analogous with shell's \fIhere
  836. Xdocuments\fR).
  837. X.sp
  838. X.TP 10
  839. X.I addauth power password
  840. XAdd users to clearance file for \fIpower\fR. If the power password is given,
  841. Xno special power is needed, otherwise the \fIsystem\fR power is required.
  842. XFor \fIroot\fR or \fIsecurity\fR powers, the corresponding power is
  843. Xrequired, or the
  844. X\fIpassword\fR must be specified. The command reads the standard input
  845. Xup to the EOF marker to get the new users.
  846. X.TP
  847. X.I approve password command
  848. XRecords the password in the command environment, then executes the command.
  849. XIf a power is required and not yet obtained, the command will look for the
  850. Xpassword in the environment and try to get the relevant power using that
  851. Xpassword. Hence, approved command (with proper password)
  852. Xwill transparently execute without the hassle of requesting the power,
  853. Xissuing the command and then releasing the power. It is up to the command
  854. Xto perform the \fIapprove\fR password test by looking at the \fIapprove\fR
  855. Xvariable in the command environment (see below). Since clearance checks
  856. X(such as those performed when requesting a power) are not performed, no
  857. Xsensitive command should ever deal with the \fIapprove\fR construct.
  858. X.TP
  859. X.I delpower power password [security]
  860. XDelete a power from the system, and its associated clearance list. The
  861. X\fIsystem\fR power is required to delete most powers except \fIroot\fR and
  862. X\fIsecurity\fR. The \fIsecurity\fR power may only be deleted by itself and
  863. Xthe \fIroot\fR power may only be deleted when the \fIsecurity\fR password
  864. Xis also specified.
  865. X.TP
  866. X.I getauth power password
  867. XGet current clearance file for a given power. No special power required if
  868. Xthe password is given or the power is already detained. Otherwise, the system
  869. Xpower is needed for all powers but \fIroot\fR or \fIsecurity\fR where the
  870. Xcorresponding power is mandatory.
  871. X.TP
  872. X.I newpower power password [alias]
  873. XAdd a new power to the system. The command then reads the standard mail input
  874. Xuntil the EOF marker to get the power clearance list. The \fIsystem\fR power
  875. Xis required to create a new power, unless it's \fIroot\fR or \fIsecurity\fR:
  876. XThe \fIsecurity\fR power is required to create \fIroot\fR and the \fIroot\fR
  877. Xpower is required to create \fIsecurity\fR.
  878. X.TP
  879. X.I passwd power old new
  880. XChange power password. It does not matter if you already hold the corresponding
  881. Xpower, you must give the proper old password. See also the \fIpassword\fR
  882. Xcommand.
  883. X.TP
  884. X.I password power new
  885. XChange power password. The corresponding power is required, or you have to get
  886. Xthe \fIsystem\fR power. To change the \fIroot\fR or \fIsecurity\fR passwords,
  887. Xyou need the corresponding power.
  888. X.TP
  889. X.I power name password
  890. XAsk for a new power. Of course, \fIroot\fR does not need to request for any
  891. Xother power but \fIsecurity\fR, less give any password. This command is not
  892. Xhonored when the server is not in trusted mode, unbeknownst to the user:
  893. Xthe error message in the transcript file is no different from the one
  894. Xobtained with an invalid password.
  895. X.TP
  896. X.I powers regexp
  897. XList all the powers matching the perl regular expression, along with their
  898. Xrespective clearance file. The \fIsystem\fR power is required to get the list.
  899. XThe \fIroot\fR or \fIsecurity\fR power are required to get access to the
  900. X\fIroot\fR or \fIsecurity\fR information, respectively.
  901. XIf no arguments are given, all the powers are listed.
  902. X.TP
  903. X.I release power
  904. XGet rid of some power.
  905. X.TP
  906. X.I remauth power password
  907. XRemove users from clearance file, getting the list by reading the standard
  908. Xmail input until the EOF marker. This command does not require any special
  909. Xpower if the proper password is given or if the power is already detained.
  910. XOtherwise, the \fIsystem\fR power is needed. For \fIroot\fR and \fIsecurity\fR
  911. Xclearance, the corresponding power is needed as well.
  912. X.TP
  913. X.I set variable value
  914. XSet the variable to the corresponding value. Useful to alter internal
  915. Xvariables like the EOF marker value, or change some command environment.
  916. XThe user may define his own variables for his commands.
  917. XFor \fIflag\fR-type variable, a value of \fIon\fR, \fIyes\fR or \fItrue\fR sets
  918. Xthe variable to \fI1\fR, any other string sets it to \fI0\fR (false).
  919. X.TP
  920. X.I setauth power password
  921. XReplace power clearance file with one obtained from standard mail input up to
  922. Xthe EOF mark. The \fIsystem\fR power is needed unless you specify the proper
  923. Xpassword or the power is already yours. As usual, \fIroot\fR or \fIsecurity\fR
  924. Xclearances can only be changed when the power is detained.
  925. X.TP
  926. X.I user [e-mail [command]]
  927. XExecute command by assuming the e-mail identity specified. Powers are lost
  928. Xwhile executing the command. The e-mail identity may be checked by the
  929. Xcommand itself, which may impose further restrictions on the execution, like
  930. Xgetting user-defined powers. Note that this command only modifies the global
  931. Xenvironment, and that it's up to the \fIcommand\fR implementation to make
  932. Xuse of that information. If no command is specified, the new identity is
  933. Xassumed until changed by another \fIuser\fR command and all the powers
  934. Xcurrently held by the user are released. If no \fIe-mail\fR address
  935. Xis given, the original user ID is restored.
  936. X'''
  937. X.SS Command Environment
  938. X.PP
  939. XThere are six types of commands and variables that can be specified in server
  940. Xmode. Two of them, \fIend\fR and \fIhelp\fR types are special and handled
  941. Xseparately. Two types \fIvar\fR and \fIflag\fR refer to variables and the last
  942. Xtwo types \fIperl\fR and \fIshell\fR refer to commands.
  943. X.PP
  944. XWhenever mailagent fires a server command, it sets up an environment for that
  945. Xcommand: if it is a \fIperl\fR-type command, then a set of perl variables are
  946. Xset before loading the command; if it is a \fIshell\fR-type command, some
  947. Xenvironment variables are initialized and file descriptor #3 is set up to
  948. Xpoint directly to the mailagent session transcript.
  949. X.PP
  950. XA \fIshell\fR-type command is forked, whilst a \fIperl\fR-type command is
  951. Xloaded directly in \fImailagent\fR within the \fIcmdenv\fR package. This
  952. Xoperates much like the PERL filtering command, only the target package differs
  953. Xand a distinct set of variables is preset.
  954. X.PP
  955. XSome commands collect additional data up to an end-of-file marker (by default
  956. Xthe string \fBEOF\fR on a line by itself) and those data are fed to shell
  957. Xcommands via \fIstdin\fR and to perl commands via the \fI@buffer\fR variable
  958. Xset up in the environment package named \fIcmdenv\fR (in which the command is
  959. Xloaded and run).
  960. X..PP
  961. XIf you define your own variables (types \fIvar\fR or \fIflag\fR), you may
  962. Xuse the builtin \fIset\fR command to modify their values. Note that no default
  963. Xvalue can be provided when defining your variable. A suitable default value
  964. Xmust be set within commands making use of them, with the advantage that
  965. Xdifferent default values may be used by different commands.
  966. X.PP
  967. XThe following \fIenvironment\fR variables are defined. Most are read-only,
  968. Xunless notified otherwise, in which case the builtin \fIset\fR command may
  969. Xbe used on them.
  970. X.TP 10
  971. X.I approve
  972. XThe approve password for \fIapprove\fR commands, empty if not within a
  973. Xbuiltin \fIapprove\fR construct.
  974. X.TP
  975. X.I auth
  976. XA flag set to true when a valid envelope was found in the mail message.
  977. XWhen this flag is false, the server cannot be put in trusted mode.
  978. X.TP
  979. X.I cmd
  980. XThe command line, as written in the message.
  981. X.TP
  982. X.I collect
  983. XInternal flag set to true while collecting input from a here-document.
  984. XIt is normally reset to false before calling the command.
  985. X.TP
  986. X.I debug
  987. XTrue when debug mode is activated (may be set).
  988. X.TP
  989. X.I disabled
  990. XA comma separated list of disabled commands, with no space between them.
  991. XThis is initialized when the SERVER command is invoked and the \fB\-d\fR
  992. Xoption is used.
  993. X.TP
  994. X.I eof
  995. XThe current end-of-file marker for here-document commands. By default set
  996. Xto 'EOF' (may be changed).
  997. X.TP
  998. X.I errors
  999. XNumber of errors so far.
  1000. X.TP
  1001. X.I jobnum
  1002. XThe job number assigned to the current mailagent.
  1003. X.TP
  1004. X.I log
  1005. XWhat was logged in the transcript, with some args possibly concealed.
  1006. X.TP
  1007. X.I name
  1008. XThe command name.
  1009. X.TP
  1010. X.I pack
  1011. XPacking mode for file sending (may be set).
  1012. X.TP
  1013. X.I path
  1014. XDestination address for file sending or notification (may be set).
  1015. X.TP
  1016. X.I powers
  1017. XA colon (:) separated list of powers the user currently has successfully
  1018. Xrequested and got.
  1019. X.TP
  1020. X.I requests
  1021. XNumber of requests processed so far.
  1022. X.TP
  1023. X.I trace
  1024. XTrue when shell commands want to be traced in transcript (may be set).
  1025. X.TP
  1026. X.I trusted
  1027. XTrue when server is in trust mode, where powers may be gained. This
  1028. Xis activated by the \fB\-t\fR option of the SERVER command, provided a
  1029. Xvalid mail envelope was found.
  1030. X.TP
  1031. X.I uid
  1032. XAddress of the sender of the message, where transcript is to be sent. By
  1033. Xextension, the real user ID for the server, which is the base of the power
  1034. Xclearance mechanism.
  1035. X.TP
  1036. X.I user
  1037. XThe effective user ID, originally the same as the uid, but may be changed
  1038. Xvia the \fIuser\fR builtin command.
  1039. X'''
  1040. X.SS Session Transcript
  1041. X.PP
  1042. XA session transcript is mailed back automatically to the user who requested
  1043. Xa server access. This transcript shows the commands ran by the user and their
  1044. Xstatus: \fIOK\fR or \fIFAILED\fR. Between those two lines, the transcript show
  1045. Xany output explicitly made by the command to the transcript. Typically, the
  1046. Xtranscript may be use to forward error message back to the user, but even
  1047. Xcommands executing correctly may want to issue an explicit message, stating
  1048. Xwhat has just been done.
  1049. X.PP
  1050. XA perl command may access the transcript via the \fIMAILER\fR file handle,
  1051. Xdefined in the \fIcmdenv\fR package, whilst a shell command may access it via
  1052. Xits file descriptor #3.
  1053. X.PP
  1054. XNote that the session transcript is mailed to the \fIsender\fR of the message,
  1055. Xi.e. whoever the envelope header line says it is. As
  1056. Xfar as the server is concerned, this e-mail address is used as the user ID,
  1057. Xjust like a plain login name can be thought of as the user id. For sensitive
  1058. Xcommands, authentication based on that information is really weak. A more
  1059. X"secure" authentication is provided by the server powers, which is
  1060. Xpassword-based. Unfortunately, the clear password has to be transmitted in the
  1061. Xmessage itself and could be eavesdropped.
  1062. X'''
  1063. X.SS Recording New Commands and Variables
  1064. X.PP
  1065. XServer commands and variables are defined in the \fIcomserver\fR file defined
  1066. Xin your \fI~/.mailagent\fR. The format of the file is that of a table with
  1067. Xitems on a row separated by tabs characters. Each line defines one command
  1068. Xor variable. Any irrelevant field may be entered as a single '-' (minus)
  1069. Xcharacter. The format allows for shell-style (#) comments.
  1070. X.PP
  1071. XEach row has the following fields:
  1072. X.Ex
  1073. X\fIname type hide collect-data path extra\fR
  1074. X.Ef
  1075. Xwhere:
  1076. X.TP 15
  1077. X.I name
  1078. Xis the name of the command or variable as recognized by the server.
  1079. X.TP
  1080. X.I type
  1081. Xis one of \fIperl\fR, \fIshell\fR, \fIvar\fR, \fIflag\fR, \fIhelp\fR
  1082. Xor \fIend\fR.
  1083. X.TP
  1084. X.I hide
  1085. Xindicates which arguments in the command are to be hidden (the command name
  1086. Xbeing argument zero) in the session transcript. Use '-' if no arguments
  1087. Xneed to be hidden. Typically, this is used to hide clear passwords in commands.
  1088. XIf more than one argument has to be hidden, then a list of numbers separated
  1089. Xby a ',' (comma) may be specified, with \fBno spaces\fR between them. For
  1090. Xinstance '2,4' would hide arguments 2 and 4 in the transcript.
  1091. X.TP
  1092. X.I collect-data
  1093. Xis a flag (specify as either 'y' or 'n', but you may use complete words 'yes'
  1094. Xor 'no') indicating whether the command collects additional data in a
  1095. Xhere-document until the EOF marker. Alternatively, you may specify '-' in place
  1096. Xof 'n'.
  1097. X.TP
  1098. X.I path
  1099. Xspecifies the path of the command (~name substitution allowed). If not relevant
  1100. X(e.g. when defining a variable) or when you want to leave it blank, use '-'.
  1101. XIf a blank path is specified for a \fIperl\fR or \fIshell\fR command, then
  1102. Xthe implementation of that command is expected to be found in \fIservdir\fR,
  1103. Xas defined in \fI~/.mailagent\fR. If the command name is \fIcmd\fR for instance,
  1104. Xthen perl command are expected there in a file named \fIcmd\fR of \fIcmd.pl\fR,
  1105. Xwhereas shell commands are expected to be found in a \fIcmd\fR of \fIcmd.sh\fR
  1106. Xfile. Note that a command is disabled if it cannot be located at the time
  1107. Xthe \fIcomserver\fR file is parsed.
  1108. X.TP
  1109. X.I extra
  1110. Xis any extra parameter needed for the command. Unlike other fields, this
  1111. Xshould be left blank if not needed. Anything up to the end of the line is
  1112. Xgrabbed by this field. Perl commands should specify the name of the perl
  1113. Xfunction to call to execute the command; if none is specified, the name of
  1114. Xthe command itself is called. Shell commands may use that field to supply
  1115. Xadditional options, which will be inserted right after the command name and
  1116. Xbefore any other user-supplied arguments. Others should leave this alone.
  1117. X'''
  1118. X.SS Special Command Types
  1119. X.PP
  1120. XThere are currently two special command types.
  1121. X.PP
  1122. XThe simplest is the \fIend\fR type. This is used to specify commands which may
  1123. Xend the server processing. By default, processing continues until the end
  1124. Xof the file is reached or a signature delimiter '--' is found. For instance,
  1125. Xyou may wish to define the command \fIquit\fR and give it the \fIend\fR type.
  1126. XAs soon as the server reaches that command, it aborts processing and discards
  1127. Xthe remaining of the message.
  1128. X.PP
  1129. XThe \fIhelp\fR type is usually attached to an \fIhelp\fR command and prints
  1130. Xhelp on a command basis, help for each command being stored under the
  1131. X\fIhelpdir\fR variable (defined in your ~/.mailagent) in a file bearing the
  1132. Xsame name as the command itself. For example, assuming a command \fIshoot\fR,
  1133. Xits help file would be expected in \fIhelpdir/shoot\fR. If no file is found
  1134. Xthere, mailagent looks in its public library ($privlibexp) for an help file.
  1135. XHelp is provided only when the help file exists and is not zero-sized.
  1136. X'''
  1137. X.SS Creating the Root Power
  1138. X.PP
  1139. XIn order to bootstrap the server, you need to create the root power. All the
  1140. Xother powers may then be created by using the server interface, which ensures
  1141. Xconsistency and logs your actions. If you don't plan using powers at all, you
  1142. Xmay skip that section.
  1143. X.PP
  1144. XFirst, you need to pick up a good password for the \fIroot\fR power. Someone
  1145. Xwith the \fIroot\fR power can do virtually anything with the server, so be
  1146. END_OF_FILE
  1147.   if test 49980 -ne `wc -c <'agent/man/mailagent.SH.03'`; then
  1148.     echo shar: \"'agent/man/mailagent.SH.03'\" unpacked with wrong size!
  1149.   fi
  1150.   # end of 'agent/man/mailagent.SH.03'
  1151. fi
  1152. echo shar: End of archive 3 \(of 26\).
  1153. cp /dev/null ark3isdone
  1154. MISSING=""
  1155. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 ; do
  1156.     if test ! -f ark${I}isdone ; then
  1157.     MISSING="${MISSING} ${I}"
  1158.     fi
  1159. done
  1160. if test "${MISSING}" = "" ; then
  1161.     echo You have unpacked all 26 archives.
  1162.     echo "Now run 'sh PACKNOTES', then read README and type Configure.'"
  1163.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1164. else
  1165.     echo You still must unpack the following archives:
  1166.     echo "        " ${MISSING}
  1167. fi
  1168. exit 0
  1169.  
  1170. exit 0 # Just in case...
  1171.