summaryrefslogtreecommitdiff
path: root/service/pixelated
diff options
context:
space:
mode:
Diffstat (limited to 'service/pixelated')
-rw-r--r--service/pixelated/adapter/mail_service.py3
-rw-r--r--service/pixelated/adapter/pixelated_mail.py6
-rw-r--r--service/pixelated/adapter/tag_service.py6
-rw-r--r--service/pixelated/user_agent.py13
4 files changed, 20 insertions, 8 deletions
diff --git a/service/pixelated/adapter/mail_service.py b/service/pixelated/adapter/mail_service.py
index c216e7ae..8be04984 100644
--- a/service/pixelated/adapter/mail_service.py
+++ b/service/pixelated/adapter/mail_service.py
@@ -35,6 +35,9 @@ class MailService:
return sorted(_mails or [], key=lambda mail: mail.headers['Date'], reverse=True)
def update_tags(self, mail_id, new_tags):
+ reserved_words = self.tag_service.extract_reserved(new_tags)
+ if len(reserved_words):
+ raise ValueError('None of the following words can be used as tags: %s' % list(reserved_words))
mail = self.mail(mail_id)
return mail.update_tags(set(new_tags))
diff --git a/service/pixelated/adapter/pixelated_mail.py b/service/pixelated/adapter/pixelated_mail.py
index 3e0f1ee0..2f13cb01 100644
--- a/service/pixelated/adapter/pixelated_mail.py
+++ b/service/pixelated/adapter/pixelated_mail.py
@@ -24,7 +24,6 @@ import pixelated.support.date
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
from pycryptopp.hash import sha256
-from pixelated.support.functional import flatten
class InputMail:
@@ -250,8 +249,9 @@ class PixelatedMail:
return self
def mark_as_not_recent(self):
- self.fdoc.content['flags'].remove(Status.PixelatedStatus.RECENT)
- self.save()
+ if Status.PixelatedStatus.RECENT in self.fdoc.content['flags']:
+ self.fdoc.content['flags'].remove(Status.PixelatedStatus.RECENT)
+ self.save()
return self
def _persist_mail_tags(self, current_tags):
diff --git a/service/pixelated/adapter/tag_service.py b/service/pixelated/adapter/tag_service.py
index 00f28b40..ecc64fad 100644
--- a/service/pixelated/adapter/tag_service.py
+++ b/service/pixelated/adapter/tag_service.py
@@ -20,7 +20,11 @@ from pixelated.adapter.tag_index import TagIndex
class TagService:
instance = None
- SPECIAL_TAGS = {Tag('inbox', True), Tag('sent', True), Tag('drafts', True), Tag('trash', True)}
+ SPECIAL_TAGS = [Tag('inbox', True), Tag('sent', True), Tag('drafts', True), Tag('trash', True)]
+
+ @classmethod
+ def extract_reserved(cls, tags):
+ return set(tag.name for tag in cls.SPECIAL_TAGS if tag.name in tags)
@classmethod
def get_instance(cls):
diff --git a/service/pixelated/user_agent.py b/service/pixelated/user_agent.py
index 2dc71bf0..8c7440b0 100644
--- a/service/pixelated/user_agent.py
+++ b/service/pixelated/user_agent.py
@@ -47,9 +47,11 @@ app = Flask(__name__, static_url_path='', static_folder=static_folder)
DISABLED_FEATURES = ['draftReply', 'signatureStatus', 'encryptionStatus', 'contacts']
-def respond_json(entity):
- response = json.dumps(entity)
- return Response(response=response, mimetype="application/json")
+def respond_json(entity, status_code=200):
+ json_response = json.dumps(entity)
+ response = Response(response=json_response, mimetype="application/json")
+ response.status_code = status_code
+ return response
@app.route('/disabled_features')
@@ -127,7 +129,10 @@ def mail(mail_id):
@app.route('/mail/<mail_id>/tags', methods=['POST'])
def mail_tags(mail_id):
new_tags = map(lambda tag: tag.lower(), request.get_json()['newtags'])
- tags = mail_service.update_tags(mail_id, new_tags)
+ try:
+ tags = mail_service.update_tags(mail_id, new_tags)
+ except ValueError as ve:
+ return respond_json(ve.message, 403)
return respond_json(list(tags))