summaryrefslogtreecommitdiff
path: root/pim/rc/invites
blob: de193edaaca6000dcf886ffe283789b7b70c9656 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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