home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Spezial / SPEZIAL2_97.zip / SPEZIAL2_97.iso / ANWEND / ONLINE / ELM23-2 / ELM23-2.ZIP / src / mkhdrs.c < prev    next >
C/C++ Source or Header  |  1993-10-10  |  4KB  |  144 lines

  1.  
  2. static char rcsid[] = "@(#)$Id: mkhdrs.c,v 4.1 90/04/28 22:43:32 syd Exp $";
  3.  
  4. /*******************************************************************************
  5.  *  The Elm Mail System  -  $Revision: 4.1 $   $State: Exp $
  6.  *
  7.  *             Copyright (c) 1986, 1987 Dave Taylor
  8.  *             Copyright (c) 1988, 1989, 1990 USENET Community Trust
  9.  *******************************************************************************
  10.  * Bug reports, patches, comments, suggestions should be sent to:
  11.  *
  12.  *    Syd Weinstein, Elm Coordinator
  13.  *    elm@DSI.COM            dsinc!elm
  14.  *
  15.  *******************************************************************************
  16.  * $Log:    mkhdrs.c,v $
  17.  * Revision 4.1  90/04/28  22:43:32  syd
  18.  * checkin of Elm 2.3 as of Release PL0
  19.  *
  20.  *
  21.  ******************************************************************************/
  22.  
  23. /** This contains all the header generating routines for the ELM
  24.     program.
  25.  
  26. **/
  27.  
  28. #include "headers.h"
  29.  
  30. extern char in_reply_to[SLEN];
  31.  
  32. char *strcpy();
  33. unsigned long sleep();
  34.  
  35. generate_reply_to(msg)
  36. int msg;
  37. {
  38.     /** Generate an 'in-reply-to' message... **/
  39.     char buffer[SLEN];
  40.  
  41.  
  42.     if (msg == -1)        /* not a reply! */
  43.       in_reply_to[0] = '\0';
  44.     else {
  45.       if (chloc(headers[msg]->from, '!') != -1)
  46.         tail_of(headers[msg]->from, buffer, 0);
  47.       else
  48.         strcpy(buffer, headers[msg]->from);
  49.       sprintf(in_reply_to, "%s from \"%s\" at %s %s %s %s",
  50.                   headers[msg]->messageid[0] == '\0'? "<no.id>":
  51.           headers[msg]->messageid,
  52.           buffer,
  53.           headers[msg]->month,
  54.           headers[msg]->day,
  55.           headers[msg]->year,
  56.           headers[msg]->time);
  57.     }
  58. }
  59.  
  60. add_mailheaders(filedesc)
  61. FILE *filedesc;
  62. {
  63.     /** Add the users .mailheaders file if available.  Allow backquoting
  64.         in the file, too, for fortunes, etc...*shudder*
  65.     **/
  66.  
  67.     FILE *fd;
  68.     char filename[SLEN], buffer[SLEN];
  69.  
  70.     sprintf(filename, "%s/%s", home, mailheaders);
  71.  
  72.     if ((fd = fopen(filename, "r")) != NULL) {
  73.       while (fgets(buffer, SLEN, fd) != NULL)
  74.         if (strlen(buffer) < 2) {
  75.           dprint(2, (debugfile,
  76.              "Strlen of line from .elmheaders is < 2 (write_header_info)"));
  77.           error1("Warning: blank line in %s ignored!", filename);
  78.           sleep(2);
  79.         }
  80.         else if (occurances_of(BACKQUOTE, buffer) >= 2)
  81.           expand_backquote(buffer, filedesc);
  82.         else
  83.           fprintf(filedesc, "%s", buffer);
  84.  
  85.         fclose(fd);
  86.     }
  87. }
  88.  
  89. expand_backquote(buffer, filedesc)
  90. char *buffer;
  91. FILE *filedesc;
  92. {
  93.     /** This routine is called with a line of the form:
  94.         Fieldname: `command`
  95.         and is expanded accordingly..
  96.     **/
  97.  
  98.     FILE *fd;
  99.     char command[SLEN], command_buffer[SLEN], fname[SLEN],
  100.          prefix[SLEN];
  101.     register int i, j = 0;
  102.  
  103.     for (i=0; buffer[i] != BACKQUOTE; i++)
  104.       prefix[j++] = buffer[i];
  105.     prefix[j] = '\0';
  106.  
  107.     j = 0;
  108.  
  109.     for (i=chloc(buffer, BACKQUOTE)+1; buffer[i] != BACKQUOTE;i++)
  110.       command[j++] = buffer[i];
  111.     command[j] = '\0';
  112.  
  113.     sprintf(fname,"%s%d%s", temp_dir, getpid(), temp_print);
  114.  
  115.     sprintf(command_buffer, "%s > %s", command, fname);
  116.  
  117.     system_call(command_buffer, SH, FALSE, FALSE);
  118.  
  119.     if ((fd = fopen(fname, "r")) == NULL) {
  120.       error1("Backquoted command \"%s\" in elmheaders failed.", command);
  121.       return;
  122.     }
  123.  
  124.     /* If we get a line that is less than 80 - length of prefix then we
  125.        can toss it on the same line, otherwise, simply prepend each line
  126.        *starting with this line* with a leading tab and cruise along */
  127.  
  128.     if (fgets(command_buffer, SLEN, fd) == NULL)
  129.       fprintf(filedesc, prefix);
  130.     else {
  131.       if (strlen(command_buffer) + strlen(prefix) < 80)
  132.         fprintf(filedesc, "%s%s", prefix, command_buffer);
  133.       else
  134.         fprintf(filedesc, "%s\n\t%s", prefix, command_buffer);
  135.  
  136.       while (fgets(command_buffer, SLEN, fd) != NULL)
  137.         fprintf(filedesc, "\t%s", command_buffer);
  138.  
  139.       fclose(fd);
  140.     }
  141.  
  142.     unlink(fname);    /* don't leave the temp file laying around! */
  143. }
  144.