From e7de8b9245f6eb5510e6c36037bc19759169b58b Mon Sep 17 00:00:00 2001 From: Josef Friedrich Date: Sun, 21 Aug 2016 22:13:13 +0200 Subject: [PATCH] Implement fetchmail (#260) (#271) To retrieve emails from external mail accounts. --- Dockerfile | 6 +++++- Makefile | 11 +++++++++-- README.md | 5 +++++ config/fetchmail.cf | 13 +++++++++++++ target/fetchmail/fetchmailrc | 7 +++++++ target/start-mailserver.sh | 9 +++++++++ test/config/fetchmail.cf | 5 +++++ test/tests.bats | 24 ++++++++++++++++++++++++ 8 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 config/fetchmail.cf create mode 100644 target/fetchmail/fetchmailrc create mode 100644 test/config/fetchmail.cf diff --git a/Dockerfile b/Dockerfile index 8d45f4ca..2965d381 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,7 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get update -q --fix-missing && \ apt-get -y install --no-install-recommends \ postfix dovecot-core dovecot-imapd dovecot-pop3d dovecot-sieve dovecot-managesieved gamin amavisd-new spamassassin razor pyzor libsasl2-modules \ clamav clamav-daemon libnet-dns-perl libmail-spf-perl bzip2 file gzip p7zip unzip arj rsyslog \ - opendkim opendkim-tools opendmarc curl fail2ban ed iptables && \ + opendkim opendkim-tools opendmarc curl fail2ban ed iptables fetchmail && \ curl -sk http://neuro.debian.net/lists/trusty.de-m.libre > /etc/apt/sources.list.d/neurodebian.sources.list && \ apt-key adv --recv-keys --keyserver hkp://pgp.mit.edu:80 0xA5D32F012649A5A9 && \ apt-get update -q --fix-missing && apt-get -y upgrade fail2ban && \ @@ -51,6 +51,10 @@ ADD target/opendkim/default-opendkim /etc/default/opendkim ADD target/opendmarc/opendmarc.conf /etc/opendmarc.conf ADD target/opendmarc/default-opendmarc /etc/default/opendmarc +# Configure fetchmail +ADD target/fetchmail/fetchmailrc /etc/fetchmailrc_general +RUN sed -i 's/START_DAEMON=no/START_DAEMON=yes/g' /etc/default/fetchmail + # Configures Postfix ADD target/postfix/main.cf target/postfix/master.cf /etc/postfix/ diff --git a/Makefile b/Makefile index 90788409..17672ec8 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ build: generate-accounts: docker run --rm -e MAIL_USER=user1@localhost.localdomain -e MAIL_PASS=mypassword -t $(NAME) /bin/sh -c 'echo "$$MAIL_USER|$$(doveadm pw -s SHA512-CRYPT -u $$MAIL_USER -p $$MAIL_PASS)"' > test/config/postfix-accounts.cf docker run --rm -e MAIL_USER=user2@otherdomain.tld -e MAIL_PASS=mypassword -t $(NAME) /bin/sh -c 'echo "$$MAIL_USER|$$(doveadm pw -s SHA512-CRYPT -u $$MAIL_USER -p $$MAIL_PASS)"' >> test/config/postfix-accounts.cf - + run: # Run containers docker run -d --name mail \ @@ -51,6 +51,13 @@ run: --cap-add=NET_ADMIN \ -h mail.my-domain.com -t $(NAME) sleep 20 + docker run -d --name mail_fetchmail \ + -v "`pwd`/test/config":/tmp/docker-mailserver \ + -v "`pwd`/test":/tmp/docker-mailserver-test \ + -e ENABLE_FETCHMAIL=1 \ + --cap-add=NET_ADMIN \ + -h mail.my-domain.com -t $(NAME) + sleep 20 docker run -d --name mail_disabled_amavis \ -v "`pwd`/test/config":/tmp/docker-mailserver \ -v "`pwd`/test":/tmp/docker-mailserver-test \ @@ -97,4 +104,4 @@ tests: clean: # Remove running test containers - docker rm -f mail mail_pop3 mail_smtponly mail_fail2ban fail-auth-mailer mail_disabled_amavis mail_disabled_spamassassin mail_disabled_clamav + docker rm -f mail mail_pop3 mail_smtponly mail_fail2ban mail_fetchmail fail-auth-mailer mail_disabled_amavis mail_disabled_spamassassin mail_disabled_clamav diff --git a/README.md b/README.md index f3b5af4f..48116a59 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ Includes: - opendkim - opendmarc - fail2ban +- fetchmail - basic [sieve support](https://github.com/tomav/docker-mailserver/wiki/Configure-Sieve-filters) using dovecot - [LetsEncrypt](https://letsencrypt.org/) and self-signed certificates - [integration tests](https://travis-ci.org/tomav/docker-mailserver) @@ -111,6 +112,10 @@ Otherwise, `iptables` won't be able to ban IPs. - **empty** => Managesieve service disabled - 1 => Enables Managesieve on port 4190 +##### ENABLE_FETCHMAIL + - **empty** => `fetchmail` disabled + - 1 => `fetchmail` enabled + ##### SA_TAG - **2.0** => add spam info headers if at, or above that level diff --git a/config/fetchmail.cf b/config/fetchmail.cf new file mode 100644 index 00000000..3a7e0c34 --- /dev/null +++ b/config/fetchmail.cf @@ -0,0 +1,13 @@ +## Example configuration: IMAP +#poll imap.example.com with proto IMAP +# user 'username' there with +# password 'secret' +# is 'user1@domain.tld' +# here ssl + +## Example configuration: POP3 +#poll pop3.example.com with proto POP3 +# user 'username' there with +# password 'secret' +# is 'user2@domain.tld' +# here options keep ssl diff --git a/target/fetchmail/fetchmailrc b/target/fetchmail/fetchmailrc new file mode 100644 index 00000000..e83f37e5 --- /dev/null +++ b/target/fetchmail/fetchmailrc @@ -0,0 +1,7 @@ +# General options + +set daemon 300 +set syslog + +# Fetch rules + diff --git a/target/start-mailserver.sh b/target/start-mailserver.sh index 3805f274..356266ac 100644 --- a/target/start-mailserver.sh +++ b/target/start-mailserver.sh @@ -352,6 +352,15 @@ if [ -f /tmp/docker-mailserver/dovecot.cf ]; then /usr/sbin/dovecot reload fi +# Enable fetchmail daemon +if [ "$ENABLE_FETCHMAIL" = 1 ]; then + if [ -f /tmp/docker-mailserver/fetchmail.cf ]; then + cat /etc/fetchmailrc_general /tmp/docker-mailserver/fetchmail.cf > /etc/fetchmailrc + fi + echo "Fetchmail enabled" + /etc/init.d/fetchmail start +fi + # Start services related to SMTP if ! [ "$DISABLE_SPAMASSASSIN" = 1 ]; then /etc/init.d/spamassassin start diff --git a/test/config/fetchmail.cf b/test/config/fetchmail.cf new file mode 100644 index 00000000..59ce814a --- /dev/null +++ b/test/config/fetchmail.cf @@ -0,0 +1,5 @@ +poll pop3.example.com with proto POP3 + user 'username' there with + password 'secret' + is 'user2@domain.tld' + here options keep ssl diff --git a/test/tests.bats b/test/tests.bats index 6a3fc876..c5e2b5c1 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -37,6 +37,16 @@ [ "$status" -eq 0 ] } +@test "checking process: fetchmail (disabled in default configuration)" { + run docker exec mail /bin/bash -c "ps aux --forest | grep -v grep | grep '/usr/bin/fetchmail'" + [ "$status" -eq 1 ] +} + +@test "checking process: fetchmail (fetchmail server enabled)" { + run docker exec mail_fetchmail /bin/bash -c "ps aux --forest | grep -v grep | grep '/usr/bin/fetchmail'" + [ "$status" -eq 0 ] +} + @test "checking process: amavis (amavis disabled by DISABLE_AMAVIS)" { run docker exec mail_disabled_amavis /bin/bash -c "ps aux --forest | grep -v grep | grep '/usr/sbin/amavisd-new'" [ "$status" -eq 1 ] @@ -436,6 +446,20 @@ [ "$status" -eq 1 ] } +# +# fetchmail +# + +@test "checking fetchmail: gerneral options in fetchmailrc are loaded" { + run docker exec mail_fetchmail grep 'set syslog' /etc/fetchmailrc + [ "$status" -eq 0 ] +} + +@test "checking fetchmail: fetchmail.cf is loaded" { + run docker exec mail_fetchmail grep 'pop3.example.com' /etc/fetchmailrc + [ "$status" -eq 0 ] +} + # # system #