diff options
author | Duda Dornelles <ddornell@thoughtworks.com> | 2014-08-11 19:07:16 -0300 |
---|---|---|
committer | Duda Dornelles <ddornell@thoughtworks.com> | 2014-08-11 19:07:40 -0300 |
commit | 275e153af3bd5546525ad77b906e34539d70d351 (patch) | |
tree | 3d986990e6ab8c932700fcbf3becb7f74a953484 /py-fake-service/app/adapter | |
parent | 9aa5a0470631cabdb2974480449cffd5e4ef9ecb (diff) |
adding mailbox parsing to py-fake-server
Diffstat (limited to 'py-fake-service/app/adapter')
-rw-r--r-- | py-fake-service/app/adapter/__init__.py | 1 | ||||
-rw-r--r-- | py-fake-service/app/adapter/mail.py | 26 | ||||
-rw-r--r-- | py-fake-service/app/adapter/mail_service.py | 19 | ||||
-rw-r--r-- | py-fake-service/app/adapter/mailset.py | 14 |
4 files changed, 60 insertions, 0 deletions
diff --git a/py-fake-service/app/adapter/__init__.py b/py-fake-service/app/adapter/__init__.py new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/py-fake-service/app/adapter/__init__.py @@ -0,0 +1 @@ + diff --git a/py-fake-service/app/adapter/mail.py b/py-fake-service/app/adapter/mail.py new file mode 100644 index 00000000..1140f062 --- /dev/null +++ b/py-fake-service/app/adapter/mail.py @@ -0,0 +1,26 @@ +from datetime import datetime + +class Mail: + + def __init__(self, mbox_mail, ident): + self.header = self._get_headers(mbox_mail) + self.ident = ident + self.body = mbox_mail.get_payload() + self.tags = self._get_tags(mbox_mail) + self.security_casing = {} + self.status = [] + + def _get_headers(self, mbox_mail): + headers = {} + headers['from'] = mbox_mail.get_from() + headers['to'] = [mbox_mail.items()['To']] + headers['subject'] = mbox_mail.items()['Subject'] + headers['date'] = datetime.fromtimestamp(random.randrange(1222222222, 1444444444)).isoformat() + return headers + + def _get_tags(self, mbox_mail): + return mbox_mail.items()['X-TW-Pixelated-Tags'].split(', ') + + + + diff --git a/py-fake-service/app/adapter/mail_service.py b/py-fake-service/app/adapter/mail_service.py new file mode 100644 index 00000000..b657e59a --- /dev/null +++ b/py-fake-service/app/adapter/mail_service.py @@ -0,0 +1,19 @@ +import os +import mailbox + + +class MailService: + MAILSET_PATH = os.join(os.environ('HOME'), 'mailset', 'mediumtagged')) + + def __init__(self): + self.mails = MailSet() + + def load_mailset(self): + mbox_filenames = [filename for filename in os.listdir(MAILSET_PATH) if mbox.startswith('mbox')] + boxes = (mailbox.mbox(os.path.join(MAILSET_PATH, mbox)) for mbox in mbox_filenames) + + for box in boxes: + message = box.popitem() + self.mails.add(message[1]) + + diff --git a/py-fake-service/app/adapter/mailset.py b/py-fake-service/app/adapter/mailset.py new file mode 100644 index 00000000..d81600e0 --- /dev/null +++ b/py-fake-service/app/adapter/mailset.py @@ -0,0 +1,14 @@ +from mail import Mail + + +class MailSet: + + def __init__(self): + self.ident = 0 + self.mails = {} + + def add(self, mbox_mail): + self.mails[self.ident] = Mail(mbox_mail) + self.ident += 1 + + |