import logging

from rest_framework import generics
from rest_framework.parsers import JSONParser, MultiPartParser
from rest_framework.request import Request
from rest_framework.response import Response

from manager.signals import email_received

logger = logging.getLogger(__name__)


class EmailsView(generics.GenericAPIView):
    """
    A view for receiving parsed email payloads.
    """

    permission_classes = []
    parser_classes = [MultiPartParser, JSONParser]

    def post(self, request: Request) -> Response:
        """
        Receive an email.

        Returns an empty response.
        """
        email = request.data
        logger.info(f"Email received from {email.get('from')} to {email.get('to')}")
        email_received.send_robust(sender=self.__class__, email=email)
        return Response()

@@ -44,17 +44,30 @@
 generics
+, serializers
 %0A
-
 from res
@@ -293,16 +293,1082 @@
 me__)%0A%0A%0A
+class EmailSerializer(serializers.Serializer):%0A    %22%22%22%0A    A serializer for emails%0A%0A    This serializer is mainly for documentation and is based on the fields%0A    sent by SendGrid. Note that Sendrid send %60from%60 and %60to%60 instead of%0A    %60sender%60 and %60recipient%60.%0A%0A    See https://sendgrid.com/docs/for-developers/parsing-email/setting-up-the-inbound-parse-webhook/#default-parameters%0A    %22%22%22%0A%0A    sender = serializers.CharField(%0A        help_text=%22Email sender, as taken from the message headers.%22%0A    )%0A%0A    recipient = serializers.CharField(%0A        help_text=%22Email recipient field, as taken from the message headers.%22%0A    )%0A%0A    subject = serializers.CharField(help_text=%22Email subject.%22)%0A%0A    text = serializers.CharField(help_text=%22Email body in plaintext formatting.%22)%0A%0A    html = serializers.CharField(%0A        help_text=%22HTML body of email. If not set, email did not have an HTML body.%22%0A    )%0A%0A    spf = serializers.CharField(%0A        help_text=%22The results of the Sender Policy Framework verification of the message sender and receiving IP address.%22%0A    )%0A%0A%0A
 class Em
@@ -1495,16 +1495,16 @@
 es = %5B%5D%0A
-
     pars
@@ -1545,16 +1545,55 @@
 NParser%5D
+%0A    serializer_class = EmailSerializer
 %0A%0A    de

Add serializer for emails