summaryrefslogtreecommitdiff
path: root/pim/rc/invites
diff options
context:
space:
mode:
Diffstat (limited to 'pim/rc/invites')
-rwxr-xr-xpim/rc/invites87
1 files changed, 87 insertions, 0 deletions
diff --git a/pim/rc/invites b/pim/rc/invites
new file mode 100755
index 0000000..de193ed
--- /dev/null
+++ b/pim/rc/invites
@@ -0,0 +1,87 @@
+#!/bin/rc
+# pim/invites -- what is waiting for your answer.
+#
+# pim/invites the next thirty days
+# pim/invites -n 7 just this week
+# pim/invites -a everything, answered or not
+#
+# Only upcoming events are looked at: an invitation you never answered
+# for a meeting last March is not a thing you need to see. Walking the
+# date tree rather than every event also keeps this to a few dozen reads
+# instead of a few thousand.
+rfork e
+
+mtpt=/mnt/pim
+days=30
+only=()
+all=()
+
+while(~ $1 -*){
+ switch($1){
+ case -m
+ mtpt=$2; shift
+ case -n
+ days=$2; shift
+ case -c
+ only=($only $2); shift
+ case -a
+ all=1
+ case *
+ echo 'usage: invites [-m mtpt] [-n days] [-c cal] [-a]' >[1=2]
+ exit usage
+ }
+ shift
+}
+
+cals=$only
+if(~ $#cals 0)
+ cals=`{pim/calendars -m $mtpt}
+
+seen=/tmp/invites.seen.$pid
+out=/tmp/invites.out.$pid
+fn sigexit { rm -f $seen $out }
+>$seen
+>$out
+
+now=`{date -n}
+i=0
+while(test $i -lt $days){
+ sec=`{echo $now + $i '*' 86400 | bc}
+ day=`{date -f YYYY/MM/DD $sec}
+ for(c in $cals){
+ d=$mtpt/calendars/$c/events/date/$day
+ if(test -d $d)
+ for(f in $d/*){
+ ev=`{sed -n 's/^event: //p' $f}
+ if(! ~ $#ev 0){
+ e=`{cleanname $d/$"ev}
+ # one line per event, not per occurrence
+ if(! grep -s '^'^$"e^'$' $seen){
+ echo $"e >>$seen
+ if(test -f $e/partstat){
+ st=`{cat $e/partstat}
+ show=()
+ if(~ $"st NEEDS-ACTION)
+ show=1
+ if(! ~ $#all 0)
+ show=1
+ if(! ~ $#show 0){
+ ep=`{sed -n 's/^epoch: //p' $f}
+ when=`{date -f 'WWW DD MMM hh:mm' $"ep}
+ sum=`{sed -n 's/^summary: //p' $f}
+ echo $"ep^' '^$"when^' '^$"st^' '^$"sum^' '^$c >>$out
+ }
+ }
+ }
+ }
+ }
+ }
+ i=`{echo $i + 1 | bc}
+}
+
+if(! test -s $out){
+ echo 'nothing waiting in the next '^$"days^' days'
+ exit 0
+}
+sort -n $out | awk -F' ' '{printf "%-22s %-13s %-9s %s\n", $2, $3, $5, $4}'
+exit 0