move offlineimap spawning to inside the loop in case it crashes, include some explanatory comments
Iris Lightshard nilix@nilfm.cc
PGP Signature
-----BEGIN PGP SIGNATURE----- iQJDBAABCAAtFiEEkFh6dA+k/6CXFXU4O3+8IhROY5gFAmEl0KsPHG5pbGl4QG5p bGZtLmNjAAoJEDt/vCIUTmOYE+IP/ROWUDTJKSYk5BNhay7TVxbW6ip/iP2EnVlN svouHB1L6ff4Kfy8EQVa80RK3X7g2mENWyUo6tldtfjaC8HhdSMVX9oyV5uXYy64 TINkbUrcZOmR/WBgapEZwy17Nkv1SonO/rKqdvcUJg68r9mvbdCj0SYKcaXb1w4s FJa4MyHMwdU5pnbEnaEiPWpU6Z/sPrhZriyAKG43cP/ueh/ZboSOjZ44S/prwCPM 6GeMVETuOxdiN7tecLCWQnYxRvUL7lCRLiL6V1B0vLmtqJs83YmTpr+XNwdTypBG vDi+GJTGjmnHjfhSUXAbv8DdlZfxly97NckPuqzluIjQ2IwLc08wtEY+X+Solx/R fkosVbA234192uek+Ee98n1jZC3P5UVPAPWz6MU8zYz13eJXPOeJk3vBD6+1OK+x 5R+OEvqCFWoiT7I1YniZwrSAQ6or7kNoqCtF6q4ANKi+COkWvarkFK9yghlLtkM7 +OfSRe14ZQSQlD5BjEjIEnxNFHjEAK9SciRhwUtD0NsmvN8T3Z8CnMhilBwYVb5/ 0Fn+Ut1l53kBTY3iSCt+Av/rsSg+vLaNAhfl7nMoWeD/qutxUAMzwkwPBxo6JQXo 0FZBJ3lmx9nwUXpBQ6FuqAThQvzyH6xRpzOylPPWuy6yEGdq0cnU1rpYVpdp/FkM CXHCTWTD =+yOQ -----END PGP SIGNATURE-----
1 files changed,
35 insertions(+),
24 deletions(-)
jump to
M
mail2mms.sh
→
mail2mms.sh
@@ -19,13 +19,6 @@ # smtp_password<the password to login to the smtp server>
. ./.config -if [ "$1" != -l ]; then - - if ! pgrep offlineimap; then - offlineimap & - fi -fi - oldnew=0 summary() {@@ -45,25 +38,43 @@ done
} 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) - 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 + + # 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