I’m quite a looser at shell scripting, so I simply ask the question here:
I try to use *.vcf (2.1) files as e.g. used by KDE’s kaddressbook on a Nokia mobile phone. Unfortunately, the VCFs as generated by KDE are incompatible with all Nokia phones I’ve owned up to now, and the KDE devs won’t install any compatibility kludges.
So I have to manually adapt the VCard-files, and I’d like to automatize this task by some yet-to-be-invented script magic.
The VCards are simple text files containing several “features” of the person they describe and are structured as follows:
BEGIN:VCARD
ADR;TYPE=home;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:xxxx
BDAY:xxx
FN;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:xxx
N;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:xxx
PHOTO;ENCODING=b;TYPE=image/jpeg:xxxxx
TEL;TYPE=CELL;TYPE=PREF:xxxx
UID:xxxx
VERSION:2.1
END:VCARD
The problems Nokia phones seem to have with this VCards:
-
“ENCODING=b”, as seen in the “PHOTO”-feature-line, is not accepted, my Nokia phones seem to need “ENCODING=BASE64”. My solution:
find . -name “*.vcf” -exec sed -i ‘s/ENCODING=b/ENCODING=BASE64/g’ {} ; -
If a line containing one feature is longer than a certain number of characters, e.g. a long address field, KDE includes a line feed consisting of hex “0x0d 0x0a 0x20”, that is a unix-like line feed plus a space. This seems to be according to VCard-standard, however my phones simply skip the part after the strange hex combination.
These word wraps within single features therefore have all to be removed. Is there a way to remove all CR/LF/SPACE-combinations in a text file automatically? -
The “PHOTO” entry contains an image and is usually also longer than one line. Nokia phones accept this image, however all features in the VCard file after “PHOTO” are skipped, i.e. including the not-so-unimportant phone numbers.
Solution: Either change the order of the features and make the PHOTO feature the last one, or - strange enough - put in several line feeds between the PHOTO feature and the following TEL feature. I’m completely at a loss how to do this by a script.
Any help appreciated to get this restructuring of VCF-files done automatically!