📜 ⬆️ ⬇️

Converter for transferring contacts from Outlook to Android, for paranoids (open source, without using synchronization with Google and third-party utilities)

Yesterday one comrade turned up, faced with the problem of transferring contacts from a smartphone to WM6 for a new Android device. After a week of vain attempts, he lowered his hands and handed over the csv file obtained from Outlook, to which he quite simply managed to connect the phone's notebook.

He tried many converters and methods, but all of them either did not give the desired result - fast and free conversion in two clicks, or distorted information due to the curly implementation of the localization of his version of Autluk. He refused to use contact binding to the account for religious and political reasons, the dictates of internal morality or way of life, I did not specify.

As a result, a little googling, but not finding a simple solution, we had to loosen the script on the great and powerful , which creates a vcf-file of contacts, which in turn is easily imported into Android using standard phone tools.

Initial data


Actually what had to face.
')
CSV

A CSV file is a plain text file in which each row is a row of a data table, and the columns within a row are separated by a separator character, which can be selected by the user and is usually a tab, semicolon, comma, etc. The first line often contains not field values, but field names.

When exporting from Outlook, you must select all fields and allow placing the names of the fields in the first line (perhaps this is enabled by default).

The result is a text file of a similar format.
Appeal; Name; Fatherland; Surname; Suffix; Organization; Department; Position; Ulitsarabadres; Street 2 address; Street address; Citybadres; DomainAdmin; Indexrabadres; Stranarabadres; Ulitsadomadres; Street2domain; Street 3 address; City Maiden; Areadomain; Sweat code; Stranadomares; Street address; Street 2 another address; Street 3 another address; City other address; Area another address; Index to another address; Other address; Telephone assistant; Raboiifax; Work phone; Telephone2; Callback; Telephone in the machine; Main telephone organization; Homefax; Home phone; Telefonom2; ISDN; Telephone portable; Anotherfax; Other phone; Pager; Main phone; Radiotelephone; Teletype telephones; Telex; Importance; Webpage; Anniversary; Birthday; Children; Assistant's name; Initials; Categories; Clue terms; Code organization; Linecode; Postponed; Floor; User1; User2; User3; User4; Mark; Potovyashikdomadres; Store another address; Sweat crabs; Profession; Location; Location rooms; Distance; Head; Information available to the Internet; Server Directory; Spouse; Set; Seth; Hobby; private; Adresselpot; Tipalpots; Short Names; Address 2 slots; Type 2 elpots; Short2mealpots; Address3elpots; Tip3 Elpot; Short3mealpots; Language [CRLF]

; Credit ;; Bee Line Account ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 067404 ;;; 067404 ;;;;;; ;;; Plain ;;;;;; K.BLS; Service ;;;;; Not determined;;;;; Plain ;;;;;;;;;;;;;;;; LYING;;;;;;;;;; [CRLF]

Other records

vCard

This is a business card format. On Android phones, this is the main format for exchanging contacts. If you are trying to send a contact by mail or SMS, then the phone will attach exactly vcf-card. The beauty of the format is that in one card (file) you can combine several contacts.

The converted entry from the example above looks like this.
BEGIN: VCARD
VERSION: 3.0
CATEGORIES: Utility
N: Bee Line Account; Credit
TEL; TYPE = cell: 067404
TEL; TYPE = home: 067404
END: VCARD

Script converter


The script is written in a convenient, simple, lightweight, cross-platform, and a bunch of different awk epithets. The field separator inside the csv is indicated at the beginning (I got a csv with a semicolon). Next, the map of csv fields to vCard fields is defined as an array of KEYS. In general, these are all settings that should work by default.

outlook2vcard.awk
BEGIN { FS = ";" KEYS[""] = "N.1"; KEYS[""] = "N.2"; KEYS[""] = "N.3"; KEYS[""] = "N.4"; KEYS[""] = "N.5"; KEYS[""] = "ORG.1"; KEYS[""] = "ORG.2"; KEYS[""] = "TITLE"; KEYS[""] = "ADR;TYPE=work.2"; KEYS["2"] = "ADR;TYPE=work.2"; KEYS["3"] = "ADR;TYPE=work.2"; KEYS[""] = "ADR;TYPE=work.3"; KEYS[""] = "ADR;TYPE=work.4"; KEYS[""] = "ADR;TYPE=work.5"; KEYS[""] = "ADR;TYPE=work.6"; KEYS[""] = "ADR;TYPE=home.1"; KEYS[""] = "ADR;TYPE=home.2"; KEYS["2"] = "ADR;TYPE=home.2"; KEYS["3"] = "ADR;TYPE=home.2"; KEYS[""] = "ADR;TYPE=home.3"; KEYS[""] = "ADR;TYPE=home.4"; KEYS[""] = "ADR;TYPE=home.5"; KEYS[""] = "ADR;TYPE=home.6"; KEYS[""] = "ADR;TYPE=postal.2"; KEYS["2"] = "ADR;TYPE=postal.2"; KEYS["3"] = "ADR;TYPE=postal.2"; KEYS[""] = "ADR;TYPE=postal.3"; KEYS[""] = "ADR;TYPE=postal.4"; KEYS[""] = "ADR;TYPE=postal.5"; KEYS[""] = "ADR;TYPE=postal.6"; KEYS[""] = "TEL;TYPE=pager"; KEYS[""] = "TEL;TYPE=work;TYPE=fax"; KEYS[""] = "TEL;TYPE=work"; KEYS["2"] = "TEL;TYPE=work"; KEYS[""] = "TEL;TYPE=X-EVOLUTION-CALLBACK"; KEYS[""] = "TEL;TYPE=car"; KEYS[""] = "TEL;TYPE=work"; KEYS[""] = "TEL;TYPE=home;TYPE=fax"; KEYS[""] = "TEL;TYPE=home"; KEYS["2"] = "TEL;TYPE=home"; KEYS["ISDN"] = "TEL;TYPE=isdn"; KEYS[""] = "TEL;TYPE=cell"; KEYS[""] = "TEL;TYPE=fax"; KEYS[""] = "TEL"; KEYS[""] = "TEL;TYPE=pager"; KEYS[""] = "TEL"; KEYS[""] = "TEL;TYPE=pcs"; KEYS[""] = "TEL;TYPE=msg"; KEYS[""] = "TEL;TYPE=msg"; KEYS[""] = ""; KEYS[""] = "URL"; KEYS[""] = "X-ANNIVERSARY"; KEYS[""] = "BDAY"; KEYS[""] = ""; KEYS[""] = "X-ASSISTANT"; KEYS[""] = ""; KEYS[""] = "CATEGORIES"; KEYS[""] = "NOTE"; KEYS[""] = ""; KEYS[""] = ""; KEYS[""] = ""; KEYS[""] = ""; KEYS["1"] = ""; KEYS["2"] = ""; KEYS["3"] = ""; KEYS["4"] = ""; KEYS[""] = ""; KEYS[""] = ""; KEYS[""] = ""; KEYS[""] = ""; KEYS[""] = ""; KEYS[""] = ""; KEYS[""] = ""; KEYS[""] = ""; KEYS[""] = ""; KEYS[""] = ""; KEYS[""] = ""; KEYS[""] = "X-SPOUSE"; KEYS[""] = ""; KEYS[""] = ""; KEYS[""] = ""; KEYS["_"] = ""; KEYS[""] = "EMAIL;TYPE=internet"; KEYS[""] = ""; KEYS[""] = ""; KEYS["2"] = "EMAIL;TYPE=internet"; KEYS["2"] = ""; KEYS["2"] = ""; KEYS["3"] = "EMAIL;TYPE=internet"; KEYS["3"] = ""; KEYS["3"] = ""; KEYS[""] = ""; } FNR == 1 { for (i = 1; i <= NF; i++) { k = KEYS[$i]; if ("" != k) { MAPS[i] = k; } } } FNR != 1 { delete PROPS; for (i = 1; i <= NF; i++) { k = MAPS[i]; if (("" != $i) && ("" != k)) { PROPS[k] = $i; } } n = asorti(PROPS, SKEYS); if (n > 0) { l = ""; print("BEGIN:VCARD"); printf("VERSION:3.0"); for (i = 1; i <= n; i++) { k = SKEYS[i]; v = PROPS[k]; if (2 == split(k, a, ".")) { k = a[1]; x = 0 + a[2]; } else { x = 1; } if (l != k) { l = k; m = 1; printf("\r\n%s:", l); } while (m < x) { m++; printf(";"); } printf("%s", v); } print("\r\nEND:VCARD"); } } function die(str) { print "Error at " FILENAME ":" FNR " " str exit } function warn(str) { print "Warning at " FILENAME ":" FNR " " str } 

How to run

Run the script from under the awk interpreter as follows:
 gawk -f outlook2vcard.awk inputfile.csv >outputfile.vcf 

As input files, you can specify multiple csv files, then they will be merged.

A spoon of tar

The script does not automatically convert the Cyrillic encoding to UTF-8 , which is native to Android. This final chord must be done manually, either using iconv for unixoids, it is also available under gnuwin32 , or with a regular notepad (notepad.exe) for window vents, opening the file, and then saving it with a new name (Save As ...) and selecting UTF-8 encoding under the new file name.

Import to phone


The method is simple and is described in a pile of blogs and forums, but I will not be lazy and will bring it again. The resulting file with the extension vcf must be put on the Androidphone memory card. Then enter contacts, press the menu button and select “Import / Export - Import from a memory card”, voila.

Source: https://habr.com/ru/post/150816/


All Articles