1
0
mirror of https://github.com/mail-in-a-box/mailinabox.git synced 2024-11-25 02:47:04 +00:00

mail.py: check that mailboxes don't exist before creating them

This commit is contained in:
Joshua Tauberer 2013-09-01 10:13:34 -04:00
parent 5b82bbb5b3
commit acaa29e8db

View File

@ -48,10 +48,17 @@ elif sys.argv[1] == "user" and sys.argv[2] in ("add", "password"):
print("User already exists.")
sys.exit(1)
# Create the user's INBOX and subscribe it.
conn.commit() # write it before next step
subprocess.check_call(["doveadm", "mailbox", "create", "-u", email, "-s", "INBOX"])
subprocess.check_call(["doveadm", "mailbox", "create", "-u", email, "-s", "Spam"])
# Create the user's INBOX and Spam folders and subscribe them.
# Check if the mailboxes exist before creating them. When creating a user that had previously
# been deleted, the mailboxes will still exist because they are still on disk.
existing_mboxes = subprocess.check_output(["doveadm", "mailbox", "list", "-u", email, "-8"]).decode("utf8").split("\n")
if "INBOX" not in existing_mboxes: subprocess.check_call(["doveadm", "mailbox", "create", "-u", email, "-s", "INBOX"])
if "Spam" not in existing_mboxes: subprocess.check_call(["doveadm", "mailbox", "create", "-u", email, "-s", "Spam"])
elif sys.argv[2] == "password":
c.execute("UPDATE users SET password=? WHERE email=?", (pw, email))
if c.rowcount != 1: