mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-12-03 12:14:12 +01:00
Merge pull request #697 from vingeni/master
fixed #413 email checking for to/cc/cci in webmail
This commit is contained in:
@@ -14,6 +14,7 @@ from .lib import (
|
|||||||
ImapEmail, create_mail_attachment
|
ImapEmail, create_mail_attachment
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from validators import validate_email_list
|
||||||
|
|
||||||
def html2plaintext(content):
|
def html2plaintext(content):
|
||||||
"""HTML to plain text translation.
|
"""HTML to plain text translation.
|
||||||
@@ -76,13 +77,14 @@ def make_body_images_inline(body):
|
|||||||
return lxml.html.tostring(html), parts
|
return lxml.html.tostring(html), parts
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ComposeMailForm(forms.Form):
|
class ComposeMailForm(forms.Form):
|
||||||
|
|
||||||
"""Compose mail form."""
|
"""Compose mail form."""
|
||||||
|
|
||||||
to = forms.CharField(label=_("To"))
|
to = forms.CharField(label=_("To"), validators=[validate_email_list])
|
||||||
cc = forms.CharField(label=_("Cc"), required=False)
|
cc = forms.CharField(label=_("Cc"), required=False, validators=[validate_email_list])
|
||||||
cci = forms.CharField(label=_("Cci"), required=False)
|
cci = forms.CharField(label=_("Cci"), required=False, validators=[validate_email_list])
|
||||||
subject = forms.CharField(
|
subject = forms.CharField(
|
||||||
label=_("Subject"),
|
label=_("Subject"),
|
||||||
max_length=255,
|
max_length=255,
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
<div class="form-group{% if form.errors.to %} has-error{% endif %}">
|
<div class="form-group{% if form.errors.to %} has-error{% endif %}">
|
||||||
<label class="col-sm-1 control-label" for="id_to">{% trans "To" %}</label>
|
<label class="col-sm-1 control-label" for="id_to">{% trans "To" %}</label>
|
||||||
<div class="col-sm-8">
|
<div class="col-sm-8">
|
||||||
<input id="id_to" name="to" class="form-control" value="{% if form.to.value %}{{ form.to.value }}{% endif %}"{% if form.to.errors %} placeholder="{% for error in form.to.errors %}{{ error }}{% endfor %}"{% endif %}>
|
<input id="id_to" name="to" class="form-control" value="{% if form.to.value %}{{ form.to.value }}{% endif %}"{% if form.to.errors %} placeholder="{% for error in form.to.errors %}{{ error }}{% endfor %}" title="{% for error in form.to.errors %}{{ error }}{% endfor %}"{% endif %}>
|
||||||
</div>
|
</div>
|
||||||
{% if not form.cc.value %}
|
{% if not form.cc.value %}
|
||||||
<div class="col-sm-2">
|
<div class="col-sm-2">
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
from django.utils.encoding import force_text
|
||||||
|
from django.utils.deconstruct import deconstructible
|
||||||
|
from django.core.validators import validate_email
|
||||||
|
from email.utils import getaddresses
|
||||||
|
|
||||||
|
class EmailListValidator(object):
|
||||||
|
"""
|
||||||
|
Validate a comma separated list of email
|
||||||
|
"""
|
||||||
|
def __call__(self, value):
|
||||||
|
value = force_text(value)
|
||||||
|
emails = map(unicode.strip, value.split(','))
|
||||||
|
addresses = getaddresses(emails)
|
||||||
|
[ validate_email(e) for r, e in addresses ]
|
||||||
|
|
||||||
|
validate_email_list = EmailListValidator()
|
||||||
|
|
||||||
Reference in New Issue
Block a user