Finish script, ready for testing
This commit is contained in:
parent
1bce00d6de
commit
66b6afd893
|
@ -10,6 +10,8 @@ RUN apt-get update \
|
||||||
&& apt-get clean && rm -fr /var/lib/apt/lists/*
|
&& apt-get clean && rm -fr /var/lib/apt/lists/*
|
||||||
|
|
||||||
RUN maildirmake /var/mail/working \
|
RUN maildirmake /var/mail/working \
|
||||||
|
&& mkdir /var/mail/working/landing \
|
||||||
|
&& mkdir /var/mail/working/extracted \
|
||||||
&& echo "to /var/mail/working" > /root/.mailfilter
|
&& echo "to /var/mail/working" > /root/.mailfilter
|
||||||
RUN touch /var/mail/save-attachments.log
|
RUN touch /var/mail/save-attachments.log
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,8 @@ if [ -d /var/mail/working ]; then
|
||||||
chown -R root /var/mail/working
|
chown -R root /var/mail/working
|
||||||
else
|
else
|
||||||
maildirmake /var/mail/working
|
maildirmake /var/mail/working
|
||||||
|
mkdir /var/mail/working/landing
|
||||||
|
mkdir /var/mail/working/extracted
|
||||||
echo "to /var/mail/working" > /root/.mailfilter
|
echo "to /var/mail/working" > /root/.mailfilter
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,51 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
LOG=/dev/stderr
|
MAILDIR=/var/mail/working
|
||||||
echo "== $(date -Is) ==" >> $LOG
|
DESTINATION=/output
|
||||||
|
DEBUG=0
|
||||||
|
|
||||||
fetchmail
|
echo "== $(date -Is) =="
|
||||||
|
|
||||||
|
# retrieve
|
||||||
|
fetchmail
|
||||||
|
|
||||||
|
# shuffle around some files to the working directory
|
||||||
|
mv $MAILDIR/new/* $MAILDIR/landing/
|
||||||
|
cd $MAILDIR/landing/
|
||||||
|
|
||||||
|
# process each message in a loop
|
||||||
|
shopt -s nullglob
|
||||||
|
for i in *
|
||||||
|
do
|
||||||
|
echo "[$(date '+%T')] Backing up $i and processing..."
|
||||||
|
cp $i $MAILDIR/cur/
|
||||||
|
mkdir $MAILDIR/extracted/$i
|
||||||
|
mv $i $MAILDIR/extracted/$i/
|
||||||
|
|
||||||
|
munpack -C $MAILDIR/extracted/$i -q $MAILDIR/extracted/$i/$i
|
||||||
|
|
||||||
|
if [ -f /config/custom-handler ]; then
|
||||||
|
# allow custom handler script to do something here
|
||||||
|
exec /config/custom-handler "$MAILDIR/extracted/$i/"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "[$(date '+%T')] Copying extracted attachments, if any..."
|
||||||
|
# need to extract date from email header
|
||||||
|
MSGTIMESTAMP=$(cat $MAILDIR/extracted/$i/$i | sed -n 's/^Date: *\([^\n]*\)/\1/p')
|
||||||
|
MSGDATE=$(date --date="$MSGTIMESTAMP" '+%F')
|
||||||
|
MSGTIME=$(date --date="$MSGTIMESTAMP" '+%H%M%S')
|
||||||
|
mkdir -p $DESTINATION/$MSGDATE/$MSGTIME
|
||||||
|
rm $MAILDIR/extracted/$i/$i
|
||||||
|
for z in $MAILDIR/extracted/$i/*
|
||||||
|
do
|
||||||
|
cp -v $z $DESTINATION/$MSGDATE/$MSGTIME/$(basename $z)
|
||||||
|
rm $z
|
||||||
|
done
|
||||||
|
done
|
||||||
|
|
||||||
|
shopt -u nullglob
|
||||||
|
|
||||||
|
if [[ $DEBUG -eq 0 ]]; then
|
||||||
|
rm -fr $MAILDIR/extracted/$i/
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "[$(date '+%T')] Done!"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user