summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorVictor Shyba <victor.shyba@gmail.com>2014-08-08 11:10:32 -0300
committerVictor Shyba <victor.shyba@gmail.com>2014-08-08 11:10:32 -0300
commitfa6561875f085cb60f6ba81e90e33ab59c6c553d (patch)
tree0e78c6e9cb367a4557cdefe631b5c581c07d7a33 /service
parent5a0d81e35b97113df983d8fd3fcbdb995606f56a (diff)
#2 +@neissi - Fix variable name and added some protection against background requests on /mail route
Diffstat (limited to 'service')
-rw-r--r--service/app/adapter/mail_service.py11
-rw-r--r--service/app/pixelated_user_agent.py20
2 files changed, 17 insertions, 14 deletions
diff --git a/service/app/adapter/mail_service.py b/service/app/adapter/mail_service.py
index a5bb1506..2c130967 100644
--- a/service/app/adapter/mail_service.py
+++ b/service/app/adapter/mail_service.py
@@ -13,10 +13,10 @@ class MailService:
def __init__(self):
try:
- self.username = 'test_user'
+ self.username = 'testuser2'
self.password = 'testpassword'
self.server_name = 'example.wazokazi.is'
- self.mailbox_name = 'inbox'
+ self.mailbox_name = 'INBOX'
self.leapdir = os.path.join(os.path.abspath("."), "leap")
self._open_leap_session()
@@ -32,8 +32,11 @@ class MailService:
self.mailbox = self.account.getMailbox(self.mailbox_name)
def mails(self, query):
- mailbox = self._switch_mailbox(query['tags'][0])
- return mailbox.messages if mailbox else []
+ if query.get('tags',False) and len(query['tags']):
+ mailbox = self._switch_mailbox(query['tags'][0])
+ return mailbox.messages.get_all() if mailbox else []
+ else:
+ return []
def _switch_mailbox(self, name):
mailbox = None
diff --git a/service/app/pixelated_user_agent.py b/service/app/pixelated_user_agent.py
index c28615ed..5b6e4b38 100644
--- a/service/app/pixelated_user_agent.py
+++ b/service/app/pixelated_user_agent.py
@@ -27,15 +27,15 @@ def respond_json(entity):
def save_draft_or_send():
ident = None
if 'sent' in request.json['tags']:
- ident = client.send_draft(converter.to_mail(request.json, account))
+ ident = mail_service.send_draft(converter.to_mail(request.json, account))
else:
- ident = client.save_draft(converter.to_mail(request.json, account))
+ ident = mail_service.save_draft(converter.to_mail(request.json, account))
return respond_json({'ident': ident})
@app.route('/mails', methods=['PUT'])
def update_draft():
- ident = client.save_draft(converter.to_mail(request.json, account))
+ ident = mail_service.save_draft(converter.to_mail(request.json, account))
return respond_json({'ident': ident})
@@ -65,44 +65,44 @@ def mails():
@app.route('/mail/<mail_id>', methods=['DELETE'])
def delete_mails(mail_id):
- client.delete_mail(mail_id)
+ mail_service.delete_mail(mail_id)
return respond_json(None)
@app.route('/tags')
def tags():
- tags = map(lambda x: converter.from_tag(x), client.all_tags())
+ tags = map(lambda x: converter.from_tag(x), mail_service.all_tags())
return respond_json(tags)
@app.route('/mail/<mail_id>')
def mail(mail_id):
- mail = client.mail(mail_id)
+ mail = mail_service.mail(mail_id)
return respond_json(converter.from_mail(mail))
@app.route('/mail/<mail_id>/tags')
def mail_tags(mail_id):
- mail = converter.from_mail(client.mail(mail_id))
+ mail = converter.from_mail(mail_service.mail(mail_id))
return respond_json(mail['tags'])
@app.route('/mail/<mail_id>/read', methods=['POST'])
def mark_mail_as_read(mail_id):
- client.mark_as_read(mail_id)
+ mail_service.mark_as_read(mail_id)
return ""
@app.route('/contacts')
def contacts():
query = search_query.compile(request.args.get("q"))
- desired_contacts = [converter.from_contact(contact) for contact in client.all_contacts(query)]
+ desired_contacts = [converter.from_contact(contact) for contact in mail_service.all_contacts(query)]
return respond_json({'contacts': desired_contacts})
@app.route('/draft_reply_for/<mail_id>')
def draft_reply_for(mail_id):
- draft = client.draft_reply_for(mail_id)
+ draft = mail_service.draft_reply_for(mail_id)
if draft:
return respond_json(converter.from_mail(draft))
else: