Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mailinabox
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
mailinabox
Commits
560cd73b
Commit
560cd73b
authored
Aug 31, 2013
by
Joshua Tauberer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add a new mail user/alias configuration tool
parent
a1260b75
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
87 additions
and
0 deletions
+87
-0
mail.py
tools/mail.py
+87
-0
No files found.
tools/mail.py
0 → 100755
View file @
560cd73b
#!/usr/bin/python3
import
sys
,
sqlite3
,
subprocess
# Load STORAGE_ROOT setting from /etc/mailinabox.conf.
env
=
{
}
for
line
in
open
(
"/etc/mailinabox.conf"
):
env
.
setdefault
(
*
line
.
strip
()
.
split
(
"="
,
1
))
# Connect to database.
conn
=
sqlite3
.
connect
(
env
[
"STORAGE_ROOT"
]
+
"/mail/users.sqlite"
)
c
=
conn
.
cursor
()
if
len
(
sys
.
argv
)
<
2
:
print
(
"Usage: "
)
print
(
" scripts/mail_db_tool.py user (lists users)"
)
print
(
" scripts/mail_db_tool.py user add user@domain.com [password]"
)
print
(
" scripts/mail_db_tool.py user password user@domain.com [password]"
)
print
(
" scripts/mail_db_tool.py user remove user@domain.com"
)
print
(
" scripts/mail_db_tool.py alias (lists aliases)"
)
print
(
" scripts/mail_db_tool.py alias add incoming.name@domain.com sent.to@other.domain.com"
)
print
(
" scripts/mail_db_tool.py alias remove incoming.name@domain.com"
)
print
()
print
(
"Removing a mail user does not delete their mail folders on disk. It only prevents IMAP/SMTP login."
)
print
()
elif
sys
.
argv
[
1
]
==
"user"
and
len
(
sys
.
argv
)
==
2
:
c
.
execute
(
'SELECT email FROM users'
)
for
row
in
c
.
fetchall
():
print
(
row
[
0
])
elif
sys
.
argv
[
1
]
==
"user"
and
sys
.
argv
[
2
]
in
(
"add"
,
"password"
):
if
len
(
sys
.
argv
)
<
5
:
if
len
(
sys
.
argv
)
<
4
:
email
=
input
(
"email: "
)
else
:
email
=
sys
.
argv
[
3
]
pw
=
input
(
"password: "
)
else
:
email
,
pw
=
sys
.
argv
[
3
:
5
]
# hash the password
pw
=
subprocess
.
check_output
([
"/usr/bin/doveadm"
,
"pw"
,
"-s"
,
"SHA512-CRYPT"
,
"-p"
,
pw
])
.
strip
()
if
sys
.
argv
[
2
]
==
"add"
:
try
:
c
.
execute
(
"INSERT INTO users (email, password) VALUES (?, ?)"
,
(
email
,
pw
))
except
sqlite3
.
IntegrityError
:
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"
])
elif
sys
.
argv
[
2
]
==
"password"
:
c
.
execute
(
"UPDATE users SET password=? WHERE email=?"
,
(
pw
,
email
))
if
c
.
rowcount
!=
1
:
print
(
"That's not a user."
)
sys
.
exit
(
1
)
elif
sys
.
argv
[
1
]
==
"user"
and
sys
.
argv
[
2
]
==
"remove"
and
len
(
sys
.
argv
)
==
4
:
c
.
execute
(
"DELETE FROM users WHERE email=?"
,
(
sys
.
argv
[
3
],))
if
c
.
rowcount
!=
1
:
print
(
"That's not a user."
)
sys
.
exit
(
1
)
elif
sys
.
argv
[
1
]
==
"alias"
and
len
(
sys
.
argv
)
==
2
:
c
.
execute
(
'SELECT source, destination FROM aliases'
)
for
row
in
c
.
fetchall
():
print
(
row
[
0
],
"=>"
,
row
[
1
])
elif
sys
.
argv
[
1
]
==
"alias"
and
sys
.
argv
[
2
]
==
"add"
and
len
(
sys
.
argv
)
==
5
:
try
:
c
.
execute
(
"INSERT INTO aliases (source, destination) VALUES (?, ?)"
,
(
sys
.
argv
[
3
],
sys
.
argv
[
4
]))
except
sqlite3
.
IntegrityError
:
print
(
"Alias already exists."
)
sys
.
exit
(
1
)
elif
sys
.
argv
[
1
]
==
"alias"
and
sys
.
argv
[
2
]
==
"remove"
and
len
(
sys
.
argv
)
==
4
:
c
.
execute
(
"DELETE FROM aliases WHERE source=?"
,
(
sys
.
argv
[
3
],))
if
c
.
rowcount
!=
1
:
print
(
"That's not an alias."
)
sys
.
exit
(
1
)
else
:
print
(
"Invalid command-line arguments."
)
conn
.
commit
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment