mail.check_uniqueness: Test initial inutile et initialisation de res
This commit is contained in:
parent
00f67697ee
commit
443876863f
1 changed files with 29 additions and 24 deletions
53
attributs.py
53
attributs.py
|
@ -754,35 +754,40 @@ class mail(rightProtectedAttr):
|
||||||
|
|
||||||
def check_uniqueness(self, liste_exclue):
|
def check_uniqueness(self, liste_exclue):
|
||||||
attr = self.__class__.__name__
|
attr = self.__class__.__name__
|
||||||
|
|
||||||
if str(self) in liste_exclue:
|
if str(self) in liste_exclue:
|
||||||
return
|
return
|
||||||
if attr in ["mailAlias", "canonicalAlias", 'mail', 'mailExt']:
|
|
||||||
mail = str(self)
|
|
||||||
|
|
||||||
_, domain = mail.split('@')
|
# On initialise le résultat, s'il vaut true en fin de course, le mail
|
||||||
if domain in config.dns.mail_crans:
|
# est déjà pris.
|
||||||
# On commence par vérifier auprès du serveur SMTP
|
res = False
|
||||||
# si l'adresse email est prise sur le réseau. Cela permet
|
|
||||||
# de tester aussi les adresses statiquement écrites dans
|
|
||||||
# aliases.db.
|
|
||||||
try:
|
|
||||||
smtp = smtplib.SMTP(smtpserv)
|
|
||||||
smtp.putcmd("vrfy", mail)
|
|
||||||
res = smtp.getreply()[0] in [250, 252]
|
|
||||||
smtp.close()
|
|
||||||
except:
|
|
||||||
print 'Serveur de mail injoignable'
|
|
||||||
|
|
||||||
check = self.conn.search(
|
mail = str(self)
|
||||||
u'(|(mail=%(mail)s)(mailAlias=%(mail)s)(canonicalAlias=%(mail)s)(mailExt=%(mail)s))' % {
|
|
||||||
'mail': mail,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
if len(check) >= 1:
|
|
||||||
res = True
|
|
||||||
|
|
||||||
if res:
|
_, domain = mail.split('@')
|
||||||
raise ValueError("Le mail %s est déjà pris." % (str(self)))
|
if domain in config.dns.mail_crans:
|
||||||
|
# On commence par vérifier auprès du serveur SMTP
|
||||||
|
# si l'adresse email est prise sur le réseau. Cela permet
|
||||||
|
# de tester aussi les adresses statiquement écrites dans
|
||||||
|
# aliases.db.
|
||||||
|
try:
|
||||||
|
smtp = smtplib.SMTP(smtpserv)
|
||||||
|
smtp.putcmd("vrfy", mail)
|
||||||
|
res = smtp.getreply()[0] in [250, 252]
|
||||||
|
smtp.close()
|
||||||
|
except:
|
||||||
|
print 'Serveur de mail injoignable'
|
||||||
|
|
||||||
|
check = self.conn.search(
|
||||||
|
u'(|(mail=%(mail)s)(mailAlias=%(mail)s)(canonicalAlias=%(mail)s)(mailExt=%(mail)s))' % {
|
||||||
|
'mail': mail,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
if len(check) >= 1:
|
||||||
|
res = True
|
||||||
|
|
||||||
|
if res:
|
||||||
|
raise ValueError("Le mail %s est déjà pris." % (str(self)))
|
||||||
|
|
||||||
def parse_value(self, mail):
|
def parse_value(self, mail):
|
||||||
if not re.match(u'^[-+_.0-9A-Za-z]+@([A-Za-z0-9]{1}[A-Za-z0-9-_]+[.])+[a-z]{2,20}$', mail):
|
if not re.match(u'^[-+_.0-9A-Za-z]+@([A-Za-z0-9]{1}[A-Za-z0-9-_]+[.])+[a-z]{2,20}$', mail):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue