diff -Naur fetchmail-5.9.6.orig/driver.c fetchmail-5.9.6/driver.c --- fetchmail-5.9.6.orig/driver.c Fri Dec 14 08:36:01 2001 +++ fetchmail-5.9.6/driver.c Fri Jan 4 19:14:17 2002 @@ -788,10 +788,7 @@ /* try to clean up all streams */ release_sink(ctl); - if (ctl->smtp_socket != -1) { - cleanupSockClose(ctl->smtp_socket); - ctl->smtp_socket = -1; - } + smtp_close(ctl); if (mailserver_socket != -1) { cleanupSockClose(mailserver_socket); mailserver_socket = -1; diff -Naur fetchmail-5.9.6.orig/fetchmail.h fetchmail-5.9.6/fetchmail.h --- fetchmail-5.9.6.orig/fetchmail.h Fri Dec 14 13:20:01 2001 +++ fetchmail-5.9.6/fetchmail.h Fri Jan 4 19:16:04 2002 @@ -462,6 +462,7 @@ int interruptible_idle(int interval); /* sink.c: forwarding */ +void smtp_close(struct query *); int smtp_open(struct query *); int stuffline(struct query *, char *); int open_sink(struct query*, struct msgblk *, int*, int*); diff -Naur fetchmail-5.9.6.orig/imap.c fetchmail-5.9.6/imap.c --- fetchmail-5.9.6.orig/imap.c Thu Jan 3 18:01:30 2002 +++ fetchmail-5.9.6/imap.c Fri Jan 4 19:13:00 2002 @@ -508,6 +508,7 @@ /* this is a while loop because imap_idle() might return on other * mailbox changes also */ while (recentcount == 0 && do_idle) { + smtp_close(ctl); ok = imap_idle(sock); if (ok) { diff -Naur fetchmail-5.9.6.orig/sink.c fetchmail-5.9.6/sink.c --- fetchmail-5.9.6.orig/sink.c Fri Dec 14 14:21:24 2001 +++ fetchmail-5.9.6/sink.c Fri Jan 4 19:15:59 2002 @@ -46,18 +46,25 @@ /* makes the open_sink()/close_sink() pair non-reentrant */ static int lmtp_responses; +void smtp_close(struct query *ctl) +/* close the socket to SMTP server */ +{ + if (ctl->smtp_socket != -1) + { + 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) && ++batchcount == ctl->batchlimit) + smtp_close(ctl); /* if no socket to any SMTP host is already set up, try to open one */ if (ctl->smtp_socket == -1) @@ -146,8 +153,7 @@ * 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); /* if opening for ESMTP failed, try SMTP */ if ((ctl->smtp_socket = SockOpen(parsed_host,portnum,NULL, @@ -158,8 +164,7 @@ SMTP_helo(ctl->smtp_socket, id_me) == SM_OK) break; /* success */ - SockClose(ctl->smtp_socket); - ctl->smtp_socket = -1; + smtp_close(ctl); } set_timeout(0); phase = oldphase;