Merge branch 'crash7-pop3-support'

This commit is contained in:
Thomas VIAL 2016-01-26 12:57:24 +01:00
commit 364748ab83
6 changed files with 48 additions and 12 deletions

View file

@ -5,9 +5,9 @@ MAINTAINER Thomas VIAL
RUN apt-get update -q --fix-missing RUN apt-get update -q --fix-missing
RUN apt-get -y upgrade RUN apt-get -y upgrade
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install vim postfix sasl2-bin courier-imap courier-imap-ssl \ RUN DEBIAN_FRONTEND=noninteractive apt-get -y install vim postfix sasl2-bin courier-imap courier-imap-ssl \
courier-authdaemon supervisor gamin amavisd-new spamassassin clamav clamav-daemon libnet-dns-perl libmail-spf-perl \ courier-pop courier-pop-ssl courier-authdaemon supervisor gamin amavisd-new spamassassin clamav clamav-daemon libnet-dns-perl libmail-spf-perl \
pyzor razor arj bzip2 cabextract cpio file gzip nomarch p7zip pax unzip zip zoo rsyslog mailutils netcat \ pyzor razor arj bzip2 cabextract cpio file gzip nomarch p7zip pax unzip zip zoo rsyslog mailutils netcat \
opendkim opendkim-tools opendkim opendkim-tools
RUN apt-get autoclean && rm -rf /var/lib/apt/lists/* RUN apt-get autoclean && rm -rf /var/lib/apt/lists/*
# Configures Saslauthd # Configures Saslauthd
@ -60,4 +60,8 @@ EXPOSE 587
EXPOSE 143 EXPOSE 143
EXPOSE 993 EXPOSE 993
# POP3 ports
EXPOSE 110
EXPOSE 995
CMD /usr/local/bin/start-mailserver.sh CMD /usr/local/bin/start-mailserver.sh

View file

@ -10,18 +10,15 @@ run:
# Copy test files # Copy test files
cp test/accounts.cf postfix/ cp test/accounts.cf postfix/
cp test/virtual postfix/ cp test/virtual postfix/
# Run container # Run containers
docker run -d --name mail \ docker run -d --name mail -v "`pwd`/postfix":/tmp/postfix -v "`pwd`/spamassassin":/tmp/spamassassin -v "`pwd`/test":/tmp/test -h mail.my-domain.com -t $(NAME):$(VERSION)
-v "`pwd`/postfix":/tmp/postfix \ docker run -d --name mail_pop3 -v "`pwd`/postfix":/tmp/postfix -v "`pwd`/spamassassin":/tmp/spamassassin -v "`pwd`/test":/tmp/test -e ENABLE_POP3=1 -h mail.my-domain.com -t $(NAME):$(VERSION)
-v "`pwd`/spamassassin":/tmp/spamassassin \
-v "`pwd`/test":/tmp/test \
-h mail.my-domain.com \
-t $(NAME):$(VERSION)
sleep 25 sleep 25
prepare: prepare:
# Reinitialize logs # Reinitialize logs
docker exec mail /bin/sh -c 'echo "" > /var/log/mail.log' docker exec mail /bin/sh -c 'echo "" > /var/log/mail.log'
docker exec mail_pop3 /bin/sh -c 'echo "" > /var/log/mail.log'
fixtures: fixtures:
# Sending test mails # Sending test mails

View file

@ -14,6 +14,8 @@ Includes:
- spamassasin - spamassasin
- clamav with automatic updates - clamav with automatic updates
- opendkim - opendkim
- [LetsEncrypt](https://letsencrypt.org/) and self-signed certificates
- optional pop3 server (add `-e ENABLE_POP3=1` to enable pop3 server)
Why I created this image: [Simple mail server with Docker](http://tvi.al/simple-mail-server-with-docker/) Why I created this image: [Simple mail server with Docker](http://tvi.al/simple-mail-server-with-docker/)

View file

@ -111,6 +111,12 @@ case $DMS_SSL in
cat "/etc/letsencrypt/live/$(hostname)/privkey.pem" "/etc/letsencrypt/live/$(hostname)/cert.pem" > "/etc/letsencrypt/live/$(hostname)/combined.pem" cat "/etc/letsencrypt/live/$(hostname)/privkey.pem" "/etc/letsencrypt/live/$(hostname)/cert.pem" > "/etc/letsencrypt/live/$(hostname)/combined.pem"
sed -i -r 's/TLS_CERTFILE=\/etc\/courier\/imapd.pem/TLS_CERTFILE=\/etc\/letsencrypt\/live\/'$(hostname)'\/combined.pem/g' /etc/courier/imapd-ssl sed -i -r 's/TLS_CERTFILE=\/etc\/courier\/imapd.pem/TLS_CERTFILE=\/etc\/letsencrypt\/live\/'$(hostname)'\/combined.pem/g' /etc/courier/imapd-ssl
# POP3 courier configuration
sed -i -r 's/POP3_TLS_REQUIRED=0/POP3_TLS_REQUIRED=1/g' /etc/courier/pop3d-ssl
sed -i -r 's/TLS_CERTFILE=\/etc\/courier\/pop3d.pem/TLS_CERTFILE=\/etc\/letsencrypt\/live\/'$(hostname)'-combined.pem/g' /etc/courier/pop3d-ssl
# needed to support gmail
sed -i -r 's/TLS_TRUSTCERTS=\/etc\/ssl\/certs/TLS_TRUSTCERTS=\/etc\/letsencrypt\/live\/'$(hostname)'-fullchain.pem/g' /etc/courier/pop3d-ssl
echo "SSL configured with letsencrypt certificates" echo "SSL configured with letsencrypt certificates"
;; ;;
@ -138,9 +144,13 @@ case $DMS_SSL in
# Courier configuration # Courier configuration
sed -i -r 's/TLS_CERTFILE=\/etc\/courier\/imapd.pem/TLS_CERTFILE=\/etc\/postfix\/ssl\/'$(hostname)'-combined.pem/g' /etc/courier/imapd-ssl sed -i -r 's/TLS_CERTFILE=\/etc\/courier\/imapd.pem/TLS_CERTFILE=\/etc\/postfix\/ssl\/'$(hostname)'-combined.pem/g' /etc/courier/imapd-ssl
echo "SSL configured with self-signed/custom certificates" # POP3 courier configuration
fi sed -i -r 's/POP3_TLS_REQUIRED=0/POP3_TLS_REQUIRED=1/g' /etc/courier/pop3d-ssl
sed -i -r 's/TLS_CERTFILE=\/etc\/courier\/pop3d.pem/TLS_CERTFILE=\/etc\/postfix\/ssl\/'$(hostname)'-combined.pem/g' /etc/courier/pop3d-ssl
echo "SSL configured with self-signed/custom certificates"
fi
;; ;;
esac esac
@ -167,6 +177,13 @@ cron
/etc/init.d/courier-authdaemon start /etc/init.d/courier-authdaemon start
/etc/init.d/courier-imap start /etc/init.d/courier-imap start
/etc/init.d/courier-imap-ssl start /etc/init.d/courier-imap-ssl start
if [ "$ENABLE_POP3" = 1 ]; then
echo "Starting POP3 services"
/etc/init.d/courier-pop start
/etc/init.d/courier-pop-ssl start
fi
/etc/init.d/spamassassin start /etc/init.d/spamassassin start
/etc/init.d/clamav-daemon start /etc/init.d/clamav-daemon start
/etc/init.d/amavis start /etc/init.d/amavis start

4
test/auth/pop3-auth.txt Normal file
View file

@ -0,0 +1,4 @@
USER user1@localhost.localdomain
PASS mypassword
LIST
quit

View file

@ -3,16 +3,24 @@
# Set up test framework # Set up test framework
source assert.sh source assert.sh
# Testing that services are running # Testing that services are running and pop3 is disabled
assert_raises "docker exec mail ps aux --forest | grep '/usr/lib/postfix/master'" 0 assert_raises "docker exec mail ps aux --forest | grep '/usr/lib/postfix/master'" 0
assert_raises "docker exec mail ps aux --forest | grep '/usr/sbin/saslauthd'" 0 assert_raises "docker exec mail ps aux --forest | grep '/usr/sbin/saslauthd'" 0
assert_raises "docker exec mail ps aux --forest | grep '/usr/sbin/clamd'" 0 assert_raises "docker exec mail ps aux --forest | grep '/usr/sbin/clamd'" 0
assert_raises "docker exec mail ps aux --forest | grep '/usr/sbin/amavisd-new'" 0 assert_raises "docker exec mail ps aux --forest | grep '/usr/sbin/amavisd-new'" 0
assert_raises "docker exec mail ps aux --forest | grep '/usr/lib/courier/courier/courierpop3d'" 1
# Testing services of pop3 container
assert_raises "docker exec mail_pop3 ps aux --forest | grep '/usr/lib/courier/courier/courierpop3d'" 0
# Testing IMAP server # Testing IMAP server
assert_raises "docker exec mail nc -w 1 0.0.0.0 143 | grep '* OK' | grep 'STARTTLS' | grep 'Courier-IMAP ready'" 0 assert_raises "docker exec mail nc -w 1 0.0.0.0 143 | grep '* OK' | grep 'STARTTLS' | grep 'Courier-IMAP ready'" 0
assert_raises "docker exec mail /bin/sh -c 'nc -w 1 0.0.0.0 143 < /tmp/test/auth/imap-auth.txt'" 0 assert_raises "docker exec mail /bin/sh -c 'nc -w 1 0.0.0.0 143 < /tmp/test/auth/imap-auth.txt'" 0
# Testing POP3 server on pop3 container
assert_raises "docker exec mail_pop3 nc -w 1 0.0.0.0 110 | grep '+OK'" 0
assert_raises "docker exec mail_pop3 /bin/sh -c 'nc -w 1 0.0.0.0 110 < /tmp/test/auth/pop3-auth.txt'" 0
# Testing SASL # Testing SASL
assert_raises "docker exec mail testsaslauthd -u user2 -r otherdomain.tld -p mypassword | grep 'OK \"Success.\"'" 0 assert_raises "docker exec mail testsaslauthd -u user2 -r otherdomain.tld -p mypassword | grep 'OK \"Success.\"'" 0
assert_raises "docker exec mail testsaslauthd -u user2 -r otherdomain.tld -p BADPASSWORD | grep 'NO \"authentication failed\"'" 0 assert_raises "docker exec mail testsaslauthd -u user2 -r otherdomain.tld -p BADPASSWORD | grep 'NO \"authentication failed\"'" 0
@ -53,5 +61,9 @@ assert "docker exec mail crontab -l" "0 1 * * * /usr/bin/freshclam --quiet"
assert_raises "docker exec mail grep 'non-null host address bits in' /var/log/mail.log" 1 assert_raises "docker exec mail grep 'non-null host address bits in' /var/log/mail.log" 1
assert_raises "docker exec mail grep ': error:' /var/log/mail.log" 1 assert_raises "docker exec mail grep ': error:' /var/log/mail.log" 1
# Testing that pop3 container log don't display errors
assert_raises "docker exec mail_pop3 grep 'non-null host address bits in' /var/log/mail.log" 1
assert_raises "docker exec mail_pop3 grep ': error:' /var/log/mail.log" 1
# Ending tests # Ending tests
assert_end assert_end