diff options
-rw-r--r-- | service/pixelated/adapter/pixelated_mail.py | 84 | ||||
-rw-r--r-- | service/pixelated/adapter/pixelated_mail_sender.py | 2 | ||||
-rw-r--r-- | service/pixelated/adapter/search.py | 2 | ||||
-rw-r--r-- | service/pixelated/controllers/mails_controller.py | 2 |
4 files changed, 35 insertions, 55 deletions
diff --git a/service/pixelated/adapter/pixelated_mail.py b/service/pixelated/adapter/pixelated_mail.py index 6ebcc089..735560c9 100644 --- a/service/pixelated/adapter/pixelated_mail.py +++ b/service/pixelated/adapter/pixelated_mail.py @@ -25,21 +25,28 @@ from email.MIMEText import MIMEText from pycryptopp.hash import sha256 -class InputMail: - FROM_EMAIL_ADDRESS = None +class Mail: - def __init__(self): - self._raw_message = None - self._fd = None - self._hd = None - self._bd = None - self._mime = None - self._chash = None + @property + def to(self): + return self.headers['To'] + + @property + def cc(self): + return self.headers['Cc'] + + @property + def bcc(self): + return self.headers['Bcc'] + + @property + def date(self): + return self.headers['Date'] def as_dict(self): statuses = [status.name for status in self.status] return { - 'header': self.headers, + 'header': {k.lower(): v for k, v in self.headers.items()}, 'ident': self.ident, 'tags': list(self.tags), 'status': statuses, @@ -47,6 +54,18 @@ class InputMail: 'body': self.body } + +class InputMail(Mail): + FROM_EMAIL_ADDRESS = None + + def __init__(self): + self._raw_message = None + self._fd = None + self._hd = None + self._bd = None + self._mime = None + self._chash = None + @property def _mime_multipart(self): if self._mime: @@ -117,15 +136,6 @@ class InputMail: def _cdocs(self): return walk.get_raw_docs(self._mime_multipart, self._mime_multipart.walk()) - def get_to(self): - return self.headers['To'] - - def get_cc(self): - return self.headers['Cc'] - - def get_bcc(self): - return self.headers['Bcc'] - def to_mime_multipart(self): mime_multipart = MIMEMultipart() @@ -156,7 +166,7 @@ class InputMail: return input_mail -class PixelatedMail: +class PixelatedMail(Mail): @staticmethod def from_soledad(fdoc, hdoc, bdoc, soledad_querier=None): @@ -197,10 +207,10 @@ class PixelatedMail: @property def status(self): - return Status.from_flags(self._flags) + return Status.from_flags(self.flags) @property - def _flags(self): + def flags(self): return self.fdoc.content.get('flags') @property @@ -234,24 +244,6 @@ class PixelatedMail: def set_mailbox(self, mailbox_name): self.fdoc.content['mbox'] = mailbox_name - def set_recent(self): - self.fdoc.content['flags'].append("\\Recent") - - def set_from(self, _from): - self.headers['From'] = [_from] - - def get_to(self): - return self.headers['To'] - - def get_cc(self): - return self.headers['Cc'] - - def get_bcc(self): - return self.headers['Bcc'] - - def get_date(self): - return self.headers['Date'] - def remove_all_tags(self): self.update_tags(set([])) @@ -282,15 +274,3 @@ class PixelatedMail: def has_tag(self, tag): return tag in self.tags - - def as_dict(self): - statuses = [status.name for status in self.status] - return { - 'header': {k.lower(): v for k, v in self.headers.items()}, - 'ident': self.ident, - 'tags': list(self.tags), - 'mailbox': self.mailbox_name, - 'status': statuses, - 'security_casing': self.security_casing, - 'body': self.body - } diff --git a/service/pixelated/adapter/pixelated_mail_sender.py b/service/pixelated/adapter/pixelated_mail_sender.py index cf30779f..bae86cd2 100644 --- a/service/pixelated/adapter/pixelated_mail_sender.py +++ b/service/pixelated/adapter/pixelated_mail_sender.py @@ -24,7 +24,7 @@ class PixelatedMailSender(): self.smtp_client = smtp_client or smtplib.SMTP('localhost', 4650) def sendmail(self, mail): - recipients = flatten([mail.get_to(), mail.get_cc(), mail.get_bcc()]) + recipients = flatten([mail.to, mail.cc, mail.bcc]) self.smtp_client.sendmail( self.account_email_address, diff --git a/service/pixelated/adapter/search.py b/service/pixelated/adapter/search.py index 69456932..859497bb 100644 --- a/service/pixelated/adapter/search.py +++ b/service/pixelated/adapter/search.py @@ -98,7 +98,7 @@ class SearchEngine(object): 'tag': u','.join(tags), 'body': unicode(mdict['body']), 'ident': unicode(mdict['ident']), - 'flags': unicode(','.join(mail._flags)) + 'flags': unicode(','.join(mail.flags)) } writer.update_document(**index_data) diff --git a/service/pixelated/controllers/mails_controller.py b/service/pixelated/controllers/mails_controller.py index 26b35831..f54fa959 100644 --- a/service/pixelated/controllers/mails_controller.py +++ b/service/pixelated/controllers/mails_controller.py @@ -31,7 +31,7 @@ class MailsController: def mails(self, _request=request): mail_ids = self._search_engine.search(_request.args.get('q')) mails = self._mail_service.mails(mail_ids) - mails = sorted(mails, key=lambda mail: dateparser.parse(mail.get_date()), reverse=True) + mails = sorted(mails, key=lambda mail: dateparser.parse(mail.date), reverse=True) response = { "stats": { |