use mailrc instead of cluttering the script; reformat summary
This commit is contained in:
parent
f2a858b364
commit
eb82854cc0
1 changed files with 26 additions and 28 deletions
54
mail2mms.sh
54
mail2mms.sh
|
@ -12,9 +12,7 @@
|
|||
# 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 @@ 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
|
||||
|
|
Loading…
Reference in a new issue