home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / misc / volume06 / showhook.mh < prev    next >
Encoding:
Internet Message Format  |  1991-08-27  |  5.5 KB

  1. From decwrl!ucbvax!tut.cis.ohio-state.edu!mailrus!ames!amdahl!uunet!allbery Fri Mar 24 22:24:53 PST 1989
  2. Article 822 of comp.sources.misc:
  3. Path: decwrl!ucbvax!tut.cis.ohio-state.edu!mailrus!ames!amdahl!uunet!allbery
  4. From: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  5. Newsgroups: comp.sources.misc
  6. Subject: v06i057: MH Mail patch to allow some action to be taken when mail is read
  7. Message-ID: <50624@uunet.UU.NET>
  8. Date: 8 Mar 89 01:24:49 GMT
  9. Sender: allbery@uunet.UU.NET
  10. Reply-To: pbrown@gldsyd.oz.au (Peter Brown)
  11. Lines: 222
  12. Approved: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  13.  
  14. Posting-number: Volume 6, Issue 57
  15. Submitted-by: pbrown@gldsyd.oz.au (Peter Brown)
  16. Archive-name: showhook.mh
  17.  
  18. [On looking this over, I note a few bugs:  specifically, the use of $s instead
  19. of %s in printf()'s (!).  It also requires that MH be configured with RPATHS,
  20. at least for the sample showhook.  Oh, well  ++bsa]
  21.  
  22. The following patch to mh's show.c and the associated code allow you to set up
  23. the mail so that some action can be taken when the mail is actually read using
  24. show, prev, or next.
  25.  
  26. The file regm.c is one that I set up to send a return receipt when the mail
  27. being read has a field "Classification:  Registered" such as Qoffice lets you
  28. put in.
  29.  
  30. The file regm.c could be easily modified to take care of other circumstances.
  31.  
  32.  
  33.  
  34. # This is a shell archive.  Remove anything before this line, then
  35. # unpack it by saving it in a file and typing "sh file".  (Files
  36. # unpacked will be owned by you and have default permissions.)
  37. #
  38. # This archive contains:
  39. # show.diff regm.c
  40.  
  41. echo x - show.diff
  42. cat > "show.diff" << '//E*O*F show.diff//'
  43. 39,41d38
  44. < #define SHOWHOOKSW 12
  45. <     "showhook", 5,
  46. 66,67c63
  47. <             msgnum,
  48. <             showhook = 0;
  49. ---
  50. >             msgnum;
  51. 115,117d110
  52. <                 case SHOWHOOKSW:
  53. <                     showhook = 1;
  54. <                     continue;
  55. 243d235
  56. 251,261d242
  57. < /* The following fork exec code was put in to set up automatic responce to
  58. <    registered mail
  59. < */
  60. <     if (showhook)
  61. <            if ( fork () == 0 )
  62. <             {
  63. <             vec[0] = "showhook";
  64. <             execvp ("showhook", vec);
  65. <             adios ("showhook", "unable to exec");
  66. <             }
  67. 268c249
  68. <             (void) mhl (vecp, vec);
  69. ---
  70. >         (void) mhl (vecp, vec);
  71. //E*O*F show.diff//
  72.  
  73. echo x - regm.c
  74. cat > "regm.c" << '//E*O*F regm.c//'
  75. #define RETURNT        0x01
  76. #define FROMT        0x02
  77. #define DATET        0x04
  78. #define SUBJECTT    0x08
  79. #define CLASST        0x10
  80.  
  81. #include <stdio.h>
  82. #include <string.h>
  83.  
  84. static char    msgfname[] = { "/tmp/REGMXXXXXX" },
  85.         outfname[] = { "/tmp/REGMXXXXXX" };
  86.  
  87. main (argc, argv)
  88. int argc;
  89. char *argv[];
  90. {
  91.  
  92.     static char *args[] = { "sendmail", "-i", "-t", (char *) 0 };
  93.  
  94.     char    sender[256],
  95.         time[256],
  96.         subject[256],
  97.         buf[256],
  98.         copybuf[BUFSIZ],
  99.         **argsp,
  100.         *tokp,
  101.         c;
  102.  
  103.     int    n,
  104.         passflag = 0;
  105.  
  106.     FILE    *msgf,
  107.         *outf,
  108.         *inf;
  109.  
  110.     while (argc-- > 1)
  111.     {
  112.         mktemp (msgfname);
  113.         if ((msgf = fopen (msgfname, "w+"))  ==  (FILE *) NULL)
  114.         {
  115.             fprintf (stderr, "$s: Couldn't open file\n", argv[0]);
  116.             lgooh (1);
  117.         }
  118.         mktemp (outfname);
  119.         if ((outf = fopen (outfname, "w+"))  ==  (FILE *) NULL)
  120.         {
  121.             fprintf (stderr, "$s: Couldn't open file\n", argv[0]);
  122.             lgooh (1);
  123.         }
  124.         if ((inf = fopen (argv[argc], "r+"))  ==  (FILE *) NULL)
  125.         {
  126.             fprintf (stderr, "$s: Couldn't open %s\n",
  127.                 argv[0], argv[argc]);
  128.             lgooh (1);
  129.         }
  130.  
  131.         while (fgets (buf, 256, inf)  !=  (char *) NULL)
  132.         {
  133.             fputs (buf, outf);
  134.  
  135.             tokp = strtok (buf, " ");
  136.             if ((strcmp (tokp, "Return-Path:")) == 0)
  137.             {
  138.                 tokp = strtok (((char *) NULL), "\n");
  139.                 strcpy (sender, tokp);
  140.                 passflag |= RETURNT;
  141.                 continue;
  142.             }
  143.             if ((strcmp (tokp, "From:")) == 0  &&
  144.                 (passflag & RETURNT) != RETURNT)
  145.             {
  146.                 tokp = strtok (((char *) NULL), " \n");
  147.                 strcpy (sender, tokp);
  148.                 passflag |= FROMT;
  149.                 continue;
  150.             }
  151.             if ((strcmp (tokp, "Date:")) == 0)
  152.             {
  153.                 tokp = strtok (((char *) NULL), "\n");
  154.                 strcpy (time, tokp);
  155.                 passflag |= DATET;
  156.                 continue;
  157.             }
  158.             if ((strcmp (tokp, "Subject:")) == 0)
  159.             {
  160.                 tokp = strtok (((char *) NULL), "\n");
  161.                 strcpy (subject, tokp);
  162.                 passflag |= SUBJECTT;
  163.                 continue;
  164.             }
  165.             if ((strcmp (tokp, "Classification:")) == 0)
  166.             {
  167.                 tokp = strtok (((char *) NULL), " \n");
  168.                 if ((strcmp (tokp, "Registered")) == 0)
  169.                 {
  170.                     fseek (outf, -11L, 1);
  171.                     fprintf (outf, "Return Receipt Sent\n");
  172.                     passflag = CLASST;
  173.                 }
  174.                 else
  175.                     lgooh (0);
  176.             }
  177.  
  178.         }
  179.         if ((passflag & CLASST) != CLASST)
  180.             lgooh (0);
  181.  
  182.         fprintf (msgf, "To: %s\n", sender);
  183.         fprintf (msgf, "Subject:  Return Receipt for: %s\n", time);
  184.         fprintf (msgf, "--------\n");
  185.         fprintf (msgf, "This message acknowledges receipt of your ");
  186.         fprintf (msgf, "message of %s ", time);
  187.         fprintf (msgf, "on the subject of: %s\n", subject);
  188.  
  189.         if ( freopen( msgfname, "r", stdin) == (FILE *) NULL)
  190.         {
  191.             fprintf (stderr, "\n\n%s: unable to reopen %s\n\n",
  192.                 argv[0], msgfname);
  193.             lgooh (1);
  194.         }
  195.  
  196.         rewind (inf);
  197.         rewind (outf);
  198.  
  199.         do
  200.             {
  201.             n = fread (copybuf, sizeof (char), BUFSIZ, outf);
  202.             fwrite (copybuf, sizeof (char), n, inf);
  203.         }
  204.         while (n == BUFSIZ);
  205.  
  206.         fclose (inf);
  207.  
  208.  
  209.         if (fork ()  ==  0)
  210.         {
  211.             execv ("/usr/lib/sendmail", args);
  212.             fprintf (stderr,
  213.                 "%s: Unable to exec /usr/lib/sendmail\n",
  214.                 argv[0]);
  215.         }
  216.         else lgooh (0);
  217.     }
  218. }
  219.  
  220. lgooh (exitval)
  221. int exitval;
  222. {
  223.  
  224.     if ((unlink (msgfname)) < 0)
  225.         fprintf (stderr, "Unable to unlink %s\n", msgfname);
  226.     if ((unlink (outfname)) < 0)
  227.         fprintf (stderr, "Unable to unlink %s\n", outfname);
  228.     exit (exitval);
  229. }
  230. //E*O*F regm.c//
  231.  
  232. exit 0
  233.  
  234.  
  235.