fix(vcf): keep every phone, email and name when converting to CSV
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
TELandEMAILoverwrote 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 matchstartsWith("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 matchkey === "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\nescapes are undone, andN/ORGare split only on unescaped;(N:Doe\;Smith;Johnis LastDoe;Smith, FirstJohn).- Quoted-printable values are decoded in their
CHARSET(UTF-8 if none), and a bareQUOTED-PRINTABLEparameter (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
TELandEMAILfields are now joined with;instead of overwriting the previous value. - Handles iPhone grouped fields like
item1.EMAIL, folded continuation lines, and Android 2.1 styleCHARSET/QUOTED-PRINTABLEvalues with charset decoding, including quoted parameter values likeENCODING="QUOTED-PRINTABLE". - Undoes
\,,\;,\\, and\nescapes and splitsN/ORGonly on unescaped semicolons; fields are decoded after splitting so an encoded=3Bisn't taken as a separator.
One row per contact with the same columns as before; multiple phone numbers or emails share a cell.