Пример #1
0
def reply(request, mlist_fqdn, message_id_hash):
    """ Sends a reply to the list.
    TODO: unit tests
    """
    if request.method != 'POST':
        raise SuspiciousOperation
    form = ReplyForm(request.POST)
    if not form.is_valid():
        return HttpResponse(form.errors.as_text(),
                            content_type="text/plain", status=400)
    store = get_store(request)
    mlist = store.get_list(mlist_fqdn)
    if form.cleaned_data["newthread"]:
        subject = form.cleaned_data["subject"]
        headers = {}
    else:
        message = store.get_message_by_hash_from_list(mlist.name, message_id_hash)
        subject = message.subject
        if not message.subject.lower().startswith("re:"):
            subject = "Re: %s" % subject
        headers = {"In-Reply-To": "<%s>" % message.message_id,
                   "References": "<%s>" % message.message_id, }
    try:
        post_to_list(request, mlist, subject, form.cleaned_data["message"],
                     headers, attachments=request.FILES.getlist('attachment'))
    except PostingFailed, e:
        return HttpResponse(str(e), content_type="text/plain", status=500)
Пример #2
0
def new_message(request, mlist_fqdn):
    """ Sends a new thread-starting message to the list.
    TODO: unit tests
    """
    store = get_store(request)
    mlist = store.get_list(mlist_fqdn)
    failure = None
    if request.method == 'POST':
        form = PostForm(request.POST)
        if form.is_valid():
            today = datetime.date.today()
            redirect_url = reverse('archives_with_month',
                                   kwargs={
                                       "mlist_fqdn": mlist_fqdn,
                                       'year': today.year,
                                       'month': today.month
                                   })
            redirect_url += "?msg=sent-ok"
            try:
                post_to_list(request,
                             mlist,
                             form.cleaned_data['subject'],
                             form.cleaned_data["message"],
                             attachments=request.FILES.getlist("attachment"))
            except PostingFailed, e:
                failure = str(e)
            else:
                return redirect(redirect_url)
Пример #3
0
 def test_sender_with_display_name(self):
     self.user.first_name = "Test"
     self.user.last_name = "User"
     posting.post_to_list(self.request, self.mlist, "Test message", "dummy")
     self.assertEqual(len(mail.outbox), 1)
     self.assertEqual(mail.outbox[0].from_email,
                      '"Test User" <*****@*****.**>')
Пример #4
0
def reply(request, mlist_fqdn, message_id_hash):
    """ Sends a reply to the list.
    TODO: unit tests
    """
    if request.method != 'POST':
        raise SuspiciousOperation
    form = ReplyForm(request.POST)
    if not form.is_valid():
        return HttpResponse(form.errors.as_text(),
                            content_type="text/plain",
                            status=400)
    store = get_store(request)
    mlist = store.get_list(mlist_fqdn)
    if form.cleaned_data["newthread"]:
        subject = form.cleaned_data["subject"]
        headers = {}
    else:
        message = store.get_message_by_hash_from_list(mlist.name,
                                                      message_id_hash)
        subject = message.subject
        if not message.subject.lower().startswith("re:"):
            subject = "Re: %s" % subject
        headers = {
            "In-Reply-To": "<%s>" % message.message_id,
            "References": "<%s>" % message.message_id,
        }
    try:
        post_to_list(request,
                     mlist,
                     subject,
                     form.cleaned_data["message"],
                     headers,
                     attachments=request.FILES.getlist('attachment'))
    except PostingFailed, e:
        return HttpResponse(str(e), content_type="text/plain", status=500)
 def test_sender_with_display_name(self):
     self.user.first_name = "Test"
     self.user.last_name = "User"
     posting.post_to_list(self.request, self.mlist, "Test message", "dummy")
     self.assertEqual(len(mail.outbox), 1)
     self.assertEqual(mail.outbox[0].from_email,
                      '"Test User" <*****@*****.**>')
Пример #6
0
def new_message(request, mlist_fqdn):
    """ Sends a new thread-starting message to the list.
    TODO: unit tests
    """
    store = get_store(request)
    mlist = store.get_list(mlist_fqdn)
    failure = None
    if request.method == 'POST':
        form = PostForm(request.POST)
        if form.is_valid():
            today = datetime.date.today()
            redirect_url = reverse(
                    'archives_with_month', kwargs={
                        "mlist_fqdn": mlist_fqdn,
                        'year': today.year,
                        'month': today.month})
            redirect_url += "?msg=sent-ok"
            try:
                post_to_list(request, mlist, form.cleaned_data['subject'],
                             form.cleaned_data["message"],
                             attachments=request.FILES.getlist("attachment"))
            except PostingFailed, e:
                failure = str(e)
            else:
                return redirect(redirect_url)
Пример #7
0
 def test_unwrap_subject_2(self):
     subject = 'This subject is wrapped with\n a newline'
     try:
         posting.post_to_list(self.request, self.mlist, subject, "dummy content")
     except ValueError as e:
         self.fail(e)
     self.assertEqual(len(mail.outbox), 1)
     self.assertEqual(mail.outbox[0].subject, subject.replace("\n ", " "))
 def test_unwrap_subject_2(self):
     subject = 'This subject is wrapped with\n a newline'
     try:
         posting.post_to_list(self.request, self.mlist, subject,
                              "dummy content")
     except ValueError as e:
         self.fail(e)
     self.assertEqual(len(mail.outbox), 1)
     self.assertEqual(mail.outbox[0].subject, subject.replace("\n ", " "))
 def test_smtp_error_raises_postingfailed(self):
     self.user.first_name = "Django"
     self.user.last_name = "User"
     self.user.save()
     with patch("hyperkitty.lib.posting.mailman.subscribe"):
         with patch('hyperkitty.lib.posting.EmailMessage', Django_mail):
             with self.assertRaises(posting.PostingFailed) as cm:
                 posting.post_to_list(self.request, self.mlist,
                                      "Dummy subject", "body")
                 self.assertEqual(
                     str(cm.exception), 'Message not sent: SMTP error 500 '
                     'Error Message')
 def test_reply_different_sender(self):
     self.user.first_name = "Django"
     self.user.last_name = "User"
     self.user.save()
     with patch("hyperkitty.lib.posting.mailman.subscribe") as sub_fn:
         posting.post_to_list(self.request, self.mlist, "Subject",
                              "Content", {"From": "*****@*****.**"})
         sub_fn.assert_called_with('list.example.com', self.user,
                                   '*****@*****.**', 'Django User')
     self.assertEqual(len(mail.outbox), 1)
     self.assertEqual(mail.outbox[0].recipients(), ["*****@*****.**"])
     self.assertEqual(mail.outbox[0].from_email,
                      '"Django User" <*****@*****.**>')
Пример #11
0
 def test_reply_different_sender(self):
     self.user.first_name = "Django"
     self.user.last_name = "User"
     self.user.save()
     with patch("hyperkitty.lib.posting.mailman.subscribe") as sub_fn:
         posting.post_to_list(
             self.request, self.mlist, "Subject", "Content",
             {"From": "*****@*****.**"})
         sub_fn.assert_called_with(
             '*****@*****.**', self.user, '*****@*****.**',
             'Django User')
     self.assertEqual(len(mail.outbox), 1)
     #print(mail.outbox[0].message())
     self.assertEqual(mail.outbox[0].recipients(), ["*****@*****.**"])
     self.assertEqual(mail.outbox[0].from_email, '"Django User" <*****@*****.**>')
Пример #12
0
def reply(request, mlist_fqdn, message_id_hash):
    """Sends a reply to the list."""
    if request.method != 'POST':
        raise SuspiciousOperation
    form = ReplyForm(request.POST)
    if not form.is_valid():
        return HttpResponse(form.errors.as_text(),
                            content_type="text/plain",
                            status=400)
    mlist = get_object_or_404(MailingList, name=mlist_fqdn)
    if form.cleaned_data["newthread"]:
        subject = form.cleaned_data["subject"]
        headers = {}
    else:
        message = get_object_or_404(Email,
                                    mailinglist=mlist,
                                    message_id_hash=message_id_hash)
        subject = reply_subject(message.subject)
        headers = {
            "In-Reply-To": "<%s>" % message.message_id,
            "References": "<%s>" % message.message_id,
        }
    try:
        subscribed_now = post_to_list(request, mlist, subject,
                                      form.cleaned_data["message"], headers)
    except PostingFailed, e:
        return HttpResponse(str(e), content_type="text/plain", status=500)
Пример #13
0
def new_message(request, mlist_fqdn):
    """ Sends a new thread-starting message to the list. """
    mlist = get_object_or_404(MailingList, name=mlist_fqdn)
    failure = None
    if request.method == "POST":
        form = PostForm(request.POST)
        if form.is_valid():
            today = datetime.date.today()
            redirect_url = reverse(
                "hk_archives_with_month", kwargs={"mlist_fqdn": mlist_fqdn, "year": today.year, "month": today.month}
            )
            redirect_url += "?msg=sent-ok"
            try:
                post_to_list(request, mlist, form.cleaned_data["subject"], form.cleaned_data["message"])
            except PostingFailed, e:
                failure = str(e)
            else:
                return redirect(redirect_url)
Пример #14
0
 def test_basic_reply(self):
     self.user.first_name = "Django"
     self.user.last_name = "User"
     self.user.save()
     with patch("hyperkitty.lib.posting.mailman.subscribe") as sub_fn:
         posting.post_to_list(
             self.request, self.mlist, "Dummy subject", "dummy content",
             {"In-Reply-To": "<msg>", "References": "<msg>"})
         sub_fn.assert_called_with(
             'list.example.com', self.user, '*****@*****.**',
             'Django User')
     self.assertEqual(len(mail.outbox), 1)
     self.assertEqual(mail.outbox[0].recipients(), ["*****@*****.**"])
     self.assertEqual(mail.outbox[0].from_email,
                      '"Django User" <*****@*****.**>')
     self.assertEqual(mail.outbox[0].subject, 'Dummy subject')
     self.assertEqual(mail.outbox[0].body, "dummy content")
     self.assertEqual(mail.outbox[0].message().get("references"), "<msg>")
     self.assertEqual(mail.outbox[0].message().get("in-reply-to"), "<msg>")
Пример #15
0
 def test_basic_reply(self):
     self.user.first_name = "Django"
     self.user.last_name = "User"
     self.user.save()
     with patch("hyperkitty.lib.posting.mailman.subscribe") as sub_fn:
         posting.post_to_list(
             self.request, self.mlist, "Dummy subject", "dummy content",
             {"In-Reply-To": "<msg>", "References": "<msg>"})
         sub_fn.assert_called_with(
             '*****@*****.**', self.user, '*****@*****.**',
             'Django User')
     self.assertEqual(len(mail.outbox), 1)
     #print(mail.outbox[0].message())
     self.assertEqual(mail.outbox[0].recipients(), ["*****@*****.**"])
     self.assertEqual(mail.outbox[0].from_email, '"Django User" <*****@*****.**>')
     self.assertEqual(mail.outbox[0].subject, 'Dummy subject')
     self.assertEqual(mail.outbox[0].body, "dummy content")
     self.assertEqual(mail.outbox[0].message().get("references"), "<msg>")
     self.assertEqual(mail.outbox[0].message().get("in-reply-to"), "<msg>")
def new_message(request, mlist_fqdn):
    """ Sends a new thread-starting message to the list. """
    if not getattr(settings, 'HYPERKITTY_ALLOW_WEB_POSTING', True):
        return HttpResponse('Posting via Hyperkitty is disabled',
                            content_type="text/plain",
                            status=403)
    mlist = get_object_or_404(MailingList, name=mlist_fqdn)
    if request.method == 'POST':
        form = get_posting_form(PostForm, request, mlist, request.POST)
        if form.is_valid():
            today = datetime.date.today()
            headers = {}
            if form.cleaned_data["sender"]:
                headers["From"] = form.cleaned_data["sender"]
            try:
                post_to_list(request, mlist, form.cleaned_data['subject'],
                             form.cleaned_data["message"], headers)
            except PostingFailed as e:
                messages.error(request, str(e))
            except ModeratedListException as e:
                return HttpResponse(str(e),
                                    content_type="text/plain",
                                    status=403)
            else:
                messages.success(request,
                                 "The message has been sent successfully.")
                redirect_url = reverse('hk_archives_with_month',
                                       kwargs={
                                           "mlist_fqdn": mlist_fqdn,
                                           'year': today.year,
                                           'month': today.month
                                       })
                return redirect(redirect_url)
    else:
        form = get_posting_form(PostForm, request, mlist)
    context = {
        "mlist": mlist,
        "post_form": form,
        'months_list': get_months(mlist),
    }
    return render(request, "hyperkitty/message_new.html", context)
Пример #17
0
def new_message(request, mlist_fqdn):
    """ Sends a new thread-starting message to the list. """
    mlist = get_object_or_404(MailingList, name=mlist_fqdn)
    failure = None
    if request.method == 'POST':
        form = PostForm(request.POST)
        if form.is_valid():
            today = datetime.date.today()
            redirect_url = reverse('hk_archives_with_month',
                                   kwargs={
                                       "mlist_fqdn": mlist_fqdn,
                                       'year': today.year,
                                       'month': today.month
                                   })
            redirect_url += "?msg=sent-ok"
            try:
                post_to_list(request, mlist, form.cleaned_data['subject'],
                             form.cleaned_data["message"])
            except PostingFailed, e:
                failure = str(e)
            else:
                return redirect(redirect_url)
Пример #18
0
def reply(request, mlist_fqdn, message_id_hash):
    """Sends a reply to the list."""
    if request.method != 'POST':
        raise SuspiciousOperation
    form = ReplyForm(request.POST)
    if not form.is_valid():
        return HttpResponse(form.errors.as_text(),
                            content_type="text/plain", status=400)
    mlist = get_object_or_404(MailingList, name=mlist_fqdn)
    if form.cleaned_data["newthread"]:
        subject = form.cleaned_data["subject"]
        headers = {}
    else:
        message = get_object_or_404(Email,
            mailinglist=mlist, message_id_hash=message_id_hash)
        subject = reply_subject(message.subject)
        headers = {"In-Reply-To": "<%s>" % message.message_id,
                   "References": "<%s>" % message.message_id, }
    try:
        post_to_list(request, mlist, subject, form.cleaned_data["message"], headers)
    except PostingFailed, e:
        return HttpResponse(str(e), content_type="text/plain", status=500)
def reply(request, mlist_fqdn, message_id_hash):
    """Sends a reply to the list."""
    if not getattr(settings, 'HYPERKITTY_ALLOW_WEB_POSTING', True):
        return HttpResponse('Posting via Hyperkitty is disabled',
                            content_type="text/plain",
                            status=403)
    mlist = get_object_or_404(MailingList, name=mlist_fqdn)
    form = get_posting_form(ReplyForm, request, mlist, request.POST)
    if not form.is_valid():
        return HttpResponse(form.errors.as_text(),
                            content_type="text/plain",
                            status=400)
    if form.cleaned_data["newthread"]:
        subject = form.cleaned_data["subject"]
        headers = {}
    else:
        message = get_object_or_404(Email,
                                    mailinglist=mlist,
                                    message_id_hash=message_id_hash)
        subject = reply_subject(message.subject)
        headers = {
            "In-Reply-To": "<%s>" % message.message_id,
            "References": "<%s>" % message.message_id,
        }
    if form.cleaned_data["sender"]:
        headers["From"] = form.cleaned_data["sender"]
    try:
        subscribed_now = post_to_list(request, mlist, subject,
                                      form.cleaned_data["message"], headers)
    except PostingFailed as e:
        return HttpResponse(str(e), content_type="text/plain", status=500)
    except ModeratedListException as e:
        return HttpResponse(str(e), content_type="text/plain", status=403)

    # TODO: if newthread, don't insert the temp mail in the thread, redirect to
    # the new thread. Should we insert the mail in the DB and flag it as
    # "temporary", to be confirmed by a later reception from mailman? This
    # looks complex, because the temp mail should only be visible by its
    # sender.

    if form.cleaned_data["newthread"]:
        html = None
    else:
        email_reply = {
            "sender_name":
            "%s %s" % (request.user.first_name, request.user.last_name),
            "sender_address": (form.cleaned_data["sender"]
                               or request.user.email),
            "content":
            form.cleaned_data["message"],
            # no need to increment, level = thread_depth - 1
            "level":
            message.thread_depth,
        }
        t = loader.get_template('hyperkitty/ajax/temp_message.html')
        html = t.render({'email': email_reply}, request)
    # TODO: make the message below translatable.
    result = {
        "result": _("Your reply has been sent and is being processed."),
        "message_html": html
    }
    if subscribed_now:
        result['result'] += (
            _("\n  You have been subscribed to {} list.").format(mlist_fqdn))
    return HttpResponse(json.dumps(result),
                        content_type="application/javascript")