From 4e92ed396de1f2d08fc0c3a3af852e3fd38ee4c0 Mon Sep 17 00:00:00 2001 From: Derek Stevens Date: Mon, 23 Aug 2021 10:00:04 -0600 Subject: [PATCH] first commit --- .gitignore | 1 + mail2mms.sh | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 .gitignore create mode 100755 mail2mms.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1f89d9f --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.config diff --git a/mail2mms.sh b/mail2mms.sh new file mode 100755 index 0000000..e431d37 --- /dev/null +++ b/mail2mms.sh @@ -0,0 +1,57 @@ +#!/bin/sh + +# Send an MMS message to your phone when new emails come in. +# The message header will have the number of new mails in the subject, +# the From and Subject fields of up to the most recent 3 new mails, +# and 'and more...' if there are more than three new mails +# Assumes you have a maildir inbox on this machine; +# you can use offlineimap or similar to sync recent mail to a maildir + +# import the config file ./.config +# addr= +# phone= +# inbox= +# smtp_server= +# smtp_user= +# smtp_password + +. ./.config + +if ! pgrep offlineimap; then + offlineimap & +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 + echo "$(summary)" \ + | mail -r nilix@nilfm.cc \ + -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 + oldnew=${newnew} + sleep 2m +done