summaryrefslogtreecommitdiff
path: root/service/app
diff options
context:
space:
mode:
authorVictor Shyba <victor.shyba@gmail.com>2014-08-11 13:22:14 -0300
committerVictor Shyba <victor.shyba@gmail.com>2014-08-11 13:22:14 -0300
commit0d2f72acbf0541cb01b0d4321278539ff1120802 (patch)
treed3d20f6af1fbc845637659e50785f9e5e660a01c /service/app
parent1001079b06db84134bae419f993af127ad9bec05 (diff)
Mails is now working and the tags call is returning hardcoded values for now
Diffstat (limited to 'service/app')
-rw-r--r--service/app/adapter/mail_converter.py24
-rw-r--r--service/app/adapter/mail_service.py12
-rw-r--r--service/app/pixelated_user_agent.py31
3 files changed, 56 insertions, 11 deletions
diff --git a/service/app/adapter/mail_converter.py b/service/app/adapter/mail_converter.py
index a77fcdb7..cf793a7a 100644
--- a/service/app/adapter/mail_converter.py
+++ b/service/app/adapter/mail_converter.py
@@ -1,11 +1,33 @@
+import dateutil.parser as dateparser
+
class MailConverter:
def __init__(self, mail_service):
pass
+ def date_to_iso(self, date):
+ return dateparser.parse(date).isoformat()
+
def from_mail(self, imap_mail):
- return inbox_mail
+ headers = imap_mail.hdoc.content['headers']
+ body = imap_mail.bdoc.content
+
+ return {
+ 'header': {
+ 'from': [headers['From']],
+ 'to': [headers['To']],
+ 'cc': headers.get('CC', []),
+ 'bcc': headers.get('BCC', []),
+ 'date': self.date_to_iso(headers['Date']),
+ 'subject': headers['Subject']
+ },
+ 'ident': imap_mail.getUID(),
+ 'tags': imap_mail.getFlags(),
+ 'status': [],
+ 'security_casing': {},
+ 'body': body['raw']
+ }
def to_mail(self, pixelated_mail, account):
raise NotImplementedError()
diff --git a/service/app/adapter/mail_service.py b/service/app/adapter/mail_service.py
index 7b33c290..a08b73f9 100644
--- a/service/app/adapter/mail_service.py
+++ b/service/app/adapter/mail_service.py
@@ -49,11 +49,7 @@ class MailService:
self.mailbox = self.account.getMailbox(self.mailbox_name)
def mails(self, query):
- if query.get('tags', False) and len(query['tags']):
- mailbox = self._switch_mailbox(query['tags'][0])
- return [m for m in mailbox.messages] if mailbox else []
- else:
- return []
+ return self.mailbox.messages or []
def _switch_mailbox(self, name):
mailbox = None
@@ -79,7 +75,9 @@ class MailService:
return []
def mail(self, mail_id):
- raise NotImplementedError()
+ for message in self.mailbox.messages:
+ if message.getUID() == int(mail_id):
+ return message
def thread(self, thread_id):
raise NotImplementedError()
@@ -116,4 +114,4 @@ class MailService:
if __name__ == '__main__':
print('Running Standalone')
- client = Client()
+ client = Client() \ No newline at end of file
diff --git a/service/app/pixelated_user_agent.py b/service/app/pixelated_user_agent.py
index 42c16262..eed47554 100644
--- a/service/app/pixelated_user_agent.py
+++ b/service/app/pixelated_user_agent.py
@@ -60,7 +60,7 @@ def mails():
if "inbox" in query['tags']:
mails = [mail for mail in mails if (lambda mail: "trash" not in mail['tags'])(mail)]
- mails = sorted(mails, key=lambda mail: mail['header']['date'], reverse=True)
+ # mails = sorted(mails, key=lambda mail: mail['header']['date'], reverse=True)
response = {
"stats": {
@@ -83,8 +83,8 @@ def delete_mails(mail_id):
@app.route('/tags')
def tags():
- tags = map(lambda x: converter.from_tag(x), mail_service.all_tags())
- return respond_json(tags)
+ #tags = map(lambda x: converter.from_tag(x), mail_service.all_tags())
+ return respond_json(['inbox'])
@app.route('/mail/<mail_id>')
@@ -127,9 +127,34 @@ def index():
def setup():
+ start_reactor()
app.config.from_envvar('PIXELATED_UA_CFG')
account = app.config['ACCOUNT']
app.run(host=app.config['HOST'], debug=app.config['DEBUG'], port=app.config['PORT'])
+from threading import Thread
+from twisted.internet import reactor
+
+import signal
+import sys
+def signal_handler(signal, frame):
+ stop_reactor_on_exit()
+ sys.exit(0)
+signal.signal(signal.SIGINT, signal_handler)
+
+def start_reactor():
+ def start_reactor_run():
+ reactor.run(False)
+
+ global REACTOR_THREAD
+ REACTOR_THREAD = Thread(target=start_reactor_run)
+ REACTOR_THREAD.start()
+
+
+def stop_reactor_on_exit():
+ reactor.callFromThread(reactor.stop)
+ global REACTOR_THREAD
+ REACTOR_THREAD = None
+
if __name__ == '__main__':
setup()