home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 3 Comm
/
03-Comm.zip
/
RDQWKSRC.ZIP
/
MAKEMAIL.C
< prev
next >
Wrap
Text File
|
1991-11-20
|
9KB
|
262 lines
/*
╔══════════════════════════════════════════════════════════════════════════╗
║ ║
║ Test routines to read, in Qmail Format - R.Cougnenc 90 - ║
║ ║
║ Public Domain ║
║ ║
╟──────────────────────────────────────────────────────────────────────────╢
║ ║
║ These modules correspond to different tests at reading in ║
║ Qmail Format. They were never planned to be released as a ║
║ package. ║
║ ║
║ Source code is not beautified or optimised as they are work ║
║ files and are distributed as is. ║
║ ║
║ The program, even at it's rustic stage is fully fonctional, ║
║ as I use it regularly... ║
║ ║
║ Feel free to use any or all of these modules, if you can sort ║
║ it out! :-) ║
║ ║
╚══════════════════════════════════════════════════════════════════════════╝
*/
/*
┌────────────────────────────────────────────────────────────────┐
│ │
│ Creating message parket in Qmail/MarkMail format. │
│ (Off-Line mail reader for PcBoard nodes) │
│ Test routines to give examples on how it works.... │
│ (c) René Cougnenc 1990 │
│ │
│ With no available documentation, it is done with what │
│ was available... it certainly contains errors, but it │
│ runs fine... │
└────────────────────────────────────────────────────────────────┘
*/
#include <stdio.h>
#include <io.h>
#include <ctype.h>
#include <stdlib.h>
#include "reader.h"
#include "qmail.h"
#include "ansi.h"
#include "makemail.h"
FILE *MsgFile,*TmpFile;
char MessageFile[MAXPATHS];
struct QmailRepType Header;
/*----------------------------------------------------------------------*/
/*----------------------------------------------------------------------*/
/*
Creating the header portion of the message corresponding to the
node.
*/
void FirstHeader()
{
char Block[128];
strupr(CurBoard) ; /* You never know */
memset (Block,0x20,128); /* fill in the blanks */
str2mem(Block,CurBoard); /* put the node name */
fwrite(Block,128,1,MsgFile); /* write this block in the file */
fflush(MsgFile);
}
/*----------------------------------------------------------------------*/
Passing the default values to the header
/*----------------------------------------------------------------------*/
void ResetHeader(Qmail)
struct QmailRepType *Qmail ;
{
memset(&Qmail->Status,0x20,sizeof(struct QmailRepType) );
/* structure filled with blanks */
/*Qmail->Status = 0x2A;*/ /* seems to be a new message */
Qmail->Status = 0x20;
str2mem(Qmail->NumMsg,"0"); /* Conference 0 */
str2mem(Qmail->MsgDate,"07-14-8920:30"); /* stupid date */
Qmail->Delete = 0xE1;
Qmail->Unknown2 = 0x00 ; /* ???? = 00 /* to send */
Qmail->Unknown3 = 0x00 ; /* ???? = 00 */
Qmail->Unknown4 = 0x20 ; /* ???? = SPACE */
Qmail->Unknown5 = 0x00 ; /* ???? = SPACE */
Qmail->Unknown6 = 0x00 ; /* ???? = 00 */
}
/*----------------------------------------------------------------------*/
/*----------------------------------------------------------------------*/
/*
Write the messsage in PcBoard format, with the translation
of cr/lf to 'π'
*/
int CodeMessage(fname,Qmail)
char *fname;
struct QmailRepType *Qmail ;
{
byte ch;
byte *ptr,*tamp;
byte tmp[20];
byte *tampon; /* to simplify tests a large size buffer */
int CountSize = 0, /* will contain total size of the text without header */
CountChar = 0,
CountBlocks = 2; /* First 128 char block is always the header */
/* open the file generated by the editor */
/*-------------------------------------*/
if( (tampon = (char *) malloc(MAXSIZE) ) == NULL )
{
printf("%s\n",txt[1] );
fclose(MsgFile);
return( ERROR );
}
if(( TmpFile = fopen(fname,"rb")) == NULL )
{
printf("%s %s\n",txt[ 51 ],fname); /* "unable to open file" */
free(tampon);
return ERROR ;
}
if( setvbuf(TmpFile,NULL,_IOFBF,VBUF) )
printf("%sCodeMsg()\n",txt[ 94 ]); /* "Setvbuf failed..." */
/* fread(tampon,1,sizeof(struct MyMessage),TmpFile );*/ /* skip my header */
/* Coding of the message in the buffer */
/*----------------------------------*/
tamp = tampon;
while(fread(&ch,1,1,TmpFile))
{
if(ch == 0x0A) ch = 227;
if(ch == 0x0D) continue ;
*tamp = ch; tamp ++;
CountChar++; CountSize ++;
if(CountChar > 127)
{
CountBlocks++;
CountChar = 0;
}
}
/* Add the signature to the program */
/*-------------------------------------*/
ptr = CurTag;
while(*ptr)
{
if(*ptr == '\n') *ptr = 227;
*tamp = *ptr;
tamp++ ; ptr++;
CountChar++; CountSize++;
if(CountChar > 127)
{
CountBlocks++;
CountChar = 0;
}
}
/* Ajust the size of the last block to 128 chars */
/*----------------------------------------------*/
while(CountChar < 128)
{
*tamp = 0x20; tamp ++;
CountChar++; CountSize++;
}
/* Put in the header the number of 128 char blocks */
/*------------------------------------------------------*/
sprintf(tmp,"%d",CountBlocks);
str2mem(Qmail->SizeMsg,tmp);
/* Write the message header and then the body */
/*------------------------------------------------------*/
printf("%s...\n",txt[ 75 ]); /* "Saving the message */
fwrite((byte *) Qmail,1,sizeof(struct QmailRepType),MsgFile);
fwrite(tampon,1,CountSize,MsgFile);
/* Close and delete the work file */
/*------------------------------------------------------*/
fclose(TmpFile);
unlink(fname);
fclose(MsgFile);
free( tampon );
return (OK );
}
/*----------------------------------------------------------------------*/
/*----------------------------------------------------------------------*/
/*
Open or create the message file
*/
void OpenRepFile()
{
int FileExist;
sprintf(MessageFile,"%s/%s%s",WorkPath,CurBoard,MSG_EXT);
if(access(MessageFile,0) == 0) FileExist = 1;
else FileExist = 0;
if(FileExist)
{
printf("%s %s \n",txt[ 76 ],MessageFile);
/* "Adding message to file" */
}
else
{
printf("%s %s \n",txt[77],MessageFile);
/* "creating file" */
}
if( ( MsgFile = fopen(MessageFile,"a+b")) == NULL)
{
printf("%s %s\n",txt[51],MessageFile); /* "unable to open file" */
perror("System");
return ;
}
if(!FileExist) FirstHeader();
}
/*----------------------------------------------------------------------*/