home *** CD-ROM | disk | FTP | other *** search
/ Netware Super Library / Netware Super Library.iso / pegamail / pmfxuucp / source / filterze.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-11  |  10.8 KB  |  272 lines

  1. // Fillterze.cpp a program to take the output produced by Pegasus Mail/PC in standalone
  2. // mode or from a Lan, and place it appropriately. with associated support .cmd and .xqt
  3. // files for mail processing using the Waffle BBS uucico and uuxqt programs.
  4. //
  5. // Pegasus Mail/PC (C) Copyright 1990, 1991, David Harris, Dunedin, New Zealand
  6. // WAFFLE  (C) Copyright 1991 by Darkside International of Mountain View CA.
  7. //
  8. // Modification Author: Michael D. Setzer II, Guam Community College, Guam
  9. // Address: MSETZERII@cup.portal.com
  10. // Permission is granted to do whatever you like with this code. If you do have
  11. // problems or suggestions, please drop me a line. No warranty whatsoever is granted
  12. // or implied, but I will attempt to make modification if information is
  13. // forward to me and it is within my capability.
  14.  
  15. // Original Author of Filter
  16. // Author: Brendan Murray, Dunedin, New Zealand
  17. // Permission is granted to do whatever you like with this code. Just about
  18. // anyone ought to be able to improve on it. No warranty whatsoever is granted
  19. // or implied.
  20. //
  21. // V1.1
  22. //
  23. //     Command line parameters.
  24. //     0:    the command
  25. //     1:    username
  26. //     2:    container file name -- full path
  27. //     3:    To: field for mail
  28. //     4:    The time in RFC 822 format  (TIME NO LONGER USED IN THIS PROGRAM)
  29. //
  30. //     Actions
  31. //     1. Take the RFC 822 message produced by pmail and prepend a uucp acceptible From line
  32. //     2. Create a .cmd file to tell UUCICO what to do
  33. //     3. Create a .xqt file to tell UUXQT what to do at the other end
  34. //
  35.  
  36. #include <stdlib.h>
  37. #include <stdio.h>
  38. #include <string.h>
  39. #include <dir.h>
  40. #include <time.h>
  41.  
  42. void main (int argc, char * argv[] )
  43. {
  44.     FILE *outfile;
  45.     FILE *infile;
  46.     char FileName[MAXPATH];                        // Filename Variable: Used for everything
  47.     char HostName[60]="NOT DEFINED";                 // LOCAL HOST NAME
  48.     char TimeZone[60]="NOT DEFINED";                   // TIME ZONE
  49.     char FullName[60]="NOT DEFINED";                    // FULL HOST AND LOCAL
  50.     char Organization[60]="NOT DEFINED";                // ORGANIZATION INFORMATION
  51.     char timeline[30];                        // Time for from line
  52.     char time2[30];                            // Time for the header
  53.     time_t t;                            // Structor for time
  54.     char drive[MAXDRIVE];                        // for fnsplit and fnmerge
  55.     char dir[MAXDIR];
  56.     char name[MAXFILE];
  57.     char a[1024];                             // Array for Reading Lines
  58.     int j,i;
  59.     char ch;
  60.  
  61.     if (argc != 4)
  62.     {
  63.         // even though Pmail probably won't display this
  64.         fprintf(stderr,"Usage: filter username container-file to-line\n");
  65.         exit(1);
  66.     }
  67.  
  68.     // if comma is on end of Mail address, trim it off
  69.     while (argv[3][strlen(argv[3])-1]==',')            argv[3][strlen(argv[3])-1]=NULL;
  70.  
  71.     // drive and directory from Spool file name from input arguments
  72.     fnsplit(argv[2], drive, dir, name, NULL);
  73.  
  74.     // Program uses Host.Dat file for storing Information about Host and timezone
  75.     // Format is 3 lines:
  76.     // HOST:  local name   Example:  HOST: GCCcc
  77.     // FULL:  full host              FULL: GCCcc.Guam.Net
  78.     // TIME:  timezone               TIME: GST +1400
  79.     // ORGAN: organization           ORGAN: Guam Community College Computer Center
  80.     // The keywords must be in ALL caps and Left justified including the :
  81.     // The values can have spaces before and/or after them
  82.     // Any lines with other values are ignored.
  83.     // Information can be in any order.
  84.     // File goes in the Spool directory
  85.  
  86.     fnmerge(FileName, drive, dir,"HOST", ".DAT");        // Get Host File name
  87.     // Open File
  88.     if ((infile = fopen(FileName,"r")) == NULL)
  89.     {
  90.         fprintf(stderr,"Open of Host file %s failed\n", FileName);
  91.         exit(1);
  92.     }
  93.     // Read Host Information from File
  94.         while (!feof(infile))
  95.         {
  96.             j=0;                            // Initialize Array Pointer to Beginning
  97.             while(((ch=fgetc(infile))!='\n') && !feof(infile))    // Read Characters till End of Line or End of File
  98.                 a[j++]=ch;                    // Store Character
  99.             a[j]=NULL;                        // Add NULL to end of String
  100.             if (strstr(a,"HOST:")!=0)                      // Check for HOST: Line
  101.                 strcpy(HostName,&a[5]);                    // If Yes, copy Information after HOST:
  102.             if (strstr(a,"FULL:")!=0)                // Check for FULL: Line
  103.                 strcpy(FullName,&a[5]);                     // If Yes, copy Information after FULL:
  104.             if (strstr(a,"TIME:")!=0)                // Check for TIME: Line
  105.                 strcpy(TimeZone,&a[5]);                     // If Yes, copy Information after TIME:
  106.             if (strstr(a,"ORGAN:")!=0)                // Check for TIME: Line
  107.                 strcpy(Organization,&a[6]);                     // If Yes, copy Information after TIME:
  108.         }
  109.     fclose(infile);                            // Close file
  110.  
  111.     // Trim Trailing blanks for fields
  112.     while (HostName[strlen(HostName)-1]==' ')            HostName[strlen(HostName)-1]=NULL;
  113.     while (FullName[strlen(FullName)-1]==' ')                       FullName[strlen(FullName)-1]=NULL;
  114.     while (TimeZone[strlen(TimeZone)-1]==' ')                       TimeZone[strlen(TimeZone)-1]=NULL;
  115.     while (Organization[strlen(Organization)-1]==' ')               Organization[strlen(Organization)-1]=NULL;
  116.  
  117.     // Trim Leading blanks from fields
  118.     while (HostName[0]==' ')                    strcpy(HostName,&HostName[1]);
  119.     while (FullName[0]==' ')                                        strcpy(FullName,&FullName[1]);
  120.     while (TimeZone[0]==' ')                                        strcpy(TimeZone,&TimeZone[1]);
  121.     while (Organization[0]==' ')                                    strcpy(Organization,&Organization[1]);
  122.  
  123.     // put 'em together and what do you get?
  124.     fnmerge(FileName, drive, dir, name, ".DAT");
  125.     //
  126.     //    create the data file for mailing
  127.     //
  128.     if ((outfile = fopen(FileName,"wb")) == NULL)
  129.     {
  130.         fprintf(stderr,"Open of DAT file %s failed\n", FileName);
  131.         exit(1);
  132.     }
  133.         if ((infile = fopen(argv[2],"r"))== NULL)
  134.         {
  135.             fprintf(stderr,"Error opening container file %s\n", argv[2]);
  136.             exit(1);
  137.         }
  138.     // Time Line for From Information
  139.             time(&t);
  140.             strcpy(timeline,ctime(&t));
  141.             timeline[24]=NULL;         // Kill newline from string
  142.  
  143.             for(i=0;i<3;i++)            // Rather than have Pmail
  144.                 time2[i]=timeline[i];           // Create the Time in the
  145.             time2[3]=',';                           // Same Format.
  146.             time2[4]=' ';                           // Weekday, day Mnth Year Time
  147.             time2[5]=timeline[8];                   // Fri,  1 Apr 1994 21:05:36
  148.             time2[6]=timeline[9];                   // This reduces the Information
  149.             time2[7]=' ';                           // passed from PMAIL. Long addresses
  150.             time2[8]=timeline[4];                   // could cause failures.
  151.             time2[9]=timeline[5];
  152.             time2[10]=timeline[6];
  153.             time2[11]=' ';
  154.             for(i=12;i<16;i++)
  155.                 time2[i]=timeline[i+8];
  156.             time2[16]=' ';
  157.             for(i=11;i<19;i++)
  158.                 time2[i+6]=timeline[i];
  159.             time2[25]=NULL;
  160.  
  161. //    fprintf(outfile,"From %s!%s %s remote from %s\n", FullName, argv[1], timeline, HostName);
  162. //      Test Change for Keuntos problem
  163.             fprintf(outfile,"From %s  %s %s remote from %s\n", argv[1], timeline, TimeZone, FullName);
  164.             fprintf(outfile,"Received: by %s (PMAIL Filter)\n", FullName);
  165.             fprintf(outfile,"\tvia UUCP; %s %s\n", time2, TimeZone);
  166.             fprintf(outfile,"\tfor <%s>\n",argv[3]);
  167.             fprintf(outfile,"Message-ID: <%s@%s>\n", name, FullName);
  168.  
  169.             while (!feof(infile))
  170.             {
  171.                 j=0;                            // Initialize Array Pointer to Beginning
  172.                 while(((ch=fgetc(infile))!='\n') && !feof(infile))    // Read Characters till End of Line or End of File
  173.                     a[j++]=ch;                    // Store Character
  174.                 a[j]=NULL;                        // Add NULL to end of String
  175.                 if (a[0]=='T' && a[1]=='o' && a[2]==':' && a[3]==' ')    // Trim extra spaces
  176.                 {                                                       // After To:
  177.                     strcpy(&a[4],&a[15]);                           // Waffle Problem, Not PMAIL
  178.                 }                                                       // But this fixes it.
  179.  
  180.                 if (a[0]=='F' && a[1]=='r' && a[2]=='o' && a[3]=='m' && a[4]==':' && a[5]==' ')           // Trim extra spaces
  181.                 {                                                                              // After From:
  182.                     strcpy(&a[6],&a[15]);                                           // Waffle Problem, Not PMAIL
  183.                 }                                                                       // But this fixes it.
  184.  
  185.                 if (a[0]=='S' && a[1]=='u' && a[2]=='b' && a[3]=='j' && a[4]=='e' && a[5]=='c'&& a[6]=='t' && a[7]==':')
  186.                     fprintf(outfile,"Organization:  %s\n",Organization);
  187.                 fprintf(outfile,"%s\n",a);
  188.             }
  189.         fclose(infile);
  190.     fclose(outfile);
  191.  
  192.  
  193. // create the ".CMD" file - commands to UUCICO (?)
  194. //     Format:
  195. //     S 0051.DAT D.home0051 brendan - 0051.DAT 0666
  196. //     S 0051.XQT X.home0051 brendan - 0051.XQT 0666
  197. //
  198. //     (roughly)
  199. //      SEND local-filename as-filename from - ????? unix-file-mode
  200. //
  201.     fnmerge(FileName, drive, dir, name, ".CMD");
  202.     if ((outfile = fopen (FileName,"w")) == NULL)
  203.     {
  204.         fprintf(stderr,"Open of CMD file %s failed\n", FileName);
  205.         exit(1);
  206.     }
  207.  
  208.         fnmerge(FileName, NULL, NULL, name, NULL);
  209.  
  210.         fprintf(outfile, "S %s.DAT D.%s%s %s - %s.DAT 0666\n", FileName, HostName, name, argv[1], FileName);
  211.         fprintf(outfile, "S %s.XQT X.%s%s %s - %s.XQT 0666\n", FileName, HostName, name, argv[1], FileName);
  212.     fclose(outfile);
  213.  
  214. //      Create the ".XQT" file --  commands to uuxqt at the other end!
  215. //
  216. //
  217. //      Format:
  218. //      U brendan home
  219. //      Z
  220. //      F D.home0051
  221. //      I D.home0051
  222. //      C rmail brendan
  223. //
  224. //      where the commands defined in the uuxqt file are (as stated by
  225. //      Ian Taylor (Ian@airs.com, uunet!airs!ian) in a newsitem posted
  226. //      to comp.unix.internals 4 Apr 1992)
  227. //
  228. //      "Here are the commands defined in uuxqt files:
  229. //
  230. //       C command-line
  231. //       I standard-input
  232. //       O standard-output [ system ]
  233. //       F required-file filename-to-use
  234. //       R requestor-address
  235. //       U user system
  236. //       Z (acknowledge if command failed; default)
  237. //       N (no acknowledgement on failure)
  238. //       n (acknowledge if command succeeded)
  239. //       B (return command input on error)
  240. //       e (process with sh)
  241. //       E (process with exec)
  242. //       M status-file
  243. //       # comment
  244. //
  245. //
  246.     fnmerge(FileName,drive, dir, name, ".XQT");
  247.     if ((outfile = fopen (FileName,"w")) == NULL)
  248.     {
  249.         fprintf(stderr,"Open of XQT file %s.XQT failed\n", FileName);
  250.         exit(1);
  251.     }
  252.         fprintf(outfile,"U %s %s\n", argv[1], FullName);
  253.         fprintf(outfile,"Z\n");
  254.         fprintf(outfile,"R %s@%s\n", argv[1], FullName);
  255.         fprintf(outfile,"F D.%s%s\n", HostName, name);
  256.         fprintf(outfile,"I D.%s%s\n", HostName, name);
  257.         fprintf(outfile,"C rmail %s\n", argv[3]);
  258.     fclose(outfile);
  259.  
  260. //     Now delete the file created by pmail, 'cos all this worked, didn't it! You might want to stop
  261. //    this from happening, as a log, since uucico deletes the files when finished, or just in case
  262. //    you're paranoid and might want to re-process it all later.
  263. //    Note: I have chosen to rename the file rather than delete it
  264. //    Later the file is stored in a Zip file
  265.     fnmerge(FileName, drive, dir, name, ".WWM");         /* RENAME FILE */
  266.     if ( (rename(argv[2],FileName)) != 0)              /* Rename Temporary File */
  267.     {
  268.         fprintf(stderr,"Failed to rename PMAIL temporary file %s %s\n", FileName, argv[2]);
  269.         exit(1);
  270.     }
  271. }
  272.