home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Spezial / SPEZIAL2_97.zip / SPEZIAL2_97.iso / ANWEND / ONLINE / ELM23-2 / ELM23-2.ZIP / doc / Filter.guide (.txt) < prev    next >
Amigaguide Document  |  1990-04-28  |  17KB  |  480 lines

  1. .\" @(#)$Id: Filter.guid,v 4.1 90/04/28 22:41:03 syd Exp $
  2. .\"  A guide to the Elm Filter program
  3. .\"  format with:
  4. .\"     'tbl tmac.n Filter.guid | troff > Filter.format'
  5. .\"  (C) Copyright 1986, 1987 Dave Taylor
  6. .\"  (C) Copyright 1988, 1989, 1990 Usenet Community Trust
  7. .\"  Elm is now in the public trust. Bug reports, comments, suggestions, flames
  8. .\"  etc. should go to:
  9. .\"    Syd Weinstein        elm@DSI.COM (dsinc!elm)
  10. .\"  $Log:    Filter.guid,v $
  11. .\" Revision 4.1  90/04/28  22:41:03  syd
  12. .\" checkin of Elm 2.3 as of Release PL0
  13. .\" Revision 3.8  90/03/26  15:12:06  syd
  14. .tm Have we been run through "tbl" first?? I hope so!
  15. .po 1i
  16. .ds h0
  17. .ds h1
  18. .ds h2
  19. .ds f0
  20. .ds f1
  21. .ds f2
  22. .nr Hy 1
  23. .nr Pt 1
  24. .nr Pi 8
  25. .lg 0
  26. .sp |3.0i
  27. .ce 99
  28. .ps 20
  29. .ss 18
  30. .vs 12
  31. \f3The Elm Filter System Guide\f1
  32. .sp 4
  33. .ps 12
  34. .ss 14
  35. .vs 14
  36. \f2What the filter program is, what it does,
  37. and how to use it\f1
  38. .sp 2
  39. Dave Taylor
  40. Hewlett-Packard Laboratories
  41. 1501 Page Mill Road
  42. Palo Alto CA
  43. 94304
  44. .sp 3
  45. email: taylor\s-1@\s+1hplabs.HP.COM  or  hplabs\s-1!\s+1taylor
  46. .sp 3
  47. >>> Elm is now in the public trust. Bug reports, comments, etc. to: <<<
  48. Syd Weinstein
  49. Datacomp Systems, Inc.
  50. 3837 Byron Road
  51. Huntingdon Valley, PA 19006-2320
  52. email: elm\s-1@\s+1DSI.COM  or  dsinc\s-1!\s+1elm
  53. .sp 3
  54. .ps 18
  55. \f3\(co\f1\s12 Copyright 1986, 1987 by Dave Taylor
  56. .ps 18
  57. \f3\(co\f1\s12 Copyright 1988, 1989, 1990 by The USENET Community Trust
  58. .ps 10
  59. .ss 12
  60. .vs 12
  61. .bp 1
  62. .sv 5v
  63. .ps 14
  64. \f3The Elm Filter System Guide\f1
  65. .ds h0 "Elm Filter Guide
  66. .ds h2 "Version 2.3
  67. .ds f0 "May 1, 1990
  68. .ds f1 "Page %
  69. .ps 10
  70. (Version 2.3)
  71. .sp 2
  72. Dave Taylor
  73. Hewlett-Packard Laboratories
  74. 1501 Page Mill Road
  75. Palo Alto CA
  76. 94304
  77. email: taylor\s-1@\s+1hplabs.HP.COM  or  hplabs\s-1!\s+1taylor
  78. .sp 2
  79. >>> Elm is now in the public trust. Bug reports, comments, etc. to: <<<
  80. Syd Weinstein
  81. Datacomp Systems, Inc.
  82. 3837 Byron Road
  83. Huntingdon Valley, PA 19006-2320
  84. email: elm\s-1@\s+1DSI.COM  or  dsinc\s-1!\s+1elm
  85. .sp 2
  86. May 1, 1990
  87. .ce 0
  88. .sp 3
  89. One of the greatest problems with the burgeoning electronic mail
  90. explosion is that I tend to get lots of mail that I don't care about.
  91. Amusingly, perhaps, I have the equivalent of electronic junk mail.
  92. Not amusing, however, is the fact that this can rapidly
  93. accumulate and end up taking over my mailbox.
  94. At the same time I often get mail that, while it is interesting
  95. and important, can easily be filed to be read later, without ever
  96. actually having to cluttering up my incoming mailbox.
  97. .sp 2
  98. This, then, is what \f2filter\f1 does!  The \f2filter\f1 program
  99. allows you to define a set of rules by which all incoming mail should
  100. be screened, and a subsequent set of actions to perform based on whether
  101. the conditions were met or not.  \f2Filter\f1 also has the ability to mail
  102. a summary of what actions it performed on the incoming mail as often as
  103. you'd like.
  104. .ne 5
  105. .hu Writing the Rules
  106. The language for writing \f2filter\f1 rules is pretty simple, actually.
  107. The fundamental structure is;
  108. .ti .5i
  109. if  (\f2condition\f1)  then  \f2action\f1
  110. Where \f2condition\f1 is constructed by an arbitrary number of
  111. individual conditions of the form ``\f2field\f1  \f2relation\f1  \f2value\f1''.
  112. (an optional further type of rule is of the form ``always \f2action\f1''
  113. but should only be used as the last rule in the ruleset, for obvious
  114. reasons).
  115. The \f2field\f1 value can be;
  116. .in .5i
  117. subject
  118. lines
  119. contains
  120. .in 0
  121. where, if ``lines'' is chosen, the \f2relation\f1 can be any of the
  122. standard relationships (`>', `<', `>=', `<=', `!=' and `=').
  123. If another action is
  124. chosen, ``contains'' can be used as the relation, ``='', or, if you'd
  125. like, you can skip the relationship entirely (e.g. `subject "joe"').
  126. The \f2value\f1 is any quoted string that is to be matched against
  127. or number if ``lines'' is the field being considered.
  128. Individual conditions are joined together by using the word ``and'',
  129. and the logic of a condition can be flipped by using ``not'' as the
  130. first word (e.g. `not subject "joe"').  We'll see more examples of
  131. this later.
  132. Note that the ``or'' logical conjunction isn't a valid part of the
  133. \f2filter\f1 conditional statement.
  134. Finally, <\f2action\f1> can be any of;
  135. .in .5i
  136. delete
  137. save   \f2foldername\f1
  138. savecopy  \f2foldername\f1
  139. forward  \f2address\f1
  140. execute  \f2command\f1
  141. leave
  142. .in 0
  143. where they result in the actions;  \f3delete\f1 deletes the message;
  144. \f3save\f1 saves a copy of the message in the specified foldername;
  145. \f3savecopy\f1 does the same as save, but also puts a copy in your mailbox;
  146. \f3forward\f1 sends the message to the specified address;
  147. \f3execute\f1 feeds the message to the specified command (or complex
  148. sequence of commands) as standard input;
  149. and \f3leave\f1 leaves the message in your mailbox.
  150. Foldernames can contain any of a number of macros, too, as we'll see in
  151. the example ruleset below.  The macros available for the string fields are;
  152. .ft CW
  153. center;
  154. lf3 lf3
  155. Macro    Meaning
  156. .ft CW
  157. %d    day of the month
  158. %D    day of the week (0-6)
  159. %h    hour of the day (0-23)
  160. %m    month of the year (0-11)
  161. %r    return address of message
  162. %s    subject of original message
  163. %S    ``Re: \f2subject of original message\fP''
  164. .ft CW
  165. %t    current hour and minute in HH:MM format
  166. %y    year (last two digits)
  167. .ft 1
  168. The rules file can also contain comments (any line starting with a `#')
  169. and blank lines.
  170. The file itself needs to reside in your .elm directory off your home directory and be
  171. called \f2.elm/filter-rules\f1.  Here's an example:
  172. .ft CW
  173.  # $HOME/.elm/filter-rules
  174.  # Filter rules for the Elm Filter program. Don't change without some
  175.  # serious thought. (remember - order counts)
  176.  # (for Dave Taylor)
  177.  # rule 1
  178.  if (from contains "!uucp") then delete
  179.  # rule 2
  180.  to "postmaster" ? save "/tmp/postmaster-mail.%d"
  181.  # rule 3
  182.  if (to "culture" and lines > 20) ? save "/users/taylor/Mail/culture"
  183.  # rule 4
  184.  subject = "filter test" ? forward "hpldat!test"
  185.  # rule 5
  186.  if [ subject = "elm" ] savecopy "/users/taylor/Mail/elm-incoming"
  187.  # rule 6
  188.  subject = "display-to-console" ? execute "cat - > /dev/console"
  189. .ft 1
  190. (notice the loose syntax \(em there are lots of valid ways to specify a
  191. rule in the \f2filter\f1 program!!)
  192. To translate these into English;
  193. .nr TW \w'1. 'u
  194. .in .5i
  195. .ti -\n(TWu
  196. 1. All messages from uucp should be summarily deleted.
  197. .ti -\n(TWu
  198. 2. All mail to postmaster should be saved in a folder (file) called
  199. /tmp/postmaster-mail.\f2numeric-day-of-the-week\f1
  200. .ti -\n(TWu
  201. 3. All mail addressed to `culture' with at least 20 lines
  202. should be automatically appended to the folder
  203. /users/taylor/Mail/culture.
  204. .ti -\n(TWu
  205. 4. All messages that contain the subject `filter test' should be forwarded to
  206. me, but via the address `hpldat!test' (to force a non-user forward)
  207. .ti -\n(TWu
  208. 5. All messages with a subject that contains the word `elm' should be saved in
  209. the folder ``/users/taylor/Mail/elm-incoming'' and also dropped into my
  210. mailbox.
  211. .ti -\n(TWu
  212. 6. Any message with the subject ``display-to-console'' will be immediately
  213. written to the console.
  214. .in 0
  215. Notice that the \f2order\f1 of the rules is very important.  If we, for
  216. example, were to get a message from `uucp' that had the subject `filter test',
  217. the \f2filter\f1 program would match rule 1 and delete the message.  It
  218. would never be forwarded to `hpldat!test'.  It is for this reason that
  219. great care should be taken with the ordering of the rules.
  220. .ne 5
  221. .hu Checking the rules out
  222. The \f2filter\f1 program has a convenient way of check out the rules you
  223. have written.  Simply invoke it with the \f3-r\f1 (\f3r\f1ules) flag;
  224. .in .5i
  225. % \f3filter -r\f1
  226. .ft CW
  227. .in .5i+\w'Rule 1: 'u
  228. .ti .5i
  229. Rule 1: if (from = "!uucp") then
  230. Delete
  231. .ti .5i
  232. Rule 2: if (to = "postmaster") then
  233. Save  /tmp/postmaster-mail.<day-of-week>
  234. .ti .5i
  235. Rule 3: if (to = "culture" and lines > 20) then
  236. Save  /users/taylor/Mail/culture
  237. .ti .5i
  238. Rule 4: if (subject = "filter test") then
  239. Forward  hpldat!test
  240. .ti .5i
  241. Rule 5: if (subject="elm") then
  242. Copy  and  Save  /users/taylor/Mail/elm-incoming
  243. .ti .5i
  244. Rule 6: if (subject="display-to-console") then
  245. Execute "cat - > /dev/console"
  246. .ft 1
  247. .in 0
  248. .ft 1
  249. There are a few things to notice \(em first off, these are the parsed and
  250. rebuilt rules, so we can see that they are all in a
  251. consistent format.  Also, notice on the filename for rule 2 that the
  252. program has correctly expanded the ``%d'' macro to be the day of the
  253. week.
  254. It is \f3highly\f1 recommended that you always check your ruleset before
  255. actually letting the program use it!
  256. .ne 5
  257. .hu Actually Using the Program
  258. Now the bad news.  If you aren't running \f2sendmail\f1 you cannot use
  259. this program as currently written.  Why?  Because the \f2filter\f1
  260. program expects to be put in your \f2.forward\f1 file and that is something
  261. that only \f2sendmail\f1 looks at!
  262. The format for the entry in the \f2.forward\f1 file (located in your
  263. home directory) is simply;
  264. .ti .5i
  265. "| /usr/local/bin/filter"
  266. Allright, it isn't quite \f2that\f1 simple!  Since \f2filter\f1 will be invoked
  267. by processes that don't know where you are logged in, you need to have some
  268. way to trap the error messages.  For ease of use, it was decided to have all
  269. the messages written to the file specified by `-o' (or \f2stderr\f1)
  270. which means that you have two main
  271. choices for the actual entry.  Either;
  272. .ti .5i
  273. "| /usr/local/bin/filter -o /dev/console"
  274. which will log all errors on the system console (each error is prefixed with
  275. ``filter (\f2username\f1)'' to distinguish it), or;
  276. .ti .5i
  277. "| /usr/local/bin/filter -o /tmp/joe.filter_errors"
  278. If you want to have a copy saved to a file.  Note that the quotes are a required
  279. part of the line.  A possible strategy would be
  280. to have the errors written to a file and to then have a few lines in
  281. your \f2.login\f1 script like:
  282. .ft CW
  283. .in .5i+\w'if 'u
  284. .ti .5i
  285. if ( -f /tmp/joe.filter_errors) then
  286. echo  "\ \ "
  287. echo "Filter program errors;"
  288. cat /tmp/joe.filter_errors
  289. echo "\ \ "
  290. .ti .5i
  291. endif
  292. .ft 1
  293. .in 0
  294. .ft 1
  295. You can also use the \f3-v\f1 flag in combination with the above to have
  296. a more verbose log file saved by having
  297. your \f2.forward\f1 file;
  298. "| /usr/local/bin/filter -vo /tmp/joe.filter_errors"
  299. Suffice to say, you can get pretty tricky with all this!!
  300. .ne 5
  301. .hu Summarizing the Actions Taken
  302. The \f2Filter\f1 program keeps a log of all actions performed, including
  303. what rules it matched against, in your .elm directory in a file
  304. called \f2.elm/filterlog\f1.  You can either directly operate on this file,
  305. or, much more recommended, you can one of the two summarize flags to
  306. the program and let \f2it\f1 do the work for you!
  307. The difference between the two is best demonstrated by example:
  308. % \f3filter -s\f1
  309. .ft CW
  310. .in .5i
  311.                 Summary of Filter Activity
  312.                 \l'\w'Summary of Filter Activity'u-'
  313. A total of 418 messages were filtered:
  314. The default rule of putting mail into your mailbox
  315. .in .5i+\w'Rule #1: 'u
  316. applied 364 times (87%)
  317. .ti .5i
  318. Rule #1: (delete message)
  319. applied 1 time (0%)
  320. .ti .5i
  321. Rule #2: (save in "/users/taylor/Filtered-Mail/netnews.12")
  322. applied 8 times (2%)
  323. .ti .5i
  324. Rule #3: (save in "/users/taylor/Filtered-Mail/postmaster.12")
  325. applied 14 times (3%)
  326. .ti .5i
  327. Rule #5: (save in "/users/taylor/Filtered-Mail/risks.12")
  328. applied 3 times (1%)
  329. .ti .5i
  330. Rule #6: (save in "/users/taylor/Filtered-Mail/rays.12")
  331. applied 28 times (7%)
  332. .ft 1
  333. .ti 0
  334. versus:
  335. .ti .5i
  336. % \f3filter -S\f1
  337. .ti .5i
  338. \f2the output as listed above, followed by:\f1
  339. .ft CW
  340. .ti .5i
  341. Explicit log of each action;
  342. .ti .5i
  343. Mail from taylor about Filter Summary
  344. PUT in mailbox: the default action
  345. .ti .5i
  346. Mail from news@hplabsz.hpl.hp.com about Newsgroup comp.editors created
  347. PUT in mailbox: the default action
  348. .ti .5i
  349. Mail from root about Log file: cleanuplog
  350. PUT in mailbox: the default action
  351. .ft 1
  352. .ti .5i
  353. [etc etc]
  354. .in 0
  355. .ft 1
  356. To actually use either of the summarizing options, there
  357. are two ways that are recommended;
  358. The preferred way is to have a line in either your \f2crontab\f1
  359. (ask your administrator for help with this) that invokes the \f2filter\f1
  360. program as often as you desire with the \f3-s\f1 flag.  For example, I
  361. have a summary mailed to me every morning at 8:00 am:
  362. .ft CW
  363.    0 8 * * * "/usr/local/bin/filter -s | elm -s 'Filter Summary' taylor"
  364. .ft 1
  365. An alternative is to have your \f2.login\f1 execute the command each time.
  366. .sp 2
  367. Note that if you want to have your log files cleared out each time the
  368. summary is generated you'll need to use the '-c' flag too.  Also,
  369. if you want to keep a long list of actions performed you can do this
  370. by saving it as you display it.  A way to do this would be, if you were to
  371. have the invocation in your \f2.login\f1 script, to use:
  372. .in .5i
  373. .ft CW
  374. echo "Filter Log;"
  375. filter -c -s | tee -a PERM.filter.log\f1
  376. .ft 1
  377. .in 0
  378. which would append a copy of all the output to the file `PERM.filter.log'
  379. and would avoid you having to read larger and larger summaries of
  380. what the program had done.
  381. .ne 5
  382. .hu Further Testing of the Ruleset
  383. With the \f2readmsg\f1 command available, it is quite easy to test the
  384. rules you've written to see if they'll do what you desire.
  385. For example, we can use the \f3-n\f1 flag to \f2filter\f1, which means
  386. `don't actually do this, just tell me what rule you matched, if any, and
  387. what action you would have performed' (you can see why a single letter
  388. flag is easier to type in!!), and feed it each message in our mailbox
  389. by using a command like;
  390. .in .5i
  391. % \f3set message=1\f1
  392. % \f3set total_messages=`messages`\f1
  393. % \f3while  (1)\f1
  394. > \f3if ($message > $total_messages) exit\f1
  395. > \f3echo processing message $message\f1
  396. > \f3readmsg -h $message | filter -n\f1
  397. > \f3echo " "\f1
  398. > \f3@ messages++\f1
  399. > \f3end\f1
  400. .in 0
  401. which will then hand each of the messages in your mailbox to the \f2filter\f1
  402. program and display what action would have been taken with that message and
  403. For example, if we do this for a few interesting messages in my mailbox,
  404. we'd end up with output like:
  405. .ft CW
  406. .in .5i
  407. Mail from taylor about filter test
  408. .ti +\w'Mail 'u
  409. FORWARDED to hpldat!taylor by rule;
  410. .ti +\w'Mail   'u
  411. subject="filter test"  ? forward "hpldat!test"
  412. Mail from bradley%hplkab@hplabsc about Re: AI-ED mailing address for HP
  413. .ti +\w'Mail 'u
  414. PUT in mailbox: the default action
  415. Mail from taylor about display-to-console
  416. .ti +\w'Mail 'u
  417. EXECUTED "cat - > /dev/console"
  418. .ft 1
  419. .in 0
  420. (sharp users will notice that this is exactly the same format as the longer
  421. summary listing)
  422. .ne 5
  423. .hu What Forwarded Messages Look Like
  424. When a message is forwarded to another user by the \f2action\f1 being specified
  425. as ``forward \f2address\f1'', then the program can generate one of two styles
  426. of message.  If the message is to you, then it'll simply add it to your mailbox
  427. in such a way as to ensure that the return address is that of the person who
  428. sent the message and so on.
  429. If not, then the message is enclosed in a message of the form:
  430. .in \w'If 'u
  431. .ft CW
  432. From taylor Thu Oct  2 15:07:04 1986
  433. Date: Thu, 2 Oct 86 15:06:58 pdt
  434. Subject: "filter test"
  435. From: The filter of taylor@hpldat <taylor>
  436. To: hpldat!taylor
  437. X-Filtered-By: filter, version 1.4
  438. -- Begin filtered message --
  439. .in +\w'-- 'u
  440. From taylor Thu Oct  2 15:06:41 1986
  441. Date: Thu, 2 Oct 86 15:06:33 pdt
  442. From: Dave Taylor <taylor>
  443. Subject: filter test
  444. Just a simple test.
  445. .in -\w'-- 'u
  446. -- End of filtered message --
  447. .ft 1
  448. .in 0
  449. The subject of the actual message is the same as the subject of the
  450. message being forwarded, but in quotes.  The `From:'  field indicates
  451. how the message was sent, and the `X-Filtered-By:' identifies what
  452. version of filter is being used.
  453. .ne 5
  454. .hu Areas to Improve
  455. While the \f2filter\f1 program as presented herein is obviously a
  456. nice addition to the set of tools available for dealing with electronic
  457. mail, there are some key features that are missing and will be added in
  458. the future based on demand.
  459. As I see it, the main things missing are;
  460. .in .5i
  461. .ti -\n(TWu
  462. 1. The ability to use regular expressions in the patterns.
  463. This would be a \f2very\f1 nice feature!
  464. .ti -\n(TWu
  465. 2. Perhaps more \f2actions\f1 available (but what?)
  466. .ti -\n(TWu
  467. 3. Certainly the ability to filter based on any field or combination of
  468. fields.
  469. .in 0
  470. .ne 5
  471. .hu Warnings and Things to Look Out For
  472. Since this is a pretty simple program, there are a few pitfalls, some
  473. of which have already been mentioned;
  474. \f3Order\f1 counts in the rules.  Beware!
  475. \f3Matching\f1 is pretty simple \(em make sure your patterns are sufficiently
  476. exclusive before having any destructive rules.
  477. .sp 2
  478. Finally, as with the rest of the \f3Elm\f1 mail system, I welcome feedback
  479. and suggestion on how to improve this program!!
  480.