CSV contact import script
From Zarafa wiki
m (added note on UTF-16 and UTF-32 encoded csv files) |
|||
| Line 82: | Line 82: | ||
The csv should be stored in /tmp. | The csv should be stored in /tmp. | ||
| + | |||
| + | '''Note''': the script does not work if the csv file is UTF-16 or UTF-32 encoded (because of how PHP handles such files). The csv file can be converted into an UTF-8 file using iconv from the GNU libc library: | ||
| + | |||
| + | '''iconv -f UTF-16 -t UTF-8 -o /tmp/name_utf-8.csv /tmp/name.csv''' | ||
Latest revision as of 17:44, 13 April 2011
The following script can import a csv file with contacts: Media:Csv2contacts.zip.
The script can be customized for different csv files.
The following lines should be changed to make a different mapping between the Zarafa contact fields and the fields in the csv file: The number correspond with the column in the csv file.
$csv_mapping = array(
"given_name" => 0,
"middle_name" => 1,
"surname" => 2,
"display_name_prefix" => 3, //title
"webpage" => 6,
"birthday" => 8,
"wedding_anniversary" => 9,
"notes" => 13,
"email_address_1" => 14, //email address only
"email_address_2" => 15,
"email_address_3" => 16,
"home_telephone_number" => 18,
"home2_telephone_number" => 19,
"cellular_telephone_number" => 20,
"pager_telephone_number" => 21,
"home_fax_number" => 22,
"home_address" => 23,
"home_address_street" => 24,
"home_address_street2" => 25,
"home_address_street3" => 26,
"home_address_pobox" => 27,
"home_address_city" => 28,
"home_address_state" => 29,
"home_address_postal_code" => 30,
"home_address_country" => 31,
"spouse_name" => 32,
"manager_name" => 34,
"assistant" => 35,
"company_telephone_number" => 37,
"office_telephone_number" => 38,
"business2_telephone_number" => 39,
"business_fax_number" => 40,
"assistant_telephone_number" => 41,
"company_name" => 42,
"job_title" => 43,
"department_name" => 44,
"office_location" => 45,
"profession" => 47,
"business_address" => 49,
"business_address_street" => 50,
"business_address_street2" => 51,
"business_address_street3" => 52,
"business_address_pobox" => 53,
"business_address_city" => 54,
"business_address_state" => 55,
"business_address_postal_code" => 56,
"business_address_country" => 57,
"other_telephone_number" => 58,
"other_address" => 60,
"other_address_street" => 61,
"other_address_street2" => 62,
"other_address_street3" => 63,
"other_address_pobox" => 64,
"other_address_city" => 65,
"other_address_state" => 66,
"other_address_postal_code" => 67,
"other_address_country" => 68,
"callback_telephone_number" => 69,
"car_telephone_number" => 70,
"isdn_number" => 71,
"radio_telephone_number" => 72,
"ttytdd_telephone_number" => 73,
"telex_telephone_number" => 74,
"sensitivity" => 84,
"categories" => 87, //semicolon separated string
);
An example CSV file is in Csv2contacts.zip.
You can run the script via the following command:
php csv2contacts.php username password name.csv
The csv should be stored in /tmp.
Note: the script does not work if the csv file is UTF-16 or UTF-32 encoded (because of how PHP handles such files). The csv file can be converted into an UTF-8 file using iconv from the GNU libc library:
iconv -f UTF-16 -t UTF-8 -o /tmp/name_utf-8.csv /tmp/name.csv