Files
webmail/lib/default-collection-name.ts
T
Linus Rath e403478a05 fix: show the default calendar and contacts by plain names, hide CalDAV addresses until asked and translate the previews
The CalDAV fallback test now clicks "Use in other apps" first, because the
address is no longer shown on every calendar row.
2026-11-04 08:05:31 +01:00

24 lines
1.1 KiB
TypeScript

/**
* Stalwart names the calendar and address book it creates for a new account
* "Stalwart Calendar (<address>)" and "Stalwart Address Book (<address>)"
* (registry defaults, 0.16 and 1.0). Settings show those as plain "Calendar"
* and "Contacts" in the user's language, the way the sidebar shows "Sent"
* instead of the server's folder name. A name the user chose stays as it is.
*/
const SERVER_DEFAULT_NAMES = {
calendar: /^Stalwart Calendar(?: \([^()]*\))?$/,
addressBook: /^Stalwart Address Book(?: \([^()]*\))?$/,
} as const;
export type DefaultCollectionKind = keyof typeof SERVER_DEFAULT_NAMES;
export function isServerDefaultCollectionName(name: string | undefined, kind: DefaultCollectionKind): boolean {
return !!name && SERVER_DEFAULT_NAMES[kind].test(name.trim());
}
/** The name to show: `plainName` for the server's own default name, else the collection's name. */
export function collectionDisplayName(name: string, kind: DefaultCollectionKind, plainName: string): string {
return isServerDefaultCollectionName(name, kind) ? plainName : name;
}