<commit_before>from django.shortcuts import redirect
from django.http import JsonResponse
from django.core.mail import EmailMessage
from django.middleware import csrf

from rest_framework.decorators import api_view


@api_view(['POST', 'GET'])
def send_contact_message(request):
    if request.method == 'POST':
        to_address = request.POST.get("to_address", "").split(',')
        from_name = request.POST.get("from_name", "")
        from_address = request.POST.get("from_address", "")
        from_string = '{} <{}>'.format(from_name, from_address)
        subject = request.POST.get("subject", "")
        message_body = request.POST.get("message_body", "")
        csrf_token = request.POST.get("csrfmiddlewaretoken", "")

        email = EmailMessage(subject,
                             message_body,
                             '<EMAIL>',
                             to_address,
                             reply_to=[from_string])
        email.send(fail_silently=False)

        #return redirect('/contact-thank-you')
        data = {'subject': subject,
                'message_body': message_body,
                'to_address': to_address,
                'reply_to': [from_string],
                'from_address': '<EMAIL>',
                'csrf_token': csrf_token,
                }

        return JsonResponse(data)
    # if this is not posting a message, let's send the csfr token back
    else:
        csrf_token = csrf.get_token(request)
        data = {'csrf_token': csrf_token}

        return JsonResponse(data)<commit_msg>Revert "return json of message being sent to debug mail issue"<commit_after>from django.shortcuts import redirect
from django.http import JsonResponse
from django.core.mail import EmailMessage
from django.middleware import csrf

from rest_framework.decorators import api_view


@api_view(['POST', 'GET'])
def send_contact_message(request):
    if request.method == 'POST':
        to_address = request.POST.get("to_address", "").split(',')
        from_name = request.POST.get("from_name", "")
        from_address = request.POST.get("from_address", "")
        from_string = '{} <{}>'.format(from_name, from_address)
        subject = request.POST.get("subject", "")
        message_body = request.POST.get("message_body", "")

        email = EmailMessage(subject,
                             message_body,
                             '<EMAIL>',
                             to_address,
                             reply_to=[from_string])
        email.send()

        return redirect('/contact-thank-you')
    # if this is not posting a message, let's send the csfr token back
    else:
        csrf_token = csrf.get_token(request)
        data = {'csrf_token': csrf_token}

        return JsonResponse(data)
{'fraction_non_alphanumeric': 0.11664860960635609, 'fraction_numerical': 0.0, 'mean_word_length': 2.317365269461078, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '860626', 'n_tokens_mistral': 772, 'n_tokens_neox': 761, 'n_words': 168}