2002-06-19 07:22:21 +02:00
|
|
|
# Base folder support
|
2016-06-04 02:23:09 +02:00
|
|
|
# Copyright (C) 2002-2016 John Goerzen & contributors
|
2002-06-19 07:22:21 +02: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.
|
2002-06-19 07:22:21 +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 07:22:21 +02:00
|
|
|
|
2015-01-08 17:13:33 +01:00
|
|
|
import os.path
|
|
|
|
import re
|
maxage: fix timezone issues, remove IMAP-IMAP support, add startdate option
1. When using maxage, local and remote messagelists are supposed to only
contain messages from at most maxage days ago. But local and remote used
different timezones to calculate what "maxage days ago" means, resulting
in removals on one side. Now, we ask the local folder for maxage days'
worth of mail, find the lowest UID, and then ask the remote folder for
all UID's starting with that lowest one.
2. maxage was fundamentally wrong in the IMAP-IMAP case: it assumed that
remote messages have UIDs in the same order as their local counterparts,
which could be false, e.g. when messages are copied in quick succession.
So, remove support for maxage in the IMAP-IMAP case.
3. Add startdate option for IMAP-IMAP syncs: use messages from the given
repository starting at startdate, and all messages from the other
repository. In the first sync, the other repository must be empty.
4. Allow maxage to be specified either as number of days to sync (as
previously) or as a fixed date.
Signed-off-by: Janna Martl <janna.martl109@gmail.com>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2015-04-07 10:14:11 +02:00
|
|
|
import time
|
2015-01-08 17:13:33 +01:00
|
|
|
from sys import exc_info
|
|
|
|
|
2015-04-06 23:48:48 +02:00
|
|
|
from offlineimap import threadutil
|
2011-01-21 16:02:27 +01:00
|
|
|
from offlineimap.ui import getglobalui
|
2011-08-15 11:00:06 +02:00
|
|
|
from offlineimap.error import OfflineImapError
|
2012-01-04 19:24:19 +01:00
|
|
|
import offlineimap.accounts
|
2012-02-05 12:17:02 +01:00
|
|
|
|
2002-06-21 08:51:21 +02:00
|
|
|
|
2020-08-30 12:40:28 +02:00
|
|
|
class BaseFolder:
|
2016-08-05 20:28:53 +02:00
|
|
|
__hash__ = None
|
|
|
|
|
2011-09-16 10:54:22 +02:00
|
|
|
def __init__(self, name, repository):
|
|
|
|
"""
|
2014-10-27 12:34:05 +01:00
|
|
|
:param name: Path & name of folder minus root or reference
|
|
|
|
:param repository: Repository() in which the folder is.
|
2011-09-16 10:54:22 +02:00
|
|
|
"""
|
2015-01-08 17:13:33 +01:00
|
|
|
|
2011-01-05 17:00:57 +01:00
|
|
|
self.ui = getglobalui()
|
2016-04-09 18:12:18 +02:00
|
|
|
self.messagelist = {}
|
2016-06-27 15:03:27 +02:00
|
|
|
# Save original name for folderfilter operations.
|
2014-03-02 13:37:41 +01:00
|
|
|
self.ffilter_name = name
|
2016-06-27 15:03:27 +02:00
|
|
|
# Top level dir name is always ''.
|
2013-07-28 13:58:30 +02:00
|
|
|
self.root = None
|
2011-09-30 17:20:11 +02:00
|
|
|
self.name = name if not name == self.getsep() else ''
|
2015-01-27 18:56:54 +01:00
|
|
|
self.newmail_hook = None
|
2016-06-27 15:03:27 +02:00
|
|
|
# Only set the newmail_hook if the IMAP folder is named 'INBOX'.
|
2015-01-27 18:56:54 +01:00
|
|
|
if self.name == 'INBOX':
|
|
|
|
self.newmail_hook = repository.newmail_hook
|
|
|
|
self.have_newmail = False
|
2020-08-29 19:39:31 +02:00
|
|
|
self.copy_ignoreUIDs = None # List of UIDs to ignore.
|
2011-09-16 10:54:22 +02:00
|
|
|
self.repository = repository
|
2011-09-19 13:41:38 +02:00
|
|
|
self.visiblename = repository.nametrans(name)
|
2011-09-30 17:20:11 +02:00
|
|
|
# In case the visiblename becomes '.' or '/' (top-level) we use
|
|
|
|
# '' as that is the name that e.g. the Maildir scanning will
|
|
|
|
# return for the top-level dir.
|
|
|
|
if self.visiblename == self.getsep():
|
2011-09-23 14:27:25 +02:00
|
|
|
self.visiblename = ''
|
2014-03-02 13:37:41 +01:00
|
|
|
|
2016-05-11 04:10:13 +02:00
|
|
|
self.repoconfname = "Repository " + repository.name
|
2016-04-09 21:58:12 +02:00
|
|
|
|
2011-09-16 10:54:24 +02:00
|
|
|
self.config = repository.getconfig()
|
2011-04-27 12:15:49 +02:00
|
|
|
|
2015-10-28 10:56:16 +01:00
|
|
|
# Do we need to use mail timestamp for filename prefix?
|
|
|
|
filename_use_mail_timestamp_global = self.config.getdefaultboolean(
|
|
|
|
"general", "filename_use_mail_timestamp", False)
|
2016-04-09 21:58:12 +02:00
|
|
|
self._filename_use_mail_timestamp = self.config.getdefaultboolean(
|
2016-05-11 04:10:13 +02:00
|
|
|
self.repoconfname,
|
2016-04-09 21:58:12 +02:00
|
|
|
"filename_use_mail_timestamp",
|
|
|
|
filename_use_mail_timestamp_global)
|
|
|
|
|
|
|
|
self._sync_deletes = self.config.getdefaultboolean(
|
2016-05-11 04:10:13 +02:00
|
|
|
self.repoconfname, "sync_deletes", True)
|
2016-10-25 21:34:38 +02:00
|
|
|
self._dofsync = self.config.getdefaultboolean("general", "fsync", True)
|
2015-10-28 10:56:16 +01:00
|
|
|
|
2014-03-02 13:37:41 +01:00
|
|
|
# Determine if we're running static or dynamic folder filtering
|
2016-06-27 15:03:27 +02:00
|
|
|
# and check filtering status.
|
2015-01-08 17:13:33 +01:00
|
|
|
self._dynamic_folderfilter = self.config.getdefaultboolean(
|
2016-05-11 04:10:13 +02:00
|
|
|
self.repoconfname, "dynamic_folderfilter", False)
|
2014-03-02 13:37:41 +01:00
|
|
|
self._sync_this = repository.should_sync_folder(self.ffilter_name)
|
|
|
|
if self._dynamic_folderfilter:
|
2020-08-29 19:39:31 +02:00
|
|
|
self.ui.debug('', "Running dynamic folder filtering on '%s'[%s]" %
|
|
|
|
(self.ffilter_name, repository))
|
2014-03-02 13:37:41 +01:00
|
|
|
elif not self._sync_this:
|
2020-08-29 19:39:31 +02:00
|
|
|
self.ui.debug('', "Filtering out '%s'[%s] due to folderfilter" %
|
|
|
|
(self.ffilter_name, repository))
|
2014-03-02 13:37:41 +01:00
|
|
|
|
2016-06-27 15:03:27 +02:00
|
|
|
# Passes for syncmessagesto.
|
2016-04-09 21:58:12 +02:00
|
|
|
self.syncmessagesto_passes = [
|
2016-07-18 18:40:17 +02:00
|
|
|
self.__syncmessagesto_copy,
|
|
|
|
self.__syncmessagesto_delete,
|
|
|
|
self.__syncmessagesto_flags,
|
2016-04-09 21:58:12 +02:00
|
|
|
]
|
2014-03-02 13:37:41 +01:00
|
|
|
|
2002-06-19 07:22:21 +02:00
|
|
|
def getname(self):
|
|
|
|
"""Returns name"""
|
|
|
|
return self.name
|
|
|
|
|
2011-03-06 20:03:05 +01:00
|
|
|
def __str__(self):
|
2015-01-14 22:58:25 +01:00
|
|
|
# FIMXE: remove calls of this. We have getname().
|
2011-03-06 20:03:05 +01:00
|
|
|
return self.name
|
|
|
|
|
2016-09-23 15:48:55 +02:00
|
|
|
def __unicode__(self):
|
|
|
|
# NOTE(sheeprine): Implicit call to this by UIBase deletingflags() which
|
|
|
|
# fails if the str is utf-8
|
|
|
|
return self.name.decode('utf-8')
|
|
|
|
|
2016-10-25 21:34:38 +02:00
|
|
|
def __enter__(self):
|
|
|
|
"""Starts a transaction. This will postpone (guaranteed) saving to disk
|
|
|
|
of all messages saved inside this transaction until its committed."""
|
|
|
|
pass
|
|
|
|
|
|
|
|
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
|
|
"""Commits a transaction, all messages saved inside this transaction
|
|
|
|
will only now be persisted to disk."""
|
|
|
|
pass
|
|
|
|
|
2011-09-16 10:54:23 +02:00
|
|
|
@property
|
|
|
|
def accountname(self):
|
|
|
|
"""Account name as string"""
|
2015-01-14 22:58:25 +01:00
|
|
|
|
2011-09-16 10:54:23 +02:00
|
|
|
return self.repository.accountname
|
|
|
|
|
2012-09-01 02:30:46 +02:00
|
|
|
@property
|
|
|
|
def sync_this(self):
|
|
|
|
"""Should this folder be synced or is it e.g. filtered out?"""
|
2015-01-14 22:58:25 +01:00
|
|
|
|
2014-03-02 13:37:41 +01:00
|
|
|
if not self._dynamic_folderfilter:
|
|
|
|
return self._sync_this
|
|
|
|
else:
|
2014-03-05 19:32:36 +01:00
|
|
|
return self.repository.should_sync_folder(self.ffilter_name)
|
2012-09-01 02:30:46 +02:00
|
|
|
|
2016-10-25 21:34:38 +02:00
|
|
|
def dofsync(self):
|
|
|
|
return self._dofsync
|
|
|
|
|
2002-07-04 03:35:05 +02:00
|
|
|
def suggeststhreads(self):
|
2016-05-18 02:48:40 +02:00
|
|
|
"""Returns True if this folder suggests using threads for actions.
|
|
|
|
|
|
|
|
Only IMAP returns True. This method must honor any CLI or configuration
|
|
|
|
option."""
|
|
|
|
|
|
|
|
return False
|
2002-07-04 03:35:05 +02:00
|
|
|
|
2014-03-16 13:27:35 +01:00
|
|
|
def waitforthread(self):
|
|
|
|
"""Implements method that waits for thread to be usable.
|
|
|
|
Should be implemented only for folders that suggest threads."""
|
2014-05-06 23:12:50 +02:00
|
|
|
raise NotImplementedError
|
2014-03-16 13:27:35 +01:00
|
|
|
|
|
|
|
def quickchanged(self, statusfolder):
|
|
|
|
""" Runs quick check for folder changes and returns changed
|
|
|
|
status: True -- changed, False -- not changed.
|
2015-01-01 21:41:11 +01:00
|
|
|
|
2014-03-16 13:27:35 +01:00
|
|
|
:param statusfolder: keeps track of the last known folder state.
|
|
|
|
"""
|
2015-01-08 17:13:33 +01:00
|
|
|
|
2014-03-16 13:27:35 +01:00
|
|
|
return True
|
|
|
|
|
2016-05-18 02:42:09 +02:00
|
|
|
def getinstancelimitnamespace(self):
|
2002-07-04 05:59:19 +02:00
|
|
|
"""For threading folders, returns the instancelimitname for
|
|
|
|
InstanceLimitedThreads."""
|
2015-01-08 17:13:33 +01:00
|
|
|
|
2012-10-18 19:23:34 +02:00
|
|
|
raise NotImplementedError
|
2002-07-04 05:59:19 +02:00
|
|
|
|
2002-07-16 04:26:58 +02:00
|
|
|
def storesmessages(self):
|
|
|
|
"""Should be true for any backend that actually saves message bodies.
|
|
|
|
(Almost all of them). False for the LocalStatus backend. Saves
|
|
|
|
us from having to slurp up messages just for localstatus purposes."""
|
2015-01-08 17:13:33 +01:00
|
|
|
|
2002-07-16 04:26:58 +02:00
|
|
|
return 1
|
|
|
|
|
2002-06-21 08:51:21 +02:00
|
|
|
def getvisiblename(self):
|
2015-01-01 21:41:11 +01:00
|
|
|
"""The nametrans-transposed name of the folder's name."""
|
|
|
|
|
2011-09-19 13:41:38 +02:00
|
|
|
return self.visiblename
|
2002-06-21 08:51:21 +02:00
|
|
|
|
2014-06-24 16:48:58 +02:00
|
|
|
def getexplainedname(self):
|
2015-01-01 21:41:11 +01:00
|
|
|
"""Name that shows both real and nametrans-mangled values."""
|
|
|
|
|
2014-06-24 16:48:58 +02:00
|
|
|
if self.name == self.visiblename:
|
|
|
|
return self.name
|
|
|
|
else:
|
2020-08-29 19:39:31 +02:00
|
|
|
return "%s [remote name %s]" % (self.visiblename, self.name)
|
2014-06-24 16:48:58 +02:00
|
|
|
|
2002-08-20 22:54:02 +02:00
|
|
|
def getrepository(self):
|
|
|
|
"""Returns the repository object that this folder is within."""
|
2015-01-08 17:13:33 +01:00
|
|
|
|
2002-08-20 22:54:02 +02:00
|
|
|
return self.repository
|
|
|
|
|
2002-06-19 07:22:21 +02:00
|
|
|
def getroot(self):
|
|
|
|
"""Returns the root of the folder, in a folder-specific fashion."""
|
2015-01-08 17:13:33 +01:00
|
|
|
|
2002-06-19 07:22:21 +02:00
|
|
|
return self.root
|
|
|
|
|
|
|
|
def getsep(self):
|
|
|
|
"""Returns the separator for this folder type."""
|
2015-01-08 17:13:33 +01:00
|
|
|
|
2002-06-19 07:22:21 +02:00
|
|
|
return self.sep
|
|
|
|
|
|
|
|
def getfullname(self):
|
2002-06-20 08:26:28 +02:00
|
|
|
if self.getroot():
|
|
|
|
return self.getroot() + self.getsep() + self.getname()
|
|
|
|
else:
|
|
|
|
return self.getname()
|
2011-04-27 12:15:49 +02:00
|
|
|
|
2003-04-18 04:18:34 +02:00
|
|
|
def getfolderbasename(self):
|
2015-01-08 17:13:33 +01:00
|
|
|
"""Return base file name of file to store Status/UID info in."""
|
|
|
|
|
2011-08-17 16:11:00 +02:00
|
|
|
if not self.name:
|
|
|
|
basename = '.'
|
2020-08-29 19:39:31 +02:00
|
|
|
else: # Avoid directory hierarchies and file names such as '/'.
|
2011-08-17 16:11:00 +02:00
|
|
|
basename = self.name.replace('/', '.')
|
2015-01-14 22:58:25 +01:00
|
|
|
# Replace with literal 'dot' if final path name is '.' as '.' is
|
2011-08-17 16:11:00 +02:00
|
|
|
# an invalid file name.
|
2016-06-27 15:03:27 +02:00
|
|
|
basename = re.sub('(^|\/)\.$', '\\1dot', basename)
|
2011-08-17 16:11:00 +02:00
|
|
|
return basename
|
2003-04-18 04:18:34 +02:00
|
|
|
|
2012-01-19 11:51:53 +01:00
|
|
|
def check_uidvalidity(self):
|
2012-01-19 11:24:16 +01:00
|
|
|
"""Tests if the cached UIDVALIDITY match the real current one
|
2011-03-06 11:17:12 +01:00
|
|
|
|
2012-01-19 11:24:16 +01:00
|
|
|
If required it saves the UIDVALIDITY value. In this case the
|
|
|
|
function is not threadsafe. So don't attempt to call it from
|
2012-01-19 11:51:53 +01:00
|
|
|
concurrent threads.
|
|
|
|
|
|
|
|
:returns: Boolean indicating the match. Returns True in case it
|
2012-02-24 11:20:22 +01:00
|
|
|
implicitely saved the UIDVALIDITY."""
|
2011-03-06 11:17:12 +01:00
|
|
|
|
2020-08-30 11:15:00 +02:00
|
|
|
if self.get_saveduidvalidity() is not None:
|
2012-01-19 11:50:19 +01:00
|
|
|
return self.get_saveduidvalidity() == self.get_uidvalidity()
|
2003-04-18 04:18:34 +02:00
|
|
|
else:
|
2012-01-19 11:53:48 +01:00
|
|
|
self.save_uidvalidity()
|
2012-01-19 11:51:53 +01:00
|
|
|
return True
|
2003-04-18 04:18:34 +02:00
|
|
|
|
|
|
|
def _getuidfilename(self):
|
2015-02-13 17:06:27 +01:00
|
|
|
"""provides UIDVALIDITY cache filename for class internal purposes."""
|
2015-01-08 17:13:33 +01:00
|
|
|
|
2003-04-18 04:18:34 +02:00
|
|
|
return os.path.join(self.repository.getuiddir(),
|
|
|
|
self.getfolderbasename())
|
2011-04-27 12:15:49 +02:00
|
|
|
|
2012-01-19 11:50:19 +01:00
|
|
|
def get_saveduidvalidity(self):
|
|
|
|
"""Return the previously cached UIDVALIDITY value
|
|
|
|
|
|
|
|
:returns: UIDVALIDITY as (long) number or None, if None had been
|
|
|
|
saved yet."""
|
2015-01-08 17:13:33 +01:00
|
|
|
|
2003-04-18 04:18:34 +02:00
|
|
|
if hasattr(self, '_base_saved_uidvalidity'):
|
|
|
|
return self._base_saved_uidvalidity
|
|
|
|
uidfilename = self._getuidfilename()
|
|
|
|
if not os.path.exists(uidfilename):
|
|
|
|
self._base_saved_uidvalidity = None
|
|
|
|
else:
|
|
|
|
file = open(uidfilename, "rt")
|
2016-05-08 16:42:52 +02:00
|
|
|
self._base_saved_uidvalidity = int(file.readline().strip())
|
2003-04-18 04:18:34 +02:00
|
|
|
file.close()
|
|
|
|
return self._base_saved_uidvalidity
|
|
|
|
|
2012-01-19 11:53:48 +01:00
|
|
|
def save_uidvalidity(self):
|
|
|
|
"""Save the UIDVALIDITY value of the folder to the cache
|
2011-03-06 11:17:12 +01:00
|
|
|
|
|
|
|
This function is not threadsafe, so don't attempt to call it
|
|
|
|
from concurrent threads."""
|
2015-01-08 17:13:33 +01:00
|
|
|
|
2012-01-19 11:24:16 +01:00
|
|
|
newval = self.get_uidvalidity()
|
2003-04-18 04:18:34 +02:00
|
|
|
uidfilename = self._getuidfilename()
|
2011-03-06 11:17:12 +01:00
|
|
|
|
2016-06-27 15:03:27 +02:00
|
|
|
with open(uidfilename + ".tmp", "wt") as uidfile:
|
2020-08-29 19:39:31 +02:00
|
|
|
uidfile.write("%d\n" % newval)
|
2011-03-06 11:17:12 +01:00
|
|
|
os.rename(uidfilename + ".tmp", uidfilename)
|
|
|
|
self._base_saved_uidvalidity = newval
|
2002-06-20 05:33:23 +02:00
|
|
|
|
2012-01-19 11:24:16 +01:00
|
|
|
def get_uidvalidity(self):
|
|
|
|
"""Retrieve the current connections UIDVALIDITY value
|
|
|
|
|
|
|
|
This function needs to be implemented by each Backend
|
2016-06-27 15:03:27 +02:00
|
|
|
:returns: UIDVALIDITY as a (long) number."""
|
2015-01-08 17:13:33 +01:00
|
|
|
|
2012-10-18 19:23:34 +02:00
|
|
|
raise NotImplementedError
|
2002-06-20 05:33:23 +02:00
|
|
|
|
|
|
|
def cachemessagelist(self):
|
2016-06-27 15:03:27 +02:00
|
|
|
"""Cache the list of messages.
|
|
|
|
|
|
|
|
Reads the message list from disk or network and stores it in memory for
|
|
|
|
later use. This list will not be re-read from disk or memory unless
|
|
|
|
this function is called again."""
|
2015-01-08 17:13:33 +01:00
|
|
|
|
2012-10-18 19:23:34 +02:00
|
|
|
raise NotImplementedError
|
2002-06-20 05:33:23 +02:00
|
|
|
|
2015-02-13 17:02:33 +01:00
|
|
|
def ismessagelistempty(self):
|
2016-04-09 18:12:18 +02:00
|
|
|
"""Is the list of messages empty."""
|
2015-02-13 17:02:33 +01:00
|
|
|
|
2020-08-28 03:32:43 +02:00
|
|
|
if len(list(self.messagelist.keys())) < 1:
|
2015-02-13 17:02:33 +01:00
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2014-01-05 16:07:03 +01:00
|
|
|
def dropmessagelistcache(self):
|
2015-02-13 17:02:33 +01:00
|
|
|
"""Empty everythings we know about messages."""
|
|
|
|
|
|
|
|
self.messagelist = {}
|
2014-01-05 16:07:03 +01:00
|
|
|
|
2002-06-20 05:33:23 +02:00
|
|
|
def getmessagelist(self):
|
2002-06-20 05:50:58 +02:00
|
|
|
"""Gets the current message list.
|
2015-01-14 22:58:25 +01:00
|
|
|
|
2002-06-20 05:50:58 +02:00
|
|
|
You must call cachemessagelist() before calling this function!"""
|
2015-01-08 17:13:33 +01:00
|
|
|
|
2016-04-09 18:12:18 +02:00
|
|
|
return self.messagelist
|
2002-06-20 05:33:23 +02:00
|
|
|
|
2014-08-03 14:47:26 +02:00
|
|
|
def msglist_item_initializer(self, uid):
|
2015-01-08 17:13:33 +01:00
|
|
|
"""Returns value for empty messagelist element with given UID.
|
2014-08-03 14:47:26 +02:00
|
|
|
|
|
|
|
This function must initialize all fields of messagelist item
|
|
|
|
and must be called every time when one creates new messagelist
|
2020-08-30 13:05:32 +02:00
|
|
|
entry to ensure that all fields that must be present are present.
|
|
|
|
|
|
|
|
:param uid: Message UID"""
|
2014-08-03 14:47:26 +02:00
|
|
|
|
|
|
|
raise NotImplementedError
|
|
|
|
|
2011-03-11 10:50:18 +01:00
|
|
|
def uidexists(self, uid):
|
2016-06-27 15:03:27 +02:00
|
|
|
"""Returns True if uid exists."""
|
2015-01-08 17:13:33 +01:00
|
|
|
|
2011-03-11 10:50:18 +01:00
|
|
|
return uid in self.getmessagelist()
|
|
|
|
|
|
|
|
def getmessageuidlist(self):
|
|
|
|
"""Gets a list of UIDs.
|
2015-01-14 22:58:25 +01:00
|
|
|
|
2011-03-11 10:50:18 +01:00
|
|
|
You may have to call cachemessagelist() before calling this function!"""
|
2015-01-08 17:13:33 +01:00
|
|
|
|
2012-07-08 05:16:56 +02:00
|
|
|
return sorted(self.getmessagelist().keys())
|
2011-03-11 10:50:18 +01:00
|
|
|
|
2011-03-09 08:53:20 +01:00
|
|
|
def getmessagecount(self):
|
|
|
|
"""Gets the number of messages."""
|
2015-01-08 17:13:33 +01:00
|
|
|
|
2011-03-09 08:53:20 +01:00
|
|
|
return len(self.getmessagelist())
|
|
|
|
|
2002-06-20 05:50:58 +02:00
|
|
|
def getmessage(self, uid):
|
|
|
|
"""Returns the content of the specified message."""
|
2015-01-08 17:13:33 +01:00
|
|
|
|
2012-10-18 19:23:34 +02:00
|
|
|
raise NotImplementedError
|
2002-06-20 05:50:58 +02:00
|
|
|
|
maxage: fix timezone issues, remove IMAP-IMAP support, add startdate option
1. When using maxage, local and remote messagelists are supposed to only
contain messages from at most maxage days ago. But local and remote used
different timezones to calculate what "maxage days ago" means, resulting
in removals on one side. Now, we ask the local folder for maxage days'
worth of mail, find the lowest UID, and then ask the remote folder for
all UID's starting with that lowest one.
2. maxage was fundamentally wrong in the IMAP-IMAP case: it assumed that
remote messages have UIDs in the same order as their local counterparts,
which could be false, e.g. when messages are copied in quick succession.
So, remove support for maxage in the IMAP-IMAP case.
3. Add startdate option for IMAP-IMAP syncs: use messages from the given
repository starting at startdate, and all messages from the other
repository. In the first sync, the other repository must be empty.
4. Allow maxage to be specified either as number of days to sync (as
previously) or as a fixed date.
Signed-off-by: Janna Martl <janna.martl109@gmail.com>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2015-04-07 10:14:11 +02:00
|
|
|
def getmaxage(self):
|
2016-06-27 15:03:27 +02:00
|
|
|
"""Return maxage.
|
|
|
|
|
|
|
|
maxage is allowed to be either an integer or a date of the form
|
|
|
|
YYYY-mm-dd. This returns a time_struct."""
|
maxage: fix timezone issues, remove IMAP-IMAP support, add startdate option
1. When using maxage, local and remote messagelists are supposed to only
contain messages from at most maxage days ago. But local and remote used
different timezones to calculate what "maxage days ago" means, resulting
in removals on one side. Now, we ask the local folder for maxage days'
worth of mail, find the lowest UID, and then ask the remote folder for
all UID's starting with that lowest one.
2. maxage was fundamentally wrong in the IMAP-IMAP case: it assumed that
remote messages have UIDs in the same order as their local counterparts,
which could be false, e.g. when messages are copied in quick succession.
So, remove support for maxage in the IMAP-IMAP case.
3. Add startdate option for IMAP-IMAP syncs: use messages from the given
repository starting at startdate, and all messages from the other
repository. In the first sync, the other repository must be empty.
4. Allow maxage to be specified either as number of days to sync (as
previously) or as a fixed date.
Signed-off-by: Janna Martl <janna.martl109@gmail.com>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2015-04-07 10:14:11 +02:00
|
|
|
|
2020-08-29 19:39:31 +02:00
|
|
|
maxagestr = self.config.getdefault("Account %s" %
|
|
|
|
self.accountname, "maxage", None)
|
2016-06-27 15:03:27 +02:00
|
|
|
if maxagestr is None:
|
maxage: fix timezone issues, remove IMAP-IMAP support, add startdate option
1. When using maxage, local and remote messagelists are supposed to only
contain messages from at most maxage days ago. But local and remote used
different timezones to calculate what "maxage days ago" means, resulting
in removals on one side. Now, we ask the local folder for maxage days'
worth of mail, find the lowest UID, and then ask the remote folder for
all UID's starting with that lowest one.
2. maxage was fundamentally wrong in the IMAP-IMAP case: it assumed that
remote messages have UIDs in the same order as their local counterparts,
which could be false, e.g. when messages are copied in quick succession.
So, remove support for maxage in the IMAP-IMAP case.
3. Add startdate option for IMAP-IMAP syncs: use messages from the given
repository starting at startdate, and all messages from the other
repository. In the first sync, the other repository must be empty.
4. Allow maxage to be specified either as number of days to sync (as
previously) or as a fixed date.
Signed-off-by: Janna Martl <janna.martl109@gmail.com>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2015-04-07 10:14:11 +02:00
|
|
|
return None
|
2016-06-27 15:03:27 +02:00
|
|
|
# Is it a number?
|
maxage: fix timezone issues, remove IMAP-IMAP support, add startdate option
1. When using maxage, local and remote messagelists are supposed to only
contain messages from at most maxage days ago. But local and remote used
different timezones to calculate what "maxage days ago" means, resulting
in removals on one side. Now, we ask the local folder for maxage days'
worth of mail, find the lowest UID, and then ask the remote folder for
all UID's starting with that lowest one.
2. maxage was fundamentally wrong in the IMAP-IMAP case: it assumed that
remote messages have UIDs in the same order as their local counterparts,
which could be false, e.g. when messages are copied in quick succession.
So, remove support for maxage in the IMAP-IMAP case.
3. Add startdate option for IMAP-IMAP syncs: use messages from the given
repository starting at startdate, and all messages from the other
repository. In the first sync, the other repository must be empty.
4. Allow maxage to be specified either as number of days to sync (as
previously) or as a fixed date.
Signed-off-by: Janna Martl <janna.martl109@gmail.com>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2015-04-07 10:14:11 +02:00
|
|
|
try:
|
|
|
|
maxage = int(maxagestr)
|
|
|
|
if maxage < 1:
|
2020-08-29 19:39:31 +02:00
|
|
|
raise OfflineImapError("invalid maxage value %d" % maxage,
|
|
|
|
OfflineImapError.ERROR.MESSAGE)
|
|
|
|
return time.gmtime(time.time() - 60 * 60 * 24 * maxage)
|
maxage: fix timezone issues, remove IMAP-IMAP support, add startdate option
1. When using maxage, local and remote messagelists are supposed to only
contain messages from at most maxage days ago. But local and remote used
different timezones to calculate what "maxage days ago" means, resulting
in removals on one side. Now, we ask the local folder for maxage days'
worth of mail, find the lowest UID, and then ask the remote folder for
all UID's starting with that lowest one.
2. maxage was fundamentally wrong in the IMAP-IMAP case: it assumed that
remote messages have UIDs in the same order as their local counterparts,
which could be false, e.g. when messages are copied in quick succession.
So, remove support for maxage in the IMAP-IMAP case.
3. Add startdate option for IMAP-IMAP syncs: use messages from the given
repository starting at startdate, and all messages from the other
repository. In the first sync, the other repository must be empty.
4. Allow maxage to be specified either as number of days to sync (as
previously) or as a fixed date.
Signed-off-by: Janna Martl <janna.martl109@gmail.com>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2015-04-07 10:14:11 +02:00
|
|
|
except ValueError:
|
2020-08-29 19:39:31 +02:00
|
|
|
pass # Maybe it was a date.
|
2016-06-27 15:03:27 +02:00
|
|
|
# Is it a date string?
|
maxage: fix timezone issues, remove IMAP-IMAP support, add startdate option
1. When using maxage, local and remote messagelists are supposed to only
contain messages from at most maxage days ago. But local and remote used
different timezones to calculate what "maxage days ago" means, resulting
in removals on one side. Now, we ask the local folder for maxage days'
worth of mail, find the lowest UID, and then ask the remote folder for
all UID's starting with that lowest one.
2. maxage was fundamentally wrong in the IMAP-IMAP case: it assumed that
remote messages have UIDs in the same order as their local counterparts,
which could be false, e.g. when messages are copied in quick succession.
So, remove support for maxage in the IMAP-IMAP case.
3. Add startdate option for IMAP-IMAP syncs: use messages from the given
repository starting at startdate, and all messages from the other
repository. In the first sync, the other repository must be empty.
4. Allow maxage to be specified either as number of days to sync (as
previously) or as a fixed date.
Signed-off-by: Janna Martl <janna.martl109@gmail.com>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2015-04-07 10:14:11 +02:00
|
|
|
try:
|
|
|
|
date = time.strptime(maxagestr, "%Y-%m-%d")
|
|
|
|
if date[0] < 1900:
|
|
|
|
raise OfflineImapError("maxage led to year %d. "
|
2020-08-29 19:39:31 +02:00
|
|
|
"Abort syncing." % date[0],
|
|
|
|
OfflineImapError.ERROR.MESSAGE)
|
2016-05-05 19:32:50 +02:00
|
|
|
if (time.mktime(date) - time.mktime(time.localtime())) > 0:
|
|
|
|
raise OfflineImapError("maxage led to future date %s. "
|
2020-08-29 19:39:31 +02:00
|
|
|
"Abort syncing." % maxagestr,
|
|
|
|
OfflineImapError.ERROR.MESSAGE)
|
maxage: fix timezone issues, remove IMAP-IMAP support, add startdate option
1. When using maxage, local and remote messagelists are supposed to only
contain messages from at most maxage days ago. But local and remote used
different timezones to calculate what "maxage days ago" means, resulting
in removals on one side. Now, we ask the local folder for maxage days'
worth of mail, find the lowest UID, and then ask the remote folder for
all UID's starting with that lowest one.
2. maxage was fundamentally wrong in the IMAP-IMAP case: it assumed that
remote messages have UIDs in the same order as their local counterparts,
which could be false, e.g. when messages are copied in quick succession.
So, remove support for maxage in the IMAP-IMAP case.
3. Add startdate option for IMAP-IMAP syncs: use messages from the given
repository starting at startdate, and all messages from the other
repository. In the first sync, the other repository must be empty.
4. Allow maxage to be specified either as number of days to sync (as
previously) or as a fixed date.
Signed-off-by: Janna Martl <janna.martl109@gmail.com>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2015-04-07 10:14:11 +02:00
|
|
|
return date
|
|
|
|
except ValueError:
|
2020-08-29 19:39:31 +02:00
|
|
|
raise OfflineImapError("invalid maxage value %s" % maxagestr,
|
|
|
|
OfflineImapError.ERROR.MESSAGE)
|
maxage: fix timezone issues, remove IMAP-IMAP support, add startdate option
1. When using maxage, local and remote messagelists are supposed to only
contain messages from at most maxage days ago. But local and remote used
different timezones to calculate what "maxage days ago" means, resulting
in removals on one side. Now, we ask the local folder for maxage days'
worth of mail, find the lowest UID, and then ask the remote folder for
all UID's starting with that lowest one.
2. maxage was fundamentally wrong in the IMAP-IMAP case: it assumed that
remote messages have UIDs in the same order as their local counterparts,
which could be false, e.g. when messages are copied in quick succession.
So, remove support for maxage in the IMAP-IMAP case.
3. Add startdate option for IMAP-IMAP syncs: use messages from the given
repository starting at startdate, and all messages from the other
repository. In the first sync, the other repository must be empty.
4. Allow maxage to be specified either as number of days to sync (as
previously) or as a fixed date.
Signed-off-by: Janna Martl <janna.martl109@gmail.com>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2015-04-07 10:14:11 +02:00
|
|
|
|
|
|
|
def getmaxsize(self):
|
2020-08-29 19:39:31 +02:00
|
|
|
return self.config.getdefaultint("Account %s" %
|
|
|
|
self.accountname, "maxsize", None)
|
maxage: fix timezone issues, remove IMAP-IMAP support, add startdate option
1. When using maxage, local and remote messagelists are supposed to only
contain messages from at most maxage days ago. But local and remote used
different timezones to calculate what "maxage days ago" means, resulting
in removals on one side. Now, we ask the local folder for maxage days'
worth of mail, find the lowest UID, and then ask the remote folder for
all UID's starting with that lowest one.
2. maxage was fundamentally wrong in the IMAP-IMAP case: it assumed that
remote messages have UIDs in the same order as their local counterparts,
which could be false, e.g. when messages are copied in quick succession.
So, remove support for maxage in the IMAP-IMAP case.
3. Add startdate option for IMAP-IMAP syncs: use messages from the given
repository starting at startdate, and all messages from the other
repository. In the first sync, the other repository must be empty.
4. Allow maxage to be specified either as number of days to sync (as
previously) or as a fixed date.
Signed-off-by: Janna Martl <janna.martl109@gmail.com>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2015-04-07 10:14:11 +02:00
|
|
|
|
|
|
|
def getstartdate(self):
|
|
|
|
""" Retrieve the value of the configuration option startdate """
|
|
|
|
datestr = self.config.getdefault("Repository " + self.repository.name,
|
2020-08-29 19:39:31 +02:00
|
|
|
'startdate', None)
|
maxage: fix timezone issues, remove IMAP-IMAP support, add startdate option
1. When using maxage, local and remote messagelists are supposed to only
contain messages from at most maxage days ago. But local and remote used
different timezones to calculate what "maxage days ago" means, resulting
in removals on one side. Now, we ask the local folder for maxage days'
worth of mail, find the lowest UID, and then ask the remote folder for
all UID's starting with that lowest one.
2. maxage was fundamentally wrong in the IMAP-IMAP case: it assumed that
remote messages have UIDs in the same order as their local counterparts,
which could be false, e.g. when messages are copied in quick succession.
So, remove support for maxage in the IMAP-IMAP case.
3. Add startdate option for IMAP-IMAP syncs: use messages from the given
repository starting at startdate, and all messages from the other
repository. In the first sync, the other repository must be empty.
4. Allow maxage to be specified either as number of days to sync (as
previously) or as a fixed date.
Signed-off-by: Janna Martl <janna.martl109@gmail.com>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2015-04-07 10:14:11 +02:00
|
|
|
try:
|
|
|
|
if not datestr:
|
|
|
|
return None
|
|
|
|
date = time.strptime(datestr, "%Y-%m-%d")
|
|
|
|
if date[0] < 1900:
|
|
|
|
raise OfflineImapError("startdate led to year %d. "
|
2020-08-29 19:39:31 +02:00
|
|
|
"Abort syncing." % date[0],
|
|
|
|
OfflineImapError.ERROR.MESSAGE)
|
2016-05-05 19:32:50 +02:00
|
|
|
if (time.mktime(date) - time.mktime(time.localtime())) > 0:
|
|
|
|
raise OfflineImapError("startdate led to future date %s. "
|
2020-08-29 19:39:31 +02:00
|
|
|
"Abort syncing." % datestr,
|
|
|
|
OfflineImapError.ERROR.MESSAGE)
|
maxage: fix timezone issues, remove IMAP-IMAP support, add startdate option
1. When using maxage, local and remote messagelists are supposed to only
contain messages from at most maxage days ago. But local and remote used
different timezones to calculate what "maxage days ago" means, resulting
in removals on one side. Now, we ask the local folder for maxage days'
worth of mail, find the lowest UID, and then ask the remote folder for
all UID's starting with that lowest one.
2. maxage was fundamentally wrong in the IMAP-IMAP case: it assumed that
remote messages have UIDs in the same order as their local counterparts,
which could be false, e.g. when messages are copied in quick succession.
So, remove support for maxage in the IMAP-IMAP case.
3. Add startdate option for IMAP-IMAP syncs: use messages from the given
repository starting at startdate, and all messages from the other
repository. In the first sync, the other repository must be empty.
4. Allow maxage to be specified either as number of days to sync (as
previously) or as a fixed date.
Signed-off-by: Janna Martl <janna.martl109@gmail.com>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2015-04-07 10:14:11 +02:00
|
|
|
return date
|
|
|
|
except ValueError:
|
|
|
|
raise OfflineImapError("invalid startdate value %s",
|
2020-08-29 19:39:31 +02:00
|
|
|
OfflineImapError.ERROR.MESSAGE)
|
maxage: fix timezone issues, remove IMAP-IMAP support, add startdate option
1. When using maxage, local and remote messagelists are supposed to only
contain messages from at most maxage days ago. But local and remote used
different timezones to calculate what "maxage days ago" means, resulting
in removals on one side. Now, we ask the local folder for maxage days'
worth of mail, find the lowest UID, and then ask the remote folder for
all UID's starting with that lowest one.
2. maxage was fundamentally wrong in the IMAP-IMAP case: it assumed that
remote messages have UIDs in the same order as their local counterparts,
which could be false, e.g. when messages are copied in quick succession.
So, remove support for maxage in the IMAP-IMAP case.
3. Add startdate option for IMAP-IMAP syncs: use messages from the given
repository starting at startdate, and all messages from the other
repository. In the first sync, the other repository must be empty.
4. Allow maxage to be specified either as number of days to sync (as
previously) or as a fixed date.
Signed-off-by: Janna Martl <janna.martl109@gmail.com>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2015-04-07 10:14:11 +02:00
|
|
|
|
|
|
|
def get_min_uid_file(self):
|
|
|
|
startuiddir = os.path.join(self.config.getmetadatadir(),
|
2020-08-29 19:39:31 +02:00
|
|
|
'Repository-' + self.repository.name, 'StartUID')
|
maxage: fix timezone issues, remove IMAP-IMAP support, add startdate option
1. When using maxage, local and remote messagelists are supposed to only
contain messages from at most maxage days ago. But local and remote used
different timezones to calculate what "maxage days ago" means, resulting
in removals on one side. Now, we ask the local folder for maxage days'
worth of mail, find the lowest UID, and then ask the remote folder for
all UID's starting with that lowest one.
2. maxage was fundamentally wrong in the IMAP-IMAP case: it assumed that
remote messages have UIDs in the same order as their local counterparts,
which could be false, e.g. when messages are copied in quick succession.
So, remove support for maxage in the IMAP-IMAP case.
3. Add startdate option for IMAP-IMAP syncs: use messages from the given
repository starting at startdate, and all messages from the other
repository. In the first sync, the other repository must be empty.
4. Allow maxage to be specified either as number of days to sync (as
previously) or as a fixed date.
Signed-off-by: Janna Martl <janna.martl109@gmail.com>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2015-04-07 10:14:11 +02:00
|
|
|
if not os.path.exists(startuiddir):
|
|
|
|
os.mkdir(startuiddir, 0o700)
|
|
|
|
return os.path.join(startuiddir, self.getfolderbasename())
|
|
|
|
|
2016-11-07 23:03:40 +01:00
|
|
|
def save_min_uid(self, min_uid):
|
|
|
|
uidfile = self.get_min_uid_file()
|
|
|
|
fd = open(uidfile, 'wt')
|
|
|
|
fd.write(str(min_uid) + "\n")
|
|
|
|
fd.close()
|
|
|
|
|
maxage: fix timezone issues, remove IMAP-IMAP support, add startdate option
1. When using maxage, local and remote messagelists are supposed to only
contain messages from at most maxage days ago. But local and remote used
different timezones to calculate what "maxage days ago" means, resulting
in removals on one side. Now, we ask the local folder for maxage days'
worth of mail, find the lowest UID, and then ask the remote folder for
all UID's starting with that lowest one.
2. maxage was fundamentally wrong in the IMAP-IMAP case: it assumed that
remote messages have UIDs in the same order as their local counterparts,
which could be false, e.g. when messages are copied in quick succession.
So, remove support for maxage in the IMAP-IMAP case.
3. Add startdate option for IMAP-IMAP syncs: use messages from the given
repository starting at startdate, and all messages from the other
repository. In the first sync, the other repository must be empty.
4. Allow maxage to be specified either as number of days to sync (as
previously) or as a fixed date.
Signed-off-by: Janna Martl <janna.martl109@gmail.com>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2015-04-07 10:14:11 +02:00
|
|
|
def retrieve_min_uid(self):
|
|
|
|
uidfile = self.get_min_uid_file()
|
|
|
|
if not os.path.exists(uidfile):
|
|
|
|
return None
|
|
|
|
try:
|
|
|
|
fd = open(uidfile, 'rt')
|
2016-05-08 16:42:52 +02:00
|
|
|
min_uid = int(fd.readline().strip())
|
maxage: fix timezone issues, remove IMAP-IMAP support, add startdate option
1. When using maxage, local and remote messagelists are supposed to only
contain messages from at most maxage days ago. But local and remote used
different timezones to calculate what "maxage days ago" means, resulting
in removals on one side. Now, we ask the local folder for maxage days'
worth of mail, find the lowest UID, and then ask the remote folder for
all UID's starting with that lowest one.
2. maxage was fundamentally wrong in the IMAP-IMAP case: it assumed that
remote messages have UIDs in the same order as their local counterparts,
which could be false, e.g. when messages are copied in quick succession.
So, remove support for maxage in the IMAP-IMAP case.
3. Add startdate option for IMAP-IMAP syncs: use messages from the given
repository starting at startdate, and all messages from the other
repository. In the first sync, the other repository must be empty.
4. Allow maxage to be specified either as number of days to sync (as
previously) or as a fixed date.
Signed-off-by: Janna Martl <janna.martl109@gmail.com>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2015-04-07 10:14:11 +02:00
|
|
|
fd.close()
|
|
|
|
return min_uid
|
|
|
|
except:
|
2020-08-29 19:39:31 +02:00
|
|
|
raise IOError("Can't read %s" % uidfile)
|
maxage: fix timezone issues, remove IMAP-IMAP support, add startdate option
1. When using maxage, local and remote messagelists are supposed to only
contain messages from at most maxage days ago. But local and remote used
different timezones to calculate what "maxage days ago" means, resulting
in removals on one side. Now, we ask the local folder for maxage days'
worth of mail, find the lowest UID, and then ask the remote folder for
all UID's starting with that lowest one.
2. maxage was fundamentally wrong in the IMAP-IMAP case: it assumed that
remote messages have UIDs in the same order as their local counterparts,
which could be false, e.g. when messages are copied in quick succession.
So, remove support for maxage in the IMAP-IMAP case.
3. Add startdate option for IMAP-IMAP syncs: use messages from the given
repository starting at startdate, and all messages from the other
repository. In the first sync, the other repository must be empty.
4. Allow maxage to be specified either as number of days to sync (as
previously) or as a fixed date.
Signed-off-by: Janna Martl <janna.martl109@gmail.com>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2015-04-07 10:14:11 +02:00
|
|
|
|
2006-08-22 03:09:36 +02:00
|
|
|
def savemessage(self, uid, content, flags, rtime):
|
2002-06-20 06:37:36 +02:00
|
|
|
"""Writes a new message, with the specified uid.
|
2002-06-21 03:12:52 +02:00
|
|
|
|
2011-03-16 16:24:07 +01:00
|
|
|
If the uid is < 0: The backend should assign a new uid and
|
|
|
|
return it. In case it cannot assign a new uid, it returns
|
|
|
|
the negative uid passed in WITHOUT saving the message.
|
2002-07-18 02:51:03 +02:00
|
|
|
|
2011-03-16 16:24:07 +01:00
|
|
|
If the backend CAN assign a new uid, but cannot find out what
|
|
|
|
this UID is (as is the case with some IMAP servers), it
|
|
|
|
returns 0 but DOES save the message.
|
2013-07-21 21:00:23 +02:00
|
|
|
|
2011-03-16 16:24:07 +01:00
|
|
|
IMAP backend should be the only one that can assign a new
|
|
|
|
uid.
|
2002-06-20 13:39:27 +02:00
|
|
|
|
|
|
|
If the uid is > 0, the backend should set the uid to this, if it can.
|
2011-03-16 16:24:07 +01:00
|
|
|
If it cannot set the uid to that, it will save it anyway.
|
|
|
|
It will return the uid assigned in any case.
|
2011-09-16 11:44:50 +02:00
|
|
|
|
|
|
|
Note that savemessage() does not check against dryrun settings,
|
|
|
|
so you need to ensure that savemessage is never called in a
|
2015-01-08 17:13:33 +01:00
|
|
|
dryrun mode."""
|
|
|
|
|
2012-10-18 19:23:34 +02:00
|
|
|
raise NotImplementedError
|
2002-06-20 05:50:58 +02:00
|
|
|
|
2006-08-22 03:09:36 +02:00
|
|
|
def getmessagetime(self, uid):
|
|
|
|
"""Return the received time for the specified message."""
|
2015-01-08 17:13:33 +01:00
|
|
|
|
2012-10-18 19:23:34 +02:00
|
|
|
raise NotImplementedError
|
2006-08-22 03:09:36 +02:00
|
|
|
|
2012-10-16 20:20:35 +02:00
|
|
|
def getmessagemtime(self, uid):
|
|
|
|
"""Returns the message modification time of the specified message."""
|
2015-01-08 17:13:33 +01:00
|
|
|
|
2012-10-16 20:20:35 +02:00
|
|
|
raise NotImplementedError
|
|
|
|
|
2002-06-20 05:50:58 +02:00
|
|
|
def getmessageflags(self, uid):
|
|
|
|
"""Returns the flags for the specified message."""
|
2015-01-08 17:13:33 +01:00
|
|
|
|
2012-10-18 19:23:34 +02:00
|
|
|
raise NotImplementedError
|
2002-06-20 05:50:58 +02:00
|
|
|
|
2015-11-20 20:09:10 +01:00
|
|
|
def getmessagekeywords(self, uid):
|
|
|
|
"""Returns the keywords for the specified message."""
|
|
|
|
|
|
|
|
raise NotImplementedError
|
|
|
|
|
2002-06-20 05:50:58 +02:00
|
|
|
def savemessageflags(self, uid, flags):
|
2011-09-16 11:44:50 +02:00
|
|
|
"""Sets the specified message's flags to the given set.
|
|
|
|
|
|
|
|
Note that this function does not check against dryrun settings,
|
|
|
|
so you need to ensure that it is never called in a
|
|
|
|
dryrun mode."""
|
2015-01-08 17:13:33 +01:00
|
|
|
|
2012-10-18 19:23:34 +02:00
|
|
|
raise NotImplementedError
|
2002-06-20 05:50:58 +02:00
|
|
|
|
2002-06-20 06:37:36 +02:00
|
|
|
def addmessageflags(self, uid, flags):
|
2016-06-27 15:03:27 +02:00
|
|
|
"""Adds the specified flags to the message's flag set.
|
|
|
|
|
|
|
|
If a given flag is already present, it will not be duplicated.
|
2011-09-16 11:44:50 +02:00
|
|
|
|
|
|
|
Note that this function does not check against dryrun settings,
|
|
|
|
so you need to ensure that it is never called in a
|
|
|
|
dryrun mode.
|
|
|
|
|
2020-08-30 13:05:32 +02:00
|
|
|
:param uid: Message UID
|
2011-08-16 12:16:46 +02:00
|
|
|
:param flags: A set() of flags"""
|
2015-01-08 17:13:33 +01:00
|
|
|
|
2011-08-16 12:16:46 +02:00
|
|
|
newflags = self.getmessageflags(uid) | flags
|
2002-06-20 06:37:36 +02:00
|
|
|
self.savemessageflags(uid, newflags)
|
|
|
|
|
2002-07-03 07:05:49 +02:00
|
|
|
def addmessagesflags(self, uidlist, flags):
|
2015-01-08 17:13:33 +01:00
|
|
|
"""Note that this function does not check against dryrun settings,
|
2011-09-16 11:44:50 +02:00
|
|
|
so you need to ensure that it is never called in a
|
|
|
|
dryrun mode."""
|
2015-01-08 17:13:33 +01:00
|
|
|
|
2002-07-03 07:05:49 +02:00
|
|
|
for uid in uidlist:
|
2015-03-21 07:15:25 +01:00
|
|
|
if self.uidexists(uid):
|
|
|
|
self.addmessageflags(uid, flags)
|
2002-07-03 07:05:49 +02:00
|
|
|
|
2002-06-20 06:37:36 +02:00
|
|
|
def deletemessageflags(self, uid, flags):
|
2016-06-27 15:03:27 +02:00
|
|
|
"""Removes each flag given from the message's flag set.
|
2011-09-16 11:44:50 +02:00
|
|
|
|
|
|
|
Note that this function does not check against dryrun settings,
|
|
|
|
so you need to ensure that it is never called in a
|
2016-06-27 15:03:27 +02:00
|
|
|
dryrun mode.
|
|
|
|
|
|
|
|
If a given flag is already removed, no action will be taken for that
|
|
|
|
flag."""
|
2015-01-08 17:13:33 +01:00
|
|
|
|
2011-08-16 12:16:46 +02:00
|
|
|
newflags = self.getmessageflags(uid) - flags
|
2002-06-20 06:37:36 +02:00
|
|
|
self.savemessageflags(uid, newflags)
|
|
|
|
|
2003-01-09 03:16:07 +01:00
|
|
|
def deletemessagesflags(self, uidlist, flags):
|
2011-09-16 11:44:50 +02:00
|
|
|
"""
|
|
|
|
Note that this function does not check against dryrun settings,
|
|
|
|
so you need to ensure that it is never called in a
|
|
|
|
dryrun mode."""
|
2015-01-08 17:13:33 +01:00
|
|
|
|
2003-01-09 03:16:07 +01:00
|
|
|
for uid in uidlist:
|
|
|
|
self.deletemessageflags(uid, flags)
|
|
|
|
|
2012-10-16 20:20:35 +02:00
|
|
|
def getmessagelabels(self, uid):
|
|
|
|
"""Returns the labels for the specified message."""
|
2015-01-14 22:58:25 +01:00
|
|
|
|
2012-10-16 20:20:35 +02:00
|
|
|
raise NotImplementedError
|
|
|
|
|
2020-10-10 15:00:34 +02:00
|
|
|
def savemessagelabels(self, uid, labels, ignorelabels=None, mtime=0):
|
2012-10-16 20:20:35 +02:00
|
|
|
"""Sets the specified message's labels to the given set.
|
|
|
|
|
|
|
|
Note that this function does not check against dryrun settings,
|
|
|
|
so you need to ensure that it is never called in a
|
|
|
|
dryrun mode."""
|
2015-01-08 17:13:33 +01:00
|
|
|
|
2020-10-10 17:23:05 +02:00
|
|
|
"""
|
|
|
|
If this function is implemented,
|
|
|
|
then it should include this code:
|
|
|
|
|
2020-10-10 15:00:34 +02:00
|
|
|
if ignorelabels is None:
|
|
|
|
ignorelabels = set()
|
2020-10-10 17:23:05 +02:00
|
|
|
"""
|
2020-10-10 15:00:34 +02:00
|
|
|
|
2012-10-16 20:20:35 +02:00
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
def addmessagelabels(self, uid, labels):
|
|
|
|
"""Adds the specified labels to the message's labels set. If a given
|
|
|
|
label is already present, it will not be duplicated.
|
|
|
|
|
|
|
|
Note that this function does not check against dryrun settings,
|
|
|
|
so you need to ensure that it is never called in a
|
|
|
|
dryrun mode.
|
|
|
|
|
2020-08-30 13:05:32 +02:00
|
|
|
:param uid: Message UID
|
2012-10-16 20:20:35 +02:00
|
|
|
:param labels: A set() of labels"""
|
2015-01-08 17:13:33 +01:00
|
|
|
|
2012-10-16 20:20:35 +02:00
|
|
|
newlabels = self.getmessagelabels(uid) | labels
|
|
|
|
self.savemessagelabels(uid, newlabels)
|
|
|
|
|
|
|
|
def addmessageslabels(self, uidlist, labels):
|
2015-01-08 17:13:33 +01:00
|
|
|
"""Note that this function does not check against dryrun settings,
|
2012-10-16 20:20:35 +02:00
|
|
|
so you need to ensure that it is never called in a
|
2020-08-30 13:05:32 +02:00
|
|
|
dryrun mode.
|
|
|
|
|
|
|
|
:param uidlist: Message UID
|
|
|
|
:param labels: Labels to add"""
|
2015-01-08 17:13:33 +01:00
|
|
|
|
2012-10-16 20:20:35 +02:00
|
|
|
for uid in uidlist:
|
|
|
|
self.addmessagelabels(uid, labels)
|
|
|
|
|
|
|
|
def deletemessagelabels(self, uid, labels):
|
2016-06-27 15:03:27 +02:00
|
|
|
"""Removes each label given from the message's label set.
|
|
|
|
|
|
|
|
If a given label is already removed, no action will be taken for that
|
|
|
|
label.
|
2012-10-16 20:20:35 +02:00
|
|
|
|
|
|
|
Note that this function does not check against dryrun settings,
|
|
|
|
so you need to ensure that it is never called in a
|
2020-08-30 13:05:32 +02:00
|
|
|
dryrun mode.
|
|
|
|
|
|
|
|
:param uid: Message uid
|
|
|
|
:param labels: Labels to delete"""
|
2015-01-08 17:13:33 +01:00
|
|
|
|
2012-10-16 20:20:35 +02:00
|
|
|
newlabels = self.getmessagelabels(uid) - labels
|
|
|
|
self.savemessagelabels(uid, newlabels)
|
|
|
|
|
|
|
|
def deletemessageslabels(self, uidlist, labels):
|
|
|
|
"""
|
|
|
|
Note that this function does not check against dryrun settings,
|
|
|
|
so you need to ensure that it is never called in a
|
|
|
|
dryrun mode."""
|
2015-01-08 17:13:33 +01:00
|
|
|
|
2012-10-16 20:20:35 +02:00
|
|
|
for uid in uidlist:
|
|
|
|
self.deletemessagelabels(uid, labels)
|
|
|
|
|
2014-06-24 19:05:21 +02:00
|
|
|
def addmessageheader(self, content, linebreak, headername, headervalue):
|
2015-01-08 17:13:33 +01:00
|
|
|
"""Adds new header to the provided message.
|
2014-06-01 20:09:44 +02:00
|
|
|
|
2014-11-20 14:18:35 +01:00
|
|
|
WARNING: This function is a bit tricky, and modifying it in the wrong way,
|
|
|
|
may easily lead to data-loss.
|
|
|
|
|
2014-06-01 20:09:44 +02:00
|
|
|
Arguments:
|
|
|
|
- content: message content, headers and body as a single string
|
2014-06-24 19:05:21 +02:00
|
|
|
- linebreak: string that carries line ending
|
2014-06-01 20:09:44 +02:00
|
|
|
- headername: name of the header to add
|
|
|
|
- headervalue: value of the header to add
|
|
|
|
|
2015-01-11 18:15:16 +01:00
|
|
|
.. note::
|
|
|
|
|
|
|
|
The following documentation will not get displayed correctly after being
|
|
|
|
processed by Sphinx. View the source of this method to read it.
|
|
|
|
|
2014-06-24 19:06:34 +02:00
|
|
|
This has to deal with strange corner cases where the header is
|
|
|
|
missing or empty. Here are illustrations for all the cases,
|
|
|
|
showing where the header gets inserted and what the end result
|
|
|
|
is. In each illustration, '+' means the added contents. Note
|
|
|
|
that these examples assume LF for linebreak, not CRLF, so '\n'
|
|
|
|
denotes a linebreak and '\n\n' corresponds to the transition
|
|
|
|
between header and body. However if the linebreak parameter
|
|
|
|
is set to '\r\n' then you would have to substitute '\r\n' for
|
|
|
|
'\n' in the below examples.
|
|
|
|
|
|
|
|
* Case 1: No '\n\n', leading '\n'
|
|
|
|
|
|
|
|
+X-Flying-Pig-Header: i am here\n
|
|
|
|
\n
|
|
|
|
This is the body\n
|
|
|
|
next line\n
|
|
|
|
|
|
|
|
* Case 2: '\n\n' at position 0
|
|
|
|
|
|
|
|
+X-Flying-Pig-Header: i am here
|
|
|
|
\n
|
|
|
|
\n
|
|
|
|
This is the body\n
|
|
|
|
next line\n
|
|
|
|
|
|
|
|
* Case 3: No '\n\n', no leading '\n'
|
|
|
|
|
|
|
|
+X-Flying-Pig-Header: i am here\n
|
|
|
|
+\n
|
|
|
|
This is the body\n
|
|
|
|
next line\n
|
|
|
|
|
|
|
|
* Case 4: '\n\n' at non-zero position
|
|
|
|
|
|
|
|
Subject: Something wrong with OI\n
|
|
|
|
From: some@person.at
|
|
|
|
+\nX-Flying-Pig-Header: i am here
|
|
|
|
\n
|
|
|
|
\n
|
|
|
|
This is the body\n
|
|
|
|
next line\n
|
2014-06-01 20:09:44 +02:00
|
|
|
"""
|
2015-01-08 17:13:33 +01:00
|
|
|
|
2020-08-29 19:39:31 +02:00
|
|
|
self.ui.debug('', 'addmessageheader: called to add %s: %s' %
|
|
|
|
(headername, headervalue))
|
2014-06-24 19:07:17 +02:00
|
|
|
|
|
|
|
insertionpoint = content.find(linebreak * 2)
|
|
|
|
if insertionpoint == -1:
|
|
|
|
self.ui.debug('', 'addmessageheader: headers were missing')
|
|
|
|
else:
|
2016-06-27 15:03:27 +02:00
|
|
|
self.ui.debug('',
|
2020-08-29 19:39:31 +02:00
|
|
|
'addmessageheader: headers end at position %d' % insertionpoint)
|
2014-06-24 19:07:17 +02:00
|
|
|
mark = '==>EOH<=='
|
2020-08-29 19:39:31 +02:00
|
|
|
contextstart = max(0, insertionpoint - 100)
|
|
|
|
contextend = min(len(content), insertionpoint + 100)
|
2016-06-27 15:27:11 +02:00
|
|
|
self.ui.debug('', 'addmessageheader: header/body transition " \
|
2020-08-29 19:39:31 +02:00
|
|
|
"context (marked by %s): %s%s%s' % (
|
|
|
|
mark, repr(content[contextstart:insertionpoint]),
|
|
|
|
mark, repr(content[insertionpoint:contextend])
|
2016-06-27 15:03:27 +02:00
|
|
|
)
|
2020-08-29 19:39:31 +02:00
|
|
|
)
|
2016-06-27 15:03:27 +02:00
|
|
|
|
|
|
|
# Hoping for case #4.
|
2014-06-24 19:05:21 +02:00
|
|
|
prefix = linebreak
|
2012-10-16 20:20:35 +02:00
|
|
|
suffix = ''
|
2016-06-27 15:03:27 +02:00
|
|
|
# Case #2.
|
2014-06-24 19:06:34 +02:00
|
|
|
if insertionpoint == 0:
|
|
|
|
prefix = ''
|
|
|
|
suffix = ''
|
2016-06-27 15:03:27 +02:00
|
|
|
# Either case #1 or #3.
|
2014-06-24 19:06:34 +02:00
|
|
|
elif insertionpoint == -1:
|
2012-10-16 20:20:35 +02:00
|
|
|
prefix = ''
|
2014-06-24 19:05:21 +02:00
|
|
|
suffix = linebreak
|
2012-10-17 21:45:19 +02:00
|
|
|
insertionpoint = 0
|
2014-06-24 19:06:34 +02:00
|
|
|
# Case #3: when body starts immediately, without preceding '\n'
|
2012-10-16 20:20:35 +02:00
|
|
|
# (this shouldn't happen with proper mail messages, but
|
|
|
|
# we seen many broken ones), we should add '\n' to make
|
|
|
|
# new (and the only header, in this case) to be properly
|
|
|
|
# separated from the message body.
|
2014-06-24 19:05:21 +02:00
|
|
|
if content[0:len(linebreak)] != linebreak:
|
|
|
|
suffix = suffix + linebreak
|
2012-10-16 20:20:35 +02:00
|
|
|
|
2016-06-27 15:03:27 +02:00
|
|
|
self.ui.debug('',
|
2020-08-29 19:39:31 +02:00
|
|
|
'addmessageheader: insertionpoint = %d' % insertionpoint)
|
2012-10-16 20:20:35 +02:00
|
|
|
headers = content[0:insertionpoint]
|
2020-08-29 19:39:31 +02:00
|
|
|
self.ui.debug('', 'addmessageheader: headers = %s' % repr(headers))
|
|
|
|
new_header = prefix + ("%s: %s" % (headername, headervalue)) + suffix
|
|
|
|
self.ui.debug('', 'addmessageheader: new_header = %s' % repr(new_header))
|
2012-10-16 20:20:35 +02:00
|
|
|
return headers + new_header + content[insertionpoint:]
|
2012-10-17 21:45:19 +02:00
|
|
|
|
|
|
|
def __find_eoh(self, content):
|
2016-06-27 15:03:27 +02:00
|
|
|
"""Searches for the point where mail headers end.
|
|
|
|
|
2012-10-17 21:45:19 +02:00
|
|
|
Either double '\n', or end of string.
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
- content: contents of the message to search in
|
|
|
|
Returns: position of the first non-header byte.
|
|
|
|
"""
|
2015-01-08 17:13:33 +01:00
|
|
|
|
2012-10-17 21:45:19 +02:00
|
|
|
eoh_cr = content.find('\n\n')
|
|
|
|
if eoh_cr == -1:
|
|
|
|
eoh_cr = len(content)
|
|
|
|
|
|
|
|
return eoh_cr
|
|
|
|
|
|
|
|
def getmessageheader(self, content, name):
|
2016-06-27 15:03:27 +02:00
|
|
|
"""Return the value of the first occurence of the given header.
|
|
|
|
|
|
|
|
Header name is case-insensitive.
|
2014-06-30 14:41:17 +02:00
|
|
|
|
2012-10-17 21:45:19 +02:00
|
|
|
Arguments:
|
|
|
|
- contents: message itself
|
|
|
|
- name: name of the header to be searched
|
|
|
|
|
2016-06-27 15:03:27 +02:00
|
|
|
Returns: header value or None if no such header was found.
|
2012-10-17 21:45:19 +02:00
|
|
|
"""
|
2015-01-08 17:13:33 +01:00
|
|
|
|
2020-08-29 19:39:31 +02:00
|
|
|
self.ui.debug('', 'getmessageheader: called to get %s' % name)
|
2012-10-17 21:45:19 +02:00
|
|
|
eoh = self.__find_eoh(content)
|
2020-08-29 19:39:31 +02:00
|
|
|
self.ui.debug('', 'getmessageheader: eoh = %d' % eoh)
|
2012-10-17 21:45:19 +02:00
|
|
|
headers = content[0:eoh]
|
2020-08-29 19:39:31 +02:00
|
|
|
self.ui.debug('', 'getmessageheader: headers = %s' % repr(headers))
|
2012-10-17 21:45:19 +02:00
|
|
|
|
2020-08-29 19:39:31 +02:00
|
|
|
m = re.search('^%s:(.*)$' % name, headers,
|
|
|
|
flags=re.MULTILINE | re.IGNORECASE)
|
2012-10-17 21:45:19 +02:00
|
|
|
if m:
|
|
|
|
return m.group(1).strip()
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
2014-11-20 14:03:15 +01:00
|
|
|
def getmessageheaderlist(self, content, name):
|
2016-06-27 15:03:27 +02:00
|
|
|
"""Return a list of values for the given header.
|
2014-11-20 14:03:15 +01:00
|
|
|
|
|
|
|
Arguments:
|
|
|
|
- contents: message itself
|
|
|
|
- name: name of the header to be searched
|
|
|
|
|
2016-06-27 15:03:27 +02:00
|
|
|
Returns: list of header values or empty list if no such header was found.
|
2014-11-20 14:03:15 +01:00
|
|
|
"""
|
2015-01-08 17:13:33 +01:00
|
|
|
|
2020-08-29 19:39:31 +02:00
|
|
|
self.ui.debug('', 'getmessageheaderlist: called to get %s' % name)
|
2014-11-20 14:03:15 +01:00
|
|
|
eoh = self.__find_eoh(content)
|
2020-08-29 19:39:31 +02:00
|
|
|
self.ui.debug('', 'getmessageheaderlist: eoh = %d' % eoh)
|
2014-11-20 14:03:15 +01:00
|
|
|
headers = content[0:eoh]
|
2020-08-29 19:39:31 +02:00
|
|
|
self.ui.debug('', 'getmessageheaderlist: headers = %s' % repr(headers))
|
2014-11-20 14:03:15 +01:00
|
|
|
|
2020-08-29 19:39:31 +02:00
|
|
|
return re.findall('^%s:(.*)$' %
|
|
|
|
name, headers, flags=re.MULTILINE | re.IGNORECASE)
|
2014-11-20 14:03:15 +01:00
|
|
|
|
2012-10-17 21:45:19 +02:00
|
|
|
def deletemessageheaders(self, content, header_list):
|
2015-01-08 17:13:33 +01:00
|
|
|
"""Deletes headers in the given list from the message content.
|
2012-10-17 21:45:19 +02:00
|
|
|
|
|
|
|
Arguments:
|
|
|
|
- content: message itself
|
|
|
|
- header_list: list of headers to be deleted or just the header name
|
|
|
|
|
2016-06-27 15:03:27 +02:00
|
|
|
We expect our message to have '\n' as line endings."""
|
2015-01-08 17:13:33 +01:00
|
|
|
|
2012-10-17 21:45:19 +02:00
|
|
|
if type(header_list) != type([]):
|
|
|
|
header_list = [header_list]
|
2020-08-30 12:40:28 +02:00
|
|
|
self.ui.debug('', 'deletemessageheaders: called to delete %s' % header_list)
|
2012-10-17 21:45:19 +02:00
|
|
|
|
2016-06-27 15:03:27 +02:00
|
|
|
if not len(header_list):
|
|
|
|
return content
|
2012-10-17 21:45:19 +02:00
|
|
|
|
|
|
|
eoh = self.__find_eoh(content)
|
2020-08-29 19:39:31 +02:00
|
|
|
self.ui.debug('', 'deletemessageheaders: end of headers = %d' % eoh)
|
2012-10-17 21:45:19 +02:00
|
|
|
headers = content[0:eoh]
|
|
|
|
rest = content[eoh:]
|
2020-08-29 19:39:31 +02:00
|
|
|
self.ui.debug('', 'deletemessageheaders: headers = %s' % repr(headers))
|
2012-10-17 21:45:19 +02:00
|
|
|
new_headers = []
|
|
|
|
for h in headers.split('\n'):
|
|
|
|
keep_it = True
|
2014-05-07 00:05:55 +02:00
|
|
|
for trim_h in header_list:
|
2020-08-29 19:39:31 +02:00
|
|
|
if len(h) > len(trim_h) and h[0:len(trim_h) + 1] == (trim_h + ":"):
|
2012-10-17 21:45:19 +02:00
|
|
|
keep_it = False
|
|
|
|
break
|
2016-06-27 15:03:27 +02:00
|
|
|
if keep_it:
|
|
|
|
new_headers.append(h)
|
2012-10-17 21:45:19 +02:00
|
|
|
|
2016-06-27 15:03:27 +02:00
|
|
|
return '\n'.join(new_headers) + rest
|
2012-10-17 21:45:19 +02:00
|
|
|
|
2011-08-30 10:52:11 +02:00
|
|
|
def change_message_uid(self, uid, new_uid):
|
2016-06-27 15:03:27 +02:00
|
|
|
"""Change the message from existing uid to new_uid.
|
2011-08-30 10:52:11 +02:00
|
|
|
|
|
|
|
If the backend supports it (IMAP does not).
|
2012-02-24 11:20:22 +01:00
|
|
|
|
2020-08-30 13:05:32 +02:00
|
|
|
:param uid: Message UID
|
2011-08-30 10:52:11 +02:00
|
|
|
:param new_uid: (optional) If given, the old UID will be changed
|
|
|
|
to a new UID. This allows backends efficient renaming of
|
|
|
|
messages if the UID has changed."""
|
2015-01-01 21:41:11 +01:00
|
|
|
|
2012-10-18 19:23:34 +02:00
|
|
|
raise NotImplementedError
|
2011-08-30 10:52:11 +02:00
|
|
|
|
2002-06-20 05:50:58 +02:00
|
|
|
def deletemessage(self, uid):
|
2015-01-08 17:13:33 +01:00
|
|
|
"""Note that this function does not check against dryrun settings,
|
2012-02-17 11:43:41 +01:00
|
|
|
so you need to ensure that it is never called in a
|
|
|
|
dryrun mode."""
|
2015-01-01 21:41:11 +01:00
|
|
|
|
2012-10-18 19:23:34 +02:00
|
|
|
raise NotImplementedError
|
2002-06-20 05:50:58 +02:00
|
|
|
|
2002-06-21 03:55:06 +02:00
|
|
|
def deletemessages(self, uidlist):
|
2015-01-08 17:13:33 +01:00
|
|
|
"""Note that this function does not check against dryrun settings,
|
2012-02-17 11:43:41 +01:00
|
|
|
so you need to ensure that it is never called in a
|
|
|
|
dryrun mode."""
|
2015-01-01 21:41:11 +01:00
|
|
|
|
2002-06-21 03:55:06 +02:00
|
|
|
for uid in uidlist:
|
|
|
|
self.deletemessage(uid)
|
|
|
|
|
2016-04-09 21:58:12 +02:00
|
|
|
def copymessageto(self, uid, dstfolder, statusfolder, register=1):
|
2011-03-06 20:03:04 +01:00
|
|
|
"""Copies a message from self to dst if needed, updating the status
|
|
|
|
|
2012-02-17 11:43:41 +01:00
|
|
|
Note that this function does not check against dryrun settings,
|
|
|
|
so you need to ensure that it is never called in a
|
|
|
|
dryrun mode.
|
|
|
|
|
2011-03-06 20:03:04 +01:00
|
|
|
:param uid: uid of the message to be copied.
|
|
|
|
:param dstfolder: A BaseFolder-derived instance
|
|
|
|
:param statusfolder: A LocalStatusFolder instance
|
|
|
|
:param register: whether we should register a new thread."
|
|
|
|
:returns: Nothing on success, or raises an Exception."""
|
2015-01-01 21:41:11 +01:00
|
|
|
|
2002-07-16 04:26:58 +02:00
|
|
|
# Sometimes, it could be the case that if a sync takes awhile,
|
|
|
|
# a message might be deleted from the maildir before it can be
|
|
|
|
# synced to the status cache. This is only a problem with
|
|
|
|
# self.getmessage(). So, don't call self.getmessage unless
|
|
|
|
# really needed.
|
2020-08-29 19:39:31 +02:00
|
|
|
if register: # Output that we start a new thread.
|
2011-11-03 13:45:44 +01:00
|
|
|
self.ui.registerthread(self.repository.account)
|
2011-08-11 12:22:35 +02:00
|
|
|
|
2011-08-15 11:00:06 +02:00
|
|
|
try:
|
|
|
|
message = None
|
|
|
|
flags = self.getmessageflags(uid)
|
|
|
|
rtime = self.getmessagetime(uid)
|
|
|
|
|
|
|
|
# If any of the destinations actually stores the message body,
|
|
|
|
# load it up.
|
|
|
|
if dstfolder.storesmessages():
|
|
|
|
message = self.getmessage(uid)
|
2015-01-14 22:58:25 +01:00
|
|
|
# Succeeded? -> IMAP actually assigned a UID. If newid
|
|
|
|
# remained negative, no server was willing to assign us an
|
|
|
|
# UID. If newid is 0, saving succeeded, but we could not
|
|
|
|
# retrieve the new UID. Ignore message in this case.
|
2011-08-30 10:52:11 +02:00
|
|
|
new_uid = dstfolder.savemessage(uid, message, flags, rtime)
|
|
|
|
if new_uid > 0:
|
|
|
|
if new_uid != uid:
|
|
|
|
# Got new UID, change the local uid to match the new one.
|
|
|
|
self.change_message_uid(uid, new_uid)
|
|
|
|
statusfolder.deletemessage(uid)
|
2011-08-15 11:00:06 +02:00
|
|
|
# Got new UID, change the local uid.
|
2016-06-27 15:03:27 +02:00
|
|
|
# Save uploaded status in the statusfolder.
|
2011-08-30 10:52:11 +02:00
|
|
|
statusfolder.savemessage(new_uid, message, flags, rtime)
|
2016-06-27 15:03:27 +02:00
|
|
|
# Check whether the mail has been seen.
|
2015-01-27 18:56:54 +01:00
|
|
|
if 'S' not in flags:
|
|
|
|
self.have_newmail = True
|
2012-01-06 21:41:04 +01:00
|
|
|
elif new_uid == 0:
|
2011-08-15 11:00:06 +02:00
|
|
|
# Message was stored to dstfolder, but we can't find it's UID
|
|
|
|
# This means we can't link current message to the one created
|
|
|
|
# in IMAP. So we just delete local message and on next run
|
|
|
|
# we'll sync it back
|
|
|
|
# XXX This could cause infinite loop on syncing between two
|
|
|
|
# IMAP servers ...
|
2011-07-26 10:59:54 +02:00
|
|
|
self.deletemessage(uid)
|
2011-08-15 11:00:06 +02:00
|
|
|
else:
|
|
|
|
raise OfflineImapError("Trying to save msg (uid %d) on folder "
|
2020-08-29 19:39:31 +02:00
|
|
|
"%s returned invalid uid %d" % (uid, dstfolder.getvisiblename(),
|
|
|
|
new_uid), OfflineImapError.ERROR.MESSAGE)
|
2020-08-30 12:40:28 +02:00
|
|
|
except KeyboardInterrupt: # Bubble up CTRL-C.
|
2011-08-30 10:52:11 +02:00
|
|
|
raise
|
2012-02-05 10:14:23 +01:00
|
|
|
except OfflineImapError as e:
|
2011-08-15 11:00:06 +02:00
|
|
|
if e.severity > OfflineImapError.ERROR.MESSAGE:
|
2020-08-29 19:39:31 +02:00
|
|
|
raise # Bubble severe errors up.
|
2011-08-15 11:00:06 +02:00
|
|
|
self.ui.error(e, exc_info()[2])
|
2012-02-05 10:14:23 +01:00
|
|
|
except Exception as e:
|
2013-08-30 19:44:46 +02:00
|
|
|
self.ui.error(e, exc_info()[2],
|
2020-08-29 19:39:31 +02:00
|
|
|
msg="Copying message %s [acc: %s]" % (uid, self.accountname))
|
2016-06-04 02:23:09 +02:00
|
|
|
raise # Raise on unknown errors, so we can fix those.
|
2011-08-15 11:00:06 +02:00
|
|
|
|
2014-03-16 13:27:35 +01:00
|
|
|
def __syncmessagesto_copy(self, dstfolder, statusfolder):
|
2015-01-14 22:58:25 +01:00
|
|
|
"""Pass1: Copy locally existing messages not on the other side.
|
2002-06-25 06:47:09 +02:00
|
|
|
|
2011-03-24 17:45:21 +01:00
|
|
|
This will copy messages to dstfolder that exist locally but are
|
|
|
|
not in the statusfolder yet. The strategy is:
|
2011-03-06 20:03:04 +01:00
|
|
|
|
|
|
|
1) Look for messages present in self but not in statusfolder.
|
2014-05-11 12:32:05 +02:00
|
|
|
2) invoke copymessageto() on those which:
|
2011-03-06 20:03:04 +01:00
|
|
|
- If dstfolder doesn't have it yet, add them to dstfolder.
|
2016-06-27 15:13:03 +02:00
|
|
|
- Update statusfolder.
|
2012-02-17 11:43:41 +01:00
|
|
|
|
2015-01-14 22:58:25 +01:00
|
|
|
This function checks and protects us from action in dryrun mode."""
|
2015-01-08 17:13:33 +01:00
|
|
|
|
2016-06-27 15:03:27 +02:00
|
|
|
# We have no new mail yet.
|
2015-01-27 18:56:54 +01:00
|
|
|
self.have_newmail = False
|
|
|
|
|
2002-07-04 03:35:05 +02:00
|
|
|
threads = []
|
2011-03-06 20:03:04 +01:00
|
|
|
|
2016-06-27 15:13:03 +02:00
|
|
|
copylist = [uid for uid in self.getmessageuidlist()
|
2020-08-29 19:39:31 +02:00
|
|
|
if not statusfolder.uidexists(uid)]
|
2011-09-29 16:51:48 +02:00
|
|
|
num_to_copy = len(copylist)
|
2016-06-27 15:13:03 +02:00
|
|
|
|
2016-06-28 23:58:03 +02:00
|
|
|
# Honor 'copy_ignore_eval' configuration option.
|
|
|
|
if self.copy_ignoreUIDs is not None:
|
|
|
|
for uid in self.copy_ignoreUIDs:
|
|
|
|
if uid in copylist:
|
|
|
|
copylist.remove(uid)
|
|
|
|
self.ui.ignorecopyingmessage(uid, self, dstfolder)
|
|
|
|
|
2016-06-27 15:13:03 +02:00
|
|
|
if num_to_copy > 0 and self.repository.account.dryrun:
|
2016-08-08 15:29:18 +02:00
|
|
|
self.ui.info("[DRYRUN] Copy {} messages from {}[{}] to {}".format(
|
2016-06-27 15:13:03 +02:00
|
|
|
num_to_copy, self, self.repository, dstfolder.repository)
|
2016-08-08 15:29:18 +02:00
|
|
|
)
|
2011-09-16 11:44:50 +02:00
|
|
|
return
|
2016-06-27 15:13:03 +02:00
|
|
|
|
2016-10-25 21:34:38 +02:00
|
|
|
with self:
|
|
|
|
for num, uid in enumerate(copylist):
|
|
|
|
# Bail out on CTRL-C or SIGTERM.
|
|
|
|
if offlineimap.accounts.Account.abort_NOW_signal.is_set():
|
|
|
|
break
|
|
|
|
|
|
|
|
if uid == 0:
|
|
|
|
self.ui.warn("Assertion that UID != 0 failed; ignoring message.")
|
|
|
|
continue
|
|
|
|
|
|
|
|
if uid > 0 and dstfolder.uidexists(uid):
|
|
|
|
# dstfolder has message with that UID already, only update status.
|
|
|
|
flags = self.getmessageflags(uid)
|
|
|
|
rtime = self.getmessagetime(uid)
|
|
|
|
statusfolder.savemessage(uid, None, flags, rtime)
|
|
|
|
continue
|
|
|
|
|
2020-08-29 19:39:31 +02:00
|
|
|
self.ui.copyingmessage(uid, num + 1, num_to_copy, self, dstfolder)
|
2016-10-25 21:34:38 +02:00
|
|
|
# Exceptions are caught in copymessageto().
|
|
|
|
if self.suggeststhreads():
|
|
|
|
self.waitforthread()
|
|
|
|
thread = threadutil.InstanceLimitedThread(
|
|
|
|
self.getinstancelimitnamespace(),
|
|
|
|
target=self.copymessageto,
|
2020-08-29 19:39:31 +02:00
|
|
|
name="Copy message from %s:%s" % (self.repository, self),
|
2016-10-25 21:34:38 +02:00
|
|
|
args=(uid, dstfolder, statusfolder)
|
|
|
|
)
|
|
|
|
thread.start()
|
|
|
|
threads.append(thread)
|
|
|
|
else:
|
|
|
|
self.copymessageto(uid, dstfolder, statusfolder, register=0)
|
|
|
|
for thread in threads:
|
2020-08-29 19:39:31 +02:00
|
|
|
thread.join() # Block until all "copy" threads are done.
|
2002-06-20 05:50:58 +02:00
|
|
|
|
2016-05-12 18:04:41 +02:00
|
|
|
# Execute new mail hook if we have new mail.
|
2015-01-27 18:56:54 +01:00
|
|
|
if self.have_newmail:
|
2020-08-30 11:15:00 +02:00
|
|
|
if self.newmail_hook is not None:
|
2016-05-12 18:04:41 +02:00
|
|
|
self.newmail_hook()
|
2015-01-27 18:56:54 +01:00
|
|
|
|
2014-03-16 13:27:35 +01:00
|
|
|
def __syncmessagesto_delete(self, dstfolder, statusfolder):
|
2015-01-14 22:58:25 +01:00
|
|
|
"""Pass 2: Remove locally deleted messages on dst.
|
2002-06-20 05:50:58 +02:00
|
|
|
|
2016-04-09 21:58:12 +02:00
|
|
|
Get all UIDs in statusfolder but not self. These are messages
|
2011-03-06 20:03:04 +01:00
|
|
|
that were deleted in 'self'. Delete those from dstfolder and
|
2012-02-17 11:43:41 +01:00
|
|
|
statusfolder.
|
|
|
|
|
2015-03-21 07:15:25 +01:00
|
|
|
This function checks and protects us from action in dryrun mode.
|
2012-02-17 11:43:41 +01:00
|
|
|
"""
|
2016-04-09 21:58:12 +02:00
|
|
|
# The list of messages to delete. If sync of deletions is disabled we
|
|
|
|
# still remove stale entries from statusfolder (neither in local nor
|
|
|
|
# remote).
|
2016-05-08 16:55:13 +02:00
|
|
|
deletelist = [uid for uid in statusfolder.getmessageuidlist()
|
|
|
|
if uid >= 0 and
|
|
|
|
not self.uidexists(uid) and
|
|
|
|
(self._sync_deletes or not dstfolder.uidexists(uid))]
|
2015-01-08 17:13:33 +01:00
|
|
|
|
2002-07-03 07:05:49 +02:00
|
|
|
if len(deletelist):
|
2015-03-21 07:15:25 +01:00
|
|
|
# Delete in statusfolder first to play safe. In case of abort, we
|
|
|
|
# won't lose message, we will just unneccessarily retransmit some.
|
|
|
|
# Delete messages from statusfolder that were either deleted by the
|
|
|
|
# user, or not being tracked (e.g. because of maxage).
|
2016-08-08 15:29:18 +02:00
|
|
|
if not self.repository.account.dryrun:
|
|
|
|
statusfolder.deletemessages(deletelist)
|
|
|
|
# Filter out untracked messages.
|
2016-05-08 16:55:13 +02:00
|
|
|
deletelist = [uid for uid in deletelist if dstfolder.uidexists(uid)]
|
2015-03-21 07:15:25 +01:00
|
|
|
if len(deletelist):
|
|
|
|
self.ui.deletingmessages(deletelist, [dstfolder])
|
2016-08-08 15:29:18 +02:00
|
|
|
if not self.repository.account.dryrun:
|
|
|
|
dstfolder.deletemessages(deletelist)
|
2011-03-06 20:03:04 +01:00
|
|
|
|
2015-11-20 20:09:12 +01:00
|
|
|
def combine_flags_and_keywords(self, uid, dstfolder):
|
|
|
|
"""Combine the message's flags and keywords using the mapping for the
|
|
|
|
destination folder."""
|
|
|
|
|
|
|
|
# Take a copy of the message flag set, otherwise
|
|
|
|
# __syncmessagesto_flags() will fail because statusflags is actually a
|
|
|
|
# reference to selfflags (which it should not, but I don't have time to
|
|
|
|
# debug THAT).
|
|
|
|
selfflags = set(self.getmessageflags(uid))
|
|
|
|
|
|
|
|
try:
|
|
|
|
keywordmap = dstfolder.getrepository().getkeywordmap()
|
2015-11-22 19:52:32 +01:00
|
|
|
if keywordmap is None:
|
|
|
|
return selfflags
|
|
|
|
|
2015-11-20 20:09:12 +01:00
|
|
|
knownkeywords = set(keywordmap.keys())
|
|
|
|
selfkeywords = self.getmessagekeywords(uid)
|
|
|
|
|
|
|
|
if not knownkeywords >= selfkeywords:
|
2016-06-27 15:03:27 +02:00
|
|
|
# Some of the message's keywords are not in the mapping, so
|
|
|
|
# skip them.
|
2015-11-20 20:09:12 +01:00
|
|
|
skipped_keywords = list(selfkeywords - knownkeywords)
|
|
|
|
selfkeywords &= knownkeywords
|
|
|
|
self.ui.warn("Unknown keywords skipped: %s\n"
|
2020-08-29 19:39:31 +02:00
|
|
|
"You may want to change your configuration to include "
|
2020-08-30 12:40:28 +02:00
|
|
|
"those\n" % skipped_keywords)
|
2015-11-20 20:09:12 +01:00
|
|
|
|
|
|
|
keywordletterset = set([keywordmap[keyw] for keyw in selfkeywords])
|
|
|
|
|
2016-06-27 15:03:27 +02:00
|
|
|
# Add the mapped keywords to the list of message flags.
|
2015-11-20 20:09:12 +01:00
|
|
|
selfflags |= keywordletterset
|
|
|
|
except NotImplementedError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
return selfflags
|
|
|
|
|
2014-03-16 13:27:35 +01:00
|
|
|
def __syncmessagesto_flags(self, dstfolder, statusfolder):
|
2015-01-14 22:58:25 +01:00
|
|
|
"""Pass 3: Flag synchronization.
|
2011-03-06 20:03:04 +01:00
|
|
|
|
|
|
|
Compare flag mismatches in self with those in statusfolder. If
|
|
|
|
msg has a valid UID and exists on dstfolder (has not e.g. been
|
|
|
|
deleted there), sync the flag change to both dstfolder and
|
|
|
|
statusfolder.
|
2012-02-17 11:43:41 +01:00
|
|
|
|
|
|
|
This function checks and protects us from action in ryrun mode.
|
2011-03-06 20:03:04 +01:00
|
|
|
"""
|
2015-01-08 17:13:33 +01:00
|
|
|
|
2011-03-06 20:03:04 +01:00
|
|
|
# For each flag, we store a list of uids to which it should be
|
|
|
|
# added. Then, we can call addmessagesflags() to apply them in
|
|
|
|
# bulk, rather than one call per message.
|
2003-01-09 03:16:07 +01:00
|
|
|
addflaglist = {}
|
|
|
|
delflaglist = {}
|
2011-03-11 10:50:18 +01:00
|
|
|
for uid in self.getmessageuidlist():
|
2011-08-16 12:16:46 +02:00
|
|
|
# Ignore messages with negative UIDs missed by pass 1 and
|
|
|
|
# don't do anything if the message has been deleted remotely
|
2011-03-11 10:50:18 +01:00
|
|
|
if uid < 0 or not dstfolder.uidexists(uid):
|
2002-06-20 06:37:36 +02:00
|
|
|
continue
|
2002-06-20 05:50:58 +02:00
|
|
|
|
2012-10-16 20:20:35 +02:00
|
|
|
if statusfolder.uidexists(uid):
|
|
|
|
statusflags = statusfolder.getmessageflags(uid)
|
|
|
|
else:
|
2011-08-16 12:16:46 +02:00
|
|
|
statusflags = set()
|
|
|
|
|
2015-11-20 20:09:12 +01:00
|
|
|
selfflags = self.combine_flags_and_keywords(uid, dstfolder)
|
2015-11-20 20:09:11 +01:00
|
|
|
|
2011-08-16 12:16:46 +02:00
|
|
|
addflags = selfflags - statusflags
|
|
|
|
delflags = statusflags - selfflags
|
2003-01-09 03:16:07 +01:00
|
|
|
|
|
|
|
for flag in addflags:
|
2020-08-30 12:42:28 +02:00
|
|
|
if flag not in addflaglist:
|
2003-01-09 03:16:07 +01:00
|
|
|
addflaglist[flag] = []
|
|
|
|
addflaglist[flag].append(uid)
|
2002-06-20 06:14:54 +02:00
|
|
|
|
2003-01-09 03:16:07 +01:00
|
|
|
for flag in delflags:
|
2020-08-30 12:42:28 +02:00
|
|
|
if flag not in delflaglist:
|
2003-01-09 03:16:07 +01:00
|
|
|
delflaglist[flag] = []
|
|
|
|
delflaglist[flag].append(uid)
|
2002-06-20 06:37:36 +02:00
|
|
|
|
2020-08-28 03:32:43 +02:00
|
|
|
for flag, uids in list(addflaglist.items()):
|
2011-08-16 12:16:46 +02:00
|
|
|
self.ui.addingflags(uids, flag, dstfolder)
|
2011-09-16 11:44:50 +02:00
|
|
|
if self.repository.account.dryrun:
|
2020-08-29 19:39:31 +02:00
|
|
|
continue # Don't actually add in a dryrun.
|
2011-08-16 12:16:46 +02:00
|
|
|
dstfolder.addmessagesflags(uids, set(flag))
|
|
|
|
statusfolder.addmessagesflags(uids, set(flag))
|
2011-04-27 12:15:49 +02:00
|
|
|
|
2020-08-28 03:32:43 +02:00
|
|
|
for flag, uids in list(delflaglist.items()):
|
2011-08-16 12:16:46 +02:00
|
|
|
self.ui.deletingflags(uids, flag, dstfolder)
|
2011-09-16 11:44:50 +02:00
|
|
|
if self.repository.account.dryrun:
|
2020-08-29 19:39:31 +02:00
|
|
|
continue # Don't actually remove in a dryrun.
|
2011-08-16 12:16:46 +02:00
|
|
|
dstfolder.deletemessagesflags(uids, set(flag))
|
|
|
|
statusfolder.deletemessagesflags(uids, set(flag))
|
2013-07-21 21:00:23 +02:00
|
|
|
|
2011-03-06 20:03:04 +01:00
|
|
|
def syncmessagesto(self, dstfolder, statusfolder):
|
|
|
|
"""Syncs messages in this folder to the destination dstfolder.
|
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
|
|
|
|
2011-03-06 20:03:04 +01:00
|
|
|
This is the high level entry for syncing messages in one direction.
|
|
|
|
Syncsteps are:
|
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
|
|
|
|
2011-03-24 17:45:21 +01:00
|
|
|
Pass1: Copy locally existing messages
|
2011-03-06 20:03:04 +01:00
|
|
|
Copy messages in self, but not statusfolder to dstfolder if not
|
2011-03-24 17:45:21 +01:00
|
|
|
already in dstfolder. dstfolder might assign a new UID (e.g. if
|
|
|
|
uploading to IMAP). Update statusfolder.
|
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
|
|
|
|
2011-03-24 17:45:21 +01:00
|
|
|
Pass2: Remove locally deleted messages
|
2011-03-06 20:03:04 +01:00
|
|
|
Get all UIDS in statusfolder but not self. These are messages
|
|
|
|
that were deleted in 'self'. Delete those from dstfolder and
|
|
|
|
statusfolder.
|
2002-06-25 06:47:09 +02:00
|
|
|
|
2011-03-06 20:03:04 +01:00
|
|
|
After this pass, the message lists should be identical wrt the
|
|
|
|
uids present (except for potential negative uids that couldn't
|
|
|
|
be placed anywhere).
|
|
|
|
|
2013-07-21 21:00:23 +02:00
|
|
|
Pass3: Synchronize flag changes
|
2011-03-06 20:03:04 +01:00
|
|
|
Compare flag mismatches in self with those in statusfolder. If
|
|
|
|
msg has a valid UID and exists on dstfolder (has not e.g. been
|
|
|
|
deleted there), sync the flag change to both dstfolder and
|
|
|
|
statusfolder.
|
|
|
|
|
2012-10-17 21:45:19 +02:00
|
|
|
Pass4: Synchronize label changes (Gmail only)
|
|
|
|
Compares label mismatches in self with those in statusfolder.
|
|
|
|
If msg has a valid UID and exists on dstfolder, syncs the labels
|
|
|
|
to both dstfolder and statusfolder.
|
|
|
|
|
2011-03-06 20:03:04 +01:00
|
|
|
:param dstfolder: Folderinstance to sync the msgs to.
|
|
|
|
:param statusfolder: LocalStatus instance to sync against.
|
2012-10-17 21:45:19 +02:00
|
|
|
"""
|
2015-01-08 17:13:33 +01:00
|
|
|
|
2016-07-18 18:40:17 +02:00
|
|
|
for action in self.syncmessagesto_passes:
|
2016-06-27 15:03:27 +02:00
|
|
|
# Bail out on CTRL-C or SIGTERM.
|
2012-01-04 19:24:19 +01:00
|
|
|
if offlineimap.accounts.Account.abort_NOW_signal.is_set():
|
|
|
|
break
|
2011-03-06 20:03:04 +01:00
|
|
|
try:
|
|
|
|
action(dstfolder, statusfolder)
|
|
|
|
except (KeyboardInterrupt):
|
|
|
|
raise
|
2012-02-05 10:14:23 +01:00
|
|
|
except OfflineImapError as e:
|
2011-08-11 12:22:35 +02:00
|
|
|
if e.severity > OfflineImapError.ERROR.FOLDER:
|
|
|
|
raise
|
2020-08-29 19:39:31 +02:00
|
|
|
self.ui.error(e, exc_info()[2], "while syncing %s [account %s]" %
|
|
|
|
(self, self.accountname))
|
2012-02-05 10:14:23 +01:00
|
|
|
except Exception as e:
|
2020-08-29 19:39:31 +02:00
|
|
|
self.ui.error(e, exc_info()[2], "while syncing %s [account %s]" %
|
|
|
|
(self, self.accountname))
|
|
|
|
raise # Raise unknown Exceptions so we can fix them.
|
2012-02-16 11:03:33 +01:00
|
|
|
|
|
|
|
def __eq__(self, other):
|
|
|
|
"""Comparisons work either on string comparing folder names or
|
2015-01-14 22:58:25 +01:00
|
|
|
on the same instance.
|
2012-02-16 11:03:33 +01:00
|
|
|
|
|
|
|
MailDirFolder('foo') == 'foo' --> True
|
|
|
|
a = MailDirFolder('foo'); a == b --> True
|
|
|
|
MailDirFolder('foo') == 'moo' --> False
|
|
|
|
MailDirFolder('foo') == IMAPFolder('foo') --> False
|
|
|
|
MailDirFolder('foo') == MaildirFolder('foo') --> False
|
|
|
|
"""
|
2015-01-08 17:13:33 +01:00
|
|
|
|
2016-05-08 15:29:41 +02:00
|
|
|
if isinstance(other, str):
|
2012-02-16 11:03:33 +01:00
|
|
|
return other == self.name
|
|
|
|
return id(self) == id(other)
|
|
|
|
|
|
|
|
def __ne__(self, other):
|
|
|
|
return not self.__eq__(other)
|