Pavan Koli has proposed merging lp:~pskoli93/postorius/validation-fix into
lp:postorius.
Commit message:
Fixes to validation during mass subscription
Requested reviews:
Florian Fuchs (flo-fuchs)
Related bugs:
Bug #1441314 in Postorius: "Wrong email ids passing validation during mass
subscription"
https://bugs.launchpad.net/postorius/+bug/1441314
For more details, see:
https://code.launchpad.net/~pskoli93/postorius/validation-fix/+merge/255461
While using the mass subscription option to subscribe many email ids, email ids
such as '@gmail.com' are passing through.
Django validators have been used now to validate the email ids.
Also some changes have been made to the file postorius/src/postorius/forms.py.
On leaving the Mail Host and Web Host column blank while creating a new domain,
a message 'Please a domain name' used to get displayed which seems not to help
much. Change has been made to now display 'Please enter a Mail Host' and
'Please enter a Web Host' if you leave that respective column blank.
--
Your team Mailman Coders is subscribed to branch lp:postorius.
=== modified file 'src/postorius/forms.py'
--- src/postorius/forms.py 2015-02-09 14:35:44 +0000
+++ src/postorius/forms.py 2015-04-08 06:26:12 +0000
@@ -30,13 +30,13 @@
"""
mail_host = forms.CharField(
label=_('Mail Host'),
- error_messages={'required': _('Please a domain name'),
- 'invalid': _('Please enter a valid domain name.')},
+ error_messages={'required': _('Please enter a Mail Host'),
+ 'invalid': _('Please enter a valid Mail Host.')},
required=True)
web_host = forms.CharField(
label=_('Web Host'),
- error_messages={'required': _('Please a domain name'),
- 'invalid': _('Please enter a valid domain name.')},
+ error_messages={'required': _('Please enter a Web Host'),
+ 'invalid': _('Please enter a valid Web Host.')},
required=True)
description = forms.CharField(
label=_('Description'),
@@ -50,7 +50,7 @@
try:
validate_email('mail@' + mail_host)
except:
- raise forms.ValidationError(_("Enter a valid Mail Host"))
+ raise forms.ValidationError(_("Please enter a valid Mail Host"))
return mail_host
def clean_web_host(self):
=== modified file 'src/postorius/models.py'
--- src/postorius/models.py 2015-02-09 14:35:44 +0000
+++ src/postorius/models.py 2015-04-08 06:26:12 +0000
@@ -35,7 +35,7 @@
from mailmanclient import MailmanConnectionError
from postorius.utils import get_client
from urllib2 import HTTPError
-
+from django.core.exceptions import ImproperlyConfigured
logger = logging.getLogger(__name__)
@@ -261,8 +261,8 @@
The following settings are recognized:
>>> EMAIL_CONFIRMATION_TEMPLATE = 'postorius/address_confirmation_message.txt'
- >>> EMAIL_CONFIRMATION_FROM = 'Confirmation needed'
- >>> EMAIL_CONFIRMATION_SUBJECT = '[email protected]'
+ >>> EMAIL_CONFIRMATION_FROM = '[email protected]'
+ >>> EMAIL_CONFIRMATION_SUBJECT = 'Confirmation needed'
:param request: The HTTP request object.
:type request: HTTPRequest
@@ -287,9 +287,13 @@
if not template_context:
template_context = Context(
{'activation_link': activation_link, 'host_url': host_url})
+
+ mail_from=getattr(settings, 'EMAIL_CONFIRMATION_FROM', getattr(settings, 'DEFAULT_FROM_EMAIL', 'NONE'))
+ if(mail_from == 'NONE'):
+ raise ImproperlyConfigured("Configurations have not been done properly, EMAIL_CONFIRMATION_FROM or DEFAULT_FROM_EMAIL value(s) have not been set")
email_subject = getattr(
settings, 'EMAIL_CONFIRMATION_SUBJECT', u'Confirmation needed')
send_mail(email_subject,
get_template(template_path).render(template_context),
- getattr(settings, 'EMAIL_CONFIRMATION_FROM'),
+ mail_from,
[self.email])
=== modified file 'src/postorius/views/list.py'
--- src/postorius/views/list.py 2015-02-09 14:35:44 +0000
+++ src/postorius/views/list.py 2015-04-08 06:26:12 +0000
@@ -27,6 +27,8 @@
from django.utils.decorators import method_decorator
from django.utils.translation import gettext as _
from urllib2 import HTTPError
+from django.core.validators import validate_email
+from django.core.exceptions import ValidationError
from postorius import utils
from postorius.models import (Domain, List, MailmanUser,
@@ -249,9 +251,10 @@
else:
emails = request.POST["emails"].splitlines()
for email in emails:
- parts = email.split('@')
- if len(parts) != 2 or '.' not in parts[1]:
- messages.error(request,
+ try:
+ validate_email( email )
+ except ValidationError:
+ messages.error(request,
'The email address %s is not valid.' %
email)
else:
_______________________________________________
Mailman-coders mailing list
[email protected]
https://mail.python.org/mailman/listinfo/mailman-coders