aboutsummaryrefslogtreecommitdiffstats
path: root/archive_folder.py
diff options
context:
space:
mode:
Diffstat (limited to 'archive_folder.py')
-rwxr-xr-xarchive_folder.py32
1 files changed, 20 insertions, 12 deletions
diff --git a/archive_folder.py b/archive_folder.py
index 2b3ba14..e321dfe 100755
--- a/archive_folder.py
+++ b/archive_folder.py
@@ -27,23 +27,15 @@ log = logging.getLogger('imapArch')
class ServerError(IOError):
pass
-
class FolderError(IOError):
pass
-
class MessageError(IOError):
pass
Capas = collections.namedtuple('Capas', ['MOVE', 'UIDPLUS'])
-def get_config():
- config = configparser.ConfigParser()
- config.read(os.path.expanduser('~/.config/imap_archiver.cfg'))
- return config
-
-
class Message(object):
"""Abstraction over one email message."""
def __init__(self, client, uid):
@@ -194,10 +186,17 @@ class Folder(object):
class EmailServer(object):
def __init__(self, serverKey=None, archive_root=None):
- config = get_config()
+ config = self.get_config()
acc_name = serverKey if serverKey is not None \
else config['general']['account']
- self.cfg = dict(config.items(acc_name))
+ if config.has_section(acc_name):
+ self.cfg = dict(config.items(acc_name))
+ else:
+ self.cfg = {
+ 'host': 'localhost',
+ 'username': 'unknown',
+ 'password': 'verysecret'
+ }
self.archive_root = archive_root
self.__box = self.__login(**self.cfg)
@@ -215,6 +214,15 @@ class EmailServer(object):
box.features_present = Capas._make(['MOVE' in capas, 'UIDPLUS' in capas])
log.debug('features_present = %s', box.features_present)
+ @staticmethod
+ @functools.lru_cache()
+ def get_config():
+ # In case the configuration file is missing, only empty list will be
+ # returned
+ config = configparser.ConfigParser()
+ config.read(os.path.expanduser('~/.config/imap_archiver.cfg'))
+ return config
+
def archive_folder(self, folder_name, before_date):
# type: (str, datetime.date) -> None
"""
@@ -270,8 +278,8 @@ if __name__ == '__main__':
args = argp.parse_args()
- if args.cmd == 'list':
- config = get_config()
+ if args.cmd == 'servers':
+ config = EmailServer.get_config()
sects = set(config.keys()) - {'DEFAULT', 'general'}
print('Available servers:\n%s' % tuple(sects))
else: