Exemplo n.º 1
0
    def archive(self, request, pk=None):
        """
        Archive an email message asynchronous through the manager and not directly on the database. Just update the
        search index by an instance variable so changes are immediately visible.
        An email message is archived by removing the inbox label and the provided label of the current inbox.
        """
        email = self.get_object()

        current_inbox = request.data['data'].get('current_inbox', '')

        # Filter out labels an user should not manipulate.
        remove_labels = []
        if current_inbox and current_inbox not in settings.GMAIL_LABELS_DONT_MANIPULATE:
            remove_labels.append(current_inbox)

        # Archiving email should always remove the inbox label.
        if settings.GMAIL_LABEL_INBOX not in remove_labels:
            remove_labels.append(settings.GMAIL_LABEL_INBOX)

        email._is_archived = True
        reindex_email_message(email)
        serializer = self.get_serializer(email, partial=True)
        add_and_remove_labels_for_message.delay(email.id,
                                                remove_labels=remove_labels)
        return Response(serializer.data)
Exemplo n.º 2
0
 def spam(self, request, pk=None):
     """
     Mark / unmark an email message as spam asynchronous through the manager and not directly on the database. Just
     update the search index by an instance variable so changes are immediately visible.
     """
     email = self.get_object()
     email._is_spam = request.data['markAsSpam']
     reindex_email_message(email)
     serializer = self.get_serializer(email, partial=True)
     toggle_spam_email_message.delay(email.id, spam=request.data['markAsSpam'])
     return Response(serializer.data)
Exemplo n.º 3
0
 def trash(self, request, pk=None):
     """
     Trash an email message asynchronous through the manager and not directly on the database. Just update the
     search index by an instance variable so changes are immediately visible.
     """
     email = self.get_object()
     email._is_trashed = True
     reindex_email_message(email)
     serializer = self.get_serializer(email, partial=True)
     trash_email_message.apply_async(args=(email.id,))
     return Response(serializer.data)
Exemplo n.º 4
0
 def star(self, request, pk=None):
     """
     Star an email message asynchronous through the manager and not directly on the database. Just update the
     search index by an instance variable so changes are immediately visible.
     """
     email = self.get_object()
     email._is_starred = request.data['starred']
     reindex_email_message(email)
     serializer = self.get_serializer(email, partial=True)
     toggle_star_email_message.delay(email.id, star=request.data['starred'])
     return Response(serializer.data)
Exemplo n.º 5
0
 def trash(self, request, pk=None):
     """
     Trash an email message asynchronous through the manager and not directly on the database. Just update the
     search index by an instance variable so changes are immediately visible.
     """
     email = self.get_object()
     email._is_trashed = True
     reindex_email_message(email)
     serializer = self.get_serializer(email, partial=True)
     trash_email_message.apply_async(args=(email.id, ))
     return Response(serializer.data)
Exemplo n.º 6
0
    def archive(self, request, pk=None):
        """
        Archive an email message asynchronous through the manager and not directly on the database. Just update the
        search index by an instance variable so changes are immediately visible.
        An email message is archived by removing the inbox label and the provided label of the current inbox.
        """
        email = self.get_object()

        current_inbox = request.data['data'].get('current_inbox', '')

        # Filter out labels an user should not manipulate.
        remove_labels = []
        if current_inbox and current_inbox not in settings.GMAIL_LABELS_DONT_MANIPULATE:
            remove_labels.append(current_inbox)

        # Archiving email should always remove the inbox label.
        if settings.GMAIL_LABEL_INBOX not in remove_labels:
            remove_labels.append(settings.GMAIL_LABEL_INBOX)

        email._is_archived = True
        reindex_email_message(email)
        serializer = self.get_serializer(email, partial=True)
        add_and_remove_labels_for_message.delay(email.id, remove_labels=remove_labels)
        return Response(serializer.data)