summaryrefslogtreecommitdiff
path: root/service/pixelated/adapter
diff options
context:
space:
mode:
Diffstat (limited to 'service/pixelated/adapter')
-rw-r--r--service/pixelated/adapter/mail_service.py6
-rw-r--r--service/pixelated/adapter/pixelated_mail.py17
-rw-r--r--service/pixelated/adapter/pixelated_mailbox.py8
-rw-r--r--service/pixelated/adapter/pixelated_mailboxes.py6
4 files changed, 28 insertions, 9 deletions
diff --git a/service/pixelated/adapter/mail_service.py b/service/pixelated/adapter/mail_service.py
index 1183dae2..5f651187 100644
--- a/service/pixelated/adapter/mail_service.py
+++ b/service/pixelated/adapter/mail_service.py
@@ -14,6 +14,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
from pixelated.adapter.tag_service import TagService
+from pixelated.support.id_gen import gen_pixelated_uid
class MailService:
@@ -33,7 +34,7 @@ class MailService:
if query['tags']:
_mails = self.mailboxes.mails_by_tag(query['tags'])
- return sorted(_mails or [], key=lambda mail: mail.date, reverse=True)
+ return sorted(_mails or [], key=lambda mail: mail.headers['date'], reverse=True)
def update_tags(self, mail_id, new_tags):
mail = self.mail(mail_id)
@@ -48,8 +49,7 @@ class MailService:
self.mail_sender.sendmail(mail)
def create_draft(self, mail):
- drafts = self.mailboxes.drafts()
- drafts.add(mail)
+ return self.mailboxes.add_draft(mail)
def send_draft(self, mail):
pass
diff --git a/service/pixelated/adapter/pixelated_mail.py b/service/pixelated/adapter/pixelated_mail.py
index df9b4bbe..92b55ad4 100644
--- a/service/pixelated/adapter/pixelated_mail.py
+++ b/service/pixelated/adapter/pixelated_mail.py
@@ -25,7 +25,13 @@ from email.MIMEText import MIMEText
class PixelatedMail:
def __init__(self):
- pass
+ self.body = ''
+ self.headers = {}
+ self.ident = None
+ self.status = []
+ self.security_casing = {}
+ self.tags = []
+ self.ident = None
@staticmethod
def from_leap_mail(leap_mail, leap_mailbox=None):
@@ -34,7 +40,7 @@ class PixelatedMail:
mail.leap_mailbox = leap_mailbox
mail.body = leap_mail.bdoc.content['raw']
mail.headers = mail._extract_headers()
- mail.date = PixelatedMail._get_date(mail.headers)
+ mail.headers['date'] = PixelatedMail._get_date(mail.headers)
mail.status = set(mail._extract_status())
mail.security_casing = {}
mail.tags = mail._extract_tags()
@@ -121,10 +127,8 @@ class PixelatedMail:
def as_dict(self):
statuses = [status.name for status in self.status]
- _headers = self.headers.copy()
- _headers['date'] = self.date
return {
- 'header': _headers,
+ 'header': self.headers,
'ident': self.ident,
'tags': list(self.tags),
'status': statuses,
@@ -147,6 +151,9 @@ class PixelatedMail:
mime_multipart['From'] = PixelatedMail.from_email_address
return mime_multipart.as_string()
+ def set_ident(self, mailbox_name, uid):
+ self.ident = gen_pixelated_uid(mailbox_name, uid)
+
@staticmethod
def from_dict(mail_dict):
return from_dict(mail_dict)
diff --git a/service/pixelated/adapter/pixelated_mailbox.py b/service/pixelated/adapter/pixelated_mailbox.py
index 191c171b..34c6c97b 100644
--- a/service/pixelated/adapter/pixelated_mailbox.py
+++ b/service/pixelated/adapter/pixelated_mailbox.py
@@ -16,6 +16,7 @@
from pixelated.adapter.pixelated_mail import PixelatedMail
from pixelated.adapter.tag_service import TagService
+from crochet import wait_for
class PixelatedMailbox:
@@ -29,6 +30,10 @@ class PixelatedMailbox:
def messages(self):
return self.leap_mailbox.messages
+ @property
+ def mailbox_name(self):
+ return self.leap_mailbox.mbox
+
def add_mailbox_tag_if_not_there(self, pixelated_mail):
if not pixelated_mail.has_tag(self.mailbox_tag):
pixelated_mail.update_tags({self.mailbox_tag}.union(pixelated_mail.tags))
@@ -58,8 +63,9 @@ class PixelatedMailbox:
original_flags = mail.leap_mail.getFlags()
self.leap_mailbox.addMessage(mail.raw_message(), original_flags)
+ @wait_for(timeout=3.0)
def add(self, mail):
- self.leap_mailbox.messages.add_msg(mail.to_smtp_format())
+ return self.leap_mailbox.messages.add_msg(mail.to_smtp_format())
@classmethod
def create(cls, account, mailbox_name='INBOX'):
diff --git a/service/pixelated/adapter/pixelated_mailboxes.py b/service/pixelated/adapter/pixelated_mailboxes.py
index 50d0ddc4..4866dbe4 100644
--- a/service/pixelated/adapter/pixelated_mailboxes.py
+++ b/service/pixelated/adapter/pixelated_mailboxes.py
@@ -26,6 +26,12 @@ class PixelatedMailBoxes():
return mails
+ def add_draft(self, mail):
+ drafts = self.drafts()
+ draft_id = drafts.add(mail)
+ mail.set_ident(drafts.mailbox_name, draft_id)
+ return mail
+
def mail(self, mail_id):
for mailbox in self.mailboxes:
mail = mailbox.mail(mail_id)