home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / shuff110.zip / SHUFFLE.DOC < prev    next >
Text File  |  1994-02-23  |  14KB  |  325 lines

  1.                  SHUFFLE v1.10
  2.             (C) 1993 by D.L. Meyer
  3.  
  4.     An E-mail re-director for use with IBM's TCP/IP for OS/2 SENDMAIL
  5.  
  6.  
  7. The one annoying thing I found about IBM's SENDMAIL handling was that mail
  8. could be sent to any 'user'@my.machine.address, and show up as my mail. 
  9. With no method to sort mail into separate queues for special processing,
  10. either.  
  11.  
  12. So I wrote this little utility, which watches the incoming mail queue 
  13. administered by SENDMAIL, and redirects mail for defined users to separate
  14. mail queues, or in-boxes, in specified directories.  I then set my LaMail
  15. instance to look at my defined 'inbox', with the certainty that it will only 
  16. see mail addressed to *my* defined userid.  This allows me to set up another
  17. 'inbox' for my wife, without my having to wade through her mail and her
  18. through mine.  It also allows me to set up separate inboxes for email which
  19. requires special processing, perhaps automated processing.
  20.  
  21. Note that I use "Inbox" above, and not "Folder".  This is because LaMail keeps 
  22. mail that it has received and processed in what it calls 'folders'.  The storage 
  23. method LaMail uses is not the same as what is used by SENDMAIL & SHUFFLE, 
  24. and what LaMail understands as its "InBox".
  25.  
  26. Also, I included the ability to specify a command to execute when mail is 
  27. received.  This allows specialized processing instead of simply dumping 
  28. the newly arrived mail into a queue.
  29.  
  30.  
  31. A More In-depth How-It-Works:
  32.  
  33. SHUFFLE runs in the background, and watches the main inbox index.  When 
  34. SHUFFLE detects that the index has been updated by SENDMAIL, it rescans the
  35. index to pick up the filename(s) of the newly arrived email message(s). It
  36. pulls the "To:", "Cc:", and the first "Received:" line out of the message header 
  37. info, and parses out the userid(s).  The first "Received:" line can, through a 
  38. very minor modification to your SENDMAIL.CF file, inform of the userid the 
  39. incoming message is intended for.  (How to do the modification is outlined below.)
  40. If the userid cannot be pulled from the "Received:" line, then the "To:" and "Cc:"
  41. lines are used.  
  42.  
  43. [ Note:  If the "Received:" method is not activated through the modification,
  44.     then 'Blind carbon-copies' (Bcc:) and mail to a userid but without a valid 
  45.     userid in "To:" line, as well as mail lacking a "To:" line, will not be processed
  46.     correctly.  ]
  47.  
  48. If the userid found is listed in the USERID file which is read at SHUFFLE
  49. startup, then the new message is copied to the separate inbox for the userid,
  50. and then removed from the main inbox.  Mail addressed to undefined userids
  51. are simply left in the master inbox for later perusal/manual disposal.  Multiple
  52. recipients of the same message on the same machine each receive their own
  53. copy, and duplicate messages (determined by comparing Message-Ids:) are
  54. automatically deleted.
  55.  
  56. An added feature allows SHUFFLE to spawn separate processes on the 
  57. arrival of mail to specified userids.  This allows specialized processing of 
  58. particular types of mail, by user crafted routines.  Also, unidentified userids 
  59. can be trapped, and processed in a like manner.  A REXX Script is included 
  60. in this package which will "bounce" these messages back to the sender.
  61.  
  62. Also, all mail addressed to the userid "root" is automatically redirected to
  63. the first userid in the userid list.
  64.  
  65. Simple, eh?
  66.  
  67. Theoretically, SHUFFLE would suck CPU cycles by constantly checking 
  68. the master inbox.  I handled this by putting a configurable sleep period in the 
  69. loop.  It defaults to scanning once a second.  (See SHUFF_DELAY below.)  
  70. Even then, SHUFFLE only looks to see if the index file's timestamp is more 
  71. recent than the last time it ran a full scan.  If the timestamp is new, only then 
  72. is a processing run performed.
  73.  
  74.  
  75. Parameters & Setup:
  76.  
  77. Setup is simple.  Just put SHUFFLE.EXE on your path, or anywhere really.
  78. Place the EMX.DLL in a directory on your LIBPATH. (Which is defined in your 
  79. CONFIG.SYS.)  
  80.  
  81. Next, create a text file containing a list of USERIDS to sort for.  Each line
  82. should be of the format "Userid   d:\inbox-path", where Userid is a case-
  83. sensitive, single word userid.  (If you want "userid" & "Userid" to be 
  84. equivalent, simple add a line for each, pointing to the same inbox.)
  85.  
  86. For instance:
  87.     user1    d:\tcpip\etc\mail\user1
  88.     user2    d:\tcpip\etc\mail\user2
  89.     User2    d:\tcpip\etc\mail\user2
  90.     ...
  91.  
  92. Notice line #3 above - SHUFFLE is case-sensitive by default, but you can account 
  93. for varied capitalizations of the Userid by having several similar Userids pointing 
  94. to the same InBox directory.
  95.  
  96. Now, you want to spawn a specialized process for all mail arriving for 'user3' - 
  97. what do you do?  Quite simple, actually.  Simply substitute the command for the
  98. process for the path in the examples above.  Preface the command with a "%" to 
  99. indicate to SHUFFLE that it is a command and not a path.
  100.  
  101. Within the command, you can include several character variable tags which will 
  102. tell SHUFFLE to substitute in various parameters.  These character tags 
  103. consist of "&&" + one of the following characters:
  104.  
  105.     "F"    Fully qualified filename of the mail message
  106.     "f"    The message's filename only
  107.     "P","p"    The mailpath - the directory where SENDMAIL leaves messages
  108.     "R","r"    The "Return-To:" address  (Sender's address)
  109.     "H"    The local host address
  110.     "U"    The userid to which the message was sent
  111.     "#"    The child number of the process being spawned.  
  112.             (Shuffle's #, not a PID)
  113.     
  114. For instance, the command for the automated mail bouncing would be:
  115.  
  116.     %d:\path\BOUNCE.CMD &&F &&H &&R &&#
  117.  
  118. This brings up the issue of default processing of unidentifiable userids.  To 
  119. enable this feature, (Disabled by default)  you must include a line in your userid list
  120. with the character "*" as a UserID.  Therefore, the complete line would be:
  121.  
  122.     *   %d:\path\BOUNCE.CMD &&F &&H &&R &&#
  123.  
  124. A caveat for specialized processing -- the called special process carries the 
  125. responsibility of disposing of the original mail message after the processing 
  126. is completed.  When a mail message is passed to a special process, it is
  127. erased from the Inbox's index, and SHUFFLE "forgets" about it.  Therefore,
  128. If the special process doesn't dispose of the incoming files, then they will 
  129. accumulate in the mail directory, doing nothing but taking up space.
  130.  
  131. Oh, by the way, SHUFFLE can be 'DETACHed', but it is probably not a good 
  132. idea if you are going to be using the special processing functions.  (Including
  133. the automatic bouncing function.)
  134.  
  135.  
  136. Command-line parameters:
  137.  
  138.   -U=    designates the file to load for the list of userids & inbox paths.
  139.   -M=   specifies the full path to the main (master) inbox.  (The one 
  140.         that SENDMAIL controls.  Default is the current directory.)
  141.  
  142. Example:
  143.     SHUFFLE -u=c:\shuffle\userids.lst -m=c:\tcpip\etc\mail
  144.  
  145.  
  146. Environment variables:
  147.  
  148.   Set SHUFF_TO=      userid & inbox paths list file
  149.   Set SHUFF_FROM=    full path to the main inbox.
  150.   Set SHUFF_DELAY=   sleep period, in milliseconds, between each scan of
  151.                      master inbox.  (Default is 1000)
  152.  
  153. IBM TCPIP requires the environment variable HOSTNAME to be set to your
  154. machine's name.  SHUFFLE will use this to match against the To: address
  155. of incoming mail in case of multiple addressees.  Since HOSTNAME is 
  156. usually only the first part of the multipart hostname.domain scheme, you 
  157. can set the variable HOSTADDR to the complete multipart name in order to 
  158. improve the validity of the checking that SHUFFLE does.  In most cases, 
  159. however, just the HOSTNAME will do.
  160.  
  161. Example:
  162.   Set HOSTADDR=larch.ag.uiuc.edu
  163.  
  164. SHUFFLE also detects duplicate messages transmitted closely together,
  165. in many cases to multiple recipients on the same machine.  This version 
  166. processes all recipients in a message, and automatically deletes duplicate 
  167. message files that it detects.  
  168.  
  169. This automatic deletion can be turned off by setting the 'NOKILLDUPS' 
  170. environment variable to 'YES' before running Shuffle.
  171.  
  172. Example: 
  173.   Set NOKILLDUPS=YES.
  174.  
  175.  
  176. Precedence -- Command line parameters override any environment variables.
  177.  
  178.  
  179. Modifying the SENDMAIL.CF file:
  180.  
  181. In order to properly process 'Blind Carbon-Copies' and mail without a "To: line,
  182. a small modification is required in the SENDMAIL.CF file on your OS/2 machine.
  183. On most implementations of Sendmail on multi-user machines, the "Received:"
  184. line(s) contain a field "for userid" (or "for userid@host") to signify the intended 
  185. recipient.  Since OS/2 is intended to be a single-user system, IBM decided to 
  186. omit this property in its implementation of Sendmail -- making the assumption 
  187. that any mail arriving was meant for whoever was using the machine.  This
  188. doesn't mean that IBM's OS/2 Sendmail is incapable of doing it, however, 
  189. it just means that we must tell it to.
  190.  
  191. While we would like to have Sendmail use the "for userid@host" format, the 
  192. current versions of OS/2 Sendmail do not seem to provide this capability.  But 
  193. it does allow use of the "for userid" format, fortunately
  194.  
  195. Here's how we make the change to include the "for userid" field --
  196.  
  197. From an OS/2 command prompt, type:
  198.  
  199.    copy %etc%\sendmail.cf %etc%\sendmail.bak <Return>
  200.  
  201. This makes a backup copy, in case something goes awry.  Now type:
  202.  
  203.    e %etc%\sendmail.cf <Return>
  204.  
  205. When the editor loads and the file is loaded, search for the text "Received:".  
  206. (Select [Edit]->[Find], and type in "Received:", pressing [OK] when done.)  
  207. The search should locate pair of lines closely resembling the following:
  208.  
  209.    HReceived: $?sfrom $s $.by $j ($v/$Z)
  210.          id $i; $b
  211.  
  212. (The second line is a continuation of the first.)
  213.  
  214. Now, change the second line to read:
  215.  
  216.          $?ufor $u; $.id $i; $b
  217.  
  218. (Actually the added text, "$?ufor $u; ", can be placed anywhere in the second 
  219. line, or at the end of the 1st line.  I recommend the second line, however, since 
  220. the first line gets pretty long already.)
  221.  
  222. After the change is complete, save the file and exit.  (Select [File]->[Save], 
  223. then [File]->[Exit].)  Be sure to kill & restart the Sendmail server process 
  224. (or simply shutdown & restart your machine) in order to place the changes 
  225. into service.
  226.  
  227.  
  228.  
  229. How to use with LaMail:
  230.  
  231. Now, how do you get LaMail to work with these separate inboxes?  Here's 
  232. what I do:
  233.  
  234. By default, LaMail creates its own INI file, and wants to locate it in the \OS2 
  235. directory.  (I prefer the \TCPIP\ETC directory, but that's me.)  LaMail also 
  236. likes to make this file Read-Only.  What I do is make a duplicate of the LAM.INI 
  237. file for each separate UserID / InBox, under a different name.  (USERID.INI, 
  238. for instance.)
  239.  
  240. I then create a batch file which does the following:
  241.   1) Removes the Read-Only attribute from LAM.INI
  242.   2) Copies USERID.INI to LAM.INI
  243.   3) Runs LAMAIL.EXE
  244.   4) Copies LAM.INI to USERID.INI on exit to save changes.
  245.  
  246. This is mine, as an example.  Modify it to suit your paths, etc.
  247.  
  248. LAM.CMD:
  249. @ECHO OFF
  250. IF ~%1==~ GOTO OUT
  251. IF NOT EXIST %ETC%\%1.INI GOTO NO_FILE
  252. ATTRIB -R %ETC%\LAM.INI
  253. COPY %ETC%\%1.INI %ETC%\LAM.INI >nul
  254. LAMAIL
  255. COPY %ETC%\LAM.INI %ETC%\%1.INI >nul
  256. GOTO OUT
  257. :NO_FILE
  258. ECHO Could not find %ETC%...
  259. :OUT
  260.  
  261.  
  262. To run LaMail, use the command:
  263.     LAM userid
  264.  
  265.  
  266.  
  267. Other related applications:
  268.  
  269. I've noticed some other possible applications for this utility as well.  
  270. Although intended for use on a single machine, one could use it to have 
  271. multiple users' mail sent to a common SENDMAIL receiver, and then parceled 
  272. out to individual Inboxes on a shared drive on a LAN.  The incoming mail is 
  273. still automatically sensed by LaMail running on other machines, which I really didn't 
  274. expect.  However, in order to reply to email, a sendmail process must be running
  275. on the other machines.  The usefullness of this method is when a user has his/her 
  276. LaMail configuration set to "Reply To:" the common SENDMAIL receiver, thereby 
  277. allowing the reading of mail from any networked machine which can use/see the
  278. person's inbox.  Outgoing email is sent from whatever machine the person is working
  279. from, yet any replies to the outgoing mail are sent back through the common 
  280. SENDMAIL receiver due to that address being in the "Reply To:" field.
  281.  
  282. This allows a user who may use any of a number of machines in a LAN to receive 
  283. email to a specific address, yet be able to read and respond to it directly from 
  284. whatever machine the user might be working on.
  285.  
  286. Who knows, with a little imagination, you might come up with something 
  287. similar, or maybe something different...
  288.  
  289.  
  290. Limitations:
  291.  
  292. SHUFFLE only handles incoming email - it does not (cannot) touch outgoing 
  293. mail.
  294.  
  295. I haven't done extensive sharing tests, yet.  But from what I've seen so far,
  296. recovery from a sharing error is quite graceful.
  297.  
  298. Also, when you modify the USERIDS.LST file, any currently running SHUFFLE 
  299. process must be killed, and SHUFFLE must be restarted to pick-up your 
  300. modifications.  (I'm looking into a PM port which will allow updating on-line, 
  301. as well as allowing a shutdown with one less "Do you want to close the 
  302. session without saving...?" question.)
  303.  
  304.  
  305. Distribution & Terms:
  306.  
  307. While I felt that taking a copyright on SHUFFLE was prudent, I am making 
  308. this version freely available for use to all who might find a use for it.  
  309. SHUFFLE version 1.10 is to be freely copyable as long as no money 
  310. changes hands.  (Now, paying for the transfer media is an obvious
  311. exception... )
  312.  
  313. As always, if you have any suggestions, or any "bugs" to report, I want to
  314. hear them.  Please e-mail them to 'shuffle@larch.ag.uiuc.edu'.
  315.  
  316. If you find SHUFFLE useful, please consider a small donation, if only to 
  317. entice further development of Shuffle.  Anyone sending $5 or more, and 
  318. their e-mail address, will be placed on a list to automatically receive 
  319. uuencoded updates via e-mail when they become available.
  320.  
  321.     Address:    D.L. Meyer
  322.         745E County Rd. 2175N
  323.         Champaign, IL 61821
  324.  
  325.