diff --git a/mail2mms.sh b/mail2mms.sh index c8dfebd..3409ea9 100755 --- a/mail2mms.sh +++ b/mail2mms.sh @@ -12,9 +12,7 @@ # addr= # phone= # inbox= -# smtp_server= -# smtp_user= -# smtp_password +# all other configuration can be done in your .mailrc . ./.config @@ -23,22 +21,38 @@ oldnew=0 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 @@ while true; do # 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