diff --git a/TODO.rst b/TODO.rst
index 5475213..3df244b 100644
--- a/TODO.rst
+++ b/TODO.rst
@@ -1,6 +1,10 @@
TODO
-----
+Envio de emails
+===============
+* Não perder o email em caso de falha de envio. Exibir o erro mas trazer a mensagem de volta para o usuário
+
Planet
======
diff --git a/src/colab/custom_settings.py b/src/colab/custom_settings.py
index b2eb8c5..ace935a 100644
--- a/src/colab/custom_settings.py
+++ b/src/colab/custom_settings.py
@@ -259,6 +259,10 @@ FEEDZILLA_SITE_TITLE = gettext(u'Planet Colab')
FEEDZILLA_SITE_DESCRIPTION = gettext(u'Colab blog aggregator')
+### Mailman API settings
+MAILMAN_API_URL = 'http://listas.interlegis.gov.br:8000'
+
+
### BrowserID / Persona
SITE_URL = 'https://colab.interlegis.leg.br'
BROWSERID_AUDIENCES = [SITE_URL]
diff --git a/src/super_archives/templates/message-thread.html b/src/super_archives/templates/message-thread.html
index 7a2fcc1..36586b7 100644
--- a/src/super_archives/templates/message-thread.html
+++ b/src/super_archives/templates/message-thread.html
@@ -74,10 +74,12 @@
$('html, body').animate({scrollTop: aTag.offset().top}, 800);
}
+ {% if user.is_active %}
function focus_reply(event) {
scrollToAnchor('#msg-reply');
$('textarea', '#msg-reply').focus();
}
+ {% endif %}
// Binding functions
$(function() {
diff --git a/src/super_archives/templates/superarchives/includes/message.html b/src/super_archives/templates/superarchives/includes/message.html
index 0159199..248e901 100644
--- a/src/super_archives/templates/superarchives/includes/message.html
+++ b/src/super_archives/templates/superarchives/includes/message.html
@@ -35,9 +35,11 @@
+ {% if user.is_active %}
+ {% endif %}
{% endif %}
@@ -48,15 +50,18 @@
{% if not reply %}
{% display_message email %}
{% else %}
-
-
-
-
-
{% trans "After sending a message it will take few minutes before it shows up in here. Why don't you grab a coffee?" %}
-
-
-
-
+
{% endif %}
diff --git a/src/super_archives/views.py b/src/super_archives/views.py
index 6d4db98..d19f8f3 100644
--- a/src/super_archives/views.py
+++ b/src/super_archives/views.py
@@ -2,6 +2,9 @@
import smtplib
import logging
+import urlparse
+
+import requests
from django import http
from django.conf import settings
@@ -21,7 +24,15 @@ from .models import MailingList, Thread, EmailAddress, EmailAddressValidation
def thread(request, mailinglist, thread_token):
+ if request.method == 'GET':
+ return thread_get(request, mailinglist, thread_token)
+ elif request.method == 'POST':
+ return thread_post(request, mailinglist, thread_token)
+ else:
+ return HttpResponseNotAllowed(['HEAD', 'GET', 'POST'])
+
+def thread_get(request, mailinglist, thread_token):
try:
first_message = queries.get_first_message_in_thread(mailinglist,
thread_token)
@@ -60,6 +71,47 @@ def thread(request, mailinglist, thread_token):
return render(request, 'message-thread.html', context)
+def thread_post(request, mailinglist, thread_token):
+ try:
+ thread = Thread.objects.get(subject_token=thread_token,
+ mailinglist__name=mailinglist)
+ except Thread.DoesNotExist:
+ raise http.Http404
+
+ data = {}
+ data['email_from'] = '{} <{}>'.format(request.user.get_full_name(),
+ request.user.email)
+ data['subject'] = thread.message_set.first().subject_clean
+ data['body'] = request.POST.get('body', '').strip()
+
+ url = urlparse.urljoin(settings.MAILMAN_API_URL, mailinglist + '/sendmail')
+
+ error_msg = None
+ try:
+ resp = requests.post(url, data=data, timeout=2)
+ except requests.exceptions.ConnectionError:
+ resp = None
+ error_msg = _('Error trying to connect to Mailman API')
+ except requests.exceptions.Timeout:
+ resp = None
+ error_msg = _('Timout trying to connect to Mailman API')
+
+ if resp and resp.status_code == 200:
+ messages.success(request, _("Your message was sent. It may take "
+ "some minutes before it's delivered. "
+ "Why don't you breath some fresh air "
+ "in the meanwhile."))
+ else:
+ if not error_msg:
+ if resp and resp.status_code == 400:
+ error_msg = _('You cannot send an empty email')
+ else:
+ error_msg = _('Unkown error trying to connect to Mailman API')
+ messages.error(request, error_msg)
+
+ return thread_get(request, mailinglist, thread_token)
+
+
def list_messages(request):
selected_lists = request.GET.get('list', [])
if selected_lists:
--
libgit2 0.21.2