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 [ -z "${values[$each]+x}" ] && values[${each}]=''
31 SUP_FIELDS=(N NICKNAME GENDER BDAY ADR TEL EMAIL X-HEALTH-INSURANCE X-HEALTH-INSURANCE-NOCONTRIB IMPP URL NOTE X-CLIENT-REFERRAL)
32 FORCE_ITEMS=(ADR TEL EMAIL NOTE X-CLIENT-REFERRAL)
33 view_card="$_EXEC/templates/view_client.sh"
34 _GET[order]="${_GET[order]:-lastname}"
35 _GET[filtertype]="${_GET[filtertype]:-name}"
39 SUP_FIELDS=(N NICKNAME GENDER BDAY X-ZACK-JOINDATE X-ZACK-LEAVEDATE EMAIL TEL IMPP ADR URL NOTE)
40 FORCE_ITEMS=(BDAY X-ZACK-JOINDATE TEL EMAIL ADR NOTE)
41 view_card="$_EXEC/templates/view_attendee.sh"
42 _GET[order]="${_GET[order]:-firstname}"
43 _GET[filtertype]="${_GET[filtertype]:-any}"
49 [ \! -f "vcard/$edit" -a \! -f "temp/$edit" ] && edit=''
52 ls -1 ${_DATA}/ical/*ics |while read file; do
53 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")"
54 echo "$(date -d "$icstime" "+%u %H%M%S")\t$file"
55 done |sort |sed -r 's:^.*\t(.*/)([^/]+)$:\2:'
59 sed -rn 's;^X-HEALTH-INSURANCE:([^\;]+)\;.*$;\1;p' ${_DATA}/vcard/*vcf \
64 case "${_GET[filtertype]}" in
66 grep -il "${_GET[filter]}" ${_DATA}/vcard/*vcf
69 egrep -xil "(FN|NICKNAME|N)(;.+)*:.*${_GET[filter]}.*" ${_DATA}/vcard/*vcf
72 egrep -xil "(ADR)(;.+)*:([^;]*;){2}${_GET[filter]}.*" ${_DATA}/vcard/*vcf
75 egrep -xil "(ADR)(;.+)*:([^;]*;){5}${_GET[filter]}.*" ${_DATA}/vcard/*vcf
78 egrep -xil "(TEL)(;.+)*:.*${_GET[filter]}.*" ${_DATA}/vcard/*vcf
81 egrep -xil "(BDAY)(;.+)*:${_GET[filter]}.*" ${_DATA}/vcard/*vcf
85 *) ls -1 ${_DATA}/vcard/*vcf 2>/dev/null
87 esac |case "${_GET[order]}" in
90 fn=$(sed -rn 's:^N(;.+)*\:([^;]*;){1} *([^;]*).*$:\3:p' "$file")
96 ln=$(sed -rn 's:^N(;.+)*\:([^;]*;){0} *([^;]*).*$:\3:p' "$file")
102 bd=$(sed -rn 's:^BDAY(;.+)*\:(.*)$:\2:p' "$file")
107 sed -r 's:^.*$:x\t&:'
109 esac |sort |sed -r 's:^.*\t(.*/)([^/]+)$:\2:'
114 sed -r ':X;N;$!bX; s;\r\n[ \t];;g; s;\r\n;\n;g;' "$1" \
116 # === turn property names to upper case, strip group names ===
118 x; s;^([^;:\.]+\.)?([^;:]+).*$;\2;;
119 y;abcdefghijklmnopqrstuvwxyz;ABCDEFGHIJKLMNOPQRSTUVWXYZ;
122 # === strip trailing CR (but keep CRs in property value) ===
125 # === Normalise various known vendor properties ===
126 s;^X-MS-CARDPICTURE(\;|:);PHOTO\1;;
127 s;^X-GENDER(\;|:);GENDER\1;;
128 s;^X-ANNIVERSARY(\;|:);ANNIVERSARY\1;;
129 s;^X-EVOLUTION-ANNIVERSARY(\;|:);ANNIVERSARY\1;;
130 s;^X-KADDRESSBOOK-X-ANNIVERSARY(\;|:);ANNIVERSARY\1;;
131 s;^X-EVOLUTION-BLOG-URL(\;|:);URL\1;;
132 s;^AGENT(\;|:);RELATED\;VALUE=text\;TYPE=agent\1;;
133 s;^X-ASSISTANT(\;|:);RELATED\;VALUE=text\;TYPE=assistant\1;;
134 s;^X-EVOLUTION-ASSISTANT(\;|:);RELATED\;VALUE=text\;TYPE=assistant\1;;
135 s;^X-KADDRESSBOOK-X-ASSISTANTSNAME(\;|:);RELATED\;VALUE=text\;TYPE=assistant\1;;
136 s;^X-MANAGER(\;|:);RELATED\;VALUE=text\;TYPE=manager\1;;
137 s;^X-EVOLUTION-MANAGER(\;|:);RELATED\;VALUE=text\;TYPE=manager\1;;
138 s;^X-KADDRESSBOOK-X-MANAGERSNAME(\;|:);RELATED\;VALUE=text\;TYPE=manager\1;;
139 s;^X-SPOUSE(\;|:);RELATED\;VALUE=text\;TYPE=spouse\1;;
140 s;^X-EVOLUTION-SPOUSE(\;|:);RELATED\;VALUE=text\;TYPE=spouse\1;;
141 s;^X-KADDRESSBOOK-X-SPOUSENAME(\;|:);RELATED\;VALUE=text\;TYPE=spouse\1;;
143 # === Normalise obsolete vendor IM properties ===
144 s;^X-AIM((\;[a-Z0-9-]+|\;[a-Z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):;IMPP\1:aim:;;
145 s;^X-ICQ((\;[a-Z0-9-]+|\;[a-Z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):;IMPP\1:aim:;;
146 s;^X-GOOGLE-TALK((\;[a-Z0-9-]+|\;[a-Z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):;IMPP\1:xmpp:;;
147 s;^X-JABBER((\;[a-Z0-9-]+|\;[a-Z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):;IMPP\1:xmpp:;;
148 s;^X-MSN((\;[a-Z0-9-]+|\;[a-Z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):;IMPP\1:msn:;;
149 s;^X-YAHOO((\;[a-Z0-9-]+|\;[a-Z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):;IMPP\1:ymsgr:;;
150 s;^X-SIP((\;[a-Z0-9-]+|\;[a-Z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):(sip:)?;IMPP\1:sip:;;
152 # === Update obsolete LABEL property ===
153 s;^LABEL((\;[a-Z0-9-]+|\;[a-Z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):(.*)$;ADR\1\;LABEL="\5":;;
155 /^([A-Z0-9-]+)((\;[a-Z0-9-]+=?|\;[a-Z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):(.*)$/{
157 s;^([A-Z0-9-]+)((\;[a-Z0-9-]+=?|\;[a-Z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):(.*)$;key='\''\1'\'';;
160 s;^([A-Z0-9-]+)((\;[a-Z0-9-]+=?|\;[a-Z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):([^\n]*)\n.*$;\2;;
161 s;'\'';'\'\\\\\'\'';g
162 s;\;([A-Z0-9-]+)(=|=(([^\;,:"]+|"[^"]+")(,[^\;,:"]+|,"[^"]+")*))?;\ntag[\1]='\''\3'\'';g
166 s;^([A-Z0-9-]+)((\;[a-Z0-9-]+=?|\;[a-Z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):([^\n]*)\n.*$;\6;;
167 # :X s;((^|[^\\])(\\\\)*)[;,];\1\n;g; s;((^|[^\\])(\\\\)*)\\([;,]);\4;g; tX;
168 s;'\'';'\'\\\\\'\'';g
169 s;^.*$;value='\''&'\'';
178 | while read -r line; do
181 value*) eval "$line";;
184 if [ -z "$key" ]; then
187 printf '%s\n' "$value" |sed -rn '
189 s;((^|[^\\])(\\\\)*),;\1\n;g;
194 | while read -r val; do
195 while [ -n "${values[$key$n]+x}" ]; do n=$((${n=-1} + 1)); done
196 if printf '%s\n' "$val" |grep -qE '((^|[^\\])(\\\\)*)\;'; then
198 values[${key}${n}]="${val}"
199 printf '%s\n' "$val" |sed -rn '
201 s;((^|[^\\])(\\\\)*)\;;\1\n;g;
206 | while read -r v; do
207 values[${key}${n}+${m}]="$(
208 printf %s\\n "${v}" \
211 s;((^|[^\\])(\\\\)*)\\n;\1\n;g;
220 values[${key}${n}]="$(
221 printf %s\\n "${val}" \
224 s;((^|[^\\])(\\\\)*)\\n;\1\n;g;
232 for t in ${(k)tag}; do
233 values[${key}${n}_${t}]="${tag[$t]}"
239 while [ -n "${values[$key$n]+x}" ]; do n=$((${n=-1} + 1)); done
248 view_card() { #Parameter: Cardfile
250 cardfile="$_DATA/vcard/${id}"
251 cachefile="$_DATA/cache/${id}.cache"
252 if [ "$cachefile" -nt "$cardfile" ]; then
256 vcf_parse "$cardfile"
257 . $view_card |tee "$cachefile"
261 edit_card() { #Parameter: Cardfile
263 cardfile="$_DATA/vcard/$id"
264 tempfile="$_DATA/temp/$id"
265 [ -f "$tempfile" ] && cardfile="$tempfile"
268 vcf_parse "$cardfile"
269 force_items $FORCE_ITEMS
270 . "$_EXEC/templates/edit_card.sh"