X-Git-Url: https://git.plutz.net/?p=confetti;a=blobdiff_plain;f=pages%2Fcards.sh;h=538146d83749fdc2b1c24d403c1a69e51487b090;hp=a90981c6a16d02ec265bc80653aed9b29b90eca4;hb=refs%2Fheads%2Fmaster;hpb=2ea56a62d0ef6e9d295d0b8931a071e6f2e0a963 diff --git a/pages/cards.sh b/pages/cards.sh deleted file mode 100755 index a90981c..0000000 --- a/pages/cards.sh +++ /dev/null @@ -1,265 +0,0 @@ -#!/bin/zsh - -# Copyright 2014 - 2017 Paul Hänsch -# -# This file is part of Confetti. -# -# Confetti is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Confetti is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Confetti. If not, see . - -BR=' -' - -force_items(){ - for each in "$@"; do - [ -z "${values[$each]+x}" ] && values[${each}]='' - done -} - -case $PROFILE in -medical) - SUP_FIELDS=(N NICKNAME GENDER BDAY ADR TEL EMAIL X-HEALTH-INSURANCE X-HEALTH-INSURANCE-NOCONTRIB IMPP URL NOTE X-CLIENT-REFERRAL) - FORCE_ITEMS=(ADR TEL EMAIL NOTE X-CLIENT-REFERRAL) - _GET[order]="${_GET[order]:-lastname}" - _GET[filtertype]="${_GET[filtertype]:-name}" - profile_medical=x -;; -circus) - SUP_FIELDS=(N NICKNAME GENDER BDAY X-ZACK-JOINDATE X-ZACK-LEAVEDATE EMAIL TEL IMPP ADR URL NOTE) - FORCE_ITEMS=(BDAY X-ZACK-JOINDATE TEL EMAIL ADR NOTE) - _GET[order]="${_GET[order]:-firstname}" - _GET[filtertype]="${_GET[filtertype]:-any}" - profile_circus=x -;; -esac - -edit="${_GET[edit]}" -[ \! -f "vcard/$edit" -a \! -f "temp/$edit" ] && edit='' - -listcourses() { - ls -1 ${_DATA}/ical/*ics |while read file; do - 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")" - echo "$(date -d "$icstime" "+%u %H%M%S")\t$file" - done |sort |sed -r 's:^.*\t(.*/)([^/]+)$:\2:' -} - -list_hi_companies(){ - sed -rn 's;^X-HEALTH-INSURANCE:([^\;]+)\;.*$;\1;p' ${_DATA}/vcard/*vcf \ - | sort -u -} - -list_categories() { - catfile="${_DATA}/mappings/categories" - sort -u "$catfile" \ - | sed -r '/^[\t ]*$/d' -} - -listcards() { - filterex='s;^([^\n]+)\n.*$;\1;p' - printf '%s\n' "${_GET[filter]}" |tr '^' '\n' \ - | sed -r 's;[]\/\(\)\\\^\$\?\.\+\*\;\[\{\}];\\\\&;g' \ - | while read each; do - case $each in - name:*) expr='(FN|NICKNAME|N)(\;[^\n]+)*:[^\n]*'"(${each#*:})";; - street:*) expr='ADR(\;[^\n]+)*:([^\;]*;){2}[^\;\n]*'"(${each#*:})";; - zip:*) expr='ADR(\;[^\n]+)*:([^\;]*;){5}[^\;\n]*'"(${each#*:})";; - any:*|:*) expr="[^\n]*"'(\;[^\n]+)*:[^\n]*'"(${each#*:})";; - *:*) expr="${each%%:*}"'(\;[^\n]+)*:[^\n]*'"(${each#*:})";; - *) expr="(${each})";; - esac - filterex='/(^|\n)'"${expr}"'/I{'"${filterex}"'}' - done - - for file in "${_DATA}/vcard/"*.vcf; do - case "${_GET[order]}" in - firstname) - printf '%s\t%s\n' "$(sed -rn 's:^N(;.+)*\:([^;]*;){1} *([^;]*).*$:\3:p' "$file")" "$file" - ;; - lastname) - printf '%s\t%s\n' "$(sed -rn 's:^N(;.+)*\:([^;]*;){0} *([^;]*).*$:\3:p' "$file")" "$file" - ;; - bdate) - printf '%s\t%s\n' "$(sed -rn 's:^BDAY(;.+)*\:(.*)$:\2:p' "$file")" "$file" - ;; - *) printf 'x\t%s\n' "$file" - ;; - esac - done \ - | sort -u |sed -r 's;^.*\t;;' \ - | while read n; do - { printf '%s\n' "$n"; cat "$n"; } \ - | sed -rn ':X;N;$!bX; {'"$filterex"'}' - done \ - | sed -r 's;^(.*/)*;;;' -} - -vcf_parse() { - unset key - sed -r ':X;N;$!bX; s;\r\n[ \t];;g; s;\r\n;\n;g;' "$1" \ - | sed -rn ' - # === turn property names to upper case, strip group names === - h; s;^([^;:]+);;; - x; s;^([^;:\.]+\.)?([^;:]+).*$;\2;; - y;abcdefghijklmnopqrstuvwxyz;ABCDEFGHIJKLMNOPQRSTUVWXYZ; - G; s;\n;;; - - # === strip trailing CR (but keep CRs in property value) === - s;\r$;;; - - # === Normalise various known vendor properties === - s;^X-MS-CARDPICTURE(\;|:);PHOTO\1;; - s;^X-GENDER(\;|:);GENDER\1;; - s;^X-ANNIVERSARY(\;|:);ANNIVERSARY\1;; - s;^X-EVOLUTION-ANNIVERSARY(\;|:);ANNIVERSARY\1;; - s;^X-KADDRESSBOOK-X-ANNIVERSARY(\;|:);ANNIVERSARY\1;; - s;^X-EVOLUTION-BLOG-URL(\;|:);URL\1;; - s;^AGENT(\;|:);RELATED\;VALUE=text\;TYPE=agent\1;; - s;^X-ASSISTANT(\;|:);RELATED\;VALUE=text\;TYPE=assistant\1;; - s;^X-EVOLUTION-ASSISTANT(\;|:);RELATED\;VALUE=text\;TYPE=assistant\1;; - s;^X-KADDRESSBOOK-X-ASSISTANTSNAME(\;|:);RELATED\;VALUE=text\;TYPE=assistant\1;; - s;^X-MANAGER(\;|:);RELATED\;VALUE=text\;TYPE=manager\1;; - s;^X-EVOLUTION-MANAGER(\;|:);RELATED\;VALUE=text\;TYPE=manager\1;; - s;^X-KADDRESSBOOK-X-MANAGERSNAME(\;|:);RELATED\;VALUE=text\;TYPE=manager\1;; - s;^X-SPOUSE(\;|:);RELATED\;VALUE=text\;TYPE=spouse\1;; - s;^X-EVOLUTION-SPOUSE(\;|:);RELATED\;VALUE=text\;TYPE=spouse\1;; - s;^X-KADDRESSBOOK-X-SPOUSENAME(\;|:);RELATED\;VALUE=text\;TYPE=spouse\1;; - - # === Normalise obsolete vendor IM properties === - s;^X-AIM((\;[A-z0-9-]+|\;[A-z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):;IMPP\1:aim:;; - s;^X-ICQ((\;[A-z0-9-]+|\;[A-z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):;IMPP\1:aim:;; - s;^X-GOOGLE-TALK((\;[A-z0-9-]+|\;[A-z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):;IMPP\1:xmpp:;; - s;^X-JABBER((\;[A-z0-9-]+|\;[A-z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):;IMPP\1:xmpp:;; - s;^X-MSN((\;[A-z0-9-]+|\;[A-z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):;IMPP\1:msn:;; - s;^X-YAHOO((\;[A-z0-9-]+|\;[A-z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):;IMPP\1:ymsgr:;; - s;^X-SIP((\;[A-z0-9-]+|\;[A-z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):(sip:)?;IMPP\1:sip:;; - - # === Update obsolete LABEL property === - s;^LABEL((\;[A-z0-9-]+|\;[A-z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):(.*)$;ADR\1\;LABEL="\5":;; - - /^([A-Z0-9-]+)((\;[A-z0-9-]+=?|\;[A-z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):(.*)$/{ - h; - s;^([A-Z0-9-]+)((\;[A-z0-9-]+=?|\;[A-z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):(.*)$;key='\''\1'\'';; - H; g; - - s;^([A-Z0-9-]+)((\;[A-z0-9-]+=?|\;[A-z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):([^\n]*)\n.*$;\2;; - s;'\'';'\'\\\\\'\'';g - s;\;([A-Z0-9-]+)(=|=(([^\;,:"]+|"[^"]+")(,[^\;,:"]+|,"[^"]+")*))?;\ntag[\1]='\''\3'\'';g - s;^\n+;;; s;\n+$;;; - /^.+$/H; g; - - s;^([A-Z0-9-]+)((\;[A-z0-9-]+=?|\;[A-z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):([^\n]*)\n.*$;\6;; - # :X s;((^|[^\\])(\\\\)*)[;,];\1\n;g; s;((^|[^\\])(\\\\)*)\\([;,]);\4;g; tX; - s;'\'';'\'\\\\\'\'';g - s;^.*$;value='\''&'\''; - H; g; - - s;^[^\n]*[\n ]+;; - s;\n+$;;; - - p; - } - ' \ - | while read -r line; do - declare -A tag - case "$line" in - value*) eval "$line";; - tag*) eval "$line";; - key*) - if [ -z "$key" ]; then - eval "$line" - else - printf '%s\n' "$value" |sed -rn ' - :X - s;((^|[^\\])(\\\\)*),;\1\n;g; - tX; - s;\\,;,;g; - p - ' \ - | while read -r val; do - while [ -n "${values[$key$n]+x}" ]; do n=$((${n=-1} + 1)); done - if printf '%s\n' "$val" |grep -qE '((^|[^\\])(\\\\)*)\;'; then - m=0 - values[${key}${n}]="${val}" - printf '%s\n' "$val" |sed -rn ' - :X - s;((^|[^\\])(\\\\)*)\;;\1\n;g; - tX; - s;\\\;;\;;g; - p - ' \ - | while read -r v; do - values[${key}${n}+${m}]="$( - printf %s\\n "${v}" \ - | sed -rn ' - :X - s;((^|[^\\])(\\\\)*)\\n;\1\n;g; - tX; - s;\\\\;\\;g; - p - ' - )" - m=$(($m + 1)) - done - else - values[${key}${n}]="$( - printf %s\\n "${val}" \ - | sed -rn ' - :X - s;((^|[^\\])(\\\\)*)\\n;\1\n;g; - tX; - s;\\\;;\;;g; - s;\\\\;\\;g; - p - ' - )" - fi - for t in ${(k)tag}; do - values[${key}${n}_${t}]="${tag[$t]}" - done - done - - eval "$line" - unset n - while [ -n "${values[$key$n]+x}" ]; do n=$((${n=-1} + 1)); done - unset value - unset tag - fi - ;; - esac - done -} - -view_card() { #Parameter: Cardfile - id="$1" - cardfile="$_DATA/vcard/${id}" - cachefile="$_DATA/cache/${id}.cache" - if [ "$cachefile" -nt "$cardfile" ]; then - cat "$cachefile" - else - declare -A values - vcf_parse "$cardfile" - . "$_EXEC/templates/view_card.sh" |tee "$cachefile" - fi -} - -edit_card() { #Parameter: Cardfile - id="$1" - cardfile="$_DATA/vcard/$id" - tempfile="$_DATA/temp/$id" - [ -f "$tempfile" ] && cardfile="$tempfile" - - declare -A values - vcf_parse "$cardfile" - force_items $FORCE_ITEMS - . "$_EXEC/templates/edit_card.sh" -}