This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
fidohub/tools/mail-in.sh
2021-04-23 23:16:36 +10:00

77 lines
1.8 KiB
Bash
Executable File

#!/bin/bash
# This script will toss incoming mail received from binkd (unless ${SEMADIR}/notoss exits) after a 5 second delay.
# Written by deon - Alterant BBS - April 2020
SEMADIR=/fido/semafore
SEMAFORE=${SEMADIR}/tossing
# For QICO calls
if [ $# -gt 0 ]; then
touch ${SEMADIR}/tossmail
fi
# If we are configured not to toss
[ -e ${SEMADIR}/notoss ] && exit
(
# Delay our start so binkd has time to finish and create the semafore
sleep 5
# Force a run anyway, if our semafore is old.
NOW=$(($(date '+%s')-300))
STAT=$(test -e ${SEMAFORE} && stat -c %Y ${SEMAFORE} || echo 0)
IN=/fido/mailer/in
INBAK=/fido/mailer/in.backup
if [ -e ${SEMADIR}/backup ]; then
cp -rl ${IN} ${INBAK}
fi
# Dont toss if already doing it.
if [ ! -e ${SEMAFORE} -o ${NOW} -ge ${STAT} ]; then
touch ${SEMAFORE}
# Inbound mail to toss
if [ -e ${SEMADIR}/tossmail ]; then
rm -f ${SEMADIR}/tossmail
hpt toss
fi
# Debugging - not sure how we use this file
if [ -e /var/log/fido/echotoss.log ]; then
cp /var/log/fido/echotoss.log /tmp/
fi
# If our filter created some messages, we should look for those.
if [ -e ${SEMADIR}/newhtick.now ]; then
rm -f ${SEMADIR}/newhtick.now
htick scan && touch ${SEMADIR}/newnet.now
fi
# If our filter created some messages, we should look for those.
if [ -e ${SEMADIR}/newecho.now ]; then
rm -f ${SEMADIR}/newecho.now
sleep 1
hpt scan
fi
# If our filter created some messages, we should look for those.
if [ -e ${SEMADIR}/newnet.now ]; then
rm -f ${SEMADIR}/newnet.now
sleep 1
hpt pack
hpt pack # For some reason htick messages dont get packed the first time?
fi
# Inbound files to toss
if [ -e ${SEMADIR}/tossfile ]; then
rm -f ${SEMADIR}/tossfile
htick toss
fi
# All done for this run...
rm -f ${SEMAFORE}
fi
) &