home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 3 Comm / 03-Comm.zip / RDQWKSRC.ZIP / MAKEMAIL.C < prev    next >
Text File  |  1991-11-20  |  9KB  |  262 lines

  1. /*
  2. ╔══════════════════════════════════════════════════════════════════════════╗
  3. ║                                                                          ║
  4. ║         Test routines to read, in Qmail Format - R.Cougnenc 90 -         ║
  5. ║                                                                          ║
  6. ║                            Public Domain                                 ║
  7. ║                                                                          ║
  8. ╟──────────────────────────────────────────────────────────────────────────╢
  9. ║                                                                          ║
  10. ║       These modules correspond to different tests at reading in          ║
  11. ║       Qmail Format. They were never planned to be released as a          ║
  12. ║       package.                                                           ║
  13. ║                                                                          ║
  14. ║       Source code is not beautified or optimised as they are work        ║
  15. ║       files and are distributed as is.                                   ║
  16. ║                                                                          ║
  17. ║       The program, even at it's rustic stage is fully fonctional,        ║
  18. ║       as I use it regularly...                                           ║
  19. ║                                                                          ║
  20. ║       Feel free to use any or all of these modules, if you can sort      ║
  21. ║       it out! :-)                                                        ║
  22. ║                                                                          ║
  23. ╚══════════════════════════════════════════════════════════════════════════╝
  24. */
  25.  
  26.  
  27.  
  28. /*
  29.      ┌────────────────────────────────────────────────────────────────┐
  30.      │                                                                │
  31.      │        Creating message parket in Qmail/MarkMail format.       │
  32.      │             (Off-Line mail reader for PcBoard nodes)           │
  33.      │     Test routines to give examples on how it works....         │
  34.      │                   (c) René Cougnenc 1990                       │
  35.      │                                                                │
  36.      │     With no available documentation, it is done with what      │
  37.      │     was available... it certainly contains errors, but it      │
  38.      │     runs fine...                                               │
  39.      └────────────────────────────────────────────────────────────────┘
  40. */
  41.  
  42.  
  43. #include <stdio.h>
  44. #include <io.h>
  45. #include <ctype.h>
  46. #include <stdlib.h>
  47. #include "reader.h"
  48. #include "qmail.h"
  49. #include "ansi.h"
  50. #include "makemail.h"
  51.  
  52.  
  53.  
  54. FILE *MsgFile,*TmpFile;
  55. char MessageFile[MAXPATHS];
  56.  
  57. struct QmailRepType Header;
  58.  
  59. /*----------------------------------------------------------------------*/
  60.  
  61.  
  62. /*----------------------------------------------------------------------*/
  63. /*
  64.  
  65.      Creating the header portion of the message corresponding to the
  66.      node.
  67.  
  68. */
  69.  
  70. void FirstHeader()
  71. {
  72.    char Block[128];
  73.    strupr(CurBoard) ;                  /* You never know */
  74.    memset (Block,0x20,128);           /* fill in the blanks */
  75.    str2mem(Block,CurBoard);           /* put the node name */
  76.    fwrite(Block,128,1,MsgFile);       /* write this block in the file */
  77.    fflush(MsgFile);
  78. }
  79. /*----------------------------------------------------------------------*/
  80.  
  81.                  Passing the default values to the header
  82.  
  83. /*----------------------------------------------------------------------*/
  84.  
  85. void ResetHeader(Qmail)
  86. struct QmailRepType *Qmail ;
  87. {
  88.  
  89.  
  90.  memset(&Qmail->Status,0x20,sizeof(struct QmailRepType) );
  91.                                             /* structure filled with blanks */
  92.  /*Qmail->Status = 0x2A;*/  /* seems to be a new message */
  93.  Qmail->Status   = 0x20;
  94.  
  95.  str2mem(Qmail->NumMsg,"0");                    /* Conference 0         */
  96.  str2mem(Qmail->MsgDate,"07-14-8920:30");       /* stupid date */
  97.  Qmail->Delete   = 0xE1;
  98.  Qmail->Unknown2 = 0x00      ;     /* ???? = 00 /* to send */
  99.  Qmail->Unknown3 = 0x00      ;     /* ???? = 00                         */
  100.  Qmail->Unknown4 = 0x20      ;     /* ???? = SPACE                      */
  101.  Qmail->Unknown5 = 0x00      ;     /* ???? = SPACE                      */
  102.  Qmail->Unknown6 = 0x00      ;     /* ???? = 00                         */
  103. }
  104. /*----------------------------------------------------------------------*/
  105.  
  106.  
  107.  
  108.  
  109. /*----------------------------------------------------------------------*/
  110. /*
  111.  
  112.  
  113.            Write the messsage in PcBoard format, with the translation
  114.            of cr/lf to 'π'
  115.  
  116. */
  117.  
  118. int CodeMessage(fname,Qmail)
  119. char *fname;
  120. struct QmailRepType *Qmail ;
  121. {
  122.  byte ch;
  123.  byte *ptr,*tamp;
  124.  byte tmp[20];
  125.  byte *tampon;          /* to simplify tests a large size buffer */
  126.  int  CountSize   = 0,  /* will contain total size of the text without header */
  127.  
  128.       CountChar   = 0,
  129.       CountBlocks = 2;  /* First 128 char block is always the header */
  130.  
  131.                     /* open the file generated by the editor */
  132.                     /*-------------------------------------*/
  133.  
  134.    if( (tampon = (char *) malloc(MAXSIZE) ) == NULL )
  135.    {
  136.      printf("%s\n",txt[1] );
  137.      fclose(MsgFile);
  138.      return( ERROR );
  139.    }
  140.  
  141.    if(( TmpFile = fopen(fname,"rb")) == NULL )
  142.    {
  143.      printf("%s %s\n",txt[ 51 ],fname);  /* "unable to open file" */
  144.      free(tampon);
  145.      return ERROR ;
  146.    }
  147.    if( setvbuf(TmpFile,NULL,_IOFBF,VBUF) )
  148.        printf("%sCodeMsg()\n",txt[ 94 ]);  /* "Setvbuf failed..." */
  149.  
  150.  
  151. /*   fread(tampon,1,sizeof(struct MyMessage),TmpFile );*/ /* skip my header */
  152.  
  153.  
  154.                    /* Coding of the message in the buffer */
  155.                    /*----------------------------------*/
  156.  
  157.    tamp = tampon;
  158.    while(fread(&ch,1,1,TmpFile))
  159.         {
  160.           if(ch == 0x0A) ch = 227;
  161.           if(ch == 0x0D) continue ;
  162.           *tamp = ch;     tamp ++;
  163.           CountChar++; CountSize ++;
  164.           if(CountChar > 127)
  165.             {
  166.               CountBlocks++;
  167.               CountChar = 0;
  168.             }
  169.         }
  170.  
  171.                    /* Add the signature to the program */
  172.                    /*-------------------------------------*/
  173.  
  174.    ptr = CurTag;
  175.    while(*ptr)
  176.         {
  177.           if(*ptr == '\n') *ptr = 227;
  178.           *tamp  =  *ptr;
  179.           tamp++ ;  ptr++;
  180.           CountChar++; CountSize++;
  181.           if(CountChar > 127)
  182.             {
  183.               CountBlocks++;
  184.               CountChar = 0;
  185.             }
  186.         }
  187.                   /* Ajust the size of the last block to 128 chars */
  188.                   /*----------------------------------------------*/
  189.  
  190.    while(CountChar < 128)
  191.         {
  192.           *tamp = 0x20;     tamp ++;
  193.           CountChar++; CountSize++;
  194.         }
  195.  
  196.                  /* Put in the header the number of 128 char blocks */
  197.                  /*------------------------------------------------------*/
  198.  
  199.    sprintf(tmp,"%d",CountBlocks);
  200.    str2mem(Qmail->SizeMsg,tmp);
  201.  
  202.                  /* Write the message header and then the body */
  203.                  /*------------------------------------------------------*/
  204.  
  205.    printf("%s...\n",txt[ 75 ]); /* "Saving the message */
  206.    fwrite((byte *) Qmail,1,sizeof(struct QmailRepType),MsgFile);
  207.    fwrite(tampon,1,CountSize,MsgFile);
  208.  
  209.                 /*  Close and delete the work file */
  210.                 /*------------------------------------------------------*/
  211.  
  212.    fclose(TmpFile);
  213.    unlink(fname);
  214.    fclose(MsgFile);
  215.    free( tampon );
  216.    return (OK );
  217. }
  218. /*----------------------------------------------------------------------*/
  219.  
  220.  
  221.  
  222.  
  223. /*----------------------------------------------------------------------*/
  224. /*
  225.                    Open or create the message file
  226.  
  227. */
  228. void OpenRepFile()
  229. {
  230. int FileExist;
  231.  
  232.  
  233.     sprintf(MessageFile,"%s/%s%s",WorkPath,CurBoard,MSG_EXT);
  234.     if(access(MessageFile,0) == 0) FileExist = 1;
  235.     else FileExist = 0;
  236.  
  237.  
  238.  
  239.     if(FileExist)
  240.       {
  241.         printf("%s %s \n",txt[ 76 ],MessageFile);
  242.         /* "Adding message to file" */
  243.       }
  244.     else
  245.       {
  246.         printf("%s %s \n",txt[77],MessageFile);
  247.         /* "creating file" */
  248.       }
  249.  
  250.  
  251.     if( ( MsgFile = fopen(MessageFile,"a+b")) == NULL)
  252.     {
  253.       printf("%s %s\n",txt[51],MessageFile); /* "unable to open file" */
  254.       perror("System");
  255.       return ;
  256.     }
  257.  
  258.     if(!FileExist) FirstHeader();
  259.  
  260. }
  261. /*----------------------------------------------------------------------*/
  262.