From: Christian Heller <c.heller@plomlompom.de>
Date: Mon, 3 Dec 2018 17:48:35 +0000 (+0100)
Subject: Handle mailbox files instead of maildirs too.
X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/%22https:/validator.w3.org/ledger?a=commitdiff_plain;h=14dfa8853e4014e8d01e6f8ab595bf64a7ec861c;p=pingmail.git
Handle mailbox files instead of maildirs too.
---
diff --git a/README b/README
index 5908bcd..9ce6207 100644
--- a/README
+++ b/README
@@ -1,5 +1,14 @@
Small shell script to regularly check a target person's responsiveness via mail.
+When run as "pingmail check", tries to derive the last time a person sent a
+mail to the local system by either a) searching a maildir for the most recent
+file matching a regex pattern (such as a "From: " field matching the target
+person), and looking at thta file's modification time, or b) checking the
+modification time of a defined mailbox file. If that point in time is too
+distant, sends an e-mail to the target person requesting some sign of life.
+After some more wait time without a sign of life, sends a warning message to
+another mail address that target person is unresponsive.
+
When run as "pingmail check", searches a maildir for the most recent file
matching a regex pattern (such as a "From: " field matching the target person),
and if the most recent file is too old, sends an e-mail to the target person
diff --git a/pingmail b/pingmail
index b59fa49..f40eb0f 100755
--- a/pingmail
+++ b/pingmail
@@ -28,19 +28,23 @@ if [ -f $ping_touch ]; then
modtime_pingfile=`stat $ping_touch --format=%Y`
fi
-# search maildir for last life sign datetime
+# search mailbox or maildir for last life sign datetime
modtime_mails=0
-while read file; do
- if [ -z $file ]; then
- break
- fi
- modtime=`stat $file --format=%Y`
- if [ "$modtime" -gt "$modtime_mails" ]; then
- modtime_mails=$modtime
- fi
-done <<EOF
+if [ ! "$mbox" = "" ]; then
+ modtime_mails=`stat "$mbox" --format=%Y`
+else
+ while read file; do
+ if [ -z $file ]; then
+ break
+ fi
+ modtime=`stat $file --format=%Y`
+ if [ "$modtime" -gt "$modtime_mails" ]; then
+ modtime_mails=$modtime
+ fi
+ done <<EOF
$(grep -lER "$matchstring" $maildir)
EOF
+fi
# find delta of last life sign datetime / test file modtime and current datetime
now=`date +%s`
diff --git a/pingmailrc.example b/pingmailrc.example
index 97a9de0..954e8ff 100644
--- a/pingmailrc.example
+++ b/pingmailrc.example
@@ -7,9 +7,6 @@ ping_touch=$testdir'/ping_touch'
# modification time is when the count for sending checker a warning mail starts
reminder_touch=$testdir'/reminder_touch'
-# to recursively search for most recent matches to $matchstring as lifesigns
-maildir=$HOME'/mail'
-
# how long to wait for lifesigns before sending a ping; double is time to wait
# for a lifesign before sending a warning message to checker
wait_time=86400
@@ -37,6 +34,12 @@ msg2checker='pingmail reporting in:\n
# mail client command reading message body from stdin and subject from parameter
mailclient_s='mutt -s'
+# mailbox file to check for most recent life sign
+mbox=$HOME'/mail/foo'
+
+# to recursively search for most recent matches to $matchstring as lifesigns
+maildir=$HOME'/mail'
+
# pattern to search $maildir for recursively for lifesigns
checked_address_escaped=`echo $checked_address | sed 's/\./\\./g'`
matchstring='^From: .*('$checked_address_escaped'|alternate@example\.org)'