mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-27 10:44:33 +00:00
email_server: aliases: Add method for checking of an alias is taken
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
b0d3bdb170
commit
b0e460b433
@ -55,6 +55,20 @@ def get(uid_number):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def exists(email_name):
|
||||||
|
"""Return whether alias is already taken."""
|
||||||
|
try:
|
||||||
|
pwd.getpwnam(email_name)
|
||||||
|
return True
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
with db_cursor() as cur:
|
||||||
|
query = 'SELECT COUNT(*) FROM Alias WHERE email_name=?'
|
||||||
|
cur.execute(query, (email_name, ))
|
||||||
|
return cur.fetchone()[0] != 0
|
||||||
|
|
||||||
|
|
||||||
def put(uid_number, email_name):
|
def put(uid_number, email_name):
|
||||||
s = """INSERT INTO Alias(email_name, uid_number, status)
|
s = """INSERT INTO Alias(email_name, uid_number, status)
|
||||||
SELECT ?,?,? WHERE NOT EXISTS(
|
SELECT ?,?,? WHERE NOT EXISTS(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user