home *** CD-ROM | disk | FTP | other *** search
/ Hall of Fame / HallofFameCDROM.cdr / proglc / msged191.src / WRITMAIL.C < prev   
Encoding:
C/C++ Source or Header  |  1988-10-28  |  3.7 KB  |  178 lines

  1. /*
  2.   
  3. Title:    MsgEd
  4.   
  5. File:    writmail.c
  6.   
  7. Author:    Jim Nutt
  8.     
  9. Copr:    1988 by Jim Nutt
  10.   
  11. Description:
  12.   
  13. writes messages back to disk.
  14.     
  15. Revision History:
  16.   
  17.     0.00    28 jan 1988    first draft
  18.     
  19. Support Files:
  20.   
  21.     msged.h
  22.   
  23. */
  24.  
  25. #define TEXTLEN 128
  26.  
  27. #include "msged.h"
  28.  
  29. int     writemsg(m, n)
  30.     MSG     m;
  31.     int     n;
  32.  
  33. {
  34.     char    path[PATHLEN];
  35.     LINE   *l;
  36.     FILE   *fp;
  37.         char    corigin[TEXTLEN];
  38.     int     i;
  39.     int    newtear = 1;
  40.  
  41.     if (!messages[n])
  42.         return (FALSE);
  43.  
  44.         memset(corigin,0,sizeof corigin);
  45.     sprintf(path,"%s\\origin",arealist[area].path);
  46.  
  47.     if ((fp = fopen(path,"rt")) != NULL) {
  48.                 fgets(corigin,sizeof(corigin),fp);
  49.         fclose(fp);
  50.     }
  51.         else if (origin != NULL)
  52.                 strcpy(corigin,origin);
  53.         else
  54.                 strcpy(corigin,username);
  55.  
  56.     sprintf(path, "%s\\%d.MSG", arealist[area].path, n);
  57.  
  58.     if ((fp = fopen(path, "wb")) == NULL)
  59.         return (FALSE);
  60.  
  61.     m.header.dest_net = m.to.net;
  62.     m.header.dest = m.to.node;
  63.  
  64.     /*
  65.      * we really only want to remap crash mail if a point...  the boss
  66.      * node can (and probably will) handle remapping the rest 
  67.      */
  68.  
  69.         if ((!m.header.crash) && (m.from.point) && (pointnet != 0)) {
  70.         m.from.net = pointnet;
  71.         m.from.node = m.from.point;
  72.         m.from.point = 0;
  73.     }
  74.  
  75.     m.header.orig_net = m.from.net;
  76.     m.header.orig = m.from.node;
  77.  
  78.     m.header.local = 1;
  79.  
  80.     if ((m.from.zone != m.to.zone) && !m.header.crash) {
  81.         m.header.dest_net = m.from.zone;
  82.         m.header.dest = m.to.zone;
  83.     }
  84.  
  85.     if (((m.to.domain != NULL) && (m.from.domain != NULL)) &&
  86.          (strcmp(m.to.domain,m.from.domain)))
  87.              for (i = 0; i < domains; i++)
  88.                  if (strcmp(domain_list[i].domain,m.to.domain) == 0) {
  89.                      m.header.dest = domain_list[i].node;
  90.                      m.header.dest_net = domain_list[i].net;
  91.                  }
  92.  
  93.     fwrite(&(m.header), sizeof(MSGHEADER), 1, fp);
  94.  
  95.     if (m.to.point)
  96.         fprintf(fp, "\01TOPT %d\r\n", m.to.point);
  97.  
  98.     if (m.from.point)
  99.         fprintf(fp, "\01FMPT %d\r\n", m.from.point);
  100.  
  101.     if (m.from.zone != m.to.zone)
  102.         fprintf(fp, "\01INTL %d:%d/%d %d:%d/%d\r\n",
  103.             m.to.zone, m.to.net, m.to.node,
  104.             m.from.zone, m.from.net, m.from.node);
  105.  
  106.     if (((m.to.domain != NULL) && (m.from.domain != NULL)) &&
  107.          (strcmp(m.to.domain,m.from.domain)))
  108.         fprintf(fp, "\01DOMAIN %s %d:%d/%d %s %d:%d/%d\r\n",
  109.             strupr(m.to.domain),m.to.zone, m.to.net, m.to.node,
  110.             strupr(m.from.domain),m.from.zone, m.from.net, m.from.node);
  111.  
  112.     l = msgbuf.first;
  113.     while (l != NULL) {
  114.         char   *s = l->text;
  115.  
  116.         if (l->text == NULL)
  117.             break;
  118.  
  119.         if (newtear)
  120.             newtear = strncmp(s,"--- ",4);
  121.  
  122.         while (*s) {
  123.             if (*s == '\n') {
  124.                 fputc('\r', fp);
  125.                 fputc('\n', fp);
  126.             }
  127.             else
  128.                 fputc(*s, fp);
  129.             s++;
  130.                 }
  131.  
  132.                 if ((strchr(l->text,'\n') == NULL) && softcr)
  133.                         fputc(0x8d,fp);
  134.  
  135.         l = l->next;
  136.  
  137.     }
  138.  
  139.     fputs("\r\n",fp);
  140.     if ((tearline && arealist[area].echomail) && newtear) {
  141.         fputs("\r\n--- msged " VERSION "\r\n", fp);
  142.         fprintf(fp," * Origin: %s (",corigin);
  143.                 if (thisnode.domain != NULL)
  144.                         fprintf(fp,"%s ",thisnode.domain);
  145.                 fprintf(fp,"%d:%d/%d",thisnode.zone,thisnode.net,thisnode.node);
  146.         if (thisnode.point != 0)
  147.             fprintf(fp,".%d",thisnode.point);
  148.         fputs(")\r\n",fp);
  149.     }
  150.     fputc(0, fp);
  151.         fclose(fp);
  152.         arealist[area].new = 1;
  153.     return (TRUE);
  154. }
  155.  
  156. int     writeheader(m, n)
  157.     MSGHEADER m;
  158.     int     n;
  159.  
  160. {
  161.     char    path[PATHLEN];
  162.     FILE   *fp;
  163.  
  164.     if (!messages[n])
  165.         return (FALSE);
  166.  
  167.     sprintf(path, "%s\\%d.MSG", arealist[area].path, n);
  168.  
  169.         if ((fp = fopen(path, "rb+")) == NULL)
  170.         return (FALSE);
  171.  
  172.         fseek(fp,0l,SEEK_SET);
  173.     fwrite(&m, sizeof(MSGHEADER), 1, fp);
  174.  
  175.     fclose(fp);
  176.     return (TRUE);
  177. }
  178.