[evolution-patches] Address book - contact migration - enhancements to csv2vcard migration routine
- From: Sean Carlos <seanc libero it>
- To: evolution-patches lists ximian com
- Subject: [evolution-patches] Address book - contact migration - enhancements to csv2vcard migration routine
- Date: Tue, 15 Mar 2005 21:45:16 +0100
I migrated about 1200 contacts to the Evolution address book using the
csv2vcard perl script provided with the FC3 evolution release (2.0.x).
It worked very well except for:
1) Categories. They were ignored.
Solution: added Category mapping to csv2vcard.
2) "Other" addresses. Visible in VCARD file, but not in Evolution 2.0.
Solution: changed occurrences of ADR;POSTAL to ADR;OTHER in csv2vcard.
While rfc2426 just specifies HOME + WORK, OTHER was accepted by
Evolution ... POSTAL was not.
3) Dates. csv2vcard makes the assumption that dates (Birthday,
anniversary) are in the format mm/dd/yy. Others are ignored.
Unfortunately, my data contained:
m/d/yyyy
mm/d/yyyy
m/dd/yyyy
mm/dd/yyyy
Solution: Added logic to handle
m/d/yy
mm/d/yy
m/dd/yy
mm/dd/yy
m/d/yyyy
mm/d/yyyy
m/dd/yyyy
mm/dd/yyyy
-> Open date issues to enhance:
a) Non US date formats, i.e. day - month - year, are not handled nor is
there a warning issued. The script should probably check the user's
current locale and at least issue a warning if it is not en_US.*
b) The script handles Y2K issues by assigning all years < 15 to 20xx.
So a grandmother born in 1914 would end up with 2014 as a birthday year.
Ideally the script should warn the user this assumption has been made
should such data be encountered.
A patch is attached. I'm not an expert perl programmer, but "it worked
for me".
I encountered several issues importing the resultant file which I'll
post to the generic evolution list.
Best regards,
Sean
--- /usr/libexec/evolution/2.0/csv2vcard 2005-02-24 21:22:06.000000000 +0100
+++ csv2vcard 2005-03-15 19:31:48.922078680 +0100
@@ -21,7 +21,17 @@
#
# Author: Michael MacDonald <mjmac ximian com>
#
-
+# Revised 2005-03-10 by Sean Carlos seanc libero it
+# 1) Added support for Category field.
+# 2) Date support was limited to mm/dd/yy.
+# Added m/d/yy m/d/yyyy
+# m/dd/yy m/dd/yyyy
+# mm/d/yy mm/d/yyyy
+# mm/dd/yyyy
+# 3) Changed ADR;POSTAL to ADR;OTHER. rfc2426 just specifies HOME + WORK but OTHER works.
+# 4) To do: Support dates in the worldwide format day - month year.
+# current logic assumes format is month day year. Probably need to test the locale or add a switch.
+#
use strict;
use diagnostics;
use Text::ParseWords;
@@ -44,7 +54,7 @@
{
my $line = shift;
- # Making some assumptions here... Prolly OK.
+ # Making some assumptions here... Probably OK.
return $line =~ /(First Name|Middle Name|Last Name)/;
}
@@ -96,7 +106,6 @@
sub build_vcard_from_line {
my ($line, %map) = @_;
my %vcard;
-
my @fields = parse_line(',', 0, $line);
my %vcard_def = ( FN => 'Title |First Name |Middle Name |Last Name |Suffix',
@@ -112,8 +121,8 @@
'TEL;HOME;VOICE' => 'Home Phone',
'TEL;HOME;VOICE2' => 'Home Phone 2',
'TEL;HOME;FAX' => 'Home Fax',
- 'ADR;POSTAL' => ';Other Street 2|;Other Street|;Other City|;Other State|;Other Postal Code|;Other Country',
- 'LABEL;QUOTED-PRINTABLE;POSTAL' => 'Other Street=0A|Other Street 2=0A|Other City,| Other State| Other Postal Code=0A|Other Country',
+ 'ADR;OTHER' => ';Other Street 2|;Other Street|;Other City|;Other State|;Other Postal Code|;Other Country',
+ 'LABEL;QUOTED-PRINTABLE;OTHER' => 'Other Street=0A|Other Street 2=0A|Other City,| Other State| Other Postal Code=0A|Other Country',
'TEL;VOICE' => 'Other Phone',
'TEL;FAX' => 'Other Fax',
'TEL;CELL' => 'Mobile Phone',
@@ -134,6 +143,7 @@
'X-EVOLUTION-ASSISTANT' => "Assistant's Name",
'TEL;X-EVOLUTION-ASSISTANT' => "Assistant's Phone",
'X-EVOLUTION-SPOUSE' => 'Spouse',
+ CATEGORIES => 'Categories',
'X-EVOLUTION-ANNIVERSARY' => 'Anniversary',
'X-EVOLUTION-MANAGER' => "Manager's Name",
'X-EVOLUTION-OFFICE' => 'Office Location',
@@ -173,7 +183,19 @@
print $fh "$temp:$vcard{ $key }\n";
} elsif ($key =~ /(BDAY|X\-EVOLUTION\-ANNIVERSARY)/o) {
my $temp = $vcard{ $key };
- if ($temp =~ /(\d\d)\/(\d\d)\/(\d\d)/) {
+# Check for date formats m/d/yyyy m/dd/yyyy mm/d/yyyy mm/dd/yyyy
+# m/d/yy m/dd/yy mm/d/yy mm/dd/yy
+# Bug: current logic assumes American format month - year.
+# Change to $key:$3-$2-$1 for Worldwide format
+ if ($temp =~ /(\d\d)\/(\d\d)\/(\d\d\d\d)/) {
+ print $fh "$key:$3-$1-$2\n";
+ } elsif ($temp =~ /(\d\d)\/(\d)\/(\d\d\d\d)/) {
+ print $fh "$key:$3-$1-0$2\n";
+ } elsif ($temp =~ /(\d)\/(\d\d)\/(\d\d\d\d)/) {
+ print $fh "$key:$3-0$1-$2\n";
+ } elsif ($temp =~ /(\d)\/(\d)\/(\d\d\d\d)/) {
+ print $fh "$key:$3-0$1-0$2\n";
+ } elsif ($temp =~ /(\d\d)\/(\d\d)\/(\d\d)/) {
# Y2k !! MS Didn't learn anything.
# Hope no one was born before 1915
if ((1900 + $3) < 1915) {
@@ -181,6 +203,24 @@
} else {
print $fh "$key:19$3-$1-$2\n";
}
+ } elsif ($temp =~ /(\d)\/(\d\d)\/(\d\d)/) {
+ if ((1900 + $3) < 1915) {
+ print $fh "$key:20$3-0$1-$2\n";
+ } else {
+ print $fh "$key:19$3-0$1-$2\n";
+ }
+ } elsif ($temp =~ /(\d\d)\/(\d)\/(\d\d)/) {
+ if ((1900 + $3) < 1915) {
+ print $fh "$key:20$3-$1-0$2\n";
+ } else {
+ print $fh "$key:19$3-$1-0$2\n";
+ }
+ } elsif ($temp =~ /(\d)\/(\d)\/(\d\d)/) {
+ if ((1900 + $3) < 1915) {
+ print $fh "$key:20$3-0$1-0$2\n";
+ } else {
+ print $fh "$key:19$3-0$1-0$2\n";
+ }
} else {
# Something's funky... Just delete the attribute
print STDERR "Couldn't figure out what to do with $key:$vcard{ $key }\n";
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]