diff options
-rw-r--r-- | driver.c | 31 | ||||
-rw-r--r-- | fetchmail.c | 6 | ||||
-rw-r--r-- | fetchmail.h | 2 | ||||
-rw-r--r-- | smtp.c | 52 | ||||
-rw-r--r-- | smtp.h | 16 |
5 files changed, 55 insertions, 52 deletions
@@ -464,26 +464,26 @@ struct idlist **xmit_names; /* list of recipient names parsed out */ } #endif /* HAVE_GETHOSTBYNAME */ -static int smtp_open(ctl) +static FILE *smtp_open(ctl) /* try to open a socket to the appropriate SMTP server for this query */ struct query *ctl; { ctl = ctl->leader; /* go to the SMTP leader for this query */ /* if no socket to this host is already set up, try to open one */ - if (ctl->smtp_socket == -1) + if (ctl->smtp_sockfp == (FILE *)NULL) { - if ((ctl->smtp_socket = Socket(ctl->smtphost, SMTP_PORT)) == -1) - return(-1); - else if (SMTP_ok(ctl->smtp_socket, NULL) != SM_OK - || SMTP_helo(ctl->smtp_socket, ctl->servername) != SM_OK) + if ((ctl->smtp_sockfp = fdopen(Socket(ctl->smtphost, SMTP_PORT), "r+")) == (FILE *)NULL) + return((FILE *)NULL); + else if (SMTP_ok(ctl->smtp_sockfp, NULL) != SM_OK + || SMTP_helo(ctl->smtp_sockfp, ctl->servername) != SM_OK) { - close(ctl->smtp_socket); - ctl->smtp_socket = -1; + fclose(ctl->smtp_sockfp); + ctl->smtp_sockfp = (FILE *)NULL; } } - return(ctl->smtp_socket); + return(ctl->smtp_sockfp); } static int gen_readmsg (sockfp, len, delimited, ctl) @@ -497,6 +497,7 @@ struct query *ctl; /* query control record */ char *bufp, *headers, *fromhdr, *tohdr, *cchdr, *bcchdr; int n, oldlen, mboxfd; int inheaders,lines,sizeticker; + FILE *sinkfp; /* read the message content from the server */ inheaders = 1; @@ -656,29 +657,31 @@ struct query *ctl; /* query control record */ } else { - if (ctl->mda[0] == '\0' && ((mboxfd = smtp_open(ctl)) < 0)) + if (ctl->mda[0] == '\0' && ((sinkfp = smtp_open(ctl)) < 0)) { free_uid_list(&xmit_names); fprintf(stderr, "fetchmail: SMTP connect failed\n"); return(PS_SMTP); } - if (SMTP_from(mboxfd, nxtaddr(fromhdr)) != SM_OK) + if (SMTP_from(sinkfp, nxtaddr(fromhdr)) != SM_OK) { fprintf(stderr, "fetchmail: SMTP listener is confused\n"); return(PS_SMTP); } for (idp = xmit_names; idp; idp = idp->next) - if (SMTP_rcpt(mboxfd, idp->id) != SM_OK) + if (SMTP_rcpt(sinkfp, idp->id) != SM_OK) { fprintf(stderr, "fetchmail: SMTP listener is upset\n"); return(PS_SMTP); } - SMTP_data(mboxfd); + SMTP_data(sinkfp); if (outlevel == O_VERBOSE) fputs("SMTP> ", stderr); + + mboxfd = fileno(sinkfp); } free_uid_list(&xmit_names); @@ -749,7 +752,7 @@ struct query *ctl; /* query control record */ else { /* write message terminator */ - if (SMTP_eom(mboxfd) != SM_OK) + if (SMTP_eom(sinkfp) != SM_OK) { fputs("fetchmail: SMTP listener refused delivery\n", stderr); return(PS_SMTP); diff --git a/fetchmail.c b/fetchmail.c index 4d55bf91..f7bce817 100644 --- a/fetchmail.c +++ b/fetchmail.c @@ -528,7 +528,7 @@ int optind; goto no_new_leader; } ctl->leader = ctl; - ctl->smtp_socket = -1; + ctl->smtp_sockfp = (FILE *)NULL; no_new_leader:; } @@ -582,8 +582,8 @@ void termhook(int sig) /* terminate all SMTP connections cleanly */ for (ctl = querylist; ctl; ctl = ctl->next) - if (ctl->leader == ctl && ctl->smtp_socket != -1) - SMTP_quit(ctl->smtp_socket); + if (ctl->leader == ctl && ctl->smtp_sockfp != (FILE *)NULL) + SMTP_quit(ctl->smtp_sockfp); if (!check_only) write_saved_lists(querylist, idfile); diff --git a/fetchmail.h b/fetchmail.h index 3cd5c104..eaf11fb0 100644 --- a/fetchmail.h +++ b/fetchmail.h @@ -94,7 +94,7 @@ struct query int active; struct query *next; /* next query control block in chain */ struct query *leader; /* pointer to this query's SMTP leader */ - int smtp_socket; /* socket descriptor for SMTP connection */ + FILE *smtp_sockfp; /* socket descriptor for SMTP connection */ unsigned int uid; /* UID of user to deliver to */ char digest [DIGESTLEN]; /* md5 digest buffer */ #ifdef HAVE_GETHOSTBYNAME @@ -18,93 +18,93 @@ #include "fetchmail.h" #include "smtp.h" -int SMTP_helo(int socket,char *host) +int SMTP_helo(FILE *sockfp,char *host) /* send a "HELO" message to the SMTP listener */ { int ok; - SockPrintf(socket,"HELO %s\r\n", host); + SockPrintf(fileno(sockfp),"HELO %s\r\n", host); if (outlevel == O_VERBOSE) fprintf(stderr, "SMTP> HELO %s\n", host); - ok = SMTP_ok(socket,NULL); + ok = SMTP_ok(sockfp,NULL); return ok; } -int SMTP_from(int socket, char *from) +int SMTP_from(FILE *sockfp, char *from) /* send a "MAIL FROM:" message to the SMTP listener */ { int ok; - SockPrintf(socket,"MAIL FROM:<%s>\r\n", from); + SockPrintf(fileno(sockfp),"MAIL FROM:<%s>\r\n", from); if (outlevel == O_VERBOSE) fprintf(stderr, "SMTP> MAIL FROM:<%s>\n", from); - ok = SMTP_ok(socket,NULL); + ok = SMTP_ok(sockfp,NULL); return ok; } -int SMTP_rcpt(int socket, char *to) +int SMTP_rcpt(FILE *sockfp, char *to) /* send a "RCPT TO:" message to the SMTP listener */ { int ok; - SockPrintf(socket,"RCPT TO:<%s>\r\n", to); + SockPrintf(fileno(sockfp),"RCPT TO:<%s>\r\n", to); if (outlevel == O_VERBOSE) fprintf(stderr, "SMTP> RCPT TO:<%s>\n", to); - ok = SMTP_ok(socket,NULL); + ok = SMTP_ok(sockfp,NULL); return ok; } -int SMTP_data(int socket) +int SMTP_data(FILE *sockfp) /* send a "DATA" message to the SMTP listener */ { int ok; - SockPrintf(socket,"DATA\r\n"); + SockPrintf(fileno(sockfp),"DATA\r\n"); if (outlevel == O_VERBOSE) fprintf(stderr, "SMTP> DATA\n"); - ok = SMTP_ok(socket,NULL); + ok = SMTP_ok(sockfp,NULL); return ok; } -int SMTP_quit(int socket) +int SMTP_quit(FILE *sockfp) /* send a "QUIT" message to the SMTP listener */ { int ok; - SockPrintf(socket,"QUIT\r\n"); + SockPrintf(fileno(sockfp),"QUIT\r\n"); if (outlevel == O_VERBOSE) fprintf(stderr, "SMTP> QUIT\n"); - ok = SMTP_ok(socket,NULL); + ok = SMTP_ok(sockfp,NULL); return ok; } -int SMTP_eom(int socket) +int SMTP_eom(FILE *sockfp) /* send a message data terminator to the SMTP listener */ { int ok; - SockPrintf(socket,".\r\n"); + SockPrintf(fileno(sockfp),".\r\n"); if (outlevel == O_VERBOSE) fprintf(stderr, "SMTP>. (EOM)\n"); - ok = SMTP_ok(socket,NULL); + ok = SMTP_ok(sockfp,NULL); return ok; } -void SMTP_rset(int socket) +void SMTP_rset(FILE *sockfp) /* send a "RSET" message to the SMTP listener */ { - SockPrintf(socket,"RSET\r\n"); + SockPrintf(fileno(sockfp),"RSET\r\n"); if (outlevel == O_VERBOSE) fprintf(stderr, "SMTP> RSET\n"); } -static int SMTP_check(int socket,char *argbuf) +static int SMTP_check(FILE *sockfp,char *argbuf) /* returns status of SMTP connection */ { int ok; char buf[SMTPBUFSIZE]; - if ((ok = read(socket, buf, sizeof(buf)-1)) > 0) { + if ((ok = read(fileno(sockfp), buf, sizeof(buf)-1)) > 0) { buf[ok] = '\0'; if (outlevel == O_VERBOSE) fprintf(stderr, "SMTP< %s", buf); @@ -120,7 +120,7 @@ static int SMTP_check(int socket,char *argbuf) return (ok); } -int SMTP_ok(int socket,char *argbuf) +int SMTP_ok(FILE *sockfp,char *argbuf) /* accepts SMTP response, returns status of SMTP connection */ { int ok; @@ -134,11 +134,11 @@ int SMTP_ok(int socket,char *argbuf) */ - ok = SMTP_check(socket,argbuf); + ok = SMTP_check(sockfp,argbuf); if (ok == SM_ERROR) /* if we got an error, */ { - SMTP_rset(socket); - ok = SMTP_check(socket,argbuf); /* how does it look now ? */ + SMTP_rset(sockfp); + ok = SMTP_check(sockfp,argbuf); /* how does it look now ? */ if (ok == SM_OK) ok = SM_ERROR; /* It's just a simple error, for*/ /* the current message */ @@ -15,14 +15,14 @@ #define SM_UNRECOVERABLE 129 #ifdef HAVE_PROTOTYPES -int SMTP_helo(int socket,char *host); -int SMTP_from(int socket,char *from); -int SMTP_rcpt(int socket,char *to); -int SMTP_data(int socket); -int SMTP_eom(int socket); -int SMTP_quit(int socket); -int SMTP_ok(int socket,char *argbuf); -void SMTP_rset(int socket); +int SMTP_helo(FILE *sockfp,char *host); +int SMTP_from(FILE *sockfp,char *from); +int SMTP_rcpt(FILE *sockfp,char *to); +int SMTP_data(FILE *sockfp); +int SMTP_eom(FILE *sockfp); +int SMTP_quit(FILE *sockfp); +int SMTP_ok(FILE *sockfp,char *argbuf); +void SMTP_rset(FILE *sockfp); #endif /* HAVE_PROTOTYPES */ #endif |