mirror of
https://github.com/bulwarkmail/webmail.git
synced 2026-11-05 00:14:18 +00:00
fix: keep the work or home mark of a second address in Google's older contacts CSV
This commit is contained in:
@@ -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', () => {
|
||||
|
||||
@@ -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' };
|
||||
|
||||
Reference in New Issue
Block a user