[PATCHv2 2/3] Re: imaplibutil: Have SELECT throw an OfflineImapError when the connection died

Nicolas Sebrecht nicolas.s-dev at laposte.net
Fri Sep 2 20:53:48 BST 2011


On Thu, Sep 01, 2011 at 11:00:59AM +0200, Sebastian Spaeth wrote:
> Imapserver.acquireconnection will succeed even whent the server connection
> has been terminated and the first IMAP operation will throw an exception.
> 
> Often this is the folder SELECT operation (e.g. after an idle timeout), as
> has been reported by John Wiegley. Catch this case and throw an
> OfflineImapError with severity FOLDER_RETRY to notify consumers that they
> are supposed to retry.

We use to have the "Reported-by: " line just above the signed-off.

> Signed-off-by: Sebastian Spaeth <Sebastian at SSpaeth.de>
> ---
>  offlineimap/imaplibutil.py |    9 ++++++++-
>  1 files changed, 8 insertions(+), 1 deletions(-)
> 
> diff --git a/offlineimap/imaplibutil.py b/offlineimap/imaplibutil.py
> index fa3a303..529af6f 100644
> --- a/offlineimap/imaplibutil.py
> +++ b/offlineimap/imaplibutil.py
> @@ -49,7 +49,14 @@ class UsefulIMAPMixIn:
>              return
>          # Wipe out all old responses, to maintain semantics with old imaplib2
>          del self.untagged_responses[:]
> -        result = self.__class__.__bases__[1].select(self, mailbox, readonly)
> +        try:
> +            result = self.__class__.__bases__[1].select(self, mailbox, readonly)
> +        except self.abort, e:
> +            # self.abort is raised when we are supposed to retry
> +            errstr = "Server '%s' closed connection, error on SELECT '%s'. Ser"\
> +                "ver said: %s" % (self.host, mailbox, e.args[0])
> +            severity = OfflineImapError.ERROR.FOLDER_RETRY
> +            raise OfflineImapError(errstr, severity) 

Are we going to loop forever if anything makes the code we try always raise
an error for an unkown reason?

-- 
Nicolas Sebrecht




More information about the OfflineIMAP-project mailing list