summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
Diffstat (limited to 'service')
-rw-r--r--service/app/adapter/mail_converter.py8
-rw-r--r--service/app/pixelated_user_agent.py16
-rw-r--r--service/app/tags.py2
-rw-r--r--service/test/adapter/mail_service_test.py6
4 files changed, 19 insertions, 13 deletions
diff --git a/service/app/adapter/mail_converter.py b/service/app/adapter/mail_converter.py
index cf793a7a..28b83d6d 100644
--- a/service/app/adapter/mail_converter.py
+++ b/service/app/adapter/mail_converter.py
@@ -1,6 +1,14 @@
import dateutil.parser as dateparser
+
class MailConverter:
+ LEAP_FLAGS = ['\\Seen',
+ '\\Answered',
+ '\\Flagged',
+ '\\Deleted',
+ '\\Draft',
+ '\\Recent',
+ 'List']
def __init__(self, mail_service):
pass
diff --git a/service/app/pixelated_user_agent.py b/service/app/pixelated_user_agent.py
index f5bc9a3a..a51fc905 100644
--- a/service/app/pixelated_user_agent.py
+++ b/service/app/pixelated_user_agent.py
@@ -6,10 +6,9 @@ from flask import Flask, request, Response
import app.search_query as search_query
from app.adapter.mail_service import MailService
from app.adapter.mail_converter import MailConverter
-from app.tags import Tag
+from app.adapter.pixelated_mail import PixelatedMail
from app.tags import Tags
-
app = Flask(__name__, static_url_path='', static_folder='../../web-ui/app')
mail_service = MailService()
@@ -57,13 +56,15 @@ def update_draft():
@app.route('/mails')
def mails():
query = search_query.compile(request.args.get("q")) if request.args.get("q") else {'tags': {}}
- mails = mail_service.drafts() if "drafts" in query['tags'] else mail_service.mails(query)
- mails = [converter.from_mail(mail) for mail in mails]
+
+ mails = [PixelatedMail(mail) for mail in mail_service.mails(query)]
if "inbox" in query['tags']:
- mails = [mail for mail in mails if (lambda mail: "trash" not in mail['tags'])(mail)]
+ mails = [mail for mail in mails if not mail.has_tag('trash')]
+
+ mails = sorted(mails, key=lambda mail: dateparser.parse(mail.headers['date']), reverse=True)
- mails = sorted(mails, key=lambda mail: dateparser.parse(mail['header']['date']), reverse=True)
+ mails = [mail.as_dict() for mail in mails]
response = {
"stats": {
@@ -93,7 +94,8 @@ def tags():
@app.route('/mail/<mail_id>')
def mail(mail_id):
mail = mail_service.mail(mail_id)
- return respond_json(converter.from_mail(mail))
+ mail = PixelatedMail(mail)
+ return respond_json(mail.as_dict())
@app.route('/mail/<mail_id>/tags')
diff --git a/service/app/tags.py b/service/app/tags.py
index 78d594dd..0f874850 100644
--- a/service/app/tags.py
+++ b/service/app/tags.py
@@ -3,7 +3,7 @@ import json
class Tag:
- def __init__(self, name, default):
+ def __init__(self, name, default=False):
self.name = name
self.default = default
self.ident = name.__hash__()
diff --git a/service/test/adapter/mail_service_test.py b/service/test/adapter/mail_service_test.py
index 9c1c4b00..0828f20a 100644
--- a/service/test/adapter/mail_service_test.py
+++ b/service/test/adapter/mail_service_test.py
@@ -1,8 +1,4 @@
-import sys
-import os
import unittest
-from mock import patch
-from mock import Mock
from app.adapter.mail_service import MailService
@@ -18,4 +14,4 @@ class MailboxException(Exception):
class TestMailService(unittest.TestCase):
def setUp(self):
- self.mail_service = MailService() \ No newline at end of file
+ self.mail_service = MailService()