fix(vcf): keep every phone, email and name when converting to CSV

JA
1d ago
+149-11

Converting a contacts export to CSV loses data. With three cards in the shapes iPhone, Google and Android contacts export write (contacts.vcf.txt):

before:
"Appleseed","John","John Appleseed","Acme\, Inc.","+1 (555) 987-6543",""
"Souza","Ana","Ana Souza","","+55 11 91234-5678","ana@work.example"
"","","","","+49 30 1234567",""

after:
"Appleseed","John","John Appleseed","Acme, Inc.","john@example.com","+1 (555) 123-4567; +1 (555) 987-6543"
"Souza","Ana","Ana Souza","","ana@home.example; ana@work.example","+55 11 91234-5678"
"Müller","Jürgen","Jürgen Müller","","","+49 170 1234567; +49 30 1234567"
  • Each TEL and EMAIL overwrote the previous one, so only the last of each was kept. They are now joined with ; .
  • item1.EMAIL (iPhone writes custom-labelled fields with a group prefix) didn't match startsWith("EMAIL"). The property name is now read without the group and parameters.
  • N;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:... (Android's 2.1 export for any non-ASCII name) didn't match key === "N", and quoted-printable values weren't decoded. Both are handled now, including = soft line breaks on quoted-printable lines.
  • Long values that iPhone and Google exports fold onto a second line (starting with a space) were cut at the fold. Folded lines are joined now.
  • \,, \;, \\ and \n escapes are undone, and N/ORG are split only on unescaped ; (N:Doe\;Smith;John is Last Doe;Smith, First John).
  • Quoted-printable values are decoded in their CHARSET (UTF-8 if none), and a bare QUOTED-PRINTABLE parameter (vCard 2.1) is accepted too.

Several phones or emails go into one cell, joined with ; , to keep one row per contact with the same columns. If you'd rather have extra columns (Phone 2, ...) I can change that.

Four new cases in tests/converters/vcf.test.ts fail before the change; one also has a base64 PHOTO line ending in == next to a TEL, to make sure only quoted-printable lines are joined. bun test (non-integration): 464 passed. The 5 failures (archive route, production info, converter discovery) fail the same way on main here. eslint, prettier --check and tsc are clean for the changed files.


Summary by cubic

Fixes VCF to CSV conversion dropping data when contacts have multiple phones, emails, or non-ASCII names.

  • Repeated TEL and EMAIL fields are now joined with ; instead of overwriting the previous value.
  • Handles iPhone grouped fields like item1.EMAIL, folded continuation lines, and Android 2.1 style CHARSET/QUOTED-PRINTABLE values with charset decoding, including quoted parameter values like ENCODING="QUOTED-PRINTABLE".
  • Undoes \,, \;, \\, and \n escapes and splits N/ORG only on unescaped semicolons; fields are decoded after splitting so an encoded =3B isn't taken as a separator.

One row per contact with the same columns as before; multiple phone numbers or emails share a cell.