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;;
if [ -z "$key" ]; then
eval "$line"
else
- values[${key}]="${value//\\r\\n/$BR}"
- for t in ${(k)tag}; do
- values[${key}_${t}]="${tag[$t]}"
+ 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"
- if [ -n "$values[$key]" ]; then
- n=0
- while [ -n "$values[$key$n]" ]; do n=$(($n + 1)); done
- key=$key$n
- fi
+ unset n
+ while [ -n "${values[$key$n]+x}" ]; do n=$((${n=-1} + 1)); done
unset value
unset tag
fi