fix: keep the work or home mark of a second address in Google's older contacts CSV

This commit is contained in:
Linus Rath
2026-11-04 11:40:09 +01:00
parent d6eacc3512
commit 5f450c6945
2 changed files with 17 additions and 1 deletions
+12
View File
@@ -330,6 +330,18 @@ describe('Google Contacts', () => {
expect(tom.keywords).toEqual({ Club: true });
expect(lea.name?.components).toEqual([{ kind: 'given', value: 'Lea' }, { kind: 'surname', value: 'van Probe' }]);
});
// "E-mail 2 - Type" reads like Outlook's "E-mail 2 Type" (always SMTP) and
// was left out, so a second address lost its work or home mark.
it("keeps the type of the second and third address in Google's older format", () => {
const text = csv(GOOGLE_OLD_HEADERS, [{
Name: 'Tom Testperson', 'E-mail 1 - Type': '* Home', 'E-mail 1 - Value': 'tom@example.org',
'E-mail 2 - Type': 'Work', 'E-mail 2 - Value': 'tom@work.example.org',
}]);
const { columns, cards } = importText(text);
expect(target(columns, 'E-mail 2 - Type')).toBe('type');
expect(Object.values(cards[0].emails ?? {})).toContainEqual({ address: 'tom@work.example.org', contexts: { work: true } });
});
});
describe('column choices', () => {
+5 -1
View File
@@ -263,10 +263,14 @@ function googleColumn(normalized: string): { family: CsvFamily; slot: string; fi
/** Each column with a sample value and the field it goes to: known headers matched, the rest "Don't import". */
export function matchColumns(table: CsvTable): CsvColumn[] {
// Outlook's "E-mail 2 Type" and Google's older "E-mail 2 - Type" read the
// same once normalised; a "… - Value" column says the file is Google's.
const googleFile = table.headers.some((h) => /^(e mail|email|phone) \d+ value$/.test(normalizeHeader(h)));
return table.headers.map((header, index) => {
const sample = table.rows.map((r) => (r[index] ?? '').trim()).find((v) => v !== '') ?? '';
const normalized = normalizeHeader(header);
if (normalized in HEADER_TARGETS) return { index, header, sample, slot: '', target: HEADER_TARGETS[normalized] };
const outlookSkip = HEADER_TARGETS[normalized] === 'skip' && googleFile && googleColumn(normalized);
if (normalized in HEADER_TARGETS && !outlookSkip) return { index, header, sample, slot: '', target: HEADER_TARGETS[normalized] };
const google = googleColumn(normalized);
if (google) {
return { index, header, sample, slot: google.slot, family: google.family, target: GOOGLE_FIELDS[google.family][google.field] ?? 'skip' };