From 3529f64e15cc4fa5e53e6d58a74cd20a09a29c7f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Wed, 6 Feb 2019 21:21:37 +0100 Subject: [PATCH] working vcard filter --- cards/list.sh | 53 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/cards/list.sh b/cards/list.sh index cb33637..8b911fb 100755 --- a/cards/list.sh +++ b/cards/list.sh @@ -2,6 +2,9 @@ . "${_EXEC}"/pdiread.sh +unescape() { [ $# = 0 ] && sed -E 's;\\(.);\1;g' || printf %s "$*" |sed -E 's;\\(.);\1;g'; } +upcase=' y;abcdefghijklmnopqrstuvwxyzäöüé;ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÜÉ;; ' + card_fullname(){ local card="$1" n1 n2 n3 n4 n5 @@ -21,6 +24,7 @@ card_fullname(){ fi } + card_item(){ local card="$1" local item cnt c @@ -30,13 +34,13 @@ card_item(){ cnt="$(pdi_count "$card" "$item")" case $item in - FN) printf '[h2 .item .FN ­%s]' "$(card_fullname "$card" |HTML)" + FN) printf '[h2 .item .FN ­%s]' "$(card_fullname "$card" |unescape |HTML)" ;; GENDER) printf '[span .item .GENDER ­%s]' "$(pdi_value "$card" GENDER |l10n)" ;; NICKNAME) seq 1 $cnt |while read c; do printf '[span .item .NICKNAME ­aka. "%s"]' \ - "$(pdi_value "$card" NICKNAME $c |HTML)" + "$(pdi_value "$card" NICKNAME $c |unescape |HTML)" done ;; X-ZACK-JOINDATE|X-ZACK-LEAVEDATE) if [ $cnt -gt 0 ]; then @@ -59,7 +63,7 @@ card_item(){ ;; PHOTO|LOGO) if [ $cnt -gt 0 ]; then printf '[img .item .%s src="data:image/%s;base64,%s"]' "$item" \ - "$(pdi_attrib "$card" "$item" |sed -r 's;^(.*;)?TYPE="?(.+)"?(;.*)?$;\2;')" \ + "$(pdi_attrib "$card" "$item" |sed -E 's;^(.*;)?TYPE="?(.+)"?(;.*)?$;\2;')" \ "$(pdi_value "$card" "$item" |grep -xE '[a-zA-Z0-9/+=]+')" fi ;; @@ -67,8 +71,8 @@ card_item(){ printf '[h3 %s]' "$(l10n EMAIL)" seq 1 $cnt |while read c; do printf '[a .item .EMAIL href="mailto:%s" ­%s]' \ - "$(pdi_value "$card" EMAIL $c |HTML)" \ - "$(pdi_value "$card" EMAIL $c |HTML)" + "$(pdi_value "$card" EMAIL $c |unescape |HTML)" \ + "$(pdi_value "$card" EMAIL $c |unescape |HTML)" done fi ;; @@ -76,7 +80,7 @@ card_item(){ printf '[h3 %s]' "$(l10n "$item")" seq 1 $cnt |while read c; do printf '[span .item .%s ­%s]' "$item" \ - "$(pdi_value "$card" "$item" $c |HTML)" + "$(pdi_value "$card" "$item" $c |unescape |HTML)" done fi ;; @@ -105,7 +109,7 @@ print_card(){ $(grep -F " ${cardfile##*/}" "$_DATA/mappings/attendance" |while read each discard; do printf '[li [a .item .attendance href="/courses#%s" ­%s]]' \ "$each" \ - "$(pdi_value "$(pdi_load "$_DATA/ical/$each")" SUMMARY |HTML)" + "$(pdi_value "$(pdi_load "$_DATA/ical/$each")" SUMMARY |unescape |HTML)" done)] $(card_item "$card" CATEGORIES) ] @@ -118,8 +122,41 @@ print_card(){ fi } -list_cards(){ +filter_cards(){ + local filter f fex='x;p;' + + filter="$(printf %s "${filter}" \ + | sed -E 's;[]\/\(\)\\\^\$\?\.\+\*\;\[\{\}];\\\\&;g; + '"$upcase" + )^" + + while [ "$filter" ]; do + f="${filter%%^*}" filter="${filter#*^}" + case $f in + '') break + ;; + ANY:*) fex="/\n.*(\;[^:]*)?:.*(${f#*:}).*\r?\n/{${fex}}" + ;; + NAME:*) fex="/\n(N|FN|NICKNAME)(\;[^:]*)?:.*(${f#*:}).*\r?\n/{${fex}}" + ;; + STREET:*|ZIP:*) fex="/\nADR(\;[^:]*)?:.*(${f#*:}).*\r?\n/{${fex}}" + ;; + *) fex="/\n${f%%:*}(\;[^:]*)?:.*(${f#*:}).*\r?\n/{${fex}}" + ;; + esac + done + for cardfile in "${_DATA}"/vcard/*.vcf; do + printf '%s\n' "$cardfile" + cat "$cardfile" + done \ + | sed -En ':X; /\nEND:VCARD\r?$/!{ N; bX; }; h; s;\n.*$;;; x; s;^[^\n]+\n;;; + '"$upcase""$fex" +} + +list_cards(){ + filter_cards \ + | while read cardfile; do print_card "$cardfile" done } -- 2.39.2