From 3177ba26421b730bdf475fc2e991eef9ab9ef067 Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Sun, 9 Jun 2019 10:05:11 -0700 Subject: Add support for Delta Also add an undocumented mailbox driver for a directory of files for ease of testing (this could probably become a maildir driver with a bit more work). Remove unecessary decode calls from the message traversal. --- email_assistant/assistant.py | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) (limited to 'email_assistant/assistant.py') diff --git a/email_assistant/assistant.py b/email_assistant/assistant.py index a784077..d39b016 100644 --- a/email_assistant/assistant.py +++ b/email_assistant/assistant.py @@ -37,7 +37,7 @@ from email_assistant import plugins # Number of days to look backwards when scanning a mailbox for the first time: IMAP_BACKFILL = 180 -class Mailbox: +class IMAPMailbox: def __init__(self, name, host, username, password, folders): self.log = logging.getLogger('assistant.mailbox') self.name = name @@ -85,6 +85,21 @@ class Mailbox: with open(self.state_file, 'w') as f: json.dump(self.uidinfo, f) +class DirMailbox: + def __init__(self, name, directory): + self.log = logging.getLogger('assistant.mailbox') + self.name = name + self.directory = directory + + def get_messages(self): + for fn in os.listdir(self.directory): + with open(os.path.join(self.directory, fn), 'rb') as f: + msg = f.read() + yield msg + + def save(self): + pass + class Calendar: def __init__(self, url, username, password, calendar): self.log = logging.getLogger('assistant.calendar') @@ -116,7 +131,7 @@ class Calendar: class Assistant: def __init__(self): - self.log = logging.getLogger('main') + self.log = logging.getLogger('assistant.main') self.geolocator = None self.tzfinder = None self.plugins = [] @@ -151,12 +166,17 @@ class Assistant: for section in config.sections(): if section.startswith('mailbox '): name = section.split()[1] - mailboxes[name] = Mailbox( - name, - config[section]['host'], - config[section]['username'], - config[section]['password'], - config[section]['folders'].split(',')) + if config[section]['type'].lower() == 'imap': + mailboxes[name] = IMAPMailbox( + name, + config[section]['host'], + config[section]['username'], + config[section]['password'], + config[section]['folders'].split(',')) + elif config[section]['type'].lower() == 'dir': + mailboxes[name] = DirMailbox( + name, + config[section]['path']) elif section.startswith('calendar '): name = section.split()[1] calendars[name] = Calendar( -- cgit v1.2.3