home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / com / utils / elm / sources / filter.gui < prev    next >
Text File  |  1990-04-28  |  17KB  |  592 lines

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