From d8360815ea07d9944f08ad378d2b89e64e1f2c9e Mon Sep 17 00:00:00 2001 From: Bruno Wagner Goncalves Date: Fri, 1 Aug 2014 17:36:14 -0300 Subject: Changed the Smail names to pixelated ones on inboxapp --- inboxapp-service/app/pixelated_service.py | 127 ++++++++++++++++++++++++++++++ inboxapp-service/app/smailback.py | 127 ------------------------------ inboxapp-service/go | 4 +- 3 files changed, 129 insertions(+), 129 deletions(-) create mode 100644 inboxapp-service/app/pixelated_service.py delete mode 100644 inboxapp-service/app/smailback.py (limited to 'inboxapp-service') diff --git a/inboxapp-service/app/pixelated_service.py b/inboxapp-service/app/pixelated_service.py new file mode 100644 index 00000000..f3eb52d7 --- /dev/null +++ b/inboxapp-service/app/pixelated_service.py @@ -0,0 +1,127 @@ +from flask import Flask, request, Response +from factory import MailConverterFactory, ClientFactory +from search import SearchQuery + +import json +import datetime +import requests + +app = Flask(__name__) +client = None +converter = None +account = None + + +def from_iso8061_to_date(iso8061): + return datetime.datetime.strptime(iso8061, "%Y-%m-%dT%H:%M:%S") + + +def respond_json(entity): + response = json.dumps(entity) + return Response(response=response, mimetype="application/json") + + +@app.route('/mails', methods=['POST']) +def save_draft_or_send(): + ident = None + if 'sent' in request.json['tags']: + ident = client.send_draft(converter.to_mail(request.json, account)) + else: + ident = client.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)) + return respond_json({'ident': ident}) + + +@app.route('/mails') +def mails(): + query = SearchQuery.compile(request.args.get("q")) + mails = client.drafts() if "drafts" in query['tags'] else client.mails(query) + mails = [converter.from_mail(mail) for mail in 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) + + response = { + "stats": { + "total": len(mails), + "read": 0, + "starred": 0, + "replied": 0 + }, + "mails": mails + } + + return respond_json(response) + + +@app.route('/mail/', methods=['DELETE']) +def delete_mails(mail_id): + client.delete_mail(mail_id) + return respond_json(None) + + +@app.route('/tags') +def tags(): + tags = map(lambda x: converter.from_tag(x), client.all_tags()) + return respond_json(tags) + + +@app.route('/mail/') +def mail(mail_id): + mail = client.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)) + return respond_json(mail['tags']) + + +@app.route('/mail//read', methods=['POST']) +def mark_mail_as_read(mail_id): + client.mark_as_read(mail_id) + return "" + + +@app.route('/contacts') +def contacts(): + query = SearchQuery.compile(request.args.get("q")) + desired_contacts = [converter.from_contact(contact) for contact in client.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) + if draft: + return respond_json(converter.from_mail(draft)) + else: + return respond_json(None) + + +@app.route('/', defaults={'path': ''}) +@app.route('/') +def redirect_to_front(path): + response = requests.get("http://localhost:9000/%s" % path) + return Response( + response=response, + status=response.status_code, + content_type=response.headers['content-type'] + ) + +if __name__ == '__main__': + app.config.from_envvar('PIXELATED_SERVICE_CFG') + provider = app.config['PROVIDER'] + account = app.config['ACCOUNT'] + + client = ClientFactory.create(provider, account) + converter = MailConverterFactory.create(provider, client) + app.run(host=app.config['HOST'], debug=app.config['DEBUG'], port=app.config['PORT']) diff --git a/inboxapp-service/app/smailback.py b/inboxapp-service/app/smailback.py deleted file mode 100644 index 4aa04030..00000000 --- a/inboxapp-service/app/smailback.py +++ /dev/null @@ -1,127 +0,0 @@ -from flask import Flask, request, Response -from factory import MailConverterFactory, ClientFactory -from search import SearchQuery - -import json -import datetime -import requests - -app = Flask(__name__) -client = None -converter = None -account = None - - -def from_iso8061_to_date(iso8061): - return datetime.datetime.strptime(iso8061, "%Y-%m-%dT%H:%M:%S") - - -def respond_json(entity): - response = json.dumps(entity) - return Response(response=response, mimetype="application/json") - - -@app.route('/mails', methods=['POST']) -def save_draft_or_send(): - ident = None - if 'sent' in request.json['tags']: - ident = client.send_draft(converter.to_mail(request.json, account)) - else: - ident = client.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)) - return respond_json({'ident': ident}) - - -@app.route('/mails') -def mails(): - query = SearchQuery.compile(request.args.get("q")) - mails = client.drafts() if "drafts" in query['tags'] else client.mails(query) - mails = [converter.from_mail(mail) for mail in 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) - - response = { - "stats": { - "total": len(mails), - "read": 0, - "starred": 0, - "replied": 0 - }, - "mails": mails - } - - return respond_json(response) - - -@app.route('/mail/', methods=['DELETE']) -def delete_mails(mail_id): - client.delete_mail(mail_id) - return respond_json(None) - - -@app.route('/tags') -def tags(): - tags = map(lambda x: converter.from_tag(x), client.all_tags()) - return respond_json(tags) - - -@app.route('/mail/') -def mail(mail_id): - mail = client.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)) - return respond_json(mail['tags']) - - -@app.route('/mail//read', methods=['POST']) -def mark_mail_as_read(mail_id): - client.mark_as_read(mail_id) - return "" - - -@app.route('/contacts') -def contacts(): - query = SearchQuery.compile(request.args.get("q")) - desired_contacts = [converter.from_contact(contact) for contact in client.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) - if draft: - return respond_json(converter.from_mail(draft)) - else: - return respond_json(None) - - -@app.route('/', defaults={'path': ''}) -@app.route('/') -def redirect_to_front(path): - response = requests.get("http://localhost:9000/%s" % path) - return Response( - response=response, - status=response.status_code, - content_type=response.headers['content-type'] - ) - -if __name__ == '__main__': - app.config.from_envvar('SMAIL_BACK_CFG') - provider = app.config['PROVIDER'] - account = app.config['ACCOUNT'] - - client = ClientFactory.create(provider, account) - converter = MailConverterFactory.create(provider, client) - app.run(host=app.config['HOST'], debug=app.config['DEBUG'], port=app.config['PORT']) diff --git a/inboxapp-service/go b/inboxapp-service/go index 58de297a..d988ade7 100755 --- a/inboxapp-service/go +++ b/inboxapp-service/go @@ -1,4 +1,4 @@ #!/bin/bash -export SMAIL_BACK_CFG=../config/inboxapp.cfg -python app/smailback.py +export PIXELATED_SERVICE_CFG=../config/inboxapp.cfg +python app/pixelated_service.py -- cgit v1.2.3