docker-offlineimap/offlineimap/repository/__init__.py
Abdó Roig-Maranges 0e4afa9132 Make GmailFolder sync GMail labels
When synclabels config flag is set to "yes" for the GMail repo,
offlineimap fetches the message labels along with the messages, and
embeds them into the body under the header X-Keywords (or whatever
'labelsheader' was set to), as a comma separated list.

It also adds an extra pass to savemessageto, that performs label
synchronization on existing messages from GMail to local, the same way
it is done with flags.

We also introduce GmailMaildir repository that adds functionality to
change message labels.  It keeps track of messages modification time,
so one can quickly detect when the labels may have changed.

Signed-off-by: Eygene Ryabinkin <rea@codelabs.ru>
2014-05-06 23:36:06 +04:00

89 lines
3.5 KiB
Python

# Copyright (C) 2002-2007 John Goerzen <jgoerzen@complete.org>
# 2010 Sebastian Spaeth <Sebastian@SSpaeth.de> and contributors
#
# 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
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# 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
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
try:
from configparser import NoSectionError
except ImportError: #python2
from ConfigParser import NoSectionError
from offlineimap.repository.IMAP import IMAPRepository, MappedIMAPRepository
from offlineimap.repository.Gmail import GmailRepository
from offlineimap.repository.Maildir import MaildirRepository
from offlineimap.repository.GmailMaildir import GmailMaildirRepository
from offlineimap.repository.LocalStatus import LocalStatusRepository
from offlineimap.error import OfflineImapError
class Repository(object):
"""Abstract class that returns the correct Repository type
instance based on 'account' and 'reqtype', e.g. a
class:`ImapRepository` instance."""
def __new__(cls, account, reqtype):
"""
:param account: :class:`Account`
:param regtype: 'remote', 'local', or 'status'"""
if reqtype == 'remote':
name = account.getconf('remoterepository')
# We don't support Maildirs on the remote side.
typemap = {'IMAP': IMAPRepository,
'Gmail': GmailRepository}
elif reqtype == 'local':
name = account.getconf('localrepository')
typemap = {'IMAP': MappedIMAPRepository,
'Maildir': MaildirRepository,
'GmailMaildir': GmailMaildirRepository}
elif reqtype == 'status':
# create and return a LocalStatusRepository
name = account.getconf('localrepository')
return LocalStatusRepository(name, account)
else:
errstr = "Repository type %s not supported" % reqtype
raise OfflineImapError(errstr, OfflineImapError.ERROR.REPO)
# Get repository type
config = account.getconfig()
try:
repostype = config.get('Repository ' + name, 'type').strip()
except NoSectionError as e:
errstr = ("Could not find section '%s' in configuration. Required "
"for account '%s'." % ('Repository %s' % name, account))
raise OfflineImapError(errstr, OfflineImapError.ERROR.REPO)
try:
repo = typemap[repostype]
except KeyError:
errstr = "'%s' repository not supported for '%s' repositories." \
% (repostype, reqtype)
raise OfflineImapError(errstr, OfflineImapError.ERROR.REPO)
return repo(name, account)
def __init__(self, account, reqtype):
"""Load the correct Repository type and return that. The
__init__ of the corresponding Repository class will be
executed instead of this stub
:param account: :class:`Account`
:param regtype: 'remote', 'local', or 'status'
"""
pass