[PATCH/RFC 5/7] Alterations to existing methods needed by the update process

Hubert Pineault hpineault at riseup.net
Sun Mar 3 08:57:01 GMT 2019


account.SyncableAccount.syncrunner():

  The update process uses two SyncableAccount instance (new and old)
  for each account found in both config files. To initialize repos, we
  use syncrunner in order to loop for imap connection and deal with
  exceptions. When in an update process, syncrunner will call
  self.get_folderlist(). Exceptions, error messages and loop handling
  are altered to deal with updating.

  I think this method should be left to its original state and the
  whole repos initialization for the update process should be in a
  distinct method.

folder.IMAP.IMAPFolder.__init__():

  Add self.imap_name, which store original imap name returned in utf7 encoding.

  With the implentation of utf8 decoding option (utf8foldernames), the
  imap name gets replaced if the option is enabled. The update process
  needs to know the original imap return (in utf7 encode) in order to
  match a config file where the utf8foldernames is enabled with a
  config file where it's disabled. (Note that the new methods
  self.getimapname returns self.imap_name)

repository.Base.Baserepository.__init__():

  Remove initialization of self.uiddir and self.mapdir. Call
  self.getmedata() where initialization is handled and the new
  property self.metadatadir is added.

repository.LocalStatus.LocalStatusRepository.__init__():

  Same logic as for Baserepository.__init__(), but specific for
  localrepos. Remove initialization of self.backend.

Signed-off-by: Hubert Pineault <hpineault at riseup.net>
---
 offlineimap/folder/IMAP.py            |  6 ++++--
 offlineimap/repository/Base.py        | 13 +++----------
 offlineimap/repository/LocalStatus.py | 25 +------------------------
 3 files changed, 8 insertions(+), 36 deletions(-)

diff --git a/offlineimap/folder/IMAP.py b/offlineimap/folder/IMAP.py
index 3a716e4..ee7ab39 100644
--- a/offlineimap/folder/IMAP.py
+++ b/offlineimap/folder/IMAP.py
@@ -49,9 +49,11 @@ class IMAPFolder(BaseFolder):
         #    querying the IMAP server, while False is used when creating
         #    a folder object from a locally available utf_8 name)
         # In any case the given name is first dequoted.
-        name = imaputil.dequote(name)
+        self.imap_name = imaputil.dequote(name)  # For update-conf mode
         if decode and repository.account.utf_8_support:
-            name = imaputil.IMAP_utf8(name)
+            name = imaputil.IMAP_utf8(self.imap_name)
+        else:
+            name = self.imap_name
         self.sep = imapserver.delim
         super(IMAPFolder, self).__init__(name, repository)
         if repository.getdecodefoldernames():
diff --git a/offlineimap/repository/Base.py b/offlineimap/repository/Base.py
index 60f926c..0a58612 100644
--- a/offlineimap/repository/Base.py
+++ b/offlineimap/repository/Base.py
@@ -34,16 +34,9 @@ class BaseRepository(CustomConfig.ConfigHelperMixin):
         self.localeval = account.getlocaleval()
         self._accountname = self.account.getname()
         self._readonly = self.getconfboolean('readonly', False)
-        self.uiddir = os.path.join(self.config.getmetadatadir(), 'Repository-' + self.name)
-        if not os.path.exists(self.uiddir):
-            os.mkdir(self.uiddir, 0o700)
-        self.mapdir = os.path.join(self.uiddir, 'UIDMapping')
-        if not os.path.exists(self.mapdir):
-            os.mkdir(self.mapdir, 0o700)
-        # FIXME: self.uiddir variable name is lying about itself.
-        self.uiddir = os.path.join(self.uiddir, 'FolderValidity')
-        if not os.path.exists(self.uiddir):
-            os.mkdir(self.uiddir, 0o700)
+
+        self.mapdir = self.uiddir = self.metadatadir = None
+        self.getmetadata()
 
         self.nametrans = lambda foldername: foldername
         self.folderfilter = lambda foldername: 1
diff --git a/offlineimap/repository/LocalStatus.py b/offlineimap/repository/LocalStatus.py
index 4ad2315..605093a 100644
--- a/offlineimap/repository/LocalStatus.py
+++ b/offlineimap/repository/LocalStatus.py
@@ -26,30 +26,7 @@ from offlineimap.error import OfflineImapError
 class LocalStatusRepository(BaseRepository):
     def __init__(self, reposname, account):
         BaseRepository.__init__(self, reposname, account)
-
-        # class and root for all backends.
-        self.backends = {}
-        self.backends['sqlite'] = {
-            'class': LocalStatusSQLiteFolder,
-            'root': os.path.join(account.getaccountmeta(), 'LocalStatus-sqlite')
-        }
-        self.backends['plain'] = {
-            'class': LocalStatusFolder,
-            'root': os.path.join(account.getaccountmeta(), 'LocalStatus')
-        }
-
-        if self.account.getconf('status_backend', None) is not None:
-            raise OfflineImapError(
-                "the 'status_backend' configuration option is not supported"
-                " anymore; please, remove this configuration option.",
-                OfflineImapError.ERROR.REPO
-            )
-        # Set class and root for sqlite.
-        self.setup_backend('sqlite')
-
-        if not os.path.exists(self.root):
-            os.mkdir(self.root, 0o700)
-
+        self.getmetadata()
         # self._folders is a dict of name:LocalStatusFolders().
         self._folders = {}
 
-- 
2.11.0




More information about the OfflineIMAP-project mailing list