From 2ab5a5fbccd339a73ca0591f7c94dca06f305d65 Mon Sep 17 00:00:00 2001 From: Chris Hanson Date: Mon, 22 May 2000 19:16:47 +0000 Subject: [PATCH] Add code to detect when the connection has been dropped. This test is performed by GUARANTEE-IMAP-CONNECTION-OPEN, and thus will be done at the beginning of every IMAIL operation. The code will transparently close the connection and reopen it. If a problem occurs during the processing of the operation, an error will be signalled, as one would expect. --- v7/src/imail/imail-imap.scm | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/v7/src/imail/imail-imap.scm b/v7/src/imail/imail-imap.scm index 9be79fd49..8cbe613c0 100644 --- a/v7/src/imail/imail-imap.scm +++ b/v7/src/imail/imail-imap.scm @@ -1,6 +1,6 @@ ;;; -*-Scheme-*- ;;; -;;; $Id: imail-imap.scm,v 1.70 2000/05/22 15:08:12 cph Exp $ +;;; $Id: imail-imap.scm,v 1.71 2000/05/22 19:16:47 cph Exp $ ;;; ;;; Copyright (c) 1999-2000 Massachusetts Institute of Technology ;;; @@ -285,7 +285,7 @@ (define memoized-imap-connections '()) (define (guarantee-imap-connection-open connection) - (if (imap-connection-port connection) + (if (test-imap-connection-open connection) #f (let ((url (imap-connection-url connection))) (let ((port @@ -317,6 +317,36 @@ (error "Unable to log in:" response))))) #t))) +(define (test-imap-connection-open connection) + (let ((port (imap-connection-port connection))) + (and port + (let* ((process + (lambda () + (process-responses connection #f + (dequeue-imap-responses connection)))) + (lose + (lambda () + (process) + (close-imap-connection connection) + #f))) + (let loop () + (cond ((not (char-ready? port)) + (process) + #t) + ((eof-object? (peek-char port)) + (lose)) + (else + (let ((response + (ignore-errors + (lambda () + (imap:read-server-response port))))) + (if (or (condition? response) + (begin + (enqueue-imap-response connection response) + (imap:response:bye? response))) + (lose) + (loop)))))))))) + (define (close-imap-connection connection) (let ((port (without-interrupts -- 2.25.1