home *** CD-ROM | disk | FTP | other *** search
/ PDA Software Library / pdasoftwarelib.iso / PSION / COMMS / PSIONMAI / PMFULLSO / SUNMAIL / MAILSEND.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-05  |  1.8 KB  |  80 lines

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