home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR3 / KA9Q212.ZIP / RMAILER.C < prev    next >
C/C++ Source or Header  |  1993-03-07  |  2KB  |  124 lines

  1. #include        "stdio.h"
  2. #include        "string.h"
  3.  
  4. char top_path[]="admin/sys:\\nos\\spool\\mqueue\\";
  5.  
  6. #define PATH_LEN 72
  7. #define FILE_LEN 13
  8.  
  9. int get_sequence()
  10. {
  11.     char    path[PATH_LEN+FILE_LEN];
  12.     FILE    *seq_fp;
  13.     long int seq_num;
  14.  
  15.     strcpy(path,top_path);
  16.     strcat(path,"sequence.seq");
  17.  
  18.     seq_fp=fopen(path,"r+");
  19.  
  20.     fscanf(seq_fp,"%d",&seq_num);
  21.  
  22.     fseek(seq_fp,0,SEEK_SET);
  23.  
  24.     fprintf(seq_fp,"%d",seq_num+1);
  25.  
  26.     fclose(seq_fp);
  27.  
  28.     return (short int)seq_num;
  29.  
  30. }
  31.  
  32. int parse_message(char *mess,char *send)
  33. {
  34.     FILE    *mess_fp;
  35.     char    type[128];
  36.     int     send_f=0;
  37.  
  38.     mess_fp=fopen(mess,"r");
  39.  
  40.     while(!feof(mess_fp)&&!(send_f==1))
  41.     {
  42.         fscanf(mess_fp,"%s",type);
  43.  
  44.         if(strncmp(type,"From:",5)==0)
  45.         {
  46.                         fscanf(mess_fp,"%s",send);
  47.  
  48.             send_f=1;
  49.         }
  50.     }
  51.  
  52.     fclose(mess_fp);
  53.     return         send_f;
  54. }
  55.  
  56. #define BUFFSIZE 1024
  57.  
  58. char    buff[BUFFSIZE];
  59.  
  60. void main(int argc,char *argv[])
  61. {
  62.     int     seq;
  63.     char    send[128];
  64.     FILE    *src_file;
  65.     FILE    *dest_file;
  66.     char    dest_path[128];
  67.     char    file_name[13];
  68.     int     num_bytes,i;
  69.  
  70.     seq=get_sequence();
  71.  
  72.     if(parse_message(argv[1],send))
  73.     {
  74.         src_file=fopen(argv[1],"r");
  75.  
  76.         strcpy(dest_path,top_path);
  77.         itoa(seq,file_name,10);
  78.  
  79.         strcat(dest_path,file_name);
  80.         strcat(dest_path,".TXT");
  81.  
  82.         dest_file=fopen(dest_path,"w+");
  83.  
  84.         do
  85.         {
  86.             num_bytes=fread(buff,1,BUFFSIZE,src_file);
  87.             fwrite(buff,1,num_bytes,dest_file);
  88.         }
  89.         while(num_bytes==BUFFSIZE)
  90.             ;
  91.  
  92.         fclose(src_file);
  93.         fclose(dest_file);
  94.  
  95.         strcpy(dest_path,top_path);
  96.         strcat(dest_path,file_name);
  97.         strcat(dest_path,".WRK");
  98.  
  99.         dest_file=fopen(dest_path,"w+");
  100.  
  101.     
  102.         if(strchr(argv[2],'@'))
  103.         {
  104.             fprintf(dest_file,"%s\n",strchr(argv[2],'@')+1);
  105.  
  106.             fprintf(dest_file,"%s\n",send);
  107.  
  108.             for(i=2;i<argc;i++)
  109.             {
  110.                 fprintf(dest_file,"%s\n",argv[i]);
  111.             }
  112.         }
  113.  
  114.         fclose(dest_file);
  115.         remove(argv[1]);
  116.  
  117.     }
  118.     else
  119.     {
  120.         printf("RMAILER Failed to send DID not send");
  121.     }
  122. }
  123.  
  124.