aboutsummaryrefslogtreecommitdiffstats
path: root/sink.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2002-02-01 02:22:24 +0000
committerEric S. Raymond <esr@thyrsus.com>2002-02-01 02:22:24 +0000
commit5ef9c343fc4b219f01498be7c88e1fdae67c35ee (patch)
tree1a2beb0020814595d15b46d10f46fd735efc2dd4 /sink.c
parentc260a67eb2a4a93567a7a975b6ebe92204fc9b49 (diff)
downloadfetchmail-5ef9c343fc4b219f01498be7c88e1fdae67c35ee.tar.gz
fetchmail-5ef9c343fc4b219f01498be7c88e1fdae67c35ee.tar.bz2
fetchmail-5ef9c343fc4b219f01498be7c88e1fdae67c35ee.zip
Sunil Shetye's fixews for IMAP and SMTP edge cases.
svn path=/trunk/; revision=3570
Diffstat (limited to 'sink.c')
-rw-r--r--sink.c28
1 files changed, 19 insertions, 9 deletions
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;