commit d1a8e36360078cb850c87b333f0fd03a6107ebc4 Author: root Date: Tue Mar 29 21:04:54 2022 +0200 init diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f4f7bdd --- /dev/null +++ b/Dockerfile @@ -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 diff --git a/README.md b/README.md new file mode 100644 index 0000000..f77cd6a --- /dev/null +++ b/README.md @@ -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}|home=/mail/user|uid=8|gid=12|mail=/mail/user/maildir` diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..780d495 --- /dev/null +++ b/docker-compose.yml @@ -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" + diff --git a/env.example b/env.example new file mode 100644 index 0000000..bab7066 --- /dev/null +++ b/env.example @@ -0,0 +1,2 @@ +COMPOSE_PROJECT_NAME=courier +DATA_BASE=/path/to/my/basedir/containing/maildirandconf diff --git a/start.sh b/start.sh new file mode 100644 index 0000000..ee22cb2 --- /dev/null +++ b/start.sh @@ -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/&2 + sleep 10 +done diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..25aac75 --- /dev/null +++ b/test.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +base=`dirname $0` +base=`readlink -f "$base"` +docker run -v "$base/conftest:/conf" --rm -it "$1" "$2" + diff --git a/userdb.example b/userdb.example new file mode 100644 index 0000000..b18afda --- /dev/null +++ b/userdb.example @@ -0,0 +1 @@ +user@example.org systempw={SHA256}0123456789abcdef=|home=/mail/maildir|uid=8|gid=12