home *** CD-ROM | disk | FTP | other *** search
/ PDA Software Library / pdasoftwarelib.iso / PSION / COMMS / PSIONMAI / PMFULLSO / SUNMAIL / SCCS / S10.C < prev    next >
Encoding:
Text File  |  1995-07-05  |  1.9 KB  |  92 lines

  1. h17452
  2. s 00079/00000/00000
  3. d D 1.1 95/07/05 19:14:41 tim 1 0
  4. c scans the mta files and processes the emails
  5. e
  6. u
  7. U
  8. f e 0
  9. t
  10. T
  11. I 1
  12. /* load in the out.mta file and send the email ad described in it */
  13. #include "project.h"
  14. #include <ctype.h>
  15. #include <string.h>
  16. #include <stdio.h>
  17. extern struct ll * inlist ;
  18. main(argc, argv)
  19. int argc ;
  20. char * argv[] ;
  21. {
  22.     int count ;
  23.     int i ;
  24.     if (argc != 2)
  25.     {
  26.         fprintf(stderr, "Usage: mailsend metafile\n") ;
  27.         exit(1) ;
  28.     }
  29.     llinit() ;
  30.     readmeta(argv[1], inlist) ;
  31.     count = 0 ;
  32.     for (i = 1 ; i <= inlist->count ; i ++ )
  33.     {
  34.         doemail(i, inlist) ;
  35.         count ++ ;
  36.     }
  37.     printf("%d emails processed\n", count) ;
  38.     llfree(inlist) ;
  39. }
  40. doemail(mailno, list)
  41. int mailno ;
  42. struct ll * list;
  43. {
  44.     struct ll * llptr ;
  45.     char fname[1024] ;
  46.     char mailcmd[1024] ;
  47.     char copycmd[1024] ;
  48.     int len;
  49.     int i ;
  50.     FILE * fd ;
  51.  
  52.     /* locate the ll entry */
  53.     llptr = llnofind(mailno, list) ;
  54.     /* convert the datafile to lower case */
  55.     len = strlen(llptr->datafile) ;
  56.     for (i = 0 ; i < len ; i ++ )
  57.     {
  58.         if (isupper(llptr->datafile[i]))
  59.             llptr->datafile[i] = (char) tolower(llptr->datafile[i]) ;
  60.     }
  61.     /* if there are no to entries, discard the email */
  62.     if (strlen(llptr->to) == 0)
  63.     {
  64.         printf("No destination addresses for number %d", i) ;
  65.         return ;
  66.     }
  67.     /* create the output file name */
  68.     sprintf(fname, "%s.mf", llptr->datafile) ;
  69.     fd = fopen(fname, "w") ;
  70.     /* write the headers to the output file */
  71.     if ((int)strlen(llptr->subject) > 0)
  72.     {
  73.         fprintf(fd, "~s %s\n", llptr->subject) ;
  74.     }
  75.     if ((int)strlen(llptr->cc) > 0)
  76.     {
  77.         fprintf(fd, "~c %s\n", llptr->cc) ;
  78.     }
  79.     if ((int)strlen(llptr->bcc) > 0)
  80.     {
  81.         fprintf(fd, "~b %s\n", llptr->bcc) ;
  82.     }
  83.     fclose(fd) ;
  84.     /* copy the rest of the input file to the output file */
  85.     sprintf(copycmd, "cat %s >> %s", llptr->datafile, fname) ;
  86.     system(copycmd) ;
  87.     /* create the mail command */
  88.     sprintf (mailcmd, "Mail %s < %s", llptr->to, fname) ;
  89.     system(mailcmd) ;
  90. }
  91. E 1
  92.