2002-06-19 06:39:00 +02:00
|
|
|
# IMAP server support
|
2007-07-04 19:51:10 +02:00
|
|
|
# Copyright (C) 2002 - 2007 John Goerzen
|
2002-06-19 06:39:00 +02:00
|
|
|
# <jgoerzen@complete.org>
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
2003-04-16 21:23:45 +02:00
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
2002-06-19 06:39:00 +02:00
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
2006-08-12 06:15:55 +02:00
|
|
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2002-06-19 06:39:00 +02:00
|
|
|
|
2011-05-04 16:45:25 +02:00
|
|
|
from offlineimap import imaplibutil, imaputil, threadutil, OfflineImapError
|
2011-01-05 17:00:55 +01:00
|
|
|
from offlineimap.ui import getglobalui
|
2011-05-19 21:02:27 +02:00
|
|
|
from threading import Lock, BoundedSemaphore, Thread, Event, currentThread
|
2011-05-11 19:34:59 +02:00
|
|
|
from thread import get_ident # python < 2.6 support
|
2011-05-19 21:02:27 +02:00
|
|
|
import offlineimap.accounts
|
2011-03-11 22:13:21 +01:00
|
|
|
import hmac
|
|
|
|
import socket
|
2008-03-09 06:46:51 +01:00
|
|
|
import base64
|
2011-08-15 11:55:42 +02:00
|
|
|
import time
|
2011-08-15 13:15:36 +02:00
|
|
|
import errno
|
2011-09-01 11:01:00 +02:00
|
|
|
from sys import exc_info
|
2011-05-04 16:45:25 +02:00
|
|
|
from socket import gaierror
|
2011-07-06 23:08:07 +02:00
|
|
|
try:
|
2011-08-15 11:55:42 +02:00
|
|
|
from ssl import SSLError, cert_time_to_seconds
|
2011-07-06 23:08:07 +02:00
|
|
|
except ImportError:
|
|
|
|
# Protect against python<2.6, use dummy and won't get SSL errors.
|
|
|
|
SSLError = None
|
2011-06-16 23:38:55 +02:00
|
|
|
|
2008-03-09 06:46:51 +01:00
|
|
|
try:
|
|
|
|
# do we have a recent pykerberos?
|
|
|
|
have_gss = False
|
|
|
|
import kerberos
|
|
|
|
if 'authGSSClientWrap' in dir(kerberos):
|
|
|
|
have_gss = True
|
|
|
|
except ImportError:
|
|
|
|
pass
|
2002-07-03 15:04:40 +02:00
|
|
|
|
2002-06-19 06:39:00 +02:00
|
|
|
class IMAPServer:
|
2011-08-12 08:31:09 +02:00
|
|
|
"""Initializes all variables from an IMAPRepository() instance
|
|
|
|
|
|
|
|
Various functions, such as acquireconnection() return an IMAP4
|
|
|
|
object on which we can operate."""
|
2008-03-09 06:46:51 +01:00
|
|
|
GSS_STATE_STEP = 0
|
|
|
|
GSS_STATE_WRAP = 1
|
2011-08-12 08:31:09 +02:00
|
|
|
def __init__(self, repos):
|
2011-01-05 17:00:55 +01:00
|
|
|
self.ui = getglobalui()
|
2011-08-12 08:31:09 +02:00
|
|
|
self.repos = repos
|
|
|
|
self.config = repos.getconfig()
|
|
|
|
self.tunnel = repos.getpreauthtunnel()
|
|
|
|
self.usessl = repos.getssl()
|
2011-09-19 08:27:18 +02:00
|
|
|
self.username = None if self.tunnel else repos.getuser()
|
2011-08-12 08:31:09 +02:00
|
|
|
self.password = None
|
2002-11-05 00:15:42 +01:00
|
|
|
self.passworderror = None
|
2007-07-05 06:04:14 +02:00
|
|
|
self.goodpassword = None
|
2011-09-19 15:07:34 +02:00
|
|
|
self.hostname = None if self.tunnel else repos.gethost()
|
2011-08-12 08:31:09 +02:00
|
|
|
self.port = repos.getport()
|
|
|
|
if self.port == None:
|
|
|
|
self.port = 993 if self.usessl else 143
|
|
|
|
self.sslclientcert = repos.getsslclientcert()
|
|
|
|
self.sslclientkey = repos.getsslclientkey()
|
|
|
|
self.sslcacertfile = repos.getsslcacertfile()
|
2011-08-16 10:48:37 +02:00
|
|
|
if self.sslcacertfile is None:
|
|
|
|
self.verifycert = None # disable cert verification
|
2002-06-19 07:22:21 +02:00
|
|
|
self.delim = None
|
|
|
|
self.root = None
|
2011-08-12 08:31:09 +02:00
|
|
|
self.maxconnections = repos.getmaxconnections()
|
2002-07-03 15:04:40 +02:00
|
|
|
self.availableconnections = []
|
|
|
|
self.assignedconnections = []
|
2002-07-11 05:51:20 +02:00
|
|
|
self.lastowner = {}
|
2002-07-03 15:04:40 +02:00
|
|
|
self.semaphore = BoundedSemaphore(self.maxconnections)
|
|
|
|
self.connectionlock = Lock()
|
2011-08-12 08:31:09 +02:00
|
|
|
self.reference = repos.getreference()
|
|
|
|
self.idlefolders = repos.getidlefolders()
|
2008-03-09 06:46:51 +01:00
|
|
|
self.gss_step = self.GSS_STATE_STEP
|
|
|
|
self.gss_vc = None
|
|
|
|
self.gssapi = False
|
2002-06-19 06:39:00 +02:00
|
|
|
|
2002-11-05 00:15:42 +01:00
|
|
|
def getpassword(self):
|
2011-08-12 08:31:09 +02:00
|
|
|
"""Returns the server password or None"""
|
|
|
|
if self.goodpassword != None: # use cached good one first
|
2007-07-05 06:04:14 +02:00
|
|
|
return self.goodpassword
|
|
|
|
|
2002-11-05 00:15:42 +01:00
|
|
|
if self.password != None and self.passworderror == None:
|
2011-08-12 08:31:09 +02:00
|
|
|
return self.password # non-failed preconfigured one
|
2002-11-05 00:15:42 +01:00
|
|
|
|
2011-08-12 08:31:09 +02:00
|
|
|
# get 1) configured password first 2) fall back to asking via UI
|
|
|
|
self.password = self.repos.getpassword() or \
|
|
|
|
self.ui.getpass(self.repos.getname(), self.config,
|
|
|
|
self.passworderror)
|
2002-11-05 00:15:42 +01:00
|
|
|
self.passworderror = None
|
|
|
|
return self.password
|
|
|
|
|
2002-06-19 07:22:21 +02:00
|
|
|
def getdelim(self):
|
|
|
|
"""Returns this server's folder delimiter. Can only be called
|
2002-07-03 15:04:40 +02:00
|
|
|
after one or more calls to acquireconnection."""
|
2002-06-19 07:22:21 +02:00
|
|
|
return self.delim
|
|
|
|
|
|
|
|
def getroot(self):
|
|
|
|
"""Returns this server's folder root. Can only be called after one
|
2002-07-03 15:04:40 +02:00
|
|
|
or more calls to acquireconnection."""
|
2002-06-19 07:22:21 +02:00
|
|
|
return self.root
|
|
|
|
|
2002-07-03 15:04:40 +02:00
|
|
|
|
2011-09-06 13:19:25 +02:00
|
|
|
def releaseconnection(self, connection, drop_conn=False):
|
|
|
|
"""Releases a connection, returning it to the pool.
|
|
|
|
|
|
|
|
:param drop_conn: If True, the connection will be released and
|
|
|
|
not be reused. This can be used to indicate broken connections."""
|
2002-07-03 15:04:40 +02:00
|
|
|
self.connectionlock.acquire()
|
|
|
|
self.assignedconnections.remove(connection)
|
2011-03-08 16:05:24 +01:00
|
|
|
# Don't reuse broken connections
|
2011-09-06 13:19:25 +02:00
|
|
|
if connection.Terminate or drop_conn:
|
2011-03-08 16:05:24 +01:00
|
|
|
connection.logout()
|
|
|
|
else:
|
|
|
|
self.availableconnections.append(connection)
|
2002-07-03 15:04:40 +02:00
|
|
|
self.connectionlock.release()
|
|
|
|
self.semaphore.release()
|
|
|
|
|
2002-11-02 23:14:02 +01:00
|
|
|
def md5handler(self, response):
|
2002-11-02 23:30:41 +01:00
|
|
|
challenge = response.strip()
|
2011-01-05 17:00:55 +01:00
|
|
|
self.ui.debug('imap', 'md5handler: got challenge %s' % challenge)
|
2002-11-06 02:10:14 +01:00
|
|
|
|
2010-12-13 18:45:42 +01:00
|
|
|
passwd = self.getpassword()
|
2002-11-06 02:10:14 +01:00
|
|
|
retval = self.username + ' ' + hmac.new(passwd, challenge).hexdigest()
|
2011-01-05 17:00:55 +01:00
|
|
|
self.ui.debug('imap', 'md5handler: returning %s' % retval)
|
2002-11-02 23:14:02 +01:00
|
|
|
return retval
|
|
|
|
|
2002-11-05 00:38:39 +01:00
|
|
|
def plainauth(self, imapobj):
|
2011-01-05 17:00:55 +01:00
|
|
|
self.ui.debug('imap', 'Attempting plain authentication')
|
2010-12-13 18:45:42 +01:00
|
|
|
imapobj.login(self.username, self.getpassword())
|
2008-03-09 06:46:51 +01:00
|
|
|
|
|
|
|
def gssauth(self, response):
|
|
|
|
data = base64.b64encode(response)
|
|
|
|
try:
|
|
|
|
if self.gss_step == self.GSS_STATE_STEP:
|
|
|
|
if not self.gss_vc:
|
|
|
|
rc, self.gss_vc = kerberos.authGSSClientInit('imap@' +
|
|
|
|
self.hostname)
|
|
|
|
response = kerberos.authGSSClientResponse(self.gss_vc)
|
|
|
|
rc = kerberos.authGSSClientStep(self.gss_vc, data)
|
|
|
|
if rc != kerberos.AUTH_GSS_CONTINUE:
|
|
|
|
self.gss_step = self.GSS_STATE_WRAP
|
|
|
|
elif self.gss_step == self.GSS_STATE_WRAP:
|
|
|
|
rc = kerberos.authGSSClientUnwrap(self.gss_vc, data)
|
|
|
|
response = kerberos.authGSSClientResponse(self.gss_vc)
|
|
|
|
rc = kerberos.authGSSClientWrap(self.gss_vc, response,
|
|
|
|
self.username)
|
|
|
|
response = kerberos.authGSSClientResponse(self.gss_vc)
|
|
|
|
except kerberos.GSSError, err:
|
|
|
|
# Kerberos errored out on us, respond with None to cancel the
|
|
|
|
# authentication
|
2011-01-05 17:00:55 +01:00
|
|
|
self.ui.debug('imap', '%s: %s' % (err[0][0], err[1][0]))
|
2008-03-09 06:46:51 +01:00
|
|
|
return None
|
|
|
|
|
|
|
|
if not response:
|
|
|
|
response = ''
|
|
|
|
return base64.b64decode(response)
|
2002-11-05 00:38:39 +01:00
|
|
|
|
2002-07-03 15:04:40 +02:00
|
|
|
def acquireconnection(self):
|
|
|
|
"""Fetches a connection from the pool, making sure to create a new one
|
|
|
|
if needed, to obey the maximum connection limits, etc.
|
|
|
|
Opens a connection to the server and returns an appropriate
|
2002-06-19 06:39:00 +02:00
|
|
|
object."""
|
|
|
|
|
2002-07-03 15:04:40 +02:00
|
|
|
self.semaphore.acquire()
|
|
|
|
self.connectionlock.acquire()
|
2002-06-19 06:39:00 +02:00
|
|
|
imapobj = None
|
2002-07-03 15:04:40 +02:00
|
|
|
|
|
|
|
if len(self.availableconnections): # One is available.
|
2002-07-11 05:51:20 +02:00
|
|
|
# Try to find one that previously belonged to this thread
|
|
|
|
# as an optimization. Start from the back since that's where
|
|
|
|
# they're popped on.
|
|
|
|
imapobj = None
|
|
|
|
for i in range(len(self.availableconnections) - 1, -1, -1):
|
|
|
|
tryobj = self.availableconnections[i]
|
2011-05-11 19:34:59 +02:00
|
|
|
if self.lastowner[tryobj] == get_ident():
|
2002-07-11 05:51:20 +02:00
|
|
|
imapobj = tryobj
|
|
|
|
del(self.availableconnections[i])
|
|
|
|
break
|
|
|
|
if not imapobj:
|
|
|
|
imapobj = self.availableconnections[0]
|
|
|
|
del(self.availableconnections[0])
|
2002-07-03 15:04:40 +02:00
|
|
|
self.assignedconnections.append(imapobj)
|
2011-05-11 19:34:59 +02:00
|
|
|
self.lastowner[imapobj] = get_ident()
|
2002-07-03 15:04:40 +02:00
|
|
|
self.connectionlock.release()
|
|
|
|
return imapobj
|
|
|
|
|
|
|
|
self.connectionlock.release() # Release until need to modify data
|
|
|
|
|
Patch for error handling / separation of accounts etc.
Dear All,
I have made the attached patch to try and make offlineimap a bit more
stable in challenging situations. It's extremely useful in slow
connection environments - but sometimes if one account had the wrong
password or the connection went down then unfortunately the whole
program would crash.
I have tested this on our connection and tried throwing at it just about
every situation - connection, up down, up, down again, change password,
error whilst copying one message, etc. I have been running this patch
for the last 5 days or so syncing 6 accounts at the moment... It seems
to work and stay alive nicely (even if your connection does not)...
Hope that this can go in for the next release... Please let me know if
anyone notices any problems with this...
Regards,
-Mike
-- Attached file included as plaintext by Ecartis --
-- File: submit
From 1d6777cab23637eb830031c7cab0ae9b8589afd6 Mon Sep 17 00:00:00 2001
From: mike <mike@mikelaptop.(none)>
Date: Mon, 24 Aug 2009 19:37:59 +0430
Subject: [PATCH] This patch attempts to introduce a little more error handling - e.g.
if one account has an error because of a changed password or something
that should not affect the other accounts.
Specifically:
If one sync run has an issue this is in a try-except clause - if it
has an auto refresh period the thread will sleep and try again - this
could be quite useful in the event of the connection going down for a
little while, changed password etc.
If one folder cannot be created an error message will be displayed through
the UI and the program will continue (e.g. permission denied to create a folder)
If one message does not want to copy for whatever resaon an error message
will be displayed through the UI and at least the other messages will
be copied
If one folder run has an exception then the others will still run
2009-08-24 17:17:57 +02:00
|
|
|
""" Must be careful here that if we fail we should bail out gracefully
|
|
|
|
and release locks / threads so that the next attempt can try...
|
|
|
|
"""
|
2002-11-05 00:15:42 +01:00
|
|
|
success = 0
|
Patch for error handling / separation of accounts etc.
Dear All,
I have made the attached patch to try and make offlineimap a bit more
stable in challenging situations. It's extremely useful in slow
connection environments - but sometimes if one account had the wrong
password or the connection went down then unfortunately the whole
program would crash.
I have tested this on our connection and tried throwing at it just about
every situation - connection, up down, up, down again, change password,
error whilst copying one message, etc. I have been running this patch
for the last 5 days or so syncing 6 accounts at the moment... It seems
to work and stay alive nicely (even if your connection does not)...
Hope that this can go in for the next release... Please let me know if
anyone notices any problems with this...
Regards,
-Mike
-- Attached file included as plaintext by Ecartis --
-- File: submit
From 1d6777cab23637eb830031c7cab0ae9b8589afd6 Mon Sep 17 00:00:00 2001
From: mike <mike@mikelaptop.(none)>
Date: Mon, 24 Aug 2009 19:37:59 +0430
Subject: [PATCH] This patch attempts to introduce a little more error handling - e.g.
if one account has an error because of a changed password or something
that should not affect the other accounts.
Specifically:
If one sync run has an issue this is in a try-except clause - if it
has an auto refresh period the thread will sleep and try again - this
could be quite useful in the event of the connection going down for a
little while, changed password etc.
If one folder cannot be created an error message will be displayed through
the UI and the program will continue (e.g. permission denied to create a folder)
If one message does not want to copy for whatever resaon an error message
will be displayed through the UI and at least the other messages will
be copied
If one folder run has an exception then the others will still run
2009-08-24 17:17:57 +02:00
|
|
|
try:
|
|
|
|
while not success:
|
|
|
|
# Generate a new connection.
|
|
|
|
if self.tunnel:
|
2011-01-05 17:00:55 +01:00
|
|
|
self.ui.connecting('tunnel', self.tunnel)
|
2011-03-22 15:51:44 +01:00
|
|
|
imapobj = imaplibutil.IMAP4_Tunnel(self.tunnel,
|
|
|
|
timeout=socket.getdefaulttimeout())
|
Patch for error handling / separation of accounts etc.
Dear All,
I have made the attached patch to try and make offlineimap a bit more
stable in challenging situations. It's extremely useful in slow
connection environments - but sometimes if one account had the wrong
password or the connection went down then unfortunately the whole
program would crash.
I have tested this on our connection and tried throwing at it just about
every situation - connection, up down, up, down again, change password,
error whilst copying one message, etc. I have been running this patch
for the last 5 days or so syncing 6 accounts at the moment... It seems
to work and stay alive nicely (even if your connection does not)...
Hope that this can go in for the next release... Please let me know if
anyone notices any problems with this...
Regards,
-Mike
-- Attached file included as plaintext by Ecartis --
-- File: submit
From 1d6777cab23637eb830031c7cab0ae9b8589afd6 Mon Sep 17 00:00:00 2001
From: mike <mike@mikelaptop.(none)>
Date: Mon, 24 Aug 2009 19:37:59 +0430
Subject: [PATCH] This patch attempts to introduce a little more error handling - e.g.
if one account has an error because of a changed password or something
that should not affect the other accounts.
Specifically:
If one sync run has an issue this is in a try-except clause - if it
has an auto refresh period the thread will sleep and try again - this
could be quite useful in the event of the connection going down for a
little while, changed password etc.
If one folder cannot be created an error message will be displayed through
the UI and the program will continue (e.g. permission denied to create a folder)
If one message does not want to copy for whatever resaon an error message
will be displayed through the UI and at least the other messages will
be copied
If one folder run has an exception then the others will still run
2009-08-24 17:17:57 +02:00
|
|
|
success = 1
|
|
|
|
elif self.usessl:
|
2011-01-05 17:00:55 +01:00
|
|
|
self.ui.connecting(self.hostname, self.port)
|
2011-09-12 09:50:41 +02:00
|
|
|
fingerprint = self.repos.get_ssl_fingerprint()
|
2011-08-12 08:31:09 +02:00
|
|
|
imapobj = imaplibutil.WrappedIMAP4_SSL(self.hostname,
|
|
|
|
self.port,
|
2011-08-15 11:55:42 +02:00
|
|
|
self.sslclientkey,
|
|
|
|
self.sslclientcert,
|
|
|
|
self.sslcacertfile,
|
|
|
|
self.verifycert,
|
2011-03-22 15:51:44 +01:00
|
|
|
timeout=socket.getdefaulttimeout(),
|
2011-09-12 09:50:41 +02:00
|
|
|
fingerprint=fingerprint
|
2011-08-15 11:55:42 +02:00
|
|
|
)
|
Patch for error handling / separation of accounts etc.
Dear All,
I have made the attached patch to try and make offlineimap a bit more
stable in challenging situations. It's extremely useful in slow
connection environments - but sometimes if one account had the wrong
password or the connection went down then unfortunately the whole
program would crash.
I have tested this on our connection and tried throwing at it just about
every situation - connection, up down, up, down again, change password,
error whilst copying one message, etc. I have been running this patch
for the last 5 days or so syncing 6 accounts at the moment... It seems
to work and stay alive nicely (even if your connection does not)...
Hope that this can go in for the next release... Please let me know if
anyone notices any problems with this...
Regards,
-Mike
-- Attached file included as plaintext by Ecartis --
-- File: submit
From 1d6777cab23637eb830031c7cab0ae9b8589afd6 Mon Sep 17 00:00:00 2001
From: mike <mike@mikelaptop.(none)>
Date: Mon, 24 Aug 2009 19:37:59 +0430
Subject: [PATCH] This patch attempts to introduce a little more error handling - e.g.
if one account has an error because of a changed password or something
that should not affect the other accounts.
Specifically:
If one sync run has an issue this is in a try-except clause - if it
has an auto refresh period the thread will sleep and try again - this
could be quite useful in the event of the connection going down for a
little while, changed password etc.
If one folder cannot be created an error message will be displayed through
the UI and the program will continue (e.g. permission denied to create a folder)
If one message does not want to copy for whatever resaon an error message
will be displayed through the UI and at least the other messages will
be copied
If one folder run has an exception then the others will still run
2009-08-24 17:17:57 +02:00
|
|
|
else:
|
2011-01-05 17:00:55 +01:00
|
|
|
self.ui.connecting(self.hostname, self.port)
|
2011-03-22 15:51:44 +01:00
|
|
|
imapobj = imaplibutil.WrappedIMAP4(self.hostname, self.port,
|
|
|
|
timeout=socket.getdefaulttimeout())
|
Patch for error handling / separation of accounts etc.
Dear All,
I have made the attached patch to try and make offlineimap a bit more
stable in challenging situations. It's extremely useful in slow
connection environments - but sometimes if one account had the wrong
password or the connection went down then unfortunately the whole
program would crash.
I have tested this on our connection and tried throwing at it just about
every situation - connection, up down, up, down again, change password,
error whilst copying one message, etc. I have been running this patch
for the last 5 days or so syncing 6 accounts at the moment... It seems
to work and stay alive nicely (even if your connection does not)...
Hope that this can go in for the next release... Please let me know if
anyone notices any problems with this...
Regards,
-Mike
-- Attached file included as plaintext by Ecartis --
-- File: submit
From 1d6777cab23637eb830031c7cab0ae9b8589afd6 Mon Sep 17 00:00:00 2001
From: mike <mike@mikelaptop.(none)>
Date: Mon, 24 Aug 2009 19:37:59 +0430
Subject: [PATCH] This patch attempts to introduce a little more error handling - e.g.
if one account has an error because of a changed password or something
that should not affect the other accounts.
Specifically:
If one sync run has an issue this is in a try-except clause - if it
has an auto refresh period the thread will sleep and try again - this
could be quite useful in the event of the connection going down for a
little while, changed password etc.
If one folder cannot be created an error message will be displayed through
the UI and the program will continue (e.g. permission denied to create a folder)
If one message does not want to copy for whatever resaon an error message
will be displayed through the UI and at least the other messages will
be copied
If one folder run has an exception then the others will still run
2009-08-24 17:17:57 +02:00
|
|
|
|
|
|
|
if not self.tunnel:
|
|
|
|
try:
|
|
|
|
# Try GSSAPI and continue if it fails
|
|
|
|
if 'AUTH=GSSAPI' in imapobj.capabilities and have_gss:
|
2011-06-02 23:04:52 +02:00
|
|
|
self.connectionlock.acquire()
|
2011-01-05 17:00:55 +01:00
|
|
|
self.ui.debug('imap',
|
Patch for error handling / separation of accounts etc.
Dear All,
I have made the attached patch to try and make offlineimap a bit more
stable in challenging situations. It's extremely useful in slow
connection environments - but sometimes if one account had the wrong
password or the connection went down then unfortunately the whole
program would crash.
I have tested this on our connection and tried throwing at it just about
every situation - connection, up down, up, down again, change password,
error whilst copying one message, etc. I have been running this patch
for the last 5 days or so syncing 6 accounts at the moment... It seems
to work and stay alive nicely (even if your connection does not)...
Hope that this can go in for the next release... Please let me know if
anyone notices any problems with this...
Regards,
-Mike
-- Attached file included as plaintext by Ecartis --
-- File: submit
From 1d6777cab23637eb830031c7cab0ae9b8589afd6 Mon Sep 17 00:00:00 2001
From: mike <mike@mikelaptop.(none)>
Date: Mon, 24 Aug 2009 19:37:59 +0430
Subject: [PATCH] This patch attempts to introduce a little more error handling - e.g.
if one account has an error because of a changed password or something
that should not affect the other accounts.
Specifically:
If one sync run has an issue this is in a try-except clause - if it
has an auto refresh period the thread will sleep and try again - this
could be quite useful in the event of the connection going down for a
little while, changed password etc.
If one folder cannot be created an error message will be displayed through
the UI and the program will continue (e.g. permission denied to create a folder)
If one message does not want to copy for whatever resaon an error message
will be displayed through the UI and at least the other messages will
be copied
If one folder run has an exception then the others will still run
2009-08-24 17:17:57 +02:00
|
|
|
'Attempting GSSAPI authentication')
|
2008-03-09 06:46:51 +01:00
|
|
|
try:
|
Patch for error handling / separation of accounts etc.
Dear All,
I have made the attached patch to try and make offlineimap a bit more
stable in challenging situations. It's extremely useful in slow
connection environments - but sometimes if one account had the wrong
password or the connection went down then unfortunately the whole
program would crash.
I have tested this on our connection and tried throwing at it just about
every situation - connection, up down, up, down again, change password,
error whilst copying one message, etc. I have been running this patch
for the last 5 days or so syncing 6 accounts at the moment... It seems
to work and stay alive nicely (even if your connection does not)...
Hope that this can go in for the next release... Please let me know if
anyone notices any problems with this...
Regards,
-Mike
-- Attached file included as plaintext by Ecartis --
-- File: submit
From 1d6777cab23637eb830031c7cab0ae9b8589afd6 Mon Sep 17 00:00:00 2001
From: mike <mike@mikelaptop.(none)>
Date: Mon, 24 Aug 2009 19:37:59 +0430
Subject: [PATCH] This patch attempts to introduce a little more error handling - e.g.
if one account has an error because of a changed password or something
that should not affect the other accounts.
Specifically:
If one sync run has an issue this is in a try-except clause - if it
has an auto refresh period the thread will sleep and try again - this
could be quite useful in the event of the connection going down for a
little while, changed password etc.
If one folder cannot be created an error message will be displayed through
the UI and the program will continue (e.g. permission denied to create a folder)
If one message does not want to copy for whatever resaon an error message
will be displayed through the UI and at least the other messages will
be copied
If one folder run has an exception then the others will still run
2009-08-24 17:17:57 +02:00
|
|
|
imapobj.authenticate('GSSAPI', self.gssauth)
|
2008-03-09 06:46:51 +01:00
|
|
|
except imapobj.error, val:
|
Patch for error handling / separation of accounts etc.
Dear All,
I have made the attached patch to try and make offlineimap a bit more
stable in challenging situations. It's extremely useful in slow
connection environments - but sometimes if one account had the wrong
password or the connection went down then unfortunately the whole
program would crash.
I have tested this on our connection and tried throwing at it just about
every situation - connection, up down, up, down again, change password,
error whilst copying one message, etc. I have been running this patch
for the last 5 days or so syncing 6 accounts at the moment... It seems
to work and stay alive nicely (even if your connection does not)...
Hope that this can go in for the next release... Please let me know if
anyone notices any problems with this...
Regards,
-Mike
-- Attached file included as plaintext by Ecartis --
-- File: submit
From 1d6777cab23637eb830031c7cab0ae9b8589afd6 Mon Sep 17 00:00:00 2001
From: mike <mike@mikelaptop.(none)>
Date: Mon, 24 Aug 2009 19:37:59 +0430
Subject: [PATCH] This patch attempts to introduce a little more error handling - e.g.
if one account has an error because of a changed password or something
that should not affect the other accounts.
Specifically:
If one sync run has an issue this is in a try-except clause - if it
has an auto refresh period the thread will sleep and try again - this
could be quite useful in the event of the connection going down for a
little while, changed password etc.
If one folder cannot be created an error message will be displayed through
the UI and the program will continue (e.g. permission denied to create a folder)
If one message does not want to copy for whatever resaon an error message
will be displayed through the UI and at least the other messages will
be copied
If one folder run has an exception then the others will still run
2009-08-24 17:17:57 +02:00
|
|
|
self.gssapi = False
|
2011-01-05 17:00:55 +01:00
|
|
|
self.ui.debug('imap',
|
Patch for error handling / separation of accounts etc.
Dear All,
I have made the attached patch to try and make offlineimap a bit more
stable in challenging situations. It's extremely useful in slow
connection environments - but sometimes if one account had the wrong
password or the connection went down then unfortunately the whole
program would crash.
I have tested this on our connection and tried throwing at it just about
every situation - connection, up down, up, down again, change password,
error whilst copying one message, etc. I have been running this patch
for the last 5 days or so syncing 6 accounts at the moment... It seems
to work and stay alive nicely (even if your connection does not)...
Hope that this can go in for the next release... Please let me know if
anyone notices any problems with this...
Regards,
-Mike
-- Attached file included as plaintext by Ecartis --
-- File: submit
From 1d6777cab23637eb830031c7cab0ae9b8589afd6 Mon Sep 17 00:00:00 2001
From: mike <mike@mikelaptop.(none)>
Date: Mon, 24 Aug 2009 19:37:59 +0430
Subject: [PATCH] This patch attempts to introduce a little more error handling - e.g.
if one account has an error because of a changed password or something
that should not affect the other accounts.
Specifically:
If one sync run has an issue this is in a try-except clause - if it
has an auto refresh period the thread will sleep and try again - this
could be quite useful in the event of the connection going down for a
little while, changed password etc.
If one folder cannot be created an error message will be displayed through
the UI and the program will continue (e.g. permission denied to create a folder)
If one message does not want to copy for whatever resaon an error message
will be displayed through the UI and at least the other messages will
be copied
If one folder run has an exception then the others will still run
2009-08-24 17:17:57 +02:00
|
|
|
'GSSAPI Authentication failed')
|
|
|
|
else:
|
|
|
|
self.gssapi = True
|
2011-06-02 23:04:52 +02:00
|
|
|
kerberos.authGSSClientClean(self.gss_vc)
|
|
|
|
self.gss_vc = None
|
|
|
|
self.gss_step = self.GSS_STATE_STEP
|
Patch for error handling / separation of accounts etc.
Dear All,
I have made the attached patch to try and make offlineimap a bit more
stable in challenging situations. It's extremely useful in slow
connection environments - but sometimes if one account had the wrong
password or the connection went down then unfortunately the whole
program would crash.
I have tested this on our connection and tried throwing at it just about
every situation - connection, up down, up, down again, change password,
error whilst copying one message, etc. I have been running this patch
for the last 5 days or so syncing 6 accounts at the moment... It seems
to work and stay alive nicely (even if your connection does not)...
Hope that this can go in for the next release... Please let me know if
anyone notices any problems with this...
Regards,
-Mike
-- Attached file included as plaintext by Ecartis --
-- File: submit
From 1d6777cab23637eb830031c7cab0ae9b8589afd6 Mon Sep 17 00:00:00 2001
From: mike <mike@mikelaptop.(none)>
Date: Mon, 24 Aug 2009 19:37:59 +0430
Subject: [PATCH] This patch attempts to introduce a little more error handling - e.g.
if one account has an error because of a changed password or something
that should not affect the other accounts.
Specifically:
If one sync run has an issue this is in a try-except clause - if it
has an auto refresh period the thread will sleep and try again - this
could be quite useful in the event of the connection going down for a
little while, changed password etc.
If one folder cannot be created an error message will be displayed through
the UI and the program will continue (e.g. permission denied to create a folder)
If one message does not want to copy for whatever resaon an error message
will be displayed through the UI and at least the other messages will
be copied
If one folder run has an exception then the others will still run
2009-08-24 17:17:57 +02:00
|
|
|
#if we do self.password = None then the next attempt cannot try...
|
|
|
|
#self.password = None
|
2011-06-02 23:04:52 +02:00
|
|
|
self.connectionlock.release()
|
Patch for error handling / separation of accounts etc.
Dear All,
I have made the attached patch to try and make offlineimap a bit more
stable in challenging situations. It's extremely useful in slow
connection environments - but sometimes if one account had the wrong
password or the connection went down then unfortunately the whole
program would crash.
I have tested this on our connection and tried throwing at it just about
every situation - connection, up down, up, down again, change password,
error whilst copying one message, etc. I have been running this patch
for the last 5 days or so syncing 6 accounts at the moment... It seems
to work and stay alive nicely (even if your connection does not)...
Hope that this can go in for the next release... Please let me know if
anyone notices any problems with this...
Regards,
-Mike
-- Attached file included as plaintext by Ecartis --
-- File: submit
From 1d6777cab23637eb830031c7cab0ae9b8589afd6 Mon Sep 17 00:00:00 2001
From: mike <mike@mikelaptop.(none)>
Date: Mon, 24 Aug 2009 19:37:59 +0430
Subject: [PATCH] This patch attempts to introduce a little more error handling - e.g.
if one account has an error because of a changed password or something
that should not affect the other accounts.
Specifically:
If one sync run has an issue this is in a try-except clause - if it
has an auto refresh period the thread will sleep and try again - this
could be quite useful in the event of the connection going down for a
little while, changed password etc.
If one folder cannot be created an error message will be displayed through
the UI and the program will continue (e.g. permission denied to create a folder)
If one message does not want to copy for whatever resaon an error message
will be displayed through the UI and at least the other messages will
be copied
If one folder run has an exception then the others will still run
2009-08-24 17:17:57 +02:00
|
|
|
|
|
|
|
if not self.gssapi:
|
2011-06-24 16:06:07 +02:00
|
|
|
if 'STARTTLS' in imapobj.capabilities and not\
|
|
|
|
self.usessl:
|
|
|
|
self.ui.debug('imap',
|
|
|
|
'Using STARTTLS connection')
|
|
|
|
imapobj.starttls()
|
|
|
|
|
Patch for error handling / separation of accounts etc.
Dear All,
I have made the attached patch to try and make offlineimap a bit more
stable in challenging situations. It's extremely useful in slow
connection environments - but sometimes if one account had the wrong
password or the connection went down then unfortunately the whole
program would crash.
I have tested this on our connection and tried throwing at it just about
every situation - connection, up down, up, down again, change password,
error whilst copying one message, etc. I have been running this patch
for the last 5 days or so syncing 6 accounts at the moment... It seems
to work and stay alive nicely (even if your connection does not)...
Hope that this can go in for the next release... Please let me know if
anyone notices any problems with this...
Regards,
-Mike
-- Attached file included as plaintext by Ecartis --
-- File: submit
From 1d6777cab23637eb830031c7cab0ae9b8589afd6 Mon Sep 17 00:00:00 2001
From: mike <mike@mikelaptop.(none)>
Date: Mon, 24 Aug 2009 19:37:59 +0430
Subject: [PATCH] This patch attempts to introduce a little more error handling - e.g.
if one account has an error because of a changed password or something
that should not affect the other accounts.
Specifically:
If one sync run has an issue this is in a try-except clause - if it
has an auto refresh period the thread will sleep and try again - this
could be quite useful in the event of the connection going down for a
little while, changed password etc.
If one folder cannot be created an error message will be displayed through
the UI and the program will continue (e.g. permission denied to create a folder)
If one message does not want to copy for whatever resaon an error message
will be displayed through the UI and at least the other messages will
be copied
If one folder run has an exception then the others will still run
2009-08-24 17:17:57 +02:00
|
|
|
if 'AUTH=CRAM-MD5' in imapobj.capabilities:
|
2011-01-05 17:00:55 +01:00
|
|
|
self.ui.debug('imap',
|
2011-06-24 16:06:07 +02:00
|
|
|
'Attempting CRAM-MD5 authentication')
|
Patch for error handling / separation of accounts etc.
Dear All,
I have made the attached patch to try and make offlineimap a bit more
stable in challenging situations. It's extremely useful in slow
connection environments - but sometimes if one account had the wrong
password or the connection went down then unfortunately the whole
program would crash.
I have tested this on our connection and tried throwing at it just about
every situation - connection, up down, up, down again, change password,
error whilst copying one message, etc. I have been running this patch
for the last 5 days or so syncing 6 accounts at the moment... It seems
to work and stay alive nicely (even if your connection does not)...
Hope that this can go in for the next release... Please let me know if
anyone notices any problems with this...
Regards,
-Mike
-- Attached file included as plaintext by Ecartis --
-- File: submit
From 1d6777cab23637eb830031c7cab0ae9b8589afd6 Mon Sep 17 00:00:00 2001
From: mike <mike@mikelaptop.(none)>
Date: Mon, 24 Aug 2009 19:37:59 +0430
Subject: [PATCH] This patch attempts to introduce a little more error handling - e.g.
if one account has an error because of a changed password or something
that should not affect the other accounts.
Specifically:
If one sync run has an issue this is in a try-except clause - if it
has an auto refresh period the thread will sleep and try again - this
could be quite useful in the event of the connection going down for a
little while, changed password etc.
If one folder cannot be created an error message will be displayed through
the UI and the program will continue (e.g. permission denied to create a folder)
If one message does not want to copy for whatever resaon an error message
will be displayed through the UI and at least the other messages will
be copied
If one folder run has an exception then the others will still run
2009-08-24 17:17:57 +02:00
|
|
|
try:
|
2011-06-24 16:06:07 +02:00
|
|
|
imapobj.authenticate('CRAM-MD5',
|
|
|
|
self.md5handler)
|
Patch for error handling / separation of accounts etc.
Dear All,
I have made the attached patch to try and make offlineimap a bit more
stable in challenging situations. It's extremely useful in slow
connection environments - but sometimes if one account had the wrong
password or the connection went down then unfortunately the whole
program would crash.
I have tested this on our connection and tried throwing at it just about
every situation - connection, up down, up, down again, change password,
error whilst copying one message, etc. I have been running this patch
for the last 5 days or so syncing 6 accounts at the moment... It seems
to work and stay alive nicely (even if your connection does not)...
Hope that this can go in for the next release... Please let me know if
anyone notices any problems with this...
Regards,
-Mike
-- Attached file included as plaintext by Ecartis --
-- File: submit
From 1d6777cab23637eb830031c7cab0ae9b8589afd6 Mon Sep 17 00:00:00 2001
From: mike <mike@mikelaptop.(none)>
Date: Mon, 24 Aug 2009 19:37:59 +0430
Subject: [PATCH] This patch attempts to introduce a little more error handling - e.g.
if one account has an error because of a changed password or something
that should not affect the other accounts.
Specifically:
If one sync run has an issue this is in a try-except clause - if it
has an auto refresh period the thread will sleep and try again - this
could be quite useful in the event of the connection going down for a
little while, changed password etc.
If one folder cannot be created an error message will be displayed through
the UI and the program will continue (e.g. permission denied to create a folder)
If one message does not want to copy for whatever resaon an error message
will be displayed through the UI and at least the other messages will
be copied
If one folder run has an exception then the others will still run
2009-08-24 17:17:57 +02:00
|
|
|
except imapobj.error, val:
|
|
|
|
self.plainauth(imapobj)
|
|
|
|
else:
|
2011-09-16 13:57:55 +02:00
|
|
|
# Use plaintext login, unless
|
|
|
|
# LOGINDISABLED (RFC2595)
|
|
|
|
if 'LOGINDISABLED' in imapobj.capabilities:
|
|
|
|
raise OfflineImapError("Plaintext login "
|
|
|
|
"disabled by server. Need to use SSL?",
|
|
|
|
OfflineImapError.ERROR.REPO)
|
2008-03-09 06:46:51 +01:00
|
|
|
self.plainauth(imapobj)
|
Patch for error handling / separation of accounts etc.
Dear All,
I have made the attached patch to try and make offlineimap a bit more
stable in challenging situations. It's extremely useful in slow
connection environments - but sometimes if one account had the wrong
password or the connection went down then unfortunately the whole
program would crash.
I have tested this on our connection and tried throwing at it just about
every situation - connection, up down, up, down again, change password,
error whilst copying one message, etc. I have been running this patch
for the last 5 days or so syncing 6 accounts at the moment... It seems
to work and stay alive nicely (even if your connection does not)...
Hope that this can go in for the next release... Please let me know if
anyone notices any problems with this...
Regards,
-Mike
-- Attached file included as plaintext by Ecartis --
-- File: submit
From 1d6777cab23637eb830031c7cab0ae9b8589afd6 Mon Sep 17 00:00:00 2001
From: mike <mike@mikelaptop.(none)>
Date: Mon, 24 Aug 2009 19:37:59 +0430
Subject: [PATCH] This patch attempts to introduce a little more error handling - e.g.
if one account has an error because of a changed password or something
that should not affect the other accounts.
Specifically:
If one sync run has an issue this is in a try-except clause - if it
has an auto refresh period the thread will sleep and try again - this
could be quite useful in the event of the connection going down for a
little while, changed password etc.
If one folder cannot be created an error message will be displayed through
the UI and the program will continue (e.g. permission denied to create a folder)
If one message does not want to copy for whatever resaon an error message
will be displayed through the UI and at least the other messages will
be copied
If one folder run has an exception then the others will still run
2009-08-24 17:17:57 +02:00
|
|
|
# Would bail by here if there was a failure.
|
|
|
|
success = 1
|
|
|
|
self.goodpassword = self.password
|
|
|
|
except imapobj.error, val:
|
|
|
|
self.passworderror = str(val)
|
|
|
|
raise
|
|
|
|
|
|
|
|
if self.delim == None:
|
|
|
|
listres = imapobj.list(self.reference, '""')[1]
|
|
|
|
if listres == [None] or listres == None:
|
|
|
|
# Some buggy IMAP servers do not respond well to LIST "" ""
|
|
|
|
# Work around them.
|
|
|
|
listres = imapobj.list(self.reference, '"*"')[1]
|
2011-03-03 10:43:03 +01:00
|
|
|
if listres == [None] or listres == None:
|
|
|
|
# No Folders were returned. This occurs, e.g. if the
|
|
|
|
# 'reference' prefix does not exist on the mail
|
|
|
|
# server. Raise exception.
|
|
|
|
err = "Server '%s' returned no folders in '%s'" % \
|
|
|
|
(self.repos.getname(), self.reference)
|
|
|
|
self.ui.warn(err)
|
|
|
|
raise Exception(err)
|
Patch for error handling / separation of accounts etc.
Dear All,
I have made the attached patch to try and make offlineimap a bit more
stable in challenging situations. It's extremely useful in slow
connection environments - but sometimes if one account had the wrong
password or the connection went down then unfortunately the whole
program would crash.
I have tested this on our connection and tried throwing at it just about
every situation - connection, up down, up, down again, change password,
error whilst copying one message, etc. I have been running this patch
for the last 5 days or so syncing 6 accounts at the moment... It seems
to work and stay alive nicely (even if your connection does not)...
Hope that this can go in for the next release... Please let me know if
anyone notices any problems with this...
Regards,
-Mike
-- Attached file included as plaintext by Ecartis --
-- File: submit
From 1d6777cab23637eb830031c7cab0ae9b8589afd6 Mon Sep 17 00:00:00 2001
From: mike <mike@mikelaptop.(none)>
Date: Mon, 24 Aug 2009 19:37:59 +0430
Subject: [PATCH] This patch attempts to introduce a little more error handling - e.g.
if one account has an error because of a changed password or something
that should not affect the other accounts.
Specifically:
If one sync run has an issue this is in a try-except clause - if it
has an auto refresh period the thread will sleep and try again - this
could be quite useful in the event of the connection going down for a
little while, changed password etc.
If one folder cannot be created an error message will be displayed through
the UI and the program will continue (e.g. permission denied to create a folder)
If one message does not want to copy for whatever resaon an error message
will be displayed through the UI and at least the other messages will
be copied
If one folder run has an exception then the others will still run
2009-08-24 17:17:57 +02:00
|
|
|
self.delim, self.root = \
|
|
|
|
imaputil.imapsplit(listres[0])[1:]
|
|
|
|
self.delim = imaputil.dequote(self.delim)
|
|
|
|
self.root = imaputil.dequote(self.root)
|
|
|
|
|
|
|
|
self.connectionlock.acquire()
|
|
|
|
self.assignedconnections.append(imapobj)
|
2011-05-11 19:34:59 +02:00
|
|
|
self.lastowner[imapobj] = get_ident()
|
Patch for error handling / separation of accounts etc.
Dear All,
I have made the attached patch to try and make offlineimap a bit more
stable in challenging situations. It's extremely useful in slow
connection environments - but sometimes if one account had the wrong
password or the connection went down then unfortunately the whole
program would crash.
I have tested this on our connection and tried throwing at it just about
every situation - connection, up down, up, down again, change password,
error whilst copying one message, etc. I have been running this patch
for the last 5 days or so syncing 6 accounts at the moment... It seems
to work and stay alive nicely (even if your connection does not)...
Hope that this can go in for the next release... Please let me know if
anyone notices any problems with this...
Regards,
-Mike
-- Attached file included as plaintext by Ecartis --
-- File: submit
From 1d6777cab23637eb830031c7cab0ae9b8589afd6 Mon Sep 17 00:00:00 2001
From: mike <mike@mikelaptop.(none)>
Date: Mon, 24 Aug 2009 19:37:59 +0430
Subject: [PATCH] This patch attempts to introduce a little more error handling - e.g.
if one account has an error because of a changed password or something
that should not affect the other accounts.
Specifically:
If one sync run has an issue this is in a try-except clause - if it
has an auto refresh period the thread will sleep and try again - this
could be quite useful in the event of the connection going down for a
little while, changed password etc.
If one folder cannot be created an error message will be displayed through
the UI and the program will continue (e.g. permission denied to create a folder)
If one message does not want to copy for whatever resaon an error message
will be displayed through the UI and at least the other messages will
be copied
If one folder run has an exception then the others will still run
2009-08-24 17:17:57 +02:00
|
|
|
self.connectionlock.release()
|
|
|
|
return imapobj
|
2011-05-04 16:45:25 +02:00
|
|
|
except Exception, e:
|
|
|
|
"""If we are here then we did not succeed in getting a
|
|
|
|
connection - we should clean up and then re-raise the
|
|
|
|
error..."""
|
Patch for error handling / separation of accounts etc.
Dear All,
I have made the attached patch to try and make offlineimap a bit more
stable in challenging situations. It's extremely useful in slow
connection environments - but sometimes if one account had the wrong
password or the connection went down then unfortunately the whole
program would crash.
I have tested this on our connection and tried throwing at it just about
every situation - connection, up down, up, down again, change password,
error whilst copying one message, etc. I have been running this patch
for the last 5 days or so syncing 6 accounts at the moment... It seems
to work and stay alive nicely (even if your connection does not)...
Hope that this can go in for the next release... Please let me know if
anyone notices any problems with this...
Regards,
-Mike
-- Attached file included as plaintext by Ecartis --
-- File: submit
From 1d6777cab23637eb830031c7cab0ae9b8589afd6 Mon Sep 17 00:00:00 2001
From: mike <mike@mikelaptop.(none)>
Date: Mon, 24 Aug 2009 19:37:59 +0430
Subject: [PATCH] This patch attempts to introduce a little more error handling - e.g.
if one account has an error because of a changed password or something
that should not affect the other accounts.
Specifically:
If one sync run has an issue this is in a try-except clause - if it
has an auto refresh period the thread will sleep and try again - this
could be quite useful in the event of the connection going down for a
little while, changed password etc.
If one folder cannot be created an error message will be displayed through
the UI and the program will continue (e.g. permission denied to create a folder)
If one message does not want to copy for whatever resaon an error message
will be displayed through the UI and at least the other messages will
be copied
If one folder run has an exception then the others will still run
2009-08-24 17:17:57 +02:00
|
|
|
self.semaphore.release()
|
|
|
|
|
|
|
|
if(self.connectionlock.locked()):
|
|
|
|
self.connectionlock.release()
|
2011-05-04 16:45:25 +02:00
|
|
|
|
2011-06-27 11:08:54 +02:00
|
|
|
severity = OfflineImapError.ERROR.REPO
|
2011-06-16 23:38:55 +02:00
|
|
|
if type(e) == gaierror:
|
2011-05-04 16:45:25 +02:00
|
|
|
#DNS related errors. Abort Repo sync
|
|
|
|
#TODO: special error msg for e.errno == 2 "Name or service not known"?
|
|
|
|
reason = "Could not resolve name '%s' for repository "\
|
|
|
|
"'%s'. Make sure you have configured the ser"\
|
2011-06-06 11:04:55 +02:00
|
|
|
"ver name correctly and that you are online."%\
|
2011-08-12 08:31:09 +02:00
|
|
|
(self.hostname, self.repos)
|
2011-06-06 11:04:55 +02:00
|
|
|
raise OfflineImapError(reason, severity)
|
|
|
|
|
2011-06-17 08:56:30 +02:00
|
|
|
elif SSLError and isinstance(e, SSLError) and e.errno == 1:
|
2011-06-06 11:04:55 +02:00
|
|
|
# SSL unknown protocol error
|
|
|
|
# happens e.g. when connecting via SSL to a non-SSL service
|
2011-08-22 10:33:55 +02:00
|
|
|
if self.port != 993:
|
2011-06-06 11:04:55 +02:00
|
|
|
reason = "Could not connect via SSL to host '%s' and non-s"\
|
|
|
|
"tandard ssl port %d configured. Make sure you connect"\
|
|
|
|
" to the correct port." % (self.hostname, self.port)
|
|
|
|
else:
|
|
|
|
reason = "Unknown SSL protocol connecting to host '%s' for"\
|
|
|
|
"repository '%s'. OpenSSL responded:\n%s"\
|
2011-08-12 08:31:09 +02:00
|
|
|
% (self.hostname, self.repos, e)
|
2011-06-06 11:04:55 +02:00
|
|
|
raise OfflineImapError(reason, severity)
|
|
|
|
|
|
|
|
elif isinstance(e, socket.error) and e.args[0] == errno.ECONNREFUSED:
|
|
|
|
# "Connection refused", can be a non-existing port, or an unauthorized
|
|
|
|
# webproxy (open WLAN?)
|
|
|
|
reason = "Connection to host '%s:%d' for repository '%s' was "\
|
|
|
|
"refused. Make sure you have the right host and port "\
|
|
|
|
"configured and that you are actually able to access the "\
|
|
|
|
"network." % (self.hostname, self.port, self.reposname)
|
2011-05-04 16:45:25 +02:00
|
|
|
raise OfflineImapError(reason, severity)
|
2011-05-24 23:45:39 +02:00
|
|
|
# Could not acquire connection to the remote;
|
|
|
|
# socket.error(last_error) raised
|
|
|
|
if str(e)[:24] == "can't open socket; error":
|
|
|
|
raise OfflineImapError("Could not connect to remote server '%s' "\
|
|
|
|
"for repository '%s'. Remote does not answer."
|
2011-08-12 08:31:09 +02:00
|
|
|
% (self.hostname, self.repos),
|
|
|
|
OfflineImapError.ERROR.REPO)
|
2011-05-04 16:45:25 +02:00
|
|
|
else:
|
|
|
|
# re-raise all other errors
|
|
|
|
raise
|
2002-06-19 06:39:00 +02:00
|
|
|
|
2002-07-03 15:04:40 +02:00
|
|
|
def connectionwait(self):
|
|
|
|
"""Waits until there is a connection available. Note that between
|
|
|
|
the time that a connection becomes available and the time it is
|
|
|
|
requested, another thread may have grabbed it. This function is
|
|
|
|
mainly present as a way to avoid spawning thousands of threads
|
|
|
|
to copy messages, then have them all wait for 3 available connections.
|
|
|
|
It's OK if we have maxconnections + 1 or 2 threads, which is what
|
|
|
|
this will help us do."""
|
2011-05-11 20:55:54 +02:00
|
|
|
self.semaphore.acquire()
|
|
|
|
self.semaphore.release()
|
2002-07-03 15:04:40 +02:00
|
|
|
|
2002-06-21 09:25:24 +02:00
|
|
|
def close(self):
|
2002-07-03 15:04:40 +02:00
|
|
|
# Make sure I own all the semaphores. Let the threads finish
|
|
|
|
# their stuff. This is a blocking method.
|
|
|
|
self.connectionlock.acquire()
|
2002-07-04 02:02:10 +02:00
|
|
|
threadutil.semaphorereset(self.semaphore, self.maxconnections)
|
2002-07-03 15:04:40 +02:00
|
|
|
for imapobj in self.assignedconnections + self.availableconnections:
|
|
|
|
imapobj.logout()
|
|
|
|
self.assignedconnections = []
|
|
|
|
self.availableconnections = []
|
2002-07-11 05:51:20 +02:00
|
|
|
self.lastowner = {}
|
Apply patch to fix autorefresh with Kerberos
Patch from Eric Dorland
Closes: #470875
From: Wouter Verhelst
Subject: kerberos authentication works only the first time
Date: Fri, 14 Mar 2008 09:28:37 +0100
Package: offlineimap
Version: 5.99.8
Severity: normal
Hi,
I have the "autorefresh" configuration option specified in my
.offlineimaprc, and am now using the kerberos authentication.
However, this kerberos authentication seems to work only the first
time
offlineimap tries to fetch mails. The next time, it fails with this
output:
Thread 'Account sync Test' terminated with exception:
Traceback (most recent call last):
File "/var/lib/python-support/python2.4/offlineimap/threadutil.py",
line 153, in run
Thread.run(self)
File "/usr/lib/python2.4/threading.py", line 422, in run
self.__target(*self.__args, **self.__kwargs)
File "/var/lib/python-support/python2.4/offlineimap/accounts.py",
line 119, in syncrunner
self.sync()
File "/var/lib/python-support/python2.4/offlineimap/accounts.py",
line 148, in sync
remoterepos.syncfoldersto(localrepos, [statusrepos])
File
"/var/lib/python-support/python2.4/offlineimap/repository/Base.py",
line 135, in syncfoldersto
srcfolders = src.getfolders()
File
"/var/lib/python-support/python2.4/offlineimap/repository/IMAP.py",
line 192, in getfolders
listresult = imapobj.list(directory =
self.imapserver.reference)[1]
File "/usr/lib/python2.4/imaplib.py", line 469, in list
typ, dat = self._simple_command(name, directory, pattern)
File "/usr/lib/python2.4/imaplib.py", line 1028, in _simple_command
return self._command_complete(name, self._command(name, *args))
File "/usr/lib/python2.4/imaplib.py", line 787, in _command
raise self.error(
error: command LIST illegal in state NONAUTH
2009-04-21 07:03:28 +02:00
|
|
|
# reset kerberos state
|
|
|
|
self.gss_step = self.GSS_STATE_STEP
|
|
|
|
self.gss_vc = None
|
|
|
|
self.gssapi = False
|
2002-07-03 15:04:40 +02:00
|
|
|
self.connectionlock.release()
|
|
|
|
|
2002-07-10 13:18:07 +02:00
|
|
|
def keepalive(self, timeout, event):
|
|
|
|
"""Sends a NOOP to each connection recorded. It will wait a maximum
|
|
|
|
of timeout seconds between doing this, and will continue to do so
|
|
|
|
until the Event object as passed is true. This method is expected
|
|
|
|
to be invoked in a separate thread, which should be join()'d after
|
|
|
|
the event is set."""
|
2011-01-05 17:00:55 +01:00
|
|
|
self.ui.debug('imap', 'keepalive thread started')
|
2002-07-10 13:18:07 +02:00
|
|
|
while 1:
|
2011-01-05 17:00:55 +01:00
|
|
|
self.ui.debug('imap', 'keepalive: top of loop')
|
2002-07-10 13:18:07 +02:00
|
|
|
if event.isSet():
|
2011-01-05 17:00:55 +01:00
|
|
|
self.ui.debug('imap', 'keepalive: event is set; exiting')
|
2002-07-10 13:18:07 +02:00
|
|
|
return
|
2011-01-05 17:00:55 +01:00
|
|
|
self.ui.debug('imap', 'keepalive: acquiring connectionlock')
|
2002-07-10 13:18:07 +02:00
|
|
|
self.connectionlock.acquire()
|
|
|
|
numconnections = len(self.assignedconnections) + \
|
|
|
|
len(self.availableconnections)
|
|
|
|
self.connectionlock.release()
|
2011-01-05 17:00:55 +01:00
|
|
|
self.ui.debug('imap', 'keepalive: connectionlock released')
|
2002-07-10 13:18:07 +02:00
|
|
|
threads = []
|
|
|
|
|
|
|
|
for i in range(numconnections):
|
2011-01-05 17:00:55 +01:00
|
|
|
self.ui.debug('imap', 'keepalive: processing connection %d of %d' % (i, numconnections))
|
2011-05-19 21:02:28 +02:00
|
|
|
if len(self.idlefolders) > i:
|
|
|
|
idler = IdleThread(self, self.idlefolders[i])
|
|
|
|
else:
|
|
|
|
idler = IdleThread(self)
|
|
|
|
idler.start()
|
|
|
|
threads.append(idler)
|
2011-01-05 17:00:55 +01:00
|
|
|
self.ui.debug('imap', 'keepalive: thread started')
|
2003-06-02 21:06:18 +02:00
|
|
|
|
2011-05-19 21:02:28 +02:00
|
|
|
self.ui.debug('imap', 'keepalive: waiting for timeout')
|
|
|
|
event.wait(timeout)
|
|
|
|
self.ui.debug('imap', 'keepalive: after wait')
|
|
|
|
|
2011-01-05 17:00:55 +01:00
|
|
|
self.ui.debug('imap', 'keepalive: joining threads')
|
2002-07-10 13:18:07 +02:00
|
|
|
|
2011-05-19 21:02:28 +02:00
|
|
|
for idler in threads:
|
2002-07-10 13:18:07 +02:00
|
|
|
# Make sure all the commands have completed.
|
2011-05-19 21:02:28 +02:00
|
|
|
idler.stop()
|
|
|
|
idler.join()
|
2009-08-12 21:49:58 +02:00
|
|
|
|
2011-01-05 17:00:55 +01:00
|
|
|
self.ui.debug('imap', 'keepalive: bottom of loop')
|
2009-02-10 01:27:48 +01:00
|
|
|
|
2011-08-15 11:55:42 +02:00
|
|
|
|
|
|
|
def verifycert(self, cert, hostname):
|
|
|
|
'''Verify that cert (in socket.getpeercert() format) matches hostname.
|
|
|
|
CRLs are not handled.
|
|
|
|
|
|
|
|
Returns error message if any problems are found and None on success.
|
|
|
|
'''
|
|
|
|
errstr = "CA Cert verifying failed: "
|
|
|
|
if not cert:
|
|
|
|
return ('%s no certificate received' % errstr)
|
|
|
|
dnsname = hostname.lower()
|
|
|
|
certnames = []
|
|
|
|
|
|
|
|
# cert expired?
|
|
|
|
notafter = cert.get('notAfter')
|
|
|
|
if notafter:
|
|
|
|
if time.time() >= cert_time_to_seconds(notafter):
|
|
|
|
return '%s certificate expired %s' % (errstr, notafter)
|
|
|
|
|
|
|
|
# First read commonName
|
|
|
|
for s in cert.get('subject', []):
|
|
|
|
key, value = s[0]
|
|
|
|
if key == 'commonName':
|
|
|
|
certnames.append(value.lower())
|
|
|
|
if len(certnames) == 0:
|
|
|
|
return ('%s no commonName found in certificate' % errstr)
|
|
|
|
|
|
|
|
# Then read subjectAltName
|
|
|
|
for key, value in cert.get('subjectAltName', []):
|
|
|
|
if key == 'DNS':
|
|
|
|
certnames.append(value.lower())
|
|
|
|
|
|
|
|
# And finally try to match hostname with one of these names
|
|
|
|
for certname in certnames:
|
|
|
|
if (certname == dnsname or
|
|
|
|
'.' in dnsname and certname == '*.' + dnsname.split('.', 1)[1]):
|
|
|
|
return None
|
|
|
|
|
|
|
|
return ('%s no matching domain name found in certificate' % errstr)
|
|
|
|
|
|
|
|
|
2011-05-19 21:02:27 +02:00
|
|
|
class IdleThread(object):
|
|
|
|
def __init__(self, parent, folder=None):
|
2011-09-12 10:37:54 +02:00
|
|
|
"""If invoked without 'folder', perform a NOOP and wait for
|
|
|
|
self.stop() to be called. If invoked with folder, switch to IDLE
|
|
|
|
mode and synchronize once we have a new message"""
|
2011-05-19 21:02:27 +02:00
|
|
|
self.parent = parent
|
|
|
|
self.folder = folder
|
2011-09-12 10:37:55 +02:00
|
|
|
self.stop_sig = Event()
|
2011-09-01 11:01:00 +02:00
|
|
|
self.ui = getglobalui()
|
2011-05-19 21:02:27 +02:00
|
|
|
if folder is None:
|
|
|
|
self.thread = Thread(target=self.noop)
|
|
|
|
else:
|
|
|
|
self.thread = Thread(target=self.idle)
|
|
|
|
self.thread.setDaemon(1)
|
|
|
|
|
|
|
|
def start(self):
|
|
|
|
self.thread.start()
|
|
|
|
|
|
|
|
def stop(self):
|
2011-09-12 10:37:55 +02:00
|
|
|
self.stop_sig.set()
|
2011-05-19 21:02:27 +02:00
|
|
|
|
|
|
|
def join(self):
|
|
|
|
self.thread.join()
|
|
|
|
|
|
|
|
def noop(self):
|
|
|
|
imapobj = self.parent.acquireconnection()
|
|
|
|
imapobj.noop()
|
2011-09-12 10:37:55 +02:00
|
|
|
self.stop_sig.wait()
|
2011-05-19 21:02:27 +02:00
|
|
|
self.parent.releaseconnection(imapobj)
|
|
|
|
|
|
|
|
def dosync(self):
|
|
|
|
remoterepos = self.parent.repos
|
|
|
|
account = remoterepos.account
|
|
|
|
localrepos = account.localrepos
|
|
|
|
remoterepos = account.remoterepos
|
|
|
|
statusrepos = account.statusrepos
|
|
|
|
remotefolder = remoterepos.getfolder(self.folder)
|
|
|
|
offlineimap.accounts.syncfolder(account.name, remoterepos, remotefolder, localrepos, statusrepos, quick=False)
|
|
|
|
ui = getglobalui()
|
|
|
|
ui.unregisterthread(currentThread())
|
|
|
|
|
|
|
|
def idle(self):
|
2011-09-12 10:37:54 +02:00
|
|
|
"""Invoke IDLE mode until timeout or self.stop() is invoked"""
|
2011-09-12 10:37:53 +02:00
|
|
|
def callback(args):
|
2011-09-12 10:37:54 +02:00
|
|
|
"""IDLE callback function invoked by imaplib2
|
|
|
|
|
|
|
|
This is invoked when a) The IMAP server tells us something
|
|
|
|
while in IDLE mode, b) we get an Exception (e.g. on dropped
|
|
|
|
connections, or c) the standard imaplib IDLE timeout of 29
|
|
|
|
minutes kicks in."""
|
2011-09-12 10:37:53 +02:00
|
|
|
result, cb_arg, exc_data = args
|
2011-09-12 10:37:57 +02:00
|
|
|
if exc_data is None and not self.stop_sig.isSet():
|
|
|
|
# No Exception, and we are not supposed to stop:
|
|
|
|
self.needsync = True
|
|
|
|
self.stop_sig.set() # continue to sync
|
2011-09-12 10:37:53 +02:00
|
|
|
|
2011-09-12 10:37:56 +02:00
|
|
|
while not self.stop_sig.isSet():
|
2011-05-19 21:02:27 +02:00
|
|
|
self.needsync = False
|
2011-05-19 21:02:31 +02:00
|
|
|
|
2011-09-01 11:01:00 +02:00
|
|
|
success = False # successfully selected FOLDER?
|
|
|
|
while not success:
|
|
|
|
imapobj = self.parent.acquireconnection()
|
|
|
|
try:
|
|
|
|
imapobj.select(self.folder)
|
|
|
|
except OfflineImapError, e:
|
|
|
|
if e.severity == OfflineImapError.ERROR.FOLDER_RETRY:
|
|
|
|
# Connection closed, release connection and retry
|
|
|
|
self.ui.error(e, exc_info()[2])
|
2011-09-12 10:37:57 +02:00
|
|
|
self.parent.releaseconnection(imapobj, True)
|
2011-09-01 11:01:00 +02:00
|
|
|
else:
|
|
|
|
raise e
|
|
|
|
else:
|
|
|
|
success = True
|
2011-05-22 09:19:29 +02:00
|
|
|
if "IDLE" in imapobj.capabilities:
|
|
|
|
imapobj.idle(callback=callback)
|
|
|
|
else:
|
2011-09-12 10:37:54 +02:00
|
|
|
self.ui.warn("IMAP IDLE not supported on server '%s'."
|
|
|
|
"Sleep until next refresh cycle." % imapobj.identifier)
|
2011-05-22 09:19:29 +02:00
|
|
|
imapobj.noop()
|
2011-09-12 10:37:55 +02:00
|
|
|
self.stop_sig.wait() # self.stop() or IDLE callback are invoked
|
2011-09-12 10:37:57 +02:00
|
|
|
try:
|
|
|
|
# End IDLE mode with noop, imapobj can point to a dropped conn.
|
2011-05-22 09:19:29 +02:00
|
|
|
imapobj.noop()
|
2011-09-12 10:37:57 +02:00
|
|
|
except imapobj.abort():
|
|
|
|
self.ui.warn('Attempting NOOP on dropped connection %s' % \
|
|
|
|
imapobj.identifier)
|
|
|
|
self.parent.releaseconnection(imapobj, True)
|
|
|
|
else:
|
|
|
|
self.parent.releaseconnection(imapobj)
|
|
|
|
|
2011-05-19 21:02:27 +02:00
|
|
|
if self.needsync:
|
2011-09-12 10:37:54 +02:00
|
|
|
# here not via self.stop, but because IDLE responded. Do
|
|
|
|
# another round and invoke actual syncing.
|
2011-09-12 10:37:55 +02:00
|
|
|
self.stop_sig.clear()
|
2011-05-19 21:02:27 +02:00
|
|
|
self.dosync()
|