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
61
mail2mms.sh
61
mail2mms.sh
|
@ -19,13 +19,6 @@
|
|||
|
||||
. ./.config
|
||||
|
||||
if [ "$1" != -l ]; then
|
||||
|
||||
if ! pgrep offlineimap; then
|
||||
offlineimap &
|
||||
fi
|
||||
fi
|
||||
|
||||
oldnew=0
|
||||
|
||||
summary() {
|
||||
|
@ -45,25 +38,43 @@ summary() {
|
|||
}
|
||||
|
||||
while true; do
|
||||
newnew=$(ls -1 ${inbox}/new | wc -l)
|
||||
if [ ${newnew} -gt ${oldnew} ]; then
|
||||
if [ "$1" = -l ]; then
|
||||
echo "$(summary)" \
|
||||
| mail -r ${addr} \
|
||||
-s "new mail [${newnew}]" \
|
||||
${phone}
|
||||
else
|
||||
echo "$(summary)" \
|
||||
| mail -r ${addr} \
|
||||
-s "new mail [${newnew}]" \
|
||||
-S smtp=${smtp_server} \
|
||||
-S smtp-use-starttls \
|
||||
-S smtp-auth=login \
|
||||
-S smtp-auth-user=${smtp_user} \
|
||||
-S smtp-auth-password=${smtp_password} \
|
||||
${phone}
|
||||
fi
|
||||
|
||||
# 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)
|
||||
|
||||
# If the number of new mails has increased
|
||||
if [ ${newnew} -gt ${oldnew} ]; then
|
||||
|
||||
# If we are on the mailserver, just mail the alert out from here
|
||||
if [ "$1" = "-l" ]; then
|
||||
echo "$(summary)" \
|
||||
| mail -r ${addr} \
|
||||
-s "new mail [${newnew}]" \
|
||||
${phone}
|
||||
|
||||
# Otherwise, use the smtp configuration from the config file to send it
|
||||
else
|
||||
echo "$(summary)" \
|
||||
| mail -r ${addr} \
|
||||
-s "new mail [${newnew}]" \
|
||||
-S smtp=${smtp_server} \
|
||||
-S smtp-use-starttls \
|
||||
-S smtp-auth=login \
|
||||
-S smtp-auth-user=${smtp_user} \
|
||||
-S smtp-auth-password=${smtp_password} \
|
||||
${phone}
|
||||
fi
|
||||
fi
|
||||
|
||||
oldnew=${newnew}
|
||||
sleep 2m
|
||||
done
|
||||
|
|
Loading…
Reference in a new issue