3 # Copyright 2014 - 2016 Paul Hänsch
5 # This file is part of Confetti.
7 # Confetti is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # Confetti is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with Confetti. If not, see <http://www.gnu.org/licenses/>.
25 view_card="$_EXEC/templates/view_client.sh"
26 edit_card="$_EXEC/templates/edit_client.sh"
27 _GET[order]="${_GET[order]:-lastname}"
28 _GET[filtertype]="${_GET[filtertype]:-name}"
32 view_card="$_EXEC/templates/view_attendee.sh"
33 edit_card="$_EXEC/templates/edit_attendee.sh"
34 _GET[order]="${_GET[order]:-firstname}"
35 _GET[filtertype]="${_GET[filtertype]:-any}"
41 [ \! -f "vcard/$edit" -a \! -f "temp/$edit" ] && edit=''
44 ls -1 ${_DATA}/ical/*ics |while read file; do
45 icstime="$(sed -rn 's:^DTSTART\:(TZID=.*\:)?([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2})([0-9]{2})([0-9]{2})Z?\r$:\2-\3-\4 \5\:\6\:\7:p' "$file")"
46 echo "$(date -d "$icstime" "+%u %H%M%S")\t$file"
47 done |sort |sed -r 's:^.*\t(.*/)([^/]+)$:\2:'
51 sed -rn 's;^X-HEALTH-INSURANCE:([^\;]+)\;.*$;\1;p' ${_DATA}/vcard/*vcf \
56 case "${_GET[filtertype]}" in
58 grep -il "${_GET[filter]}" ${_DATA}/vcard/*vcf
61 egrep -xil "(FN|NICKNAME|N)(;.+)*:.*${_GET[filter]}.*" ${_DATA}/vcard/*vcf
64 egrep -xil "(ADR)(;.+)*:([^;]*;){2}${_GET[filter]}.*" ${_DATA}/vcard/*vcf
67 egrep -xil "(ADR)(;.+)*:([^;]*;){5}${_GET[filter]}.*" ${_DATA}/vcard/*vcf
70 egrep -xil "(TEL)(;.+)*:.*${_GET[filter]}.*" ${_DATA}/vcard/*vcf
73 egrep -xil "(BDAY)(;.+)*:${_GET[filter]}.*" ${_DATA}/vcard/*vcf
77 *) ls -1 ${_DATA}/vcard/*vcf 2>/dev/null
79 esac |case "${_GET[order]}" in
82 fn=$(sed -rn 's:^N(;.+)*\:([^;]*;){1} *([^;]*).*$:\3:p' "$file")
88 ln=$(sed -rn 's:^N(;.+)*\:([^;]*;){0} *([^;]*).*$:\3:p' "$file")
94 bd=$(sed -rn 's:^BDAY(;.+)*\:(.*)$:\2:p' "$file")
101 esac |sort |sed -r 's:^.*\t(.*/)([^/]+)$:\2:'
106 sed -r ':X;N;$!bX; s;\r\n[ \t];;g; s;\r\n;\n;g;' "$1" \
108 # === turn property names to upper case, strip group names ===
110 x; s;^([^;:\.]+\.)?([^;:]+).*$;\2;;
111 y;abcdefghijklmnopqrstuvwxyz;ABCDEFGHIJKLMNOPQRSTUVWXYZ;
116 # === Normalise various known vendor properties ===
117 s;^X-MS-CARDPICTURE(\;|:);PHOTO\1;;
118 s;^X-GENDER(\;|:);GENDER\1;;
119 s;^X-ANNIVERSARY(\;|:);ANNIVERSARY\1;;
120 s;^X-EVOLUTION-ANNIVERSARY(\;|:);ANNIVERSARY\1;;
121 s;^X-KADDRESSBOOK-X-ANNIVERSARY(\;|:);ANNIVERSARY\1;;
122 s;^X-EVOLUTION-BLOG-URL(\;|:);URL\1;;
123 s;^AGENT(\;|:);RELATED\;VALUE=text\;TYPE=agent\1;;
124 s;^X-ASSISTANT(\;|:);RELATED\;VALUE=text\;TYPE=assistant\1;;
125 s;^X-EVOLUTION-ASSISTANT(\;|:);RELATED\;VALUE=text\;TYPE=assistant\1;;
126 s;^X-KADDRESSBOOK-X-ASSISTANTSNAME(\;|:);RELATED\;VALUE=text\;TYPE=assistant\1;;
127 s;^X-MANAGER(\;|:);RELATED\;VALUE=text\;TYPE=manager\1;;
128 s;^X-EVOLUTION-MANAGER(\;|:);RELATED\;VALUE=text\;TYPE=manager\1;;
129 s;^X-KADDRESSBOOK-X-MANAGERSNAME(\;|:);RELATED\;VALUE=text\;TYPE=manager\1;;
130 s;^X-SPOUSE(\;|:);RELATED\;VALUE=text\;TYPE=spouse\1;;
131 s;^X-EVOLUTION-SPOUSE(\;|:);RELATED\;VALUE=text\;TYPE=spouse\1;;
132 s;^X-KADDRESSBOOK-X-SPOUSENAME(\;|:);RELATED\;VALUE=text\;TYPE=spouse\1;;
134 # === Normalise obsolete vendor IM properties ===
135 s;^X-AIM((\;[a-Z0-9-]+|\;[a-Z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):;IMPP\1:aim:;;
136 s;^X-ICQ((\;[a-Z0-9-]+|\;[a-Z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):;IMPP\1:aim:;;
137 s;^X-GOOGLE-TALK((\;[a-Z0-9-]+|\;[a-Z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):;IMPP\1:xmpp:;;
138 s;^X-JABBER((\;[a-Z0-9-]+|\;[a-Z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):;IMPP\1:xmpp:;;
139 s;^X-MSN((\;[a-Z0-9-]+|\;[a-Z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):;IMPP\1:msn:;;
140 s;^X-YAHOO((\;[a-Z0-9-]+|\;[a-Z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):;IMPP\1:ymsgr:;;
141 s;^X-SIP((\;[a-Z0-9-]+|\;[a-Z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):(sip:)?;IMPP\1:sip:;;
143 # === Update obsolete LABEL property ===
144 s;^LABEL((\;[a-Z0-9-]+|\;[a-Z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):(.*)$;ADR\1\;LABEL="\5":;;
146 /^([A-Z0-9-]+)((\;[a-Z0-9-]+=?|\;[a-Z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):(.*)$/{
148 s;^([A-Z0-9-]+)((\;[a-Z0-9-]+=?|\;[a-Z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):(.*)$;key='\''\1'\'';;
151 s;^([A-Z0-9-]+)((\;[a-Z0-9-]+=?|\;[a-Z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):([^\n]*)\n.*$;\2;;
152 s;'\'';'\'\\\\\'\'';g
153 s;\;([A-Z0-9-]+)(=|=(([^\;,:"]+|"[^"]+")(,[^\;,:"]+|,"[^"]+")*))?;\ntag[\1]='\''\3'\'';g
157 s;^([A-Z0-9-]+)((\;[a-Z0-9-]+=?|\;[a-Z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):([^\n]*)\n.*$;\6;;
158 # :X s;((^|[^\\])(\\\\)*)[;,];\1\n;g; s;((^|[^\\])(\\\\)*)\\([;,]);\4;g; tX;
159 s;'\'';'\'\\\\\'\'';g
160 s;^.*$;value='\''&'\'';
169 | while read -r line; do
172 value*) eval "$line";;
175 if [ -z "$key" ]; then
178 values[${key}]="${value//\\r\\n/$BR}"
179 for t in ${(k)tag}; do
180 values[${key}_${t}]="${tag[$t]}"
183 if [ -n "$values[$key]" ]; then
185 while [ -n "$values[$key$n]" ]; do n=$(($n + 1)); done
196 view_card() { #Parameter: Cardfile
198 cardfile="$_DATA/vcard/${id}"
199 cachefile="$_DATA/cache/${id}.cache"
200 if [ "$cachefile" -nt "$cardfile" ]; then
204 vcf_parse "$cardfile"
205 . $view_card |tee "$cachefile"
209 edit_card() { #Parameter: Cardfile
211 cardfile="$_DATA/vcard/$id"
212 tempfile="$_DATA/temp/$id"
213 [ -f "$tempfile" ] && cardfile="$tempfile"
216 vcf_parse "$cardfile"