all repos — mail2mms @ eb82854cc04a8c3772a3b4b617b2c795952fc70e

YOU'VE GOT MAIL! notify via MMS of new mail in your inbox

use mailrc instead of cluttering the script; reformat summary
Iris Lightshard nilix@nilfm.cc
PGP Signature
-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEEkFh6dA+k/6CXFXU4O3+8IhROY5gFAmGhvR0ACgkQO3+8IhRO
Y5iPVw//RDm47AplEEolD6BP6im/ws99hJZ7zw6d2DeNOQUk3cJEuqgcVCT9INrn
MQ7r2YN9opgZwKFnVikeJpOWUoKqv8nUuUFR+Uaq5M7jnPUNXDSUvwHWbJSSwL/A
7pTSd2J0a1HByzUsGqbz/CI/yOcl7b3wBLge1Ri42v4cdevl7dpy/TVqC6uuVzyW
6pQWDvIrRbWiAit+Hpt9s78iSUIP4NafFW1kl7QrJe69oFFlUHGmNSdAA/1unTQb
k+517roG3KCg06fOT851lllKLE7sGgosV5trn/OeNJyoG7WZBNiSHjEZLLViCTnx
U6pxoZXJEPY4f8+HkgpVdGnn8rYEVYzwQkERcxSqLwdqibnRoH5FmLy8Kl3MDEc7
bqLpinUS1ImpxLiPV7gzv2wDKTB9MWVH4hEGopbqZyzvrpw7FkXc9HeZKNHoPpqC
4gdsnKoy1Ma7JRorEF1Pid/asdOIsiOaaIVJlLrGm7UsO3SWk6ewU2Xej2LfUPbg
AnoKAVT/aEmNfLk/BIoaEDpWi2Wg0qX7z9MYQ6IlRWrNP02Z4FaqxJLJaII1aibD
JVYcl2FWHtHvre/Bz16UmiPhMkj6UK+hAxsFZhL844cJbjz5hiCuUX49LdfyYIFG
VKTG1TUUsb9JD/f4Hkx//opT/wEmMLXTnvkKrTxWsow/VnewJ7M=
=NSvV
-----END PGP SIGNATURE-----
commit

eb82854cc04a8c3772a3b4b617b2c795952fc70e

parent

f2a858b364f3c1233fa591a84576529f1f7cc596

1 files changed, 26 insertions(+), 28 deletions(-)

jump to
M mail2mms.shmail2mms.sh

@@ -12,9 +12,7 @@ # import the config file ./.config

# addr=<the address the notification will appear to be sent from> # phone=<your phone number in email address form (eg, 9876543210@mms.att.net)> # inbox=<the location of the maildir folder corresponding to the inbox> -# smtp_server=<the address and port (address:port) of your smtp server> -# smtp_user=<the username you use on your smtp server> -# smtp_password<the password to login to the smtp server> +# all other configuration can be done in your .mailrc . ./.config

@@ -23,22 +21,38 @@

summary() { i=0 for m in $(\ls -1r ${inbox}/new/*); do + + # if there are more than 3 new messages, + # just hint that there is more i=$((i + 1)) if [ ${i} -gt 3 ]; then echo "and more..." break fi + + # grab the From and Subject headers subject=$(grep ^Subject: ${m} | head -n 1) from=$(grep ^From: ${m} | head -n 1) - echo ${from} - echo ${subject} - echo + + # extract just the email address from the From header + # ie, discard all tokens but the last + # and remove angle brackets if present + set -- $from + while [ ${#} -gt 1 ]; do + shift + done + echo -n $(echo ${@} | sed -e s/[\<\>]//g) + + # now append the message after discarding the Subject: key + set -- $subject + shift + echo ": \"${@}\"" done } while true; do - # sync mailbox if this is not the mailserver + # Sync the inbox if we are not the mailserver if [ "$1" != "-l" ]; then mbsync -a fi

@@ -48,28 +62,12 @@ 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 + echo "$(summary)" \ + | mail -r ${addr} \ + -s "new mail [${newnew}]" \ + ${phone} fi oldnew=${newnew} - sleep 2m + sleep 10m done