Tuesday, November 9, 2010

VCARD quoted-printable decoding and importing to outlook

My father replaced an old LG KU380 and wanted to transfer his contacts to his new Ericson mobile phone. Unluckily for me, LG provided some software that was promising to synchronize the mobile phone with the outlook, but it wouldn’t stay connected with the phone for more than one minute. Thus, every 100 contacts it would stall and start over again. The next available option was to export the contacts in a vcf file from within the mobile phone and transfer the generated file via Bluetooth.

The file had the following format:
BEGIN:VCARD VERSION:2.1 N;ENCODING=QUOTED-PRINTABLE;CHARSET=UTF-8:;=CE=91 TEL;HOME;CELL;CHARSET=UTF-8:123456789 REV:20141012T151100Z END:VCARD BEGIN:VCARD VERSION:2.1 N;ENCODING=QUOTED-PRINTABLE;CHARSET=UTF-8:;=CE=91=CE=B1 TEL;HOME;CELL;CHARSET=UTF-8:6900000000 REV:20140313T085200Z END:VCARD ...



 
which is an aggregation of multiple VCARDs (starting on BEGIN:VCARD up to END:VCARD) that contained the name of the contact (the lines that starts with N) and some telephones. The problem was that this file was encoded in QUOTED-PRINTABLE using UTF-8 character set and as you can see from the above sample, Greeks could not be decrypted (even from outlook and live mail). Moreover, LG didn’t support all Greek letters. The names were saved in a GSM 7-bit like format (where capital b is used instead of β etc).


Finally, I had to aggregate the phone numbers of each contact person into a single contact card (instead of having a different vcard for each and every number).


The resulted code (vb.net console application) is well commented and available in the following link:


6 comments:

Anonymous said...

Christos:

You posted a comment on the Dr's Office blog back in July regarding building a RAID after Windows has been installed. Your system configuration, while different, I think, from he one in the post, is very similar to mine (OS on an SSD, RAID on 2 HDDs), and I'm having the same problem. I haven't tried the fix yet and I'm wondering if you have any additional pointers. Can you let me know at Karl at Lautman dot com? Thanks a lot.

Karl

Aggelos said...

Had the same problem when exporting contacts from Sony Ericsson G900 through their portal and importing into Outlook. I ported the code to C# and worked great! Thanks a lot!

anybody said...

Where is the download link?
I can't see one. Very frustrating since this seems to be exactly what I need :-(

Andreas Botsikas said...

I am terribly sorry for that. Skydrive has been updated and all my perma links have stoped working! What kind of perma link are they!?!??! Hopefully you will be able to see the download link now. Let me know how it goes.

Udun said...

Well - very interesting post - I am on the same shoes except that I have also names encoded in what seems to be unicode - when I open the .vcf in Notepad++ and I change encoding to any of the unicode options I get x9B where I should see Λ or xA3 for Σ. Do you understand what is happening ?
Also the vd script you linked is giving me a null object exception in line : ccontact.Numbers.Add(l.Substring(l.IndexOf(":") + 1))
Know nothing on VB so I can't help - VS2010

BTW - would be great if you simplified your script to handle generic cases - my vcf file is imported in google contacts just fine as far as the CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE: entries are concerned - the only thing that's garbled is the contacts I referred to above - give it a whirl !

Anonymous said...

Magic of
CHARSET=UTF-8;
ENCODING=QUOTED-PRINTABLE
revealed ...

I am russian, but this greek post help me to figure out an absolute formula.

I am try to describe it in a follow c# like notation

char.ConvertFromUtf32((0xHI-0xC2)*0x40 + 0xLO);

in this case
0xHI is a left code in pair
0xLO is a right code in pair
0xC2 is A ZERO point
0x40 is a hi-block offset or shift

for example related to greek
"=CF=81" easy come to "ρ"(U+03C1) unicode character
(0xCF-0xC2)*0x40 + 0x81)
1. CF-C2 = D
2. D * 40 = 340
3. 340 + 81 = 3C1

Hope it will be usefull for somebody for any character in any cases

Aleksandr Diomin
mailto:diomin@gmail.com