diff options
Diffstat (limited to 'service/pixelated')
-rw-r--r-- | service/pixelated/adapter/mailstore/leap_mailstore.py | 21 | ||||
-rw-r--r-- | service/pixelated/adapter/services/mail_service.py | 21 | ||||
-rw-r--r-- | service/pixelated/resources/__init__.py | 11 | ||||
-rw-r--r-- | service/pixelated/resources/mails_resource.py | 6 |
4 files changed, 47 insertions, 12 deletions
diff --git a/service/pixelated/adapter/mailstore/leap_mailstore.py b/service/pixelated/adapter/mailstore/leap_mailstore.py index c3c93cc3..c34d2b16 100644 --- a/service/pixelated/adapter/mailstore/leap_mailstore.py +++ b/service/pixelated/adapter/mailstore/leap_mailstore.py @@ -13,6 +13,7 @@ # # You should have received a copy of the GNU Affero General Public License # along with Pixelated. If not, see <http://www.gnu.org/licenses/>. +from uuid import uuid4 from leap.mail.adaptors.soledad import SoledadMailAdaptor from twisted.internet import defer from pixelated.adapter.mailstore.mailstore import MailStore, underscore_uuid @@ -32,6 +33,10 @@ class LeapMail(Mail): self._flags = flags @property + def ident(self): + return self._mail_id + + @property def mail_id(self): return self._mail_id @@ -84,6 +89,8 @@ class LeapMailStore(MailStore): defer.returnValue(leap_mail) except AttributeError, e: + import traceback + traceback.print_exc() defer.returnValue(None) def get_mails(self, mail_ids): @@ -199,12 +206,24 @@ class LeapMailStore(MailStore): map = (yield self._mailbox_uuid_to_name_map()) defer.returnValue(map[uuid]) + @defer.inlineCallbacks def _get_or_create_mailbox(self, mailbox_name): - return SoledadMailAdaptor().get_or_create_mbox(self.soledad, mailbox_name) + mailbox_name_upper = mailbox_name.upper() + mbx = yield SoledadMailAdaptor().get_or_create_mbox(self.soledad, mailbox_name_upper) + if mbx.uuid is None: + mbx.uuid = str(uuid4()) + yield mbx.update(self.soledad) + defer.returnValue(mbx) def _fetch_msg_from_soledad(self, mail_id, load_body=False): return SoledadMailAdaptor().get_msg_from_mdoc_id(Message, self.soledad, mail_id, get_cdocs=load_body) + @defer.inlineCallbacks + def _dump_soledad(self): + gen, docs = yield self.soledad.get_all_docs() + for doc in docs: + print '\n%s\n' % doc + def _is_empty_message(message): return (message is None) or (message.get_wrapper().mdoc.doc_id is None) diff --git a/service/pixelated/adapter/services/mail_service.py b/service/pixelated/adapter/services/mail_service.py index 23cbc5f7..5e4d7a6d 100644 --- a/service/pixelated/adapter/services/mail_service.py +++ b/service/pixelated/adapter/services/mail_service.py @@ -29,15 +29,20 @@ class MailService(object): @defer.inlineCallbacks def all_mails(self): - defer.returnValue((yield self.querier.all_mails())) + mails = yield self.mail_store.all_mails() + defer.returnValue(mails) @defer.inlineCallbacks def mails(self, query, window_size, page): mail_ids, total = self.search_engine.search(query, window_size, page) - mails = yield self.querier.mails(mail_ids) - - defer.returnValue((mails, total)) + try: + mails = yield self.mail_store.get_mails(mail_ids) + defer.returnValue((mails, total)) + except Exception, e: + import traceback + traceback.print_exc() + raise @defer.inlineCallbacks def update_tags(self, mail_id, new_tags): @@ -65,7 +70,7 @@ class MailService(object): return [_use_current_casing(new_tag.lower()) if new_tag.lower() in current_tags_lower else new_tag for new_tag in new_tags] def mail(self, mail_id): - return self.querier.mail(mail_id) + return self.mail_store.get_mail(mail_id) def attachment(self, attachment_id, encoding): return self.querier.attachment(attachment_id, encoding) @@ -104,10 +109,10 @@ class MailService(object): @defer.inlineCallbacks def delete_mail(self, mail_id): mail = yield self.mail(mail_id) - if mail.mailbox_name == 'TRASH': - yield self.delete_permanent(mail_id) + if mail.mailbox_name.upper() == u'TRASH': + yield self.mail_store.delete_mail(mail_id) else: - trashed_mail = yield self.mailboxes.move_to_trash(mail_id) + trashed_mail = yield self.mail_store.move_mail_to_mailbox(mail_id, 'TRASH') self.search_engine.index_mail(trashed_mail) def recover_mail(self, mail_id): diff --git a/service/pixelated/resources/__init__.py b/service/pixelated/resources/__init__.py index b244900a..c65e19f3 100644 --- a/service/pixelated/resources/__init__.py +++ b/service/pixelated/resources/__init__.py @@ -17,15 +17,22 @@ import json +class SetEncoder(json.JSONEncoder): + def default(self, obj): + if isinstance(obj, set): + return list(obj) + return super(SetEncoder, self).default(obj) + + def respond_json(entity, request, status_code=200): - json_response = json.dumps(entity) + json_response = json.dumps(entity, cls=SetEncoder) request.responseHeaders.addRawHeader(b"content-type", b"application/json") request.code = status_code return json_response def respond_json_deferred(entity, request, status_code=200): - json_response = json.dumps(entity) + json_response = json.dumps(entity, cls=SetEncoder) request.responseHeaders.addRawHeader(b"content-type", b"application/json") request.code = status_code request.write(json_response) diff --git a/service/pixelated/resources/mails_resource.py b/service/pixelated/resources/mails_resource.py index d4e8372e..9658bd82 100644 --- a/service/pixelated/resources/mails_resource.py +++ b/service/pixelated/resources/mails_resource.py @@ -123,6 +123,11 @@ class MailsResource(Resource): }) d.addCallback(lambda res: respond_json_deferred(res, request)) + def error_handler(error): + print error + + d.addErrback(error_handler) + return NOT_DONE_YET def render_POST(self, request): @@ -146,7 +151,6 @@ class MailsResource(Resource): return server.NOT_DONE_YET def render_PUT(self, request): - print '\nrender_PUT\n' content_dict = json.loads(request.content.read()) _mail = InputMail.from_dict(content_dict) draft_id = content_dict.get('ident') |