move offlineimap spawning to inside the loop in case it crashes, include some explanatory comments
This commit is contained in:
parent
004cb7ff56
commit
a73e912971
1 changed files with 36 additions and 25 deletions
27
mail2mms.sh
27
mail2mms.sh
|
@ -19,13 +19,6 @@
|
||||||
|
|
||||||
. ./.config
|
. ./.config
|
||||||
|
|
||||||
if [ "$1" != -l ]; then
|
|
||||||
|
|
||||||
if ! pgrep offlineimap; then
|
|
||||||
offlineimap &
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
oldnew=0
|
oldnew=0
|
||||||
|
|
||||||
summary() {
|
summary() {
|
||||||
|
@ -45,13 +38,30 @@ summary() {
|
||||||
}
|
}
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
|
|
||||||
|
# Start offlineimap if it's not running and we are not on the mailserver
|
||||||
|
# Sometimes it can crash, so it's in the loop here instead of at startup
|
||||||
|
|
||||||
|
if [ "$1" != -l ]; then
|
||||||
|
if ! pgrep offlineimap; then
|
||||||
|
offlineimap &
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Count the number of new mails
|
||||||
newnew=$(ls -1 ${inbox}/new | wc -l)
|
newnew=$(ls -1 ${inbox}/new | wc -l)
|
||||||
|
|
||||||
|
# If the number of new mails has increased
|
||||||
if [ ${newnew} -gt ${oldnew} ]; then
|
if [ ${newnew} -gt ${oldnew} ]; then
|
||||||
if [ "$1" = -l ]; then
|
|
||||||
|
# If we are on the mailserver, just mail the alert out from here
|
||||||
|
if [ "$1" = "-l" ]; then
|
||||||
echo "$(summary)" \
|
echo "$(summary)" \
|
||||||
| mail -r ${addr} \
|
| mail -r ${addr} \
|
||||||
-s "new mail [${newnew}]" \
|
-s "new mail [${newnew}]" \
|
||||||
${phone}
|
${phone}
|
||||||
|
|
||||||
|
# Otherwise, use the smtp configuration from the config file to send it
|
||||||
else
|
else
|
||||||
echo "$(summary)" \
|
echo "$(summary)" \
|
||||||
| mail -r ${addr} \
|
| mail -r ${addr} \
|
||||||
|
@ -64,6 +74,7 @@ while true; do
|
||||||
${phone}
|
${phone}
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
oldnew=${newnew}
|
oldnew=${newnew}
|
||||||
sleep 2m
|
sleep 2m
|
||||||
done
|
done
|
||||||
|
|
Loading…
Reference in a new issue