summaryrefslogtreecommitdiff
path: root/email_assistant/assistant.py
diff options
context:
space:
mode:
Diffstat (limited to 'email_assistant/assistant.py')
-rw-r--r--email_assistant/assistant.py36
1 files changed, 28 insertions, 8 deletions
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
37# Number of days to look backwards when scanning a mailbox for the first time: 37# Number of days to look backwards when scanning a mailbox for the first time:
38IMAP_BACKFILL = 180 38IMAP_BACKFILL = 180
39 39
40class Mailbox: 40class IMAPMailbox:
41 def __init__(self, name, host, username, password, folders): 41 def __init__(self, name, host, username, password, folders):
42 self.log = logging.getLogger('assistant.mailbox') 42 self.log = logging.getLogger('assistant.mailbox')
43 self.name = name 43 self.name = name
@@ -85,6 +85,21 @@ class Mailbox:
85 with open(self.state_file, 'w') as f: 85 with open(self.state_file, 'w') as f:
86 json.dump(self.uidinfo, f) 86 json.dump(self.uidinfo, f)
87 87
88class DirMailbox:
89 def __init__(self, name, directory):
90 self.log = logging.getLogger('assistant.mailbox')
91 self.name = name
92 self.directory = directory
93
94 def get_messages(self):
95 for fn in os.listdir(self.directory):
96 with open(os.path.join(self.directory, fn), 'rb') as f:
97 msg = f.read()
98 yield msg
99
100 def save(self):
101 pass
102
88class Calendar: 103class Calendar:
89 def __init__(self, url, username, password, calendar): 104 def __init__(self, url, username, password, calendar):
90 self.log = logging.getLogger('assistant.calendar') 105 self.log = logging.getLogger('assistant.calendar')
@@ -116,7 +131,7 @@ class Calendar:
116 131
117class Assistant: 132class Assistant:
118 def __init__(self): 133 def __init__(self):
119 self.log = logging.getLogger('main') 134 self.log = logging.getLogger('assistant.main')
120 self.geolocator = None 135 self.geolocator = None
121 self.tzfinder = None 136 self.tzfinder = None
122 self.plugins = [] 137 self.plugins = []
@@ -151,12 +166,17 @@ class Assistant:
151 for section in config.sections(): 166 for section in config.sections():
152 if section.startswith('mailbox '): 167 if section.startswith('mailbox '):
153 name = section.split()[1] 168 name = section.split()[1]
154 mailboxes[name] = Mailbox( 169 if config[section]['type'].lower() == 'imap':
155 name, 170 mailboxes[name] = IMAPMailbox(
156 config[section]['host'], 171 name,
157 config[section]['username'], 172 config[section]['host'],
158 config[section]['password'], 173 config[section]['username'],
159 config[section]['folders'].split(',')) 174 config[section]['password'],
175 config[section]['folders'].split(','))
176 elif config[section]['type'].lower() == 'dir':
177 mailboxes[name] = DirMailbox(
178 name,
179 config[section]['path'])
160 elif section.startswith('calendar '): 180 elif section.startswith('calendar '):
161 name = section.split()[1] 181 name = section.split()[1]
162 calendars[name] = Calendar( 182 calendars[name] = Calendar(