Compare commits

..

2 commits

5 changed files with 84 additions and 0 deletions

View file

@ -85,6 +85,7 @@ UID | GID | Container | Notes
95 | 95 | shiori | Shiori bookmark system, built from source 95 | 95 | shiori | Shiori bookmark system, built from source
999 | 994 | certbot | The same user & group as fabio, because file permissions 999 | 994 | certbot | The same user & group as fabio, because file permissions
2100 | 2100 | redis | 2100 | 2100 | redis |
10000 | 10000 | imap-download | Uses fetchmail to download emails and extract attachments
## Development Notes ## Development Notes

View file

@ -0,0 +1,29 @@
ARG REPO_LOCATION
# ARG BASE_VERSION
FROM ${REPO_LOCATION}minideb
RUN install_packages ca-certificates fetchmail procmail inotify-tools mpack
RUN mkdir /srv/home \
&& ln -s /mnt/fetchmailrc /srv/home/.fetchmailrc \
&& mkdir /tmp/maildir
ENV HOME /srv/home
COPY ./procmail.conf /srv/procmail.conf
COPY ./run.sh /srv/run.sh
VOLUME /mnt/fetchmailrc
VOLUME /mnt/output
# Example fetchmailrc file:
#
# poll starbeamrainbowlabs.com protocol IMAP
# user "user@example.com" with pass "PASSWORD_HERE"
# idle
# ssl
USER 10000:10000
ENTRYPOINT [ "/srv/run.sh" ]

View file

@ -0,0 +1,5 @@
CORRECTHOME=/tmp/maildir
MAILDIR=$CORRECTHOME/
:0
Mail/

48
images/imap-download/run.sh Executable file
View file

@ -0,0 +1,48 @@
#!/usr/bin/env bash
temp_dir="$(mktemp --tmpdir -d "imap-download-XXXXXXX")";
on_exit() {
rm -rf "${temp_dir}";
}
trap on_exit EXIT;
do_fetchmail() {
fetchmail --mda "/usr/bin/procmail -m /srv/procmail.conf";
}
log_msg() {
echo "$(date -u +"%Y-%m-%d %H:%M:%S") imap-download: $*";
}
dir_newmail="/tmp/maildir/Mail/new";
target_dir="/mnt/output";
do_attachments() {
while :; do # : = infinite loop
# Wait for an update
# inotifywait's non-0 exit code forces an exit for some reason :-/
inotifywait -qr --event create --format '%:e %f' "${dir_newmail}";
while read -r filename; do
log_msg "Processing email ${filename}";
# Move the email to a temporary directory for processing
mv "${filename}" "${temp_dir}";
# Unpack the attachments
munpack -C "${temp_dir}" "${filename}";
# Delete the original email file and any description files
rm "${filename}";
find "${temp_dir}" -iname '*.desc' -delete;
# Move the attachment files to the output directory
while read -r attachment; do
log_msg "Extracted attachment ${attachment}";
mv "${attachment}" "${target_dir}";
done < <(find "${temp_dir}" -type f);
done < <(find "${dir_newmail}" -type f);
done
}
do_fetchmail &
do_attachments

View file

@ -0,0 +1 @@
docker