From fa6561875f085cb60f6ba81e90e33ab59c6c553d Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Fri, 8 Aug 2014 11:10:32 -0300 Subject: #2 +@neissi - Fix variable name and added some protection against background requests on /mail route --- service/app/adapter/mail_service.py | 11 +++++++---- service/app/pixelated_user_agent.py | 20 ++++++++++---------- 2 files changed, 17 insertions(+), 14 deletions(-) (limited to 'service') 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/', 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/') 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//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//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/') 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: -- cgit v1.2.3