2021-08-23 16:00:04 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# Send an MMS message to your phone when new emails come in.
|
2021-08-23 18:25:42 +00:00
|
|
|
# The message will have the number of new mails in the subject
|
|
|
|
# and the body will contain the From and Subject fields of up to the 3
|
|
|
|
# most recent new mails. If the new mail count is above 3, there will also
|
|
|
|
# be 'and more...' at the end.
|
2021-08-23 16:00:04 +00:00
|
|
|
# Assumes you have a maildir inbox on this machine;
|
|
|
|
# you can use offlineimap or similar to sync recent mail to a maildir
|
2021-08-23 18:25:42 +00:00
|
|
|
# or use -l if this machine is actually your mailserver
|
2021-08-23 16:00:04 +00:00
|
|
|
|
|
|
|
# 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>
|
|
|
|
|
|
|
|
. ./.config
|
|
|
|
|
2021-08-23 18:25:42 +00:00
|
|
|
if [ "$1" != -l ]; then
|
|
|
|
|
|
|
|
if ! pgrep offlineimap; then
|
|
|
|
offlineimap &
|
|
|
|
fi
|
2021-08-23 16:00:04 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
oldnew=0
|
|
|
|
|
|
|
|
summary() {
|
|
|
|
i=0
|
|
|
|
for m in $(ls -1r ${inbox}/new/*); do
|
|
|
|
i=$((i + 1))
|
|
|
|
if [ ${i} -gt 3 ]; then
|
|
|
|
echo "and more..."
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
subject=$(grep ^Subject: ${m} | head -n 1)
|
|
|
|
from=$(grep ^From: ${m} | head -n 1)
|
|
|
|
echo ${from}
|
|
|
|
echo ${subject}
|
|
|
|
echo
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
while true; do
|
|
|
|
newnew=$(ls -1 ${inbox}/new | wc -l)
|
|
|
|
if [ ${newnew} -gt ${oldnew} ]; then
|
2021-08-23 18:25:42 +00:00
|
|
|
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
|
2021-08-23 16:00:04 +00:00
|
|
|
fi
|
|
|
|
oldnew=${newnew}
|
|
|
|
sleep 2m
|
|
|
|
done
|