2015-01-01 21:41:11 +01:00
|
|
|
# Copyright (C) 2003-2015 John Goerzen & contributors
|
2003-01-04 05:57:46 +01:00
|
|
|
#
|
|
|
|
# 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.
|
2003-01-04 05:57:46 +01: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
|
2003-01-04 05:57:46 +01:00
|
|
|
|
2009-01-14 07:05:00 +01:00
|
|
|
from subprocess import Popen, PIPE
|
2011-05-07 17:40:32 +02:00
|
|
|
from threading import Event
|
2003-01-04 05:57:46 +01:00
|
|
|
import os
|
2011-08-11 12:22:35 +02:00
|
|
|
from sys import exc_info
|
2011-01-28 01:46:29 +01:00
|
|
|
import traceback
|
2008-12-02 20:12:36 +01:00
|
|
|
|
2015-01-01 21:41:11 +01:00
|
|
|
from offlineimap import mbnames, CustomConfig, OfflineImapError
|
|
|
|
from offlineimap import globals
|
|
|
|
from offlineimap.repository import Repository
|
|
|
|
from offlineimap.ui import getglobalui
|
|
|
|
from offlineimap.threadutil import InstanceLimitedThread
|
|
|
|
|
2011-07-08 12:23:16 +02:00
|
|
|
try:
|
|
|
|
import fcntl
|
|
|
|
except:
|
|
|
|
pass # ok if this fails, we can do without
|
|
|
|
|
2015-01-01 21:41:11 +01:00
|
|
|
# FIXME: spaghetti code alert!
|
2003-04-18 04:18:34 +02:00
|
|
|
def getaccountlist(customconfig):
|
|
|
|
return customconfig.getsectionlist('Account')
|
|
|
|
|
2015-01-01 21:41:11 +01:00
|
|
|
# FIXME: spaghetti code alert!
|
2003-04-18 04:18:34 +02:00
|
|
|
def AccountListGenerator(customconfig):
|
|
|
|
return [Account(customconfig, accountname)
|
|
|
|
for accountname in getaccountlist(customconfig)]
|
|
|
|
|
2015-01-01 21:41:11 +01:00
|
|
|
# FIXME: spaghetti code alert!
|
2003-04-18 04:18:34 +02:00
|
|
|
def AccountHashGenerator(customconfig):
|
|
|
|
retval = {}
|
|
|
|
for item in AccountListGenerator(customconfig):
|
|
|
|
retval[item.getname()] = item
|
|
|
|
return retval
|
|
|
|
|
2003-01-04 05:57:46 +01:00
|
|
|
|
2003-04-18 04:18:34 +02:00
|
|
|
class Account(CustomConfig.ConfigHelperMixin):
|
2011-05-02 17:11:40 +02:00
|
|
|
"""Represents an account (ie. 2 repositories) to sync
|
|
|
|
|
|
|
|
Most of the time you will actually want to use the derived
|
|
|
|
:class:`accounts.SyncableAccount` which contains all functions used
|
|
|
|
for syncing an account."""
|
2011-05-07 17:40:32 +02:00
|
|
|
#signal gets set when we should stop looping
|
2012-01-04 19:24:19 +01:00
|
|
|
abort_soon_signal = Event()
|
|
|
|
#signal gets set on CTRL-C/SIGTERM
|
|
|
|
abort_NOW_signal = Event()
|
2011-05-02 17:11:40 +02:00
|
|
|
|
2003-01-04 05:57:46 +01:00
|
|
|
def __init__(self, config, name):
|
2011-05-02 17:11:40 +02:00
|
|
|
"""
|
|
|
|
:param config: Representing the offlineimap configuration file.
|
|
|
|
:type config: :class:`offlineimap.CustomConfig.CustomConfigParser`
|
|
|
|
|
|
|
|
:param name: A string denoting the name of the Account
|
|
|
|
as configured"""
|
2003-01-04 05:57:46 +01:00
|
|
|
self.config = config
|
|
|
|
self.name = name
|
|
|
|
self.metadatadir = config.getmetadatadir()
|
|
|
|
self.localeval = config.getlocaleval()
|
2011-09-15 13:56:04 +02:00
|
|
|
# current :mod:`offlineimap.ui`, can be used for logging:
|
2011-01-05 17:00:55 +01:00
|
|
|
self.ui = getglobalui()
|
2003-04-29 04:25:42 +02:00
|
|
|
self.refreshperiod = self.getconffloat('autorefresh', 0.0)
|
2011-09-15 13:56:04 +02:00
|
|
|
# should we run in "dry-run" mode?
|
|
|
|
self.dryrun = self.config.getboolean('general', 'dry-run')
|
Daniel Jacobowitz patches
fixes deb#433732
Date: Sun, 30 Sep 2007 13:54:56 -0400
From: Daniel Jacobowitz <drow@false.org>
To: offlineimap@complete.org
Subject: Assorted patches
Here's the result of a lazy Sunday hacking on offlineimap. Sorry for
not breaking this into multiple patches. They're mostly logically
independent so just ask if that would make a difference.
First, a new -q (quick) option. The quick option means to only update
folders that seem to have had significant changes. For Maildir, any
change to any message UID or flags is significant, because checking
the flags doesn't add a significant cost. For IMAP, only a change to
the total number of messages or a change in the UID of the most recent
message is significant. This should catch everything except for
flags changes.
The difference in bandwidth is astonishing: a quick sync takes 80K
instead of 5.3MB, and 28 seconds instead of 90.
There's a configuration variable that lets you say every tenth sync
should update flags, but let all the intervening ones be lighter.
Second, a fix to the UID validity problems many people have been
reporting with Courier. As discussed in Debian bug #433732, I changed
the UID validity check to use SELECT unless the server complains that
the folder is read-only. This avoids the Courier bug (see the Debian
log for more details). This won't fix existing validity errors, you
need to remove the local status and validity files by hand and resync.
Third, some speedups in Maildir checking. It's still pretty slow
due to a combination of poor performance in os.listdir (never reads
more than 4K of directory entries at a time) and some semaphore that
leads to lots of futex wake operations, but at least this saves
20% or so of the CPU time running offlineimap on a single folder:
Time with quick refresh and md5 in loop: 4.75s user 0.46s system 12%
cpu 41.751 total
Time with quick refresh and md5 out of loop: 4.38s user 0.50s system
14% cpu 34.799 total
Time using string compare to check folder: 4.11s user 0.47s system 13%
cpu 34.788 total
And fourth, some display fixes for Curses.Blinkenlights. I made
warnings more visible, made the new quick sync message cyan, and
made all not explicitly colored messages grey. That last one was
really bugging me. Any time OfflineIMAP printed a warning in
this UI, it had even odds of coming out black on black!
Anyway, I hope these are useful. I'm happy to revise them if you see
a problem.
--
Daniel Jacobowitz
CodeSourcery
2007-10-01 23:20:37 +02:00
|
|
|
self.quicknum = 0
|
2003-04-29 04:25:42 +02:00
|
|
|
if self.refreshperiod == 0.0:
|
2003-01-04 05:57:46 +01:00
|
|
|
self.refreshperiod = None
|
|
|
|
|
2003-04-18 04:18:34 +02:00
|
|
|
def getlocaleval(self):
|
|
|
|
return self.localeval
|
|
|
|
|
2014-10-05 09:49:08 +02:00
|
|
|
# Interface from CustomConfig.ConfigHelperMixin
|
2003-04-18 04:18:34 +02:00
|
|
|
def getconfig(self):
|
|
|
|
return self.config
|
|
|
|
|
|
|
|
def getname(self):
|
|
|
|
return self.name
|
|
|
|
|
2011-04-27 12:15:50 +02:00
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
2011-06-30 15:18:03 +02:00
|
|
|
def getaccountmeta(self):
|
|
|
|
return os.path.join(self.metadatadir, 'Account-' + self.name)
|
|
|
|
|
2014-10-05 09:49:08 +02:00
|
|
|
# Interface from CustomConfig.ConfigHelperMixin
|
2003-04-18 04:18:34 +02:00
|
|
|
def getsection(self):
|
|
|
|
return 'Account ' + self.getname()
|
2003-01-04 05:57:46 +01:00
|
|
|
|
2011-05-07 17:40:32 +02:00
|
|
|
@classmethod
|
|
|
|
def set_abort_event(cls, config, signum):
|
|
|
|
"""Set skip sleep/abort event for all accounts
|
2003-01-04 05:57:46 +01:00
|
|
|
|
2011-05-07 17:40:32 +02:00
|
|
|
If we want to skip a current (or the next) sleep, or if we want
|
|
|
|
to abort an autorefresh loop, the main thread can use
|
|
|
|
set_abort_event() to send the corresponding signal. Signum = 1
|
|
|
|
implies that we want all accounts to abort or skip the current
|
|
|
|
or next sleep phase. Signum = 2 will end the autorefresh loop,
|
2012-01-04 19:24:19 +01:00
|
|
|
ie all accounts will return after they finished a sync. signum=3
|
|
|
|
means, abort NOW, e.g. on SIGINT or SIGTERM.
|
2011-05-07 17:40:32 +02:00
|
|
|
|
|
|
|
This is a class method, it will send the signal to all accounts.
|
|
|
|
"""
|
|
|
|
if signum == 1:
|
|
|
|
# resync signal, set config option for all accounts
|
|
|
|
for acctsection in getaccountlist(config):
|
|
|
|
config.set('Account ' + acctsection, "skipsleep", '1')
|
|
|
|
elif signum == 2:
|
|
|
|
# don't autorefresh anymore
|
2012-01-04 19:24:19 +01:00
|
|
|
cls.abort_soon_signal.set()
|
|
|
|
elif signum == 3:
|
|
|
|
# abort ASAP
|
|
|
|
cls.abort_NOW_signal.set()
|
2011-05-07 17:40:32 +02:00
|
|
|
|
|
|
|
def get_abort_event(self):
|
|
|
|
"""Checks if an abort signal had been sent
|
|
|
|
|
|
|
|
If the 'skipsleep' config option for this account had been set,
|
|
|
|
with `set_abort_event(config, 1)` it will get cleared in this
|
|
|
|
function. Ie, we will only skip one sleep and not all.
|
|
|
|
|
|
|
|
:returns: True, if the main thread had called
|
|
|
|
:meth:`set_abort_event` earlier, otherwise 'False'.
|
|
|
|
"""
|
|
|
|
skipsleep = self.getconfboolean("skipsleep", 0)
|
|
|
|
if skipsleep:
|
|
|
|
self.config.set(self.getsection(), "skipsleep", '0')
|
2012-01-04 19:24:19 +01:00
|
|
|
return skipsleep or Account.abort_soon_signal.is_set() or \
|
|
|
|
Account.abort_NOW_signal.is_set()
|
2011-05-07 17:40:32 +02:00
|
|
|
|
2014-03-16 13:27:35 +01:00
|
|
|
def _sleeper(self):
|
2011-05-07 17:40:32 +02:00
|
|
|
"""Sleep if the account is set to autorefresh
|
|
|
|
|
|
|
|
:returns: 0:timeout expired, 1: canceled the timer,
|
|
|
|
2:request to abort the program,
|
|
|
|
100: if configured to not sleep at all.
|
|
|
|
"""
|
2003-01-04 05:57:46 +01:00
|
|
|
if not self.refreshperiod:
|
|
|
|
return 100
|
2003-04-18 04:18:34 +02:00
|
|
|
|
|
|
|
kaobjs = []
|
|
|
|
|
|
|
|
if hasattr(self, 'localrepos'):
|
|
|
|
kaobjs.append(self.localrepos)
|
|
|
|
if hasattr(self, 'remoterepos'):
|
|
|
|
kaobjs.append(self.remoterepos)
|
|
|
|
|
|
|
|
for item in kaobjs:
|
|
|
|
item.startkeepalive()
|
2011-10-26 16:47:21 +02:00
|
|
|
|
2009-07-17 07:03:29 +02:00
|
|
|
refreshperiod = int(self.refreshperiod * 60)
|
2011-05-07 17:40:32 +02:00
|
|
|
sleepresult = self.ui.sleep(refreshperiod, self)
|
Patch for signal handling to start a sync by Jim Pryor
Here's the way I'd like to use offlineimap on my laptop:
1. Have a regular cron job running infrequently. The cron job
checks to see
if I'm online, plugged in, and that no other copy of offlineimap is
running. If
all of these conditions are satisfied, it runs offlineimap just once:
"offlineimap -o -u Noninteractive.Quiet"
2. When I start up mutt, I do it by calling a wrapper script that
delays
until cron-started copies of offlineimap have finished, then starts
offlineimap
on its regular, stay-alive and keep checking schedule. When I quit
mutt, the
wrapper script tells offlineimap to stop.
This way I get frequent regular checks while I have mutt running, but
I don't
waste my battery/cpu checking frequently for mail when I'm not
interested in
it.
To make this work, though, it'd be nicer if it were easier to tell
offlineimap,
from the outside, things like "terminate cleanly now" and "when you've
finished
synching, then terminate instead of sleeping and synching again."
OK, to put my money where my mouth is, I attach two patches against
offlineimap
6.0.3.
The first, "cleanup.patch", cleans up a few spots that tend to throw
exceptions
for me as offlineimap is exiting from a KeyboardInterrupt.
The second adds signaling capabilities to offlineimap.
* sending a SIGTERM tells offlineimap to terminate immediately but
cleanly,
just as if "q" had been pressed in the GUI interface
* sending a SIGUSR1 tells every account to do a full sync asap: if
it's
sleeping, then wake up and do the sync now. If it's mid-sync, then
re-synch
any folders whose syncing has already been started or completed, and
continue
to synch the other, queued but not-yet-synched folders.
* sending a SIGHUP tells every account to die as soon as it can (but
not
immediately: only after finishing any synch it's now engaged in)
* sending a SIGUSR2 tells every account to do a full sync asap (as
with
SIGUSR1), then die
It's tricky to mix signals with threads, but I think I've done this
correctly.
I've been using it now for a few weeks without any obvious
problems. But I'm passing it
on so that others can review the code and test it out on their
systems. I developed the
patch when I was running Python 2.5.2, but to my knowledge I don't use
any Python 2.5-specific
code. Now I'm using the patch with Python 2.6.
Although I said "without any obvious problems," let me confess that
I'm
seeing offlineimap regularly choke when I do things like this: start
up
my offlineimap-wrapped copy of mutt, wait a while, put the machine to
sleep (not sure if offlineimap is active in the background or idling),
move to a different spot, wake the machine up again and it acquires a
new network, sometimes a wired network instead of wifi. Offlineimap
doesn't like that so much. I don't yet have any reason to think the
problems here come from my patches. But I'm just acknowledging them,
so
that if others are able to use offlineimap without any difficulty in
situations like I described, then maybe the fault is with my patches.
2008-12-01 23:13:16 +01:00
|
|
|
|
2008-08-03 00:04:32 +02:00
|
|
|
# Cancel keepalive
|
|
|
|
for item in kaobjs:
|
|
|
|
item.stopkeepalive()
|
2011-05-07 17:40:32 +02:00
|
|
|
|
|
|
|
if sleepresult:
|
2012-01-04 19:24:19 +01:00
|
|
|
if Account.abort_soon_signal.is_set() or \
|
|
|
|
Account.abort_NOW_signal.is_set():
|
2011-05-07 17:40:32 +02:00
|
|
|
return 2
|
|
|
|
self.quicknum = 0
|
|
|
|
return 1
|
|
|
|
return 0
|
2011-06-30 15:18:03 +02:00
|
|
|
|
|
|
|
def serverdiagnostics(self):
|
|
|
|
"""Output diagnostics for all involved repositories"""
|
|
|
|
remote_repo = Repository(self, 'remote')
|
|
|
|
local_repo = Repository(self, 'local')
|
|
|
|
#status_repo = Repository(self, 'status')
|
|
|
|
self.ui.serverdiagnostics(remote_repo, 'Remote')
|
|
|
|
self.ui.serverdiagnostics(local_repo, 'Local')
|
|
|
|
#self.ui.serverdiagnostics(statusrepos, 'Status')
|
2011-10-26 16:47:21 +02:00
|
|
|
|
|
|
|
|
2011-01-31 15:53:35 +01:00
|
|
|
class SyncableAccount(Account):
|
2011-05-02 17:11:40 +02:00
|
|
|
"""A syncable email account connecting 2 repositories
|
2011-01-31 15:53:35 +01:00
|
|
|
|
2011-05-02 17:11:40 +02:00
|
|
|
Derives from :class:`accounts.Account` but contains the additional
|
|
|
|
functions :meth:`syncrunner`, :meth:`sync`, :meth:`syncfolders`,
|
|
|
|
used for syncing."""
|
2011-01-31 15:53:35 +01:00
|
|
|
|
2011-07-08 12:23:16 +02:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
Account.__init__(self, *args, **kwargs)
|
|
|
|
self._lockfd = None
|
|
|
|
self._lockfilepath = os.path.join(self.config.getmetadatadir(),
|
|
|
|
"%s.lock" % self)
|
|
|
|
|
2014-03-16 13:27:35 +01:00
|
|
|
def __lock(self):
|
2011-07-08 12:23:16 +02:00
|
|
|
"""Lock the account, throwing an exception if it is locked already"""
|
|
|
|
self._lockfd = open(self._lockfilepath, 'w')
|
|
|
|
try:
|
|
|
|
fcntl.lockf(self._lockfd, fcntl.LOCK_EX|fcntl.LOCK_NB)
|
|
|
|
except NameError:
|
|
|
|
#fcntl not available (Windows), disable file locking... :(
|
|
|
|
pass
|
|
|
|
except IOError:
|
|
|
|
self._lockfd.close()
|
2012-02-05 11:49:28 +01:00
|
|
|
raise OfflineImapError("Could not lock account %s. Is another "
|
|
|
|
"instance using this account?" % self,
|
2015-01-11 21:44:24 +01:00
|
|
|
OfflineImapError.ERROR.REPO), \
|
|
|
|
None, exc_info()[2]
|
2011-07-08 12:23:16 +02:00
|
|
|
|
2014-03-16 13:27:35 +01:00
|
|
|
def _unlock(self):
|
2011-07-08 12:23:16 +02:00
|
|
|
"""Unlock the account, deleting the lock file"""
|
|
|
|
#If we own the lock file, delete it
|
|
|
|
if self._lockfd and not self._lockfd.closed:
|
|
|
|
self._lockfd.close()
|
|
|
|
try:
|
|
|
|
os.unlink(self._lockfilepath)
|
|
|
|
except OSError:
|
|
|
|
pass #Failed to delete for some reason.
|
|
|
|
|
2011-05-07 17:40:32 +02:00
|
|
|
def syncrunner(self):
|
2011-11-03 13:45:44 +01:00
|
|
|
self.ui.registerthread(self)
|
2012-08-31 20:34:54 +02:00
|
|
|
try:
|
|
|
|
accountmetadata = self.getaccountmeta()
|
|
|
|
if not os.path.exists(accountmetadata):
|
|
|
|
os.mkdir(accountmetadata, 0o700)
|
|
|
|
|
|
|
|
self.remoterepos = Repository(self, 'remote')
|
|
|
|
self.localrepos = Repository(self, 'local')
|
|
|
|
self.statusrepos = Repository(self, 'status')
|
|
|
|
except OfflineImapError as e:
|
|
|
|
self.ui.error(e, exc_info()[2])
|
|
|
|
if e.severity >= OfflineImapError.ERROR.CRITICAL:
|
|
|
|
raise
|
|
|
|
return
|
2009-08-16 14:42:39 +02:00
|
|
|
|
2011-05-04 16:45:28 +02:00
|
|
|
# Loop account sync if needed (bail out after 3 failures)
|
|
|
|
looping = 3
|
2003-01-04 05:57:46 +01:00
|
|
|
while looping:
|
2011-09-29 17:22:02 +02:00
|
|
|
self.ui.acct(self)
|
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:
|
2014-03-16 13:27:35 +01:00
|
|
|
self.__lock()
|
|
|
|
self.__sync()
|
2011-09-29 17:22:02 +02:00
|
|
|
except (KeyboardInterrupt, SystemExit):
|
|
|
|
raise
|
2012-02-05 10:14:23 +01:00
|
|
|
except OfflineImapError as e:
|
2011-09-29 17:22:02 +02:00
|
|
|
# Stop looping and bubble up Exception if needed.
|
|
|
|
if e.severity >= OfflineImapError.ERROR.REPO:
|
|
|
|
if looping:
|
|
|
|
looping -= 1
|
|
|
|
if e.severity >= OfflineImapError.ERROR.CRITICAL:
|
|
|
|
raise
|
|
|
|
self.ui.error(e, exc_info()[2])
|
2012-02-05 10:14:23 +01:00
|
|
|
except Exception as e:
|
2011-09-29 17:22:02 +02:00
|
|
|
self.ui.error(e, exc_info()[2], msg = "While attempting to sync"
|
|
|
|
" account '%s'" % self)
|
|
|
|
else:
|
|
|
|
# after success sync, reset the looping counter to 3
|
|
|
|
if self.refreshperiod:
|
|
|
|
looping = 3
|
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
|
|
|
finally:
|
2011-09-29 17:22:02 +02:00
|
|
|
self.ui.acctdone(self)
|
2014-03-16 13:27:35 +01:00
|
|
|
self._unlock()
|
|
|
|
if looping and self._sleeper() >= 2:
|
2011-10-26 16:47:21 +02:00
|
|
|
looping = 0
|
2009-08-16 14:42:39 +02:00
|
|
|
|
2012-09-01 02:16:06 +02:00
|
|
|
def get_local_folder(self, remotefolder):
|
|
|
|
"""Return the corresponding local folder for a given remotefolder"""
|
|
|
|
return self.localrepos.getfolder(
|
|
|
|
remotefolder.getvisiblename().
|
|
|
|
replace(self.remoterepos.getsep(), self.localrepos.getsep()))
|
|
|
|
|
2014-03-16 13:27:35 +01:00
|
|
|
def __sync(self):
|
2011-05-07 17:40:32 +02:00
|
|
|
"""Synchronize the account once, then return
|
|
|
|
|
|
|
|
Assumes that `self.remoterepos`, `self.localrepos`, and
|
|
|
|
`self.statusrepos` has already been populated, so it should only
|
|
|
|
be called from the :meth:`syncrunner` function.
|
|
|
|
"""
|
|
|
|
folderthreads = []
|
Daniel Jacobowitz patches
fixes deb#433732
Date: Sun, 30 Sep 2007 13:54:56 -0400
From: Daniel Jacobowitz <drow@false.org>
To: offlineimap@complete.org
Subject: Assorted patches
Here's the result of a lazy Sunday hacking on offlineimap. Sorry for
not breaking this into multiple patches. They're mostly logically
independent so just ask if that would make a difference.
First, a new -q (quick) option. The quick option means to only update
folders that seem to have had significant changes. For Maildir, any
change to any message UID or flags is significant, because checking
the flags doesn't add a significant cost. For IMAP, only a change to
the total number of messages or a change in the UID of the most recent
message is significant. This should catch everything except for
flags changes.
The difference in bandwidth is astonishing: a quick sync takes 80K
instead of 5.3MB, and 28 seconds instead of 90.
There's a configuration variable that lets you say every tenth sync
should update flags, but let all the intervening ones be lighter.
Second, a fix to the UID validity problems many people have been
reporting with Courier. As discussed in Debian bug #433732, I changed
the UID validity check to use SELECT unless the server complains that
the folder is read-only. This avoids the Courier bug (see the Debian
log for more details). This won't fix existing validity errors, you
need to remove the local status and validity files by hand and resync.
Third, some speedups in Maildir checking. It's still pretty slow
due to a combination of poor performance in os.listdir (never reads
more than 4K of directory entries at a time) and some semaphore that
leads to lots of futex wake operations, but at least this saves
20% or so of the CPU time running offlineimap on a single folder:
Time with quick refresh and md5 in loop: 4.75s user 0.46s system 12%
cpu 41.751 total
Time with quick refresh and md5 out of loop: 4.38s user 0.50s system
14% cpu 34.799 total
Time using string compare to check folder: 4.11s user 0.47s system 13%
cpu 34.788 total
And fourth, some display fixes for Curses.Blinkenlights. I made
warnings more visible, made the new quick sync message cyan, and
made all not explicitly colored messages grey. That last one was
really bugging me. Any time OfflineIMAP printed a warning in
this UI, it had even odds of coming out black on black!
Anyway, I hope these are useful. I'm happy to revise them if you see
a problem.
--
Daniel Jacobowitz
CodeSourcery
2007-10-01 23:20:37 +02:00
|
|
|
|
2008-10-01 07:03:04 +02:00
|
|
|
hook = self.getconf('presynchook', '')
|
|
|
|
self.callhook(hook)
|
|
|
|
|
Daniel Jacobowitz patches
fixes deb#433732
Date: Sun, 30 Sep 2007 13:54:56 -0400
From: Daniel Jacobowitz <drow@false.org>
To: offlineimap@complete.org
Subject: Assorted patches
Here's the result of a lazy Sunday hacking on offlineimap. Sorry for
not breaking this into multiple patches. They're mostly logically
independent so just ask if that would make a difference.
First, a new -q (quick) option. The quick option means to only update
folders that seem to have had significant changes. For Maildir, any
change to any message UID or flags is significant, because checking
the flags doesn't add a significant cost. For IMAP, only a change to
the total number of messages or a change in the UID of the most recent
message is significant. This should catch everything except for
flags changes.
The difference in bandwidth is astonishing: a quick sync takes 80K
instead of 5.3MB, and 28 seconds instead of 90.
There's a configuration variable that lets you say every tenth sync
should update flags, but let all the intervening ones be lighter.
Second, a fix to the UID validity problems many people have been
reporting with Courier. As discussed in Debian bug #433732, I changed
the UID validity check to use SELECT unless the server complains that
the folder is read-only. This avoids the Courier bug (see the Debian
log for more details). This won't fix existing validity errors, you
need to remove the local status and validity files by hand and resync.
Third, some speedups in Maildir checking. It's still pretty slow
due to a combination of poor performance in os.listdir (never reads
more than 4K of directory entries at a time) and some semaphore that
leads to lots of futex wake operations, but at least this saves
20% or so of the CPU time running offlineimap on a single folder:
Time with quick refresh and md5 in loop: 4.75s user 0.46s system 12%
cpu 41.751 total
Time with quick refresh and md5 out of loop: 4.38s user 0.50s system
14% cpu 34.799 total
Time using string compare to check folder: 4.11s user 0.47s system 13%
cpu 34.788 total
And fourth, some display fixes for Curses.Blinkenlights. I made
warnings more visible, made the new quick sync message cyan, and
made all not explicitly colored messages grey. That last one was
really bugging me. Any time OfflineIMAP printed a warning in
this UI, it had even odds of coming out black on black!
Anyway, I hope these are useful. I'm happy to revise them if you see
a problem.
--
Daniel Jacobowitz
CodeSourcery
2007-10-01 23:20:37 +02:00
|
|
|
quickconfig = self.getconfint('quick', 0)
|
|
|
|
if quickconfig < 0:
|
|
|
|
quick = True
|
|
|
|
elif quickconfig > 0:
|
|
|
|
if self.quicknum == 0 or self.quicknum > quickconfig:
|
|
|
|
self.quicknum = 1
|
|
|
|
quick = False
|
|
|
|
else:
|
|
|
|
self.quicknum = self.quicknum + 1
|
|
|
|
quick = True
|
|
|
|
else:
|
|
|
|
quick = False
|
|
|
|
|
2003-01-04 05:57:46 +01:00
|
|
|
try:
|
2003-04-18 04:18:34 +02:00
|
|
|
remoterepos = self.remoterepos
|
|
|
|
localrepos = self.localrepos
|
|
|
|
statusrepos = self.statusrepos
|
2011-12-01 10:27:12 +01:00
|
|
|
|
|
|
|
# init repos with list of folders, so we have them (and the
|
|
|
|
# folder delimiter etc)
|
|
|
|
remoterepos.getfolders()
|
|
|
|
localrepos.getfolders()
|
|
|
|
|
2012-01-05 14:05:51 +01:00
|
|
|
remoterepos.sync_folder_structure(localrepos, statusrepos)
|
2011-09-30 08:58:08 +02:00
|
|
|
# replicate the folderstructure between REMOTE to LOCAL
|
2011-09-15 12:06:06 +02:00
|
|
|
if not localrepos.getconfboolean('readonly', False):
|
2011-05-01 20:18:29 +02:00
|
|
|
self.ui.syncfolders(remoterepos, localrepos)
|
2003-01-04 05:57:46 +01:00
|
|
|
|
2011-05-07 17:40:32 +02:00
|
|
|
# iterate through all folders on the remote repo and sync
|
|
|
|
for remotefolder in remoterepos.getfolders():
|
2012-01-04 19:24:19 +01:00
|
|
|
# check for CTRL-C or SIGTERM
|
|
|
|
if Account.abort_NOW_signal.is_set(): break
|
2012-09-01 02:16:06 +02:00
|
|
|
|
2012-09-01 03:12:16 +02:00
|
|
|
if not remotefolder.sync_this:
|
2012-09-01 02:16:06 +02:00
|
|
|
self.ui.debug('', "Not syncing filtered folder '%s'"
|
2015-01-08 17:13:33 +01:00
|
|
|
"[%s]"% (remotefolder, remoterepos))
|
2012-09-01 02:16:06 +02:00
|
|
|
continue # Ignore filtered folder
|
2012-09-01 03:12:16 +02:00
|
|
|
localfolder = self.get_local_folder(remotefolder)
|
|
|
|
if not localfolder.sync_this:
|
|
|
|
self.ui.debug('', "Not syncing filtered folder '%s'"
|
2015-01-08 17:13:33 +01:00
|
|
|
"[%s]"% (localfolder, localfolder.repository))
|
2012-09-01 03:12:16 +02:00
|
|
|
continue # Ignore filtered folder
|
2013-02-05 04:49:56 +01:00
|
|
|
if not globals.options.singlethreading:
|
2013-01-17 12:02:41 +01:00
|
|
|
thread = InstanceLimitedThread(\
|
|
|
|
instancename = 'FOLDER_' + self.remoterepos.getname(),
|
|
|
|
target = syncfolder,
|
2015-01-08 17:13:33 +01:00
|
|
|
name = "Folder %s [acc: %s]"% (remotefolder.getexplainedname(), self),
|
2013-01-17 12:02:41 +01:00
|
|
|
args = (self, remotefolder, quick))
|
|
|
|
thread.start()
|
|
|
|
folderthreads.append(thread)
|
|
|
|
else:
|
|
|
|
syncfolder(self, remotefolder, quick)
|
2011-05-07 17:40:32 +02:00
|
|
|
# wait for all threads to finish
|
|
|
|
for thr in folderthreads:
|
|
|
|
thr.join()
|
2011-09-15 13:56:04 +02:00
|
|
|
# Write out mailbox names if required and not in dry-run mode
|
|
|
|
if not self.dryrun:
|
|
|
|
mbnames.write()
|
2007-07-06 18:46:29 +02:00
|
|
|
localrepos.forgetfolders()
|
|
|
|
remoterepos.forgetfolders()
|
2011-04-27 11:44:24 +02:00
|
|
|
except:
|
|
|
|
#error while syncing. Drop all connections that we have, they
|
|
|
|
#might be bogus by now (e.g. after suspend)
|
|
|
|
localrepos.dropconnections()
|
|
|
|
remoterepos.dropconnections()
|
|
|
|
raise
|
|
|
|
else:
|
|
|
|
# sync went fine. Hold or drop depending on config
|
2003-04-18 04:18:34 +02:00
|
|
|
localrepos.holdordropconnections()
|
|
|
|
remoterepos.holdordropconnections()
|
2008-10-01 07:03:04 +02:00
|
|
|
|
|
|
|
hook = self.getconf('postsynchook', '')
|
|
|
|
self.callhook(hook)
|
|
|
|
|
|
|
|
def callhook(self, cmd):
|
2012-01-04 19:24:19 +01:00
|
|
|
# check for CTRL-C or SIGTERM and run postsynchook
|
|
|
|
if Account.abort_NOW_signal.is_set():
|
|
|
|
return
|
2008-10-01 07:03:04 +02:00
|
|
|
if not cmd:
|
|
|
|
return
|
|
|
|
try:
|
|
|
|
self.ui.callhook("Calling hook: " + cmd)
|
2011-09-15 13:56:04 +02:00
|
|
|
if self.dryrun: # don't if we are in dry-run mode
|
|
|
|
return
|
2008-10-01 07:03:04 +02:00
|
|
|
p = Popen(cmd, shell=True,
|
|
|
|
stdin=PIPE, stdout=PIPE, stderr=PIPE,
|
|
|
|
close_fds=True)
|
|
|
|
r = p.communicate()
|
|
|
|
self.ui.callhook("Hook stdout: %s\nHook stderr:%s\n" % r)
|
|
|
|
self.ui.callhook("Hook return code: %d" % p.returncode)
|
2011-08-11 12:22:35 +02:00
|
|
|
except (KeyboardInterrupt, SystemExit):
|
|
|
|
raise
|
2012-02-05 10:14:23 +01:00
|
|
|
except Exception as e:
|
2011-08-11 12:22:35 +02:00
|
|
|
self.ui.error(e, exc_info()[2], msg = "Calling hook")
|
2011-01-31 15:53:35 +01:00
|
|
|
|
2011-11-03 13:27:35 +01:00
|
|
|
def syncfolder(account, remotefolder, quick):
|
2013-01-17 12:02:41 +01:00
|
|
|
"""Synchronizes given remote folder for the specified account.
|
2011-08-14 13:38:13 +02:00
|
|
|
|
|
|
|
Filtered folders on the remote side will not invoke this function."""
|
2015-01-08 17:13:33 +01:00
|
|
|
|
2011-11-03 13:27:35 +01:00
|
|
|
remoterepos = account.remoterepos
|
|
|
|
localrepos = account.localrepos
|
|
|
|
statusrepos = account.statusrepos
|
|
|
|
|
2011-01-05 17:00:55 +01:00
|
|
|
ui = getglobalui()
|
2011-11-03 13:45:44 +01:00
|
|
|
ui.registerthread(account)
|
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:
|
|
|
|
# Load local folder.
|
2012-09-01 02:16:06 +02:00
|
|
|
localfolder = account.get_local_folder(remotefolder)
|
|
|
|
|
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
|
|
|
# Write the mailboxes
|
2013-08-27 16:11:57 +02:00
|
|
|
mbnames.add(account.name, localfolder.getname(),
|
|
|
|
localrepos.getlocalroot())
|
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
|
|
|
|
|
|
|
# Load status folder.
|
|
|
|
statusfolder = statusrepos.getfolder(remotefolder.getvisiblename().\
|
|
|
|
replace(remoterepos.getsep(),
|
|
|
|
statusrepos.getsep()))
|
2012-01-19 11:24:16 +01:00
|
|
|
if localfolder.get_uidvalidity() == None:
|
2012-01-19 11:54:16 +01:00
|
|
|
# This is a new folder, so delete the status cache to be
|
|
|
|
# sure we don't have a conflict.
|
|
|
|
# TODO: This does not work. We always return a value, need
|
|
|
|
# to rework this...
|
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
|
|
|
statusfolder.deletemessagelist()
|
|
|
|
|
|
|
|
statusfolder.cachemessagelist()
|
|
|
|
|
|
|
|
if quick:
|
|
|
|
if not localfolder.quickchanged(statusfolder) \
|
|
|
|
and not remotefolder.quickchanged(statusfolder):
|
|
|
|
ui.skippingfolder(remotefolder)
|
|
|
|
localrepos.restore_atime()
|
|
|
|
return
|
|
|
|
|
|
|
|
# Load local folder
|
|
|
|
ui.syncingfolder(remoterepos, remotefolder, localrepos, localfolder)
|
|
|
|
ui.loadmessagelist(localrepos, localfolder)
|
|
|
|
localfolder.cachemessagelist()
|
2011-03-09 08:53:20 +01:00
|
|
|
ui.messagelistloaded(localrepos, localfolder, localfolder.getmessagecount())
|
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
|
|
|
|
2012-01-19 11:51:53 +01:00
|
|
|
# If either the local or the status folder has messages and
|
|
|
|
# there is a UID validity problem, warn and abort. If there are
|
|
|
|
# no messages, UW IMAPd loses UIDVALIDITY. But we don't really
|
|
|
|
# need it if both local folders are empty. So, in that case,
|
|
|
|
# just save it off.
|
2011-03-09 08:53:20 +01:00
|
|
|
if localfolder.getmessagecount() or statusfolder.getmessagecount():
|
2012-01-19 11:51:53 +01:00
|
|
|
if not localfolder.check_uidvalidity():
|
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
|
|
|
ui.validityproblem(localfolder)
|
|
|
|
localrepos.restore_atime()
|
|
|
|
return
|
2012-01-19 11:51:53 +01:00
|
|
|
if not remotefolder.check_uidvalidity():
|
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
|
|
|
ui.validityproblem(remotefolder)
|
|
|
|
localrepos.restore_atime()
|
|
|
|
return
|
|
|
|
else:
|
2012-01-19 11:53:48 +01:00
|
|
|
# Both folders empty, just save new UIDVALIDITY
|
|
|
|
localfolder.save_uidvalidity()
|
|
|
|
remotefolder.save_uidvalidity()
|
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
|
|
|
|
|
|
|
# Load remote folder.
|
|
|
|
ui.loadmessagelist(remoterepos, remotefolder)
|
|
|
|
remotefolder.cachemessagelist()
|
|
|
|
ui.messagelistloaded(remoterepos, remotefolder,
|
2011-03-09 08:53:20 +01:00
|
|
|
remotefolder.getmessagecount())
|
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
|
|
|
|
|
|
|
# Synchronize remote changes.
|
2011-09-15 12:06:06 +02:00
|
|
|
if not localrepos.getconfboolean('readonly', False):
|
2011-05-01 20:18:29 +02:00
|
|
|
ui.syncingmessages(remoterepos, remotefolder, localrepos, localfolder)
|
|
|
|
remotefolder.syncmessagesto(localfolder, statusfolder)
|
|
|
|
else:
|
|
|
|
ui.debug('imap', "Not syncing to read-only repository '%s'" \
|
|
|
|
% localrepos.getname())
|
2011-10-26 16:47:21 +02:00
|
|
|
|
2011-03-06 20:03:04 +01:00
|
|
|
# Synchronize local changes
|
2011-09-15 12:06:06 +02:00
|
|
|
if not remoterepos.getconfboolean('readonly', False):
|
2011-05-01 20:18:29 +02:00
|
|
|
ui.syncingmessages(localrepos, localfolder, remoterepos, remotefolder)
|
|
|
|
localfolder.syncmessagesto(remotefolder, statusfolder)
|
|
|
|
else:
|
|
|
|
ui.debug('', "Not syncing to read-only repository '%s'" \
|
|
|
|
% remoterepos.getname())
|
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
|
|
|
|
|
|
|
statusfolder.save()
|
|
|
|
localrepos.restore_atime()
|
2011-01-12 11:15:08 +01:00
|
|
|
except (KeyboardInterrupt, SystemExit):
|
|
|
|
raise
|
2012-02-05 10:14:23 +01:00
|
|
|
except OfflineImapError as e:
|
2011-05-07 18:39:13 +02:00
|
|
|
# bubble up severe Errors, skip folder otherwise
|
|
|
|
if e.severity > OfflineImapError.ERROR.FOLDER:
|
|
|
|
raise
|
|
|
|
else:
|
2011-09-26 15:27:04 +02:00
|
|
|
ui.error(e, exc_info()[2], msg = "Aborting sync, folder '%s' "
|
2012-09-01 02:16:06 +02:00
|
|
|
"[acc: '%s']" % (localfolder, account))
|
2012-02-05 10:14:23 +01:00
|
|
|
except Exception as e:
|
2011-08-11 12:22:35 +02:00
|
|
|
ui.error(e, msg = "ERROR in syncfolder for %s folder %s: %s" % \
|
2011-11-03 13:27:35 +01:00
|
|
|
(account, remotefolder.getvisiblename(),
|
2011-03-24 10:13:56 +01:00
|
|
|
traceback.format_exc()))
|