diff --git a/src/postorius/views/list.py b/src/postorius/views/list.py index 54591e3..41f214d 100644 --- a/src/postorius/views/list.py +++ b/src/postorius/views/list.py @@ -22,6 +22,9 @@ from django.contrib.auth.decorators import (login_required, user_passes_test) from django.core.urlresolvers import reverse +from django.core.validators import validate_email +from django.core.exceptions import ValidationError + from django.shortcuts import render_to_response, redirect from django.template import RequestContext from django.utils.decorators import method_decorator @@ -284,24 +287,22 @@ else: emails = request.POST["emails"].splitlines() for email in emails: - parts = email.split('@') - if len(parts) != 2 or '.' not in parts[1]: + try: + validate_email(email) + self.mailing_list.unsubscribe(email.lower()) + messages.success(request, + 'The address %s has been unsubscribed from %s.' % + (email, self.mailing_list.fqdn_listname)) + except MailmanApiError: + return utils.render_api_error(request) + except HTTPError, e: + messages.error(request, e) + except ValueError, e: + messages.error(request, e) + except ValidationError: messages.error(request, - 'The email address %s is not valid.' % - email) - else: - try: - self.mailing_list.unsubscribe(email.lower()) - messages.success( - request, - 'The address %s has been unsubscribed from %s.' % - (email, self.mailing_list.fqdn_listname)) - except MailmanApiError: - return utils.render_api_error(request) - except HTTPError, e: - messages.error(request, e) - except ValueError, e: - messages.error(request, e) + 'The email address %s is not valid.' % + email) return redirect('mass_removal', self.mailing_list.list_id) def _get_choosable_domains(request):