From 5ef9c343fc4b219f01498be7c88e1fdae67c35ee Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Fri, 1 Feb 2002 02:22:24 +0000 Subject: Sunil Shetye's fixews for IMAP and SMTP edge cases. svn path=/trunk/; revision=3570 --- sink.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'sink.c') diff --git a/sink.c b/sink.c index e7e4d5c0..8b7484c4 100644 --- a/sink.c +++ b/sink.c @@ -46,17 +46,29 @@ /* makes the open_sink()/close_sink() pair non-reentrant */ static int lmtp_responses; +void smtp_close(struct query *ctl, int sayquit) +/* close the socket to SMTP server */ +{ + if (ctl->smtp_socket != -1) + { + if (sayquit) + SMTP_quit(ctl->smtp_socket); + SockClose(ctl->smtp_socket); + ctl->smtp_socket = -1; + } + batchcount = 0; +} + int smtp_open(struct query *ctl) /* try to open a socket to the appropriate SMTP server for this query */ { char *parsed_host = NULL; /* maybe it's time to close the socket in order to force delivery */ - if (NUM_NONZERO(ctl->batchlimit) && (ctl->smtp_socket != -1) && ++batchcount == ctl->batchlimit) - { - SockClose(ctl->smtp_socket); - ctl->smtp_socket = -1; - batchcount = 0; + if (NUM_NONZERO(ctl->batchlimit)) { + if (batchcount == ctl->batchlimit) + smtp_close(ctl, 1); + batchcount++; } /* if no socket to any SMTP host is already set up, try to open one */ @@ -146,8 +158,7 @@ int smtp_open(struct query *ctl) * RFC 1869 warns that some listeners hang up on a failed EHLO, * so it's safest not to assume the socket will still be good. */ - SockClose(ctl->smtp_socket); - ctl->smtp_socket = -1; + smtp_close(ctl, 0); /* if opening for ESMTP failed, try SMTP */ if ((ctl->smtp_socket = SockOpen(parsed_host,portnum,NULL, @@ -158,8 +169,7 @@ int smtp_open(struct query *ctl) SMTP_helo(ctl->smtp_socket, id_me) == SM_OK) break; /* success */ - SockClose(ctl->smtp_socket); - ctl->smtp_socket = -1; + smtp_close(ctl, 0); } set_timeout(0); phase = oldphase; -- cgit v1.2.3