email_server: aliases: Drop validation already done by form

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa authored and James Valleroy committed 2021-10-30 15:23:12 -04:00
1 parent f5d1cb474f
commit 19d45514de
1 file changed
-12
@@ -8,9 +8,6 @@ import os
import pwd
import sqlite3
from django.core.exceptions import ValidationError
from django.utils.translation import gettext_lazy as _
from plinth.modules.email_server import lock
from . import models
@@ -75,17 +72,8 @@ def put(uid_number, email_name):
SELECT 1 FROM Alias WHERE email_name=?
)"""
email_name = models.sanitize_email_name(email_name)
# email_name cannot be the same as a user name
try:
pwd.getpwnam(email_name)
raise ValidationError(_('The alias was taken'))
except KeyError:
pass
with db_cursor() as cur:
cur.execute(s, (email_name, uid_number, 1, email_name))
if cur.rowcount == 0:
raise ValidationError(_('The alias was taken'))
schedule_hash_update()