Implement fetchmail (#260) (#271)

To retrieve emails from external mail accounts.
This commit is contained in:
Josef Friedrich 2016-08-21 22:13:13 +02:00 committed by Thomas VIAL
parent 8b289f6717
commit e7de8b9245
8 changed files with 77 additions and 3 deletions

View File

@ -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/

View File

@ -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

View File

@ -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

13
config/fetchmail.cf Normal file
View File

@ -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

View File

@ -0,0 +1,7 @@
# General options
set daemon 300
set syslog
# Fetch rules

View File

@ -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

5
test/config/fetchmail.cf Normal file
View File

@ -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

View File

@ -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
#