def mail_tags(self, mail_id): new_tags = map(lambda tag: tag.lower(), request.get_json()['newtags']) try: self._mail_service.update_tags(mail_id, new_tags) mail = self._mail_service.mail(mail_id) self._search_engine.index_mail(mail) except ValueError as ve: return respond_json(ve.message, 403) return respond_json(mail.as_dict())
def mail_tags(self, request, mail_id): content_dict = json.loads(request.content.read()) new_tags = map(lambda tag: tag.lower(), content_dict['newtags']) try: self._mail_service.update_tags(mail_id, new_tags) mail = self._mail_service.mail(mail_id) self._search_engine.index_mail(mail) except ValueError as ve: return respond_json(ve.message, request, 403) return respond_json(mail.as_dict(), request)
def mail_tags(self, request, mail_id): content_dict = json.loads(request.content.read()) new_tags = map(lambda tag: tag.lower(), content_dict['newtags']) try: self._mail_service.update_tags(mail_id, new_tags) mail = self._mail_service.mail(mail_id) self._search_engine.index_mail(mail) except ValueError as ve: return respond_json(ve.message, request, 403) return respond_json(mail.as_dict(), request)
def send_mail(self, _request=request): try: _mail = InputMail.from_dict(_request.json) draft_id = _request.json.get('ident') if draft_id: self._search_engine.remove_from_index(draft_id) _mail = self._mail_service.send(draft_id, _mail) self._search_engine.index_mail(_mail) return respond_json(_mail.as_dict()) except Exception as error: return respond_json({'message': self._format_exception(error)}, status_code=422)
def send_mail(self, request): try: content_dict = json.loads(request.content.read()) _mail = InputMail.from_dict(content_dict) draft_id = content_dict.get('ident') if draft_id: self._search_engine.remove_from_index(draft_id) _mail = self._mail_service.send(draft_id, _mail) self._search_engine.index_mail(_mail) return respond_json(_mail.as_dict(), request) except Exception as error: return respond_json({'message': self._format_exception(error)}, request, status_code=422)
def send_mail(self, request): try: content_dict = json.loads(request.content.read()) _mail = InputMail.from_dict(content_dict) draft_id = content_dict.get('ident') if draft_id: self._search_engine.remove_from_index(draft_id) _mail = self._mail_service.send(draft_id, _mail) self._search_engine.index_mail(_mail) return respond_json(_mail.as_dict(), request) except Exception as error: return respond_json({'message': self._format_exception(error)}, request, status_code=422)
def delete_mail(self, request, mail_id): mail = self._mail_service.mail(mail_id) if mail.mailbox_name == 'TRASH': self._mail_service.delete_permanent(mail_id) else: trashed_mail = self._mail_service.delete_mail(mail_id) self._search_engine.index_mail(trashed_mail) return respond_json(None, request)
def delete_mail(self, request, mail_id): mail = self._mail_service.mail(mail_id) if mail.mailbox_name == 'TRASH': self._mail_service.delete_permanent(mail_id) else: trashed_mail = self._mail_service.delete_mail(mail_id) self._search_engine.index_mail(trashed_mail) return respond_json(None, request)
def sync_info(self): _sync_info = { 'is_syncing': self.current != self.total, 'count': { 'current': self.current, 'total': self.total, 'progress': self._get_progress() } } return respond_json(_sync_info)
def features(self, request): try: disabled_features = {'logout': os.environ['DISPATCHER_LOGOUT_URL']} except KeyError: disabled_features = {} return respond_json( { 'disabled_features': self.DISABLED_FEATURES, 'dispatcher_features': disabled_features }, request)
def sync_info(self, request): _sync_info = { 'is_syncing': self.current != self.total, 'count': { 'current': self.current, 'total': self.total, 'progress': self._get_progress() } } return respond_json(_sync_info, request)
def update_draft(self): _mail = InputMail.from_dict(request.json) draft_id = request.json.get('ident') if draft_id: ident = self._draft_service.update_draft(draft_id, _mail).ident self._search_engine.remove_from_index(draft_id) else: ident = self._draft_service.create_draft(_mail).ident self._search_engine.index_mail(self._mail_service.mail(ident)) return respond_json({'ident': ident})
def mails(self, _request=request): mail_ids, total = self._search_engine.search(_request.args.get('q'), _request.args.get('w'), _request.args.get('p')) mails = self._mail_service.mails(mail_ids) response = { "stats": { "total": total, }, "mails": [mail.as_dict() for mail in mails] } return respond_json(response)
def update_draft(self, request): content_dict = json.loads(request.content.read()) _mail = InputMail.from_dict(content_dict) draft_id = content_dict.get('ident') if draft_id: ident = self._draft_service.update_draft(draft_id, _mail).ident self._search_engine.remove_from_index(draft_id) else: ident = self._draft_service.create_draft(_mail).ident self._search_engine.index_mail(self._mail_service.mail(ident)) return respond_json({'ident': ident}, request)
def update_draft(self, request): content_dict = json.loads(request.content.read()) _mail = InputMail.from_dict(content_dict) draft_id = content_dict.get('ident') if draft_id: ident = self._draft_service.update_draft(draft_id, _mail).ident self._search_engine.remove_from_index(draft_id) else: ident = self._draft_service.create_draft(_mail).ident self._search_engine.index_mail(self._mail_service.mail(ident)) return respond_json({'ident': ident}, request)
def tags(self, request): query = request.args.get('q', [''])[0] skip_default_tags = request.args.get('skipDefaultTags') tags = self._search_engine.tags(query=query, skip_default_tags=skip_default_tags) return respond_json(tags, request)
def delete_mails(self, request): idents = json.loads(request.form['idents']) for ident in idents: self.delete_mail(ident) return respond_json(None, request)
def mail(self, request, mail_id): mail = self._mail_service.mail(mail_id) return respond_json(mail.as_dict(), request)
def reply_all_template(self, request, mail_id): mail = self._mail_service.reply_all_template(mail_id) return respond_json(mail, request)
def mail(self, request, mail_id): mail = self._mail_service.mail(mail_id) return respond_json(mail.as_dict(), request)
def features(self, request): try: disabled_features = {'logout': os.environ['DISPATCHER_LOGOUT_URL']} except KeyError: disabled_features = {} return respond_json({'disabled_features': self.DISABLED_FEATURES, 'dispatcher_features': disabled_features}, request)
def delete_mails(self, request): idents = json.loads(request.form['idents']) for ident in idents: self.delete_mail(ident) return respond_json(None, request)