home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / elm / elm2.4 / src / mkhdrs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-08  |  4.0 KB  |  152 lines

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