This commit is contained in:
root 2022-03-29 21:04:54 +02:00
commit d1a8e36360
7 changed files with 158 additions and 0 deletions

34
Dockerfile Normal file

@ -0,0 +1,34 @@
FROM gentoo/portage:latest as portage
FROM gentoo/stage3:amd64
COPY --from=portage /var/db/repos/gentoo /var/db/repos/gentoo
# courier and pythonfilter install + activate + cleanup
RUN echo '=mail-filter/courier-pythonfilter-3.0.2-r1' > /etc/portage/package.accept_keywords && \
emerge mail-mta/courier mail-filter/courier-pythonfilter dev-python/pyspf dev-python/pydns && \
ln -s /usr/bin/pythonfilter /usr/libexec/filters && \
filterctl start pythonfilter && \
rm -rf /var/db/repos/gentoo
# courier config
RUN sed -i 's;^TCPDOPTS=.\+$;TCPDOPTS="-stderrlogger=/usr/sbin/courierlogger -nodnslookup -noidentlookup";' /etc/courier/esmtpd && \
sed -i 's;^TCPDOPTS=.\+$;TCPDOPTS="-stderrlogger=/usr/sbin/courierlogger -nodnslookup -noidentlookup";' /etc/courier/imapd && \
sed -i 's;^DEFAULTDELIVERY=.\+$;DEFAULTDELIVERY="| /usr/bin/maildrop";' /etc/courier/courierd && \
sed -i 's;^MAILDROPDEFAULT=.\+$;MAILDROPDEFAULT="./maildir";' /etc/courier/courierd && \
sed -i 's;^authmodulelist=.\+$;authmodulelist="authuserdb";' /etc/courier/authlib/authdaemonrc
#RUN sed -i 's;^DEFAULTDELIVERY=.\+$;DEFAULTDELIVERY="./maildir";' /etc/courier/courierd
# courier runtime
ADD start.sh /
RUN chmod +x /start.sh
ADD userdb.example /etc/courier/authlib
EXPOSE 25
EXPOSE 143
EXPOSE 993
VOLUME /conf
VOLUME /mail
CMD /start.sh

15
README.md Normal file

@ -0,0 +1,15 @@
# docker-courier
Docker image providing full [Courier MTA](http://www.courier-mta.org/) suite (not just IMAP)
# Usage
1. `git clone https://github.com/tuxmainy/docker-courier.git`
2. `cp env.example .env`
3. edit .env
4. make sure volume directories are present
5. `docker-compose up -d`
# add users
1. `echo -n 'mypassword' |openssl sha256 -binary |base64`
2. add new user to userdb:
`user@example.org systempw={SHA256}<your generated hash goes here>|home=/mail/user|uid=8|gid=12|mail=/mail/user/maildir`

32
docker-compose.yml Normal file

@ -0,0 +1,32 @@
version: "3.7"
services:
server:
build:
context: .
network_mode: bridge
ports:
- "138.201.55.55:25:25"
- "138.201.55.55:143:143"
- "138.201.55.55:993:993"
- "2a01:4f8:172:101f::2:25:25"
- "2a01:4f8:172:101f::2:143:143"
- "2a01:4f8:172:101f::2:993:993"
volumes:
- conf:/etc/courier
- mail:/mail
- /dev/log:/dev/log
hostname: devloop.de
restart: always
volumes:
conf:
driver_opts:
type: "none"
o: "bind"
device: "${DATA_BASE}/conf"
mail:
driver_opts:
type: "none"
o: "bind"
device: "${DATA_BASE}/mail"

2
env.example Normal file

@ -0,0 +1,2 @@
COMPOSE_PROJECT_NAME=courier
DATA_BASE=/path/to/my/basedir/containing/maildirandconf

68
start.sh Normal file

@ -0,0 +1,68 @@
#!/bin/bash
#test -e /etc/courier/esmtpd || cp -a /etc/courier.docker/* /etc/courier
OVERRIDE_CONF='/conf'
CONF='/etc/courier'
for d in `find "${OVERRIDE_CONF}" -mindepth 1 -type d`; do
basedir=`echo "${d}" |sed "s;^${OVERRIDE_CONF}/;;"`
confdir="${CONF}/${basedir}"
if [[ ! -e "${confdir}" ]]; then
mkdir "${confdir}"
elif [[ ! -d "${confdir}" ]]; then
echo "${confdir} is not a directory. Thus cannot override with a directory."
exit 1
fi
done
for f in `find "${OVERRIDE_CONF}" -mindepth 1 -type f ! -name '*.docker'`; do
basefile=`echo "${f}" |sed "s;^${OVERRIDE_CONF}/;;"`
conffile="${CONF}/${basefile}"
if [[ ! -e "${conffile}" ]]; then
cp -a "${f}" "${conffile}"
elif [[ -f "${conffile}" ]]; then
mv "${conffile}" "${f}.docker"
cp -a "${f}" "${conffile}"
else
echo "${conffile} is not a file. Thus cannot override with a file."
fi
done
/usr/sbin/makeacceptmailfor
/usr/sbin/makealiases
/usr/sbin/makeuserdb
/usr/sbin/makehosteddomains
/usr/sbin/makealiases
/usr/sbin/makesmtpaccess
#/usr/lib/courier/courier-authlib/authdaemond &
#/usr/sbin/couriertcpd -address=0 -maxprocs=40 -maxperip=20 -nodnslookup -noidentlookup 143 /usr/lib/courier/courier/imaplogin /usr/bin/imapd Maildir
/usr/sbin/authdaemond start
sleep 1
for home in `/usr/sbin/authenumerate |awk '{print $4}'`; do
if [[ ! -e "$home" ]]; then
mkdir -p "$home"
/usr/bin/maildirmake "$home/maildir"
fi
done
chown -R 8:12 /mail
chown -R 8:12 /etc/courier
chmod go-wrx /etc/courier/maildroprc
/usr/sbin/esmtpd start
/usr/sbin/courier-imapd start
/usr/sbin/courier-imapd-ssl start
/usr/sbin/courier start
#umask 0111
while true; do
#nc -lU /dev/log |sed 's/</\n</g' >&2
sleep 10
done

6
test.sh Executable file

@ -0,0 +1,6 @@
#!/bin/bash
base=`dirname $0`
base=`readlink -f "$base"`
docker run -v "$base/conftest:/conf" --rm -it "$1" "$2"

1
userdb.example Normal file

@ -0,0 +1 @@
user@example.org systempw={SHA256}0123456789abcdef=|home=/mail/maildir|uid=8|gid=12