changeset 167:56dee4beb64e

write_mailbody_from_file is now write_mailbody_from_fd
author mmj
date Fri, 04 Jun 2004 01:11:00 +1000
parents d21de0cea7cd
children 88772c4e7bd4
files include/mail-functions.h include/mlmmj-send.h src/mail-functions.c src/mlmmj-send.c
diffstat 4 files changed, 20 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/include/mail-functions.h	Fri Jun 04 00:50:02 2004 +1000
+++ b/include/mail-functions.h	Fri Jun 04 01:11:00 2004 +1000
@@ -17,7 +17,7 @@
 int write_mail_from(int sockfd, const char *from_addr);
 int write_rcpt_to(int sockfd, const char *rcpt_addr);
 int write_custom_line(int sockfd, const char *line);
-int write_mailbody_from_file(int sockfd, FILE *infile);
+int write_mailbody_from_fd(int sockfd, int fd);
 int write_replyto(int sockfd, const char *replyaddr);
 int write_dot(int sockfd);
 int write_quit(int sockfd);
--- a/include/mlmmj-send.h	Fri Jun 04 00:50:02 2004 +1000
+++ b/include/mlmmj-send.h	Fri Jun 04 01:11:00 2004 +1000
@@ -10,10 +10,10 @@
 #define MMJML_SEND_H
 
 int send_mail(int sockfd, const char *from, const char *to,
-	      const char *replyto, FILE *mailfile,
+	      const char *replyto, int mailfd,
 	      const char *listdir, const char *mlmmjbounce);
 int send_mail_many(int sockfd, const char *from, const char *replyto,
-		   FILE *mailfile, FILE *subfile, const char *listaddr,
+		   int mailfd, FILE *subfile, const char *listaddr,
 		   const char *archivefilename, const char *listdir,
 		   const char *mlmmjbounce);
 int initsmtp(int *sockfd, const char *relayhost);
--- a/src/mail-functions.c	Fri Jun 04 00:50:02 2004 +1000
+++ b/src/mail-functions.c	Fri Jun 04 01:11:00 2004 +1000
@@ -101,7 +101,7 @@
 }
 
 
-int write_mailbody_from_file(int sockfd, FILE *infile)
+int write_mailbody_from_fd(int sockfd, int fd)
 {
 	char buf[WRITE_BUFSIZE+3];
 	size_t len, bytes_written;
@@ -113,8 +113,8 @@
 	
 	/* Read from beginning of the file */
 
-	if(fseek(infile, 0L, SEEK_SET) == -1) {
-		log_error(LOG_ARGS, "fseek() failed");
+	if(lseek(fd, 0L, SEEK_SET) < 0) {
+		log_error(LOG_ARGS, "lseek() failed");
 		return errno;
 	}
 	
@@ -124,7 +124,7 @@
 		errno = 0;  /* We must reset errno, otherwise we can't
 			     * determine if we hit EOF or an error
 			     * occurred */
-		if(!fgets(bufp, WRITE_BUFSIZE, infile)) {
+		if(read(fd, bufp, WRITE_BUFSIZE) < 0) {
 			if (errno == EINTR) {
 				errno = 0;
 				continue;
--- a/src/mlmmj-send.c	Fri Jun 04 00:50:02 2004 +1000
+++ b/src/mlmmj-send.c	Fri Jun 04 01:11:00 2004 +1000
@@ -140,7 +140,7 @@
 }
 
 int send_mail(int sockfd, const char *from, const char *to,
-	      const char *replyto, FILE *mailfile,
+	      const char *replyto, int mailfd,
 	      const char *listdir, const char *mlmmjbounce)
 {
 	int retval = 0;
@@ -205,7 +205,7 @@
 		}
 	}
 
-	retval = write_mailbody_from_file(sockfd, mailfile);
+	retval = write_mailbody_from_fd(sockfd, mailfd);
 	if(retval) {
 		log_error(LOG_ARGS, "Could not write mailbody\n");
 		return retval;
@@ -278,7 +278,7 @@
 }
 
 int send_mail_many(int sockfd, const char *from, const char *replyto,
-		   FILE *mailfile, FILE *subfile, const char *listaddr,
+		   int mailfd, FILE *subfile, const char *listaddr,
 		   const char *archivefilename, const char *listdir,
 		   const char *mlmmjbounce)
 {
@@ -290,12 +290,12 @@
 		chomp(addr);
 		if(from)
 			sendres = send_mail(sockfd, from, addr, replyto,
-					    mailfile, listdir, NULL);
+					    mailfd, listdir, NULL);
 		else {
 			bounceaddr = bounce_from_adr(addr, listaddr,
 						     archivefilename);
 			sendres = send_mail(sockfd, bounceaddr, addr, replyto,
-				  mailfile, listdir, mlmmjbounce);
+				  mailfd, listdir, mlmmjbounce);
 			free(bounceaddr);
 		}
 		if(sendres && listaddr && archivefilename) {
@@ -368,7 +368,7 @@
 int main(int argc, char **argv)
 {
 	size_t len = 0;
-	int sockfd = 0, opt, mindex;
+	int sockfd = 0, mailfd = 0, opt, mindex;
 	int deletewhensent = 1, sendres, archive = 1;
 	char *listaddr, *mailfilename = NULL, *subfilename = NULL;
 	char *replyto = NULL, *bounceaddr = NULL, *to_addr = NULL;
@@ -376,7 +376,7 @@
 	char *listctrl = NULL, *subddirname = NULL, *listdir = NULL;
 	char *mlmmjbounce = NULL, *bindir;
 	DIR *subddir;
-	FILE *subfile = NULL, *mailfile = NULL, *tmpfile;
+	FILE *subfile = NULL, *tmpfile;
 	struct dirent *dp;
 	
 	log_set_name(argv[0]);
@@ -455,7 +455,7 @@
 	
 	/* initialize file with mail to send */
 
-	if((mailfile = fopen(mailfilename, "r")) == NULL) {
+	if((mailfd = open(mailfilename, O_RDONLY)) < 0) {
 	        log_error(LOG_ARGS, "Could not open '%s'", mailfilename);
 		exit(EXIT_FAILURE);
 	}
@@ -502,7 +502,7 @@
 	case '1': /* A single mail is to be sent */
 		initsmtp(&sockfd, relayhost);
 		sendres = send_mail(sockfd, bounceaddr, to_addr,
-				replyto, mailfile, listdir, NULL);
+				replyto, mailfd, listdir, NULL);
 		endsmtp(&sockfd);
 		if(sendres) {
 			/* error, so keep it in the queue */
@@ -530,7 +530,7 @@
 		break;
 	case '2': /* Moderators */
 		initsmtp(&sockfd, relayhost);
-		if(send_mail_many(sockfd, bounceaddr, NULL, mailfile, subfile,
+		if(send_mail_many(sockfd, bounceaddr, NULL, mailfd, subfile,
 			       NULL, NULL, listdir, NULL))
 			close(sockfd);
 		else
@@ -538,7 +538,7 @@
 		break;
 	case '3': /* resending earlier failed mails */
 		initsmtp(&sockfd, relayhost);
-		if(send_mail_many(sockfd, NULL, NULL, mailfile, subfile,
+		if(send_mail_many(sockfd, NULL, NULL, mailfd, subfile,
 				listaddr, mailfilename, listdir, mlmmjbounce))
 			close(sockfd);
 		else
@@ -572,7 +572,7 @@
 			free(subfilename);
 
 			initsmtp(&sockfd, relayhost);
-			sendres = send_mail_many(sockfd, NULL, NULL, mailfile,
+			sendres = send_mail_many(sockfd, NULL, NULL, mailfd,
 					subfile, listaddr, archivefilename,
 					listdir, mlmmjbounce);
 			if (sendres) {
@@ -596,6 +596,6 @@
 	} else if(deletewhensent)
 		unlink(mailfilename);
 
-	fclose(mailfile);
+	close(mailfd);
 	return EXIT_SUCCESS;
 }