home *** CD-ROM | disk | FTP | other *** search
- /* load in the out.mta file and send the email ad described in it */
- #include "project.h"
- #include <ctype.h>
- #include <string.h>
- #include <stdio.h>
- extern struct ll * inlist ;
- main(argc, argv)
- int argc ;
- char * argv[] ;
- {
- int count ;
- int i ;
- if (argc != 2)
- {
- fprintf(stderr, "Usage: mailsend metafile\n") ;
- exit(1) ;
- }
- llinit() ;
- readmeta(argv[1], inlist) ;
- count = 0 ;
- for (i = 1 ; i <= inlist->count ; i ++ )
- {
- doemail(i, inlist) ;
- count ++ ;
- }
- printf("%d emails processed\n", count) ;
- llfree(inlist) ;
- }
- doemail(mailno, list)
- int mailno ;
- struct ll * list;
- {
- struct ll * llptr ;
- char fname[1024] ;
- char mailcmd[1024] ;
- char copycmd[1024] ;
- int len;
- int i ;
- FILE * fd ;
-
- /* locate the ll entry */
- llptr = llnofind(mailno, list) ;
- /* convert the datafile to lower case */
- len = strlen(llptr->datafile) ;
- for (i = 0 ; i < len ; i ++ )
- {
- if (isupper(llptr->datafile[i]))
- llptr->datafile[i] = (char) tolower(llptr->datafile[i]) ;
- }
- /* if there are no to entries, discard the email */
- if (strlen(llptr->to) == 0)
- {
- printf("No destination addresses for number %d", i) ;
- return ;
- }
- /* create the output file name */
- sprintf(fname, "%s.mf", llptr->datafile) ;
- fd = fopen(fname, "w") ;
- /* write the headers to the output file */
- if ((int)strlen(llptr->subject) > 0)
- {
- fprintf(fd, "~s %s\n", llptr->subject) ;
- }
- if ((int)strlen(llptr->cc) > 0)
- {
- fprintf(fd, "~c %s\n", llptr->cc) ;
- }
- if ((int)strlen(llptr->bcc) > 0)
- {
- fprintf(fd, "~b %s\n", llptr->bcc) ;
- }
- fclose(fd) ;
- /* copy the rest of the input file to the output file */
- sprintf(copycmd, "cat %s >> %s", llptr->datafile, fname) ;
- system(copycmd) ;
- /* create the mail command */
- sprintf (mailcmd, "Mail %s < %s", llptr->to, fname) ;
- system(mailcmd) ;
- }
-