ordering of vcard attributes + parsing of name (n,fn,nickname)
[confetti] / pages / attendees.sh
1 #!/bin/sh
2
3 listcards() {
4   ls -1 ${_DATA}/vcard/*vcf
5 }
6
7 vcf_parse() {
8   tr -d '\n' <"$1" |sed -r 's:\r ::g;s:\r:\n:g' \
9   | sed -rn '
10     s:^PHOTO:001 PHOTO:p;
11     s:^X-MS-CARDPICTURE:001 PHOTO:p;
12     s:^LOGO:002 LOGO:p;
13     s:^FN:003 FN:p;
14     s:^NICKNAME:005 NICKNAME:p;
15     s:^N:004 N:p
16     s:^SOUND:006 SOUND:p;
17     s:^GENDER:007 GENDER:p;
18     s:^X-GENDER:007 GENDER:p;
19     s:^KIND:008 KIND:p;
20     s:^TITLE:009 TITLE:p;
21     s:^ROLE:010 ROLE:p;
22     s:^ORG:011 ORG:p;
23     s:^MEMBER:012 MEMBER:p;
24     s:^CATEGORIES:013 CATEGORIES:p;
25     s:^ANNIVERSARY:014 ANNIVERSARY:p;
26     s:^X-ANNIVERSARY:014 ANNIVERSARY:p;
27     s:^X-EVOLUTION-ANNIVERSARY:014 ANNIVERSARY:p;
28     s:^X-KADDRESSBOOK-X-Anniversary:014 ANNIVERSARY:p;
29     s:^BDAY:015 BDAY:p;
30     s:^EMAIL:016 EMAIL:p;
31     s:^TEL:017 TEL:p;
32     s:^IMPP:018 IMPP:p;
33     s:^X-AIM(;[^"\:]+|;"[^"]+")*\:(.*)$:018 IMPP\1\:aim\:\2:p;
34     s:^X-ICQ(;[^"\:]+|;"[^"]+")*\:(.*)$:018 IMPP\1\:aim\:\2:p;
35     s:^X-GOOGLE-TALK(;[^"\:]+|;"[^"]+")*\:(.*)$:018 IMPP\1\:xmpp\:\2:p;
36     s:^X-JABBER(;[^"\:]+|;"[^"]+")*\:(.*)$:018 IMPP\1\:xmpp\:\2:p;
37     s:^X-MSN(;[^"\:]+|;"[^"]+")*\:(.*)$:018 IMPP\1\:msn\:\2:p;
38     s:^X-YAHOO(;[^"\:]+|;"[^"]+")*\:(.*)$:018 IMPP\1\:ymsgr\:\2:p;
39     s:^X-SIP(;[^"\:]+|;"[^"]+")*\:(sip\:)?(.*)$:018 IMPP\1\:sip\:\3:p;
40     s:^ADR:019 ADR:p;
41     s:^LABEL:020 LABEL:p;
42     s:^URL:021 URL:p;
43     s:^X-EVOLUTION-BLOG-URL:021 URL:p;
44     s:^LANG:022 LANG:p;
45     s:^NOTE:023 NOTE:p;
46
47     s:^RELATED:025 RELATED:p;
48     s:^AGENT:025 RELATED\;TYPE=agent:p;
49     s:^X-ASSISTANT:025 RELATED\;TYPE=assistant;VALUE=text:p;
50     s:^X-EVOLUTION-ASSISTANT:025 RELATED\;TYPE=assistant;VALUE=text:p;
51     s:^X-KADDRESSBOOK-X-AssistantsName:025 RELATED\;TYPE=assistant;VALUE=text:p;
52     s:^X-MANAGER:025 RELATED\;TYPE=manager;VALUE=text:p;
53     s:^X-EVOLUTION-MANAGER:025 RELATED\;TYPE=manager;VALUE=text:p;
54     s:^X-KADDRESSBOOK-X-ManagersName:025 RELATED\;TYPE=manager;VALUE=text:p;
55     s:^X-SPOUSE:025 RELATED\;TYPE=spouse;VALUE=text:p;
56     s:^X-EVOLUTION-SPOUSE:025 RELATED\;TYPE=spouse;VALUE=text:p;
57     s:^X-KADDRESSBOOK-X-SpouseName:025 RELATED\;TYPE=spouse;VALUE=text:p;
58
59     s:^BEGIN.*$::;
60     s:^CALADRURI.*$::;
61     s:^CALURI.*$::;
62     s:^CLASS.*$::;
63     s:^CLIENTPIDMAP.*$::;
64     s:^END.*$::;
65     s:^FBURL.*$::;
66     s:^GEO.*$::;
67     s:^MAILER.*$::;
68     s:^NAME.*$::;
69     s:^PRODID.*$::;
70     s:^PROFILE.*$::;
71     s:^REV.*$::;
72     s:^SORT-STRING.*$::;
73     s:^SOURCE.*$::;
74     s:^TZ.*$::;
75     s:^UID.*$::;
76     s:^VERSION.*$::;
77     s:^XML.*$::;
78
79     s:^([A-Z].*)$:024 \1:p;
80     ' \
81   | sort |while read -r line; do
82     case "$line" in
83       001*)
84         echo -E "$line"
85         ;;
86       002*)
87         echo -E "$line"
88         ;;
89       003*)
90         fn=$(echo "$line" |sed -r 's:^[0-9]{3} ([^;\:]+)(;[^"\:]+|;"[^"]+")*\:(.*)$:\3:g' |tr -d '\r')
91         ;;
92       004*)
93         n=$(echo "$line" |sed -rn 's:^([0-9]{3} )([^;\:]+)(;[^"\:]+|;"[^"]+")*\:([^;]*)(\;[^;]*)(\;[^;]*)?(\;[^;]*)?(\;[^;]*)?$:\7 \5 \6 \4 \8:gp' |sed -r 's:,: :;s:\;: :g;s: +: :g' |tr -d '\r')
94         ;;
95       005*)
96         nick=$(echo "$line" |sed -r 's:^[0-9]{3} ([^;\:]+)(;[^"\:]+|;"[^"]+")*\:(.*)$:\3:g' |tr -d '\r')
97         ;;
98       *) [ -n "$fn" -a -n "$nick" ] && fn="$fn aka. $nick"
99          [ -n "$n"  -a -n "$nick" ] &&  n="$n aka. $nick"
100          [ -n "$fn" -a -z "$n" ] && echo "003 FN:$fn"
101          [ -n "$n" ]             && echo "003 FN:$n"
102          [ -z "$fn" -a -z "$n" ] && echo "003 FN:$nick"
103          echo -E "$line"
104          cat
105         ;;
106     esac
107   done | sed -r 's:^[0-9]{3} ([^;\:]+)(;[^"\:]+|;"[^"]+")*\:(.*)$:key=\1\nvalue=\3\ntag=\2:g'
108 }
109
110 case "$1" in
111   title)
112     echo "Teilnehmende"
113   ;;
114   css)
115     . ${_EXEC}/templates/attendees.css.sh
116   ;;
117   body)
118     . ${_EXEC}/templates/attendees.html.sh
119   ;;
120 esac
121