home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3590 < prev    next >
Encoding:
Internet Message Format  |  1991-07-06  |  8.5 KB

  1. From: magnus%thep.lu.se@Urd.lth.se (Magnus Olsson)
  2. Newsgroups: alt.sources
  3. Subject: autosign utility for Mail User's Shell (mush)  part 01/01
  4. Message-ID: <1991Jul4.151009.12461@lth.se>
  5. Date: 4 Jul 91 15:10:09 GMT
  6.  
  7. Submitted-by: magnus@thep.lu.se
  8. Archive-name: autosign/part01
  9.  
  10. autosign
  11.  
  12. A utility for use with the Mail User's Shell (mush)
  13.  
  14. by Magnus Olsson (magnus@thep.lu.se)
  15.  
  16.  
  17. The Mail User's Shell (mush), by Dan Heller (argv@sun.com), has options for
  18. automatically appending your signature and/or a "fortune cookie" to all
  19. outgoing mail. The options are rather flexible; for example, you can use one
  20. signature for letters to certain domains and another one for other domains.
  21.  
  22. However, you may wish for greater flexibility than that provided by mush.
  23. Version 7 (and later) of mush allows you to specify a program that is called
  24. to sign your mail. autosign.c is an example of such a program.
  25.  
  26. Once you have installed it, every time you send a mail message you will be
  27. given a menu of signatures to choose from. You select one of these and it is
  28. appended to your message (you may of course also choose not to append any
  29. signature at all). autosign will then call your system's "fortune cookie"
  30. program to generate a fortune cookie. This will be shown to you beefore it is
  31. appended, and you'll be given the options to either append it to the message,
  32. or to generate a new fortune (this way, you can e.g. avoid appending rude
  33. jokes to letters to your boss - many of the quotes in fortune databases tend
  34. to be rather obscene), or not to append one at all.
  35.  
  36. No modification to mush is needed, only a line in your .mushrc file.
  37.  
  38. There is no Makefile (what use is that when the program consist of just one
  39. file?) and no manpage either - the instructions in the README file should 
  40. suffice.
  41.  
  42. Magnus Olsson                   | \e+      /_
  43. Dept. of Theoretical Physics    |  \  Z   / q
  44. University of Lund, Sweden      |   >----<           
  45. Internet: magnus@thep.lu.se     |  /      \===== g
  46. Bitnet: THEPMO@SELDC52          | /e-      \q
  47.  
  48.  
  49. ---- Cut Here and feed the following to sh ----
  50. #!/bin/sh
  51. # This is autosign, a shell archive (produced by shar 3.49)
  52. # To extract the files from this archive, save it to a file, remove
  53. # everything above the "!/bin/sh" line above, and type "sh file_name".
  54. #
  55. # made 07/04/1991 15:07 UTC by magnus@thep.lu.se
  56. # Source directory /usr/users/magnus/source/autosign
  57. #
  58. # existing files will NOT be overwritten unless -c is specified
  59. #
  60. # This shar contains:
  61. # length  mode       name
  62. # ------ ---------- ------------------------------------------
  63. #   2655 -rw-r--r-- README
  64. #   2480 -rw-r--r-- autosign.c
  65. #
  66. # ============= README ==============
  67. if test -f 'README' -a X"$1" != X"-c"; then
  68.     echo 'x - skipping README (File already exists)'
  69. else
  70. echo 'x - extracting README (Text)'
  71. sed 's/^X//' << 'SHAR_EOF' > 'README' &&
  72. autosign
  73. X
  74. A utility for use with the Mail User's Shell (mush)
  75. X
  76. by Magnus Olsson (magnus@thep.lu.se)
  77. July 4, 1991
  78. X
  79. This program is in the public domain.
  80. X
  81. ===========================================================================
  82. X
  83. The Mail User's Shell (mush), by Dan Heller (argv@sun.com), has options for
  84. automatically appending your signature and/or a "fortune cookie" to all
  85. outgoing mail. The options are rather flexible; for example, you can use one
  86. signature for letters to certain domains and another one for other domains.
  87. X
  88. However, you may wish for greater flexibility than that provided by mush.
  89. Version 7 (and later) of mush allows you to specify a program that is called
  90. to sign your mail. autosign.c is an example of such a program.
  91. X
  92. Once you have installed it, every time you send a mail message you will be
  93. given a menu of signatures to choose from. You select one of these and it is
  94. appended to your message (you may of course also choose not to append any
  95. signature at all). autosign will then call your system's "fortune cookie"
  96. program to generate a fortune cookie. This will be shown to you beefore it is
  97. appended, and you'll be given the options to either append it to the message,
  98. or to generate a new fortune (this way, you can e.g. avoid appending rude
  99. jokes to letters to your boss - many of the quotes in fortune databases tend
  100. to be rather obscene), or not to append one at all.
  101. X
  102. No modification to mush is needed, only a line in your .mushrc file.
  103. X
  104. X
  105. X
  106. Installation:
  107. X
  108. First edit the file autosign.c to suit your needs.
  109. As it is, it gives you a choice of two different signatures. These signatures
  110. should be kept in different files. The macros SIG1 and SIG2 should be defined
  111. as the full paths of these files.
  112. If you need another number of signatures than 2, you must define one macro for
  113. each file. The "switch (ans)" statement must also be changed, but the
  114. modifications are trivial.
  115. The macro FORTUNE should be defined as the full path of the program to
  116. generate fortune cookies on your system.
  117. X
  118. Then compile autosign with the following command:
  119. cc -o autosign autosign.c
  120. and move the resulting file autosign to somewhere in your path.
  121. On some systems, such as Ultrix, you'll have to do a 'rehash', too.
  122. X
  123. Then edit your .mushrc file to contain the line
  124. set autosign="| autosign"
  125. X
  126. That should be all!
  127. X
  128. X
  129. Note:
  130. X
  131. This program has been tested on a DECstation 3100 running RISC Ultrix 4.1. It
  132. has not been tried on any other system. It believe it should work on any
  133. system running BSD 4.x Unix.
  134. X
  135. Disclaimer:
  136. X
  137. The author will accept no responsibily whatsoever for any damage or unwanted
  138. effects caused by the use of this software. 
  139. X
  140. X
  141. SHAR_EOF
  142. chmod 0644 README ||
  143. echo 'restore of README failed'
  144. Wc_c="`wc -c < 'README'`"
  145. test 2655 -eq "$Wc_c" ||
  146.     echo 'README: original size 2655, current size' "$Wc_c"
  147. fi
  148. # ============= autosign.c ==============
  149. if test -f 'autosign.c' -a X"$1" != X"-c"; then
  150.     echo 'x - skipping autosign.c (File already exists)'
  151. else
  152. echo 'x - extracting autosign.c (Text)'
  153. sed 's/^X//' << 'SHAR_EOF' > 'autosign.c' &&
  154. /**********************************
  155. X * autosign.c              *
  156. X * A program to attach signatures *
  157. X * to outgoing mail          *
  158. X * Designed to be called by mush  *
  159. X *                  *
  160. X * Written by Magnus Olsson      *
  161. X *       (magnus@thep.lu.se)      *
  162. X *                  July 4, 1991  *
  163. X *                  *
  164. X *   This program is donated to   *
  165. X *       the public domain        *   
  166. X *                  *
  167. X *     The author takes no        *
  168. X *  responsibily whatsoever for   *
  169. X * any damage or unwanted effects *
  170. X *   caused by the use of this    *
  171. X *          software.             *
  172. X **********************************/
  173. X
  174. #include <stdio.h>
  175. #define READ 0
  176. #define WRITE 1
  177. #define MAX 9999 
  178. /* MAX is the maximum number of characters allowed in a single fortune */
  179. X
  180. /* SIG1 and SIG2 are the full paths of the signature files */
  181. #define SIG1 "/usr/users/magnus/.signature"
  182. #define SIG2 "/usr/users/magnus/mail/sig2"
  183. /* FORTUNE is the full path to the fortune cookie program */
  184. #define FORTUNE "/usr/local/bin/cookie"
  185. X
  186. main ()
  187. X
  188. {
  189. X    char ans,s [MAX+1];
  190. X    int i;
  191. X    FILE *sigfile;
  192. X    int Pipe [2]; 
  193. X    char *fname;
  194. X    
  195. X    fprintf (stderr,"1: Signature 1\n2: Signature 2\n3: No signature ");
  196. X    scanf ("%c",&ans);
  197. X    fprintf (stderr,"%c\n",ans);
  198. X
  199. X    switch (ans) {
  200. X    case '1': fname = SIG1;  break;
  201. X    case '2': fname = SIG2;  break;
  202. X    default:  fname = NULL;
  203. X    }
  204. X    if (fname) {
  205. X        if (sigfile = fopen (fname, "r")) {
  206. X        do {
  207. X            if (fgets (s,100,sigfile))
  208. X              printf ("%s",s);
  209. X        } while (! feof (sigfile));
  210. X        fclose (sigfile);
  211. X        }
  212. X    else
  213. X        fprintf (stderr,"Couldn't open signature file %s\n",fname);
  214. X    }
  215. X            
  216. X    do {
  217. X        if (pipe (Pipe)) {
  218. X             fprintf (stderr,"Couldn't create pipe\n");
  219. X        exit (1);
  220. X    }
  221. X        switch (fork ()) {
  222. X        case -1: fprintf (stderr,"Couldn't spawn subprocess\n");
  223. X             exit (1);
  224. X        case  0: /* Child process */
  225. X                 dup2 (Pipe [WRITE],1);  /* Redirect stdout to the pipe */
  226. X                     close (Pipe [WRITE]);
  227. X                 execl (FORTUNE,NULL);   /* Print a fortune to the pipe and terminate process*/
  228. X        default: /* Parent process */
  229. X                  i = read (Pipe [READ],s,MAX); /* Read the output of the fortune program */
  230. X             s [i] = '\0'; /* End-if-string marker */
  231. X             close (Pipe [READ]);
  232. X        }
  233. X    fprintf (stderr,"%s\nAdd the above fortune? (Yes/No/Another) ",s);
  234. X    scanf ("%c",&ans);
  235. X    fprintf (stderr,"%c\n",ans);
  236. X    ans = toupper (ans);
  237. X    } while (ans == 'A');  
  238. X    if (ans == 'Y')
  239. X        puts (s);
  240. }
  241. X
  242. X
  243. X
  244. X
  245. SHAR_EOF
  246. chmod 0644 autosign.c ||
  247. echo 'restore of autosign.c failed'
  248. Wc_c="`wc -c < 'autosign.c'`"
  249. test 2480 -eq "$Wc_c" ||
  250.     echo 'autosign.c: original size 2480, current size' "$Wc_c"
  251. fi
  252. exit 0
  253.