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/>.
20 [ -z "${_GET[order]}" ] && _GET[order]="firstname"
23 ls -1 ${_DATA}/ical/*ics |while read file; do
24 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")"
25 echo "$(date -d "$icstime" "+%u %H%M%S")\t$file"
26 done |sort |sed -r 's:^.*\t(.*/)([^/]+)$:\2:'
30 case "${_GET[filtertype]}" in
32 grep -il "${_GET[filter]}" ${_DATA}/vcard/*vcf
35 egrep -xil "(FN|NICKNAME|N)(;.+)*:.*${_GET[filter]}.*" ${_DATA}/vcard/*vcf
38 egrep -xil "(ADR)(;.+)*:([^;]*;){2}${_GET[filter]}.*" ${_DATA}/vcard/*vcf
41 egrep -xil "(ADR)(;.+)*:([^;]*;){5}${_GET[filter]}.*" ${_DATA}/vcard/*vcf
44 egrep -xil "(TEL)(;.+)*:.*${_GET[filter]}.*" ${_DATA}/vcard/*vcf
47 egrep -xil "(BDAY)(;.+)*:${_GET[filter]}.*" ${_DATA}/vcard/*vcf
51 *) ls -1 ${_DATA}/vcard/*vcf 2>/dev/null
53 esac |case "${_GET[order]}" in
56 fn=$(sed -rn 's:^N(;.+)*\:([^;]*;){1} *([^;]*).*$:\3:p' "$file")
62 ln=$(sed -rn 's:^N(;.+)*\:([^;]*;){0} *([^;]*).*$:\3:p' "$file")
68 bd=$(sed -rn 's:^BDAY(;.+)*\:(.*)$:\2:p' "$file")
75 esac |sort |sed -r 's:^.*\t(.*/)([^/]+)$:\2:'
79 tr -d '\n' <"$1" |sed -r 's:\r ::g;s:\r:\n:g' \
81 s:^X-MS-CARDPICTURE:PHOTO:p;
83 s:^X-ANNIVERSARY:ANNIVERSARY:p;
84 s:^X-EVOLUTION-ANNIVERSARY:ANNIVERSARY:p;
85 s:^X-KADDRESSBOOK-X-Anniversary:ANNIVERSARY:p;
86 s:^X-AIM(;[^"\:]+|;"[^"]+")*\:(.*)$:IMPP\1\:aim\:\2:p;
87 s:^X-ICQ(;[^"\:]+|;"[^"]+")*\:(.*)$:IMPP\1\:aim\:\2:p;
88 s:^X-GOOGLE-TALK(;[^"\:]+|;"[^"]+")*\:(.*)$:IMPP\1\:xmpp\:\2:p;
89 s:^X-JABBER(;[^"\:]+|;"[^"]+")*\:(.*)$:IMPP\1\:xmpp\:\2:p;
90 s:^X-MSN(;[^"\:]+|;"[^"]+")*\:(.*)$:IMPP\1\:msn\:\2:p;
91 s:^X-YAHOO(;[^"\:]+|;"[^"]+")*\:(.*)$:IMPP\1\:ymsgr\:\2:p;
92 s:^X-SIP(;[^"\:]+|;"[^"]+")*\:(sip\:)?(.*)$:IMPP\1\:sip\:\3:p;
93 s:^LABEL(;[^"\:]+|;"[^"]+")*\:(.*)$:ADR;LABEL="\2"\1\::p;
94 s:^X-EVOLUTION-BLOG-URL:URL:p;
96 s:^AGENT:RELATED\;TYPE=agent:p;
97 s:^X-ASSISTANT:RELATED\;TYPE=assistant;VALUE=text:p;
98 s:^X-EVOLUTION-ASSISTANT:RELATED\;TYPE=assistant;VALUE=text:p;
99 s:^X-KADDRESSBOOK-X-AssistantsName:RELATED\;TYPE=assistant;VALUE=text:p;
100 s:^X-MANAGER:RELATED\;TYPE=manager;VALUE=text:p;
101 s:^X-EVOLUTION-MANAGER:RELATED\;TYPE=manager;VALUE=text:p;
102 s:^X-KADDRESSBOOK-X-ManagersName:RELATED\;TYPE=manager;VALUE=text:p;
103 s:^X-SPOUSE:RELATED\;TYPE=spouse;VALUE=text:p;
104 s:^X-EVOLUTION-SPOUSE:RELATED\;TYPE=spouse;VALUE=text:p;
105 s:^X-KADDRESSBOOK-X-SpouseName:RELATED\;TYPE=spouse;VALUE=text:p;
109 | sed -r 's:^([^;\:]+)(;[^"\:]+|;"[^"]+")*\:(.*)$:key="\1"\nvalue="\3"\ntag=\2:g' \
110 | while read -r line; do
112 key=*) printf %s\\n "$line"
114 value=*) printf %s\\n "$line"
118 | sed -r 's:^tag=::;s:\;([A-Z+_-]+="[^"]+"|[A-Z+_-]+=[^\;]+):\n\1:g;' \
119 | sed -r 's:([A-Z+_-]+)="?(.*)"?:tag\[\1\]="\2":g' \
121 | sort |while read -r tag; do
122 nt="$(printf %s "$tag" |sed -r 's:^tag\[([A-Z+_-]+)\]="(.*)"$:\1:')"
123 nv="$(printf %s "$tag" |sed -r 's:^tag\[([A-Z+_-]+)\]="(.*)"$:\2:')"
124 [ "$nt" = "$ot" ] && vl="$nv,$vl" || vl="$nv"
125 printf %s\\n "tag[$nt]=\"$vl\""
131 | sed -r 's:[\\$`]:\\&:g'
134 view_card() { #Parameter: Cardfile
136 cardfile="$_DATA/vcard/${id}"
137 cachefile="$_DATA/cache/${id}.cache"
139 if [ "$cachefile" -nt "$cardfile" ]; then
144 vcf_parse "$cardfile" |while read -r line; do
147 value*) eval "$line";;
150 if [ -z "$key" ]; then
153 values[$key]="$value"
154 for t in ${(k)tag}; do
155 tags[${key}_$t]="$tag[$t]"
158 if [ -n "$values[$key]" ]; then
160 while [ -n "$values[$key$n]" ]; do n=$(($n + 1)); done
169 . $view_card |tee "$cachefile"
173 edit_card() { #Parameter: Cardfile
175 cardfile="$_DATA/vcard/$id"
176 tempfile="$_DATA/temp/$id"
177 [ -f "$tempfile" ] && cardfile="$tempfile"
182 vcf_parse "$cardfile" |while read -r line; do
185 value*) eval "$line";;
188 if [ -z "$key" ]; then
191 [ -n "$value" ] && values[$key]="$value" || values[$key]='\r'
192 for t in ${(k)tag}; do
193 tags[${key}_$t]="$tag[$t]"
196 if [ -n "$values[$key]" ]; then
198 while [ -n "$values[${key}${n}]" ]; do n=$(($n + 1)); done