import: a work address stays in the source
The editor's address rows carry no type, so a carried work address
would land as an unmarked second one beside the home.
Assisted-by: GLM-5.3 via pi
diff --git a/lib/pro_tacts/import/macos.rb b/lib/pro_tacts/import/macos.rb
index 47e6146..e71bab7 100644
--- a/lib/pro_tacts/import/macos.rb
+++ b/lib/pro_tacts/import/macos.rb
@@ -333,7 +333,7 @@ module ProTacts
"EMAIL;type=INTERNET;type=WORK",
"item#.EMAIL;type=INTERNET"
],
- "ADR" => ["ADR;type=HOME", "item#.ADR;type=HOME"],
+ "ADR" => ["ADR;type=HOME", "item#.ADR;type=HOME", "ADR;type=WORK", "item#.ADR;type=WORK"],
"X-ABRELATEDNAMES" => ["item#.X-ABRELATEDNAMES"],
"X-MAIDENNAME" => ["X-MAIDENNAME"]
}.freeze #: Hash[String, Array[String]]
@@ -384,11 +384,18 @@ module ProTacts
# (`/O=microsoft/OU=.../cn=algersha`) — so it is not a spelling to
# learn but a row this address book has no field for, and it goes
# the way the DROPPED properties go, the source keeping the line.
- # The form is still checked around this, so a value like it in a
- # spelling nobody has seen is reported like any other.
+ # A work address goes the same way for the opposite reason: the
+ # editor's address rows carry no type, so a work address would
+ # land as an unmarked second one beside the home, and the one
+ # address the fields can hold without lying is the home — the
+ # work stays in the source. The form is still checked around
+ # this, so a value like it in a spelling nobody has seen is
+ # reported like any other.
#: (String name, VCard::Parser::Property property) -> bool
def self.dropped_value?(name, property)
- name == "EMAIL" && !property.value.include?("@")
+ return true if name == "EMAIL" && !property.value.include?("@")
+
+ name == "ADR" && property.parameters.any? { |key, value| key.casecmp?("TYPE") && value.casecmp?("WORK") }
end
# A line unfolded, without its terminator.
diff --git a/test/pro_tacts/import/test_macos.rb b/test/pro_tacts/import/test_macos.rb
index 56f9f94..c61adf3 100644
--- a/test/pro_tacts/import/test_macos.rb
+++ b/test/pro_tacts/import/test_macos.rb
@@ -159,6 +159,32 @@ class ImportMacosTest < Minitest::Test
end
end
+ # The editor's address rows carry no type, so the work address would
+ # land as an unmarked second one beside the home; the home is the one
+ # the fields can hold, and the work stays in the source.
+ def test_a_work_address_is_dropped_and_the_home_carried
+ in_tmpdir do |dir|
+ lines = [
+ "ADR;type=HOME:;;12 Marylebone Rd;London;;NW1 5LS;",
+ "ADR;type=WORK:;;17 Clerkenwell Rd;London;;EC1R 5BQ;",
+ "item3.ADR;type=WORK;type=pref:;;4 Russell Sq;London;;WC1B 4JP;"
+ ]
+ plan = Macos.plan(dir, [record("A:ABPerson", lines:)], created_at: CREATED_AT)
+
+ assert_equal [{"street" => "12 Marylebone Rd", "locality" => "London", "postal_code" => "NW1 5LS"}],
+ plan.card(plan.contacts.first.id).addresses
+ end
+ end
+
+ def test_a_work_address_alone_is_no_address_at_all
+ in_tmpdir do |dir|
+ lines = ["item1.ADR;type=WORK:;;17 Clerkenwell Rd;London;;EC1R 5BQ;"]
+ plan = Macos.plan(dir, [record("A:ABPerson", lines:)], created_at: CREATED_AT)
+
+ assert_empty plan.card(plan.contacts.first.id).addresses
+ end
+ end
+
# A work number is a number, and one Contacts labelled is too — the
# label riding the annotation rail to the row it names, where a
# labelled email's and address's are still dropped