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
7f63c199
Commit
7f63c199
authored
Sep 01, 2013
by
Joshua Tauberer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move the sieve script configuration to tools/mail.py
parent
0c199b2e
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
30 additions
and
40 deletions
+30
-40
dovecot_sieve.txt
conf/dovecot_sieve.txt
+8
-0
add_mail_user.sh
scripts/add_mail_user.sh
+0
-13
spamassassin.sh
scripts/spamassassin.sh
+2
-2
start.sh
scripts/start.sh
+9
-2
users_update.sh
scripts/users_update.sh
+0
-22
mail.py
tools/mail.py
+11
-1
No files found.
conf/dovecot_sieve.txt
0 → 100644
View file @
7f63c199
require ["regex", "fileinto", "imap4flags"];
if allof (header :regex "X-Spam-Status" "^Yes") {
setflag "\\\\Seen";
fileinto "Spam";
stop;
}
scripts/add_mail_user.sh
deleted
100644 → 0
View file @
0c199b2e
# Create a new email user.
##########################
echo
echo
"Set up your first email account..."
read
-e
-i
"user@
`
hostname
`
"
-p
"Email Address: "
EMAIL_ADDR
read
-e
-p
"Email Password (blank to skip): "
EMAIL_PW
if
[
!
-z
"
$EMAIL_PW
"
]
;
then
echo
"INSERT INTO users (email, password) VALUES ('
$EMAIL_ADDR
', '
`
doveadm pw
-s
SHA512-CRYPT
-p
$EMAIL_PW
`
');"
\
| sqlite3
$STORAGE_ROOT
/mail/users.sqlite
fi
scripts/spamassassin.sh
View file @
7f63c199
...
...
@@ -6,8 +6,8 @@
# message over LMTP to dovecot for local delivery.
# In order to move spam automatically into the Spam folder we use the dovecot sieve
# plugin.
Unfortunately, each mail box needs its own sieve script set to do the
#
filtering work. So users_update.sh must be run any time a new
mail user is created.
# plugin.
The tools/mail.py tool creates the necessary sieve script for each mail
#
user when the
mail user is created.
# Install packages.
apt-get
-q
-y
install
spampd dovecot-sieve dovecot-antispam
...
...
scripts/start.sh
View file @
7f63c199
...
...
@@ -59,6 +59,13 @@ EOF
.
scripts/dkim.sh
.
scripts/spamassassin.sh
.
scripts/dns_update.sh
.
scripts/add_mail_user.sh
.
scripts/users_update.sh
if
[
-z
`
tools/mail.py user
`
]
;
then
# The outut of "tools/mail.py user" is a list of mail users. If there
# are none configured, ask the user to configure one.
echo
echo
"Let's create your first mail user."
read
-e
-i
"user@
`
hostname
`
"
-p
"Email Address: "
EMAIL_ADDR
tools/mail.py user add
$EMAIL_ADDR
# will ask for password
fi
scripts/users_update.sh
deleted
100644 → 0
View file @
0c199b2e
# Install dovecot sieve scripts to automatically move spam into the Spam folder.
db_path
=
$STORAGE_ROOT
/mail/users.sqlite
for
user
in
`
echo
"SELECT email FROM users;"
| sqlite3
$db_path
`
;
do
maildir
=
`
echo
$user
|
sed
"s/
\(
.*
\)
@
\(
.*
\)
/
\2\/\1
/"
`
# Write the sieve file to move mail classified as spam into the spam folder.
mkdir
-p
$STORAGE_ROOT
/mail/mailboxes/
$maildir
;
# in case user has not received any mail
cat
>
$STORAGE_ROOT
/mail/mailboxes/
$maildir
/.dovecot.sieve
<<
EOF
;
require ["regex", "fileinto", "imap4flags"];
if allof (header :regex "X-Spam-Status" "^Yes") {
setflag "
\\\\
Seen";
fileinto "Spam";
stop;
}
EOF
done
tools/mail.py
View file @
7f63c199
#!/usr/bin/python3
import
sys
,
sqlite3
,
subprocess
import
sys
,
sqlite3
,
subprocess
,
shutil
,
os
# Load STORAGE_ROOT setting from /etc/mailinabox.conf.
env
=
{
}
...
...
@@ -59,6 +59,16 @@ elif sys.argv[1] == "user" and sys.argv[2] in ("add", "password"):
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"
])
# Create the user's sieve script to move spam into the Spam folder, and make it owned by mail.
maildirstat
=
os
.
stat
(
env
[
"STORAGE_ROOT"
]
+
"/mail/mailboxes"
)
(
em_user
,
em_domain
)
=
email
.
split
(
"@"
,
1
)
user_mail_dir
=
env
[
"STORAGE_ROOT"
]
+
(
"/mail/mailboxes/
%
s/
%
s"
%
(
em_domain
,
em_user
))
if
not
os
.
path
.
exists
(
user_mail_dir
):
os
.
makedirs
(
user_mail_dir
)
os
.
chown
(
user_mail_dir
,
maildirstat
.
st_uid
,
maildirstat
.
st_gid
)
shutil
.
copyfile
(
"conf/dovecot_sieve.txt"
,
user_mail_dir
+
"/.dovecot.sieve"
)
os
.
chown
(
user_mail_dir
+
"/.dovecot.sieve"
,
maildirstat
.
st_uid
,
maildirstat
.
st_gid
)
elif
sys
.
argv
[
2
]
==
"password"
:
c
.
execute
(
"UPDATE users SET password=? WHERE email=?"
,
(
pw
,
email
))
if
c
.
rowcount
!=
1
:
...
...
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