From 42093ed8f395ec89affeafb7877ddb5cc6d8c36f Mon Sep 17 00:00:00 2001 From: Aero Mail Dev Date: Thu, 16 Apr 2026 03:13:16 +0000 Subject: [PATCH] feat: add separate CalDAV endpoint settings per account MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ImapCredentials now has caldavHost/caldavPort/caldavSecure/caldavPath. When set, CalDavProvider uses them instead of the IMAP host. caldavPath skips autodiscovery and hits the URL directly. Both AddAccountDialog and EditAccountDialog have a collapsible "Настройки CalDAV" section (same pattern as SMTP). Co-Authored-By: Claude Sonnet 4.6 --- src/main/providers/caldav.provider.ts | 31 ++++++++++-- .../components/accounts/AddAccountDialog.vue | 48 +++++++++++++++++++ .../components/accounts/EditAccountDialog.vue | 48 +++++++++++++++++++ src/shared/types/account.ts | 5 ++ 4 files changed, 127 insertions(+), 5 deletions(-) diff --git a/src/main/providers/caldav.provider.ts b/src/main/providers/caldav.provider.ts index 6f63539..341a656 100644 --- a/src/main/providers/caldav.provider.ts +++ b/src/main/providers/caldav.provider.ts @@ -206,28 +206,49 @@ export class CalDavProvider { private readonly basicAuthHeader: string private basePath: string | null = null + private staticBasePath: string | null = null private authMode: AuthMode = 'basic' constructor(config: AccountConfig) { const creds = config.credentials as ImapCredentials - this.hostname = creds.host - this.protocol = creds.secure ? 'https' : 'http' - this.port = creds.secure ? 443 : 80 + + // CalDAV endpoint: use dedicated settings when provided, fall back to IMAP host + const calSecure = creds.caldavSecure ?? creds.secure + this.hostname = creds.caldavHost || creds.host + this.protocol = calSecure ? 'https' : 'http' + this.port = creds.caldavPort ?? (calSecure ? 443 : 80) this.username = creds.username this.password = creds.password this.allowSelfSigned = creds.smtpAllowSelfSigned ?? false + + // If a static CalDAV path is configured, skip autodiscovery + this.staticBasePath = creds.caldavPath?.trim() || null + this.basicAuthHeader = 'Basic ' + Buffer.from(`${this.username}:${this.password}`).toString('base64') } // ── Discovery ────────────────────────────────────────────────────────────── async connect(): Promise { + if (this.staticBasePath) { + // User supplied an explicit path — verify it works, skip autodiscovery + const result = await this.req('PROPFIND', this.staticBasePath, { Depth: '0' }) + if (result.status !== 207 && result.status !== 200) { + throw new Error( + `CalDAV path "${this.staticBasePath}" on ${this.hostname} returned HTTP ${result.status}. ` + + `Check the CalDAV URL and credentials.` + ) + } + this.basePath = this.staticBasePath + return + } + this.basePath = await this.discoverBasePath() if (!this.basePath) { throw new Error( `CalDAV endpoint not found on ${this.hostname}. ` + - `Verified paths: /.well-known/caldav, /EWS/Calendar/. ` + - `Ensure Exchange CalDAV is enabled (Exchange 2013+).` + `Tried: /.well-known/caldav, /EWS/Calendar/. ` + + `Set the CalDAV URL explicitly in account settings, or ensure Exchange CalDAV is enabled (Exchange 2013+).` ) } } diff --git a/src/renderer/src/components/accounts/AddAccountDialog.vue b/src/renderer/src/components/accounts/AddAccountDialog.vue index 2cfda49..af568bb 100644 --- a/src/renderer/src/components/accounts/AddAccountDialog.vue +++ b/src/renderer/src/components/accounts/AddAccountDialog.vue @@ -34,6 +34,12 @@ const smtpSecure = ref(false) const smtpAllowSelfSigned = ref(false) const showSmtp = ref(false) +const caldavHost = ref('') +const caldavPort = ref(443) +const caldavSecure = ref(true) +const caldavPath = ref('') +const showCaldav = ref(false) + function generateId(): string { return `${Date.now()}-${Math.random().toString(36).slice(2, 9)}` } @@ -57,6 +63,14 @@ async function handleSubmit(): Promise { smtpSecure: smtpSecure.value, ...(smtpAllowSelfSigned.value ? { smtpAllowSelfSigned: true } : {}) } + : {}), + ...(showCaldav.value && caldavHost.value + ? { + caldavHost: caldavHost.value, + caldavPort: caldavPort.value, + caldavSecure: caldavSecure.value, + ...(caldavPath.value.trim() ? { caldavPath: caldavPath.value.trim() } : {}) + } : {}) } const config: AccountConfig = { @@ -173,6 +187,40 @@ const isFormValid = computed(() => imapHost.value && imapUsername.value && imapP + +
+ +
+
+
+ + +
+
+ + +
+
+
+ +
+
+ + +
+
+
+ diff --git a/src/renderer/src/components/accounts/EditAccountDialog.vue b/src/renderer/src/components/accounts/EditAccountDialog.vue index aa14d2d..56dbd55 100644 --- a/src/renderer/src/components/accounts/EditAccountDialog.vue +++ b/src/renderer/src/components/accounts/EditAccountDialog.vue @@ -32,6 +32,12 @@ const smtpPort = ref(creds.smtpPort ?? 587) const smtpSecure = ref(creds.smtpSecure ?? false) const showSmtp = ref(!!creds.smtpHost) +const caldavHost = ref(creds.caldavHost ?? '') +const caldavPort = ref(creds.caldavPort ?? 443) +const caldavSecure = ref(creds.caldavSecure ?? true) +const caldavPath = ref(creds.caldavPath ?? '') +const showCaldav = ref(!!creds.caldavHost) + async function handleSubmit(): Promise { testing.value = true error.value = '' @@ -45,6 +51,14 @@ async function handleSubmit(): Promise { password: imapPassword.value, ...(showSmtp.value && smtpHost.value ? { smtpHost: smtpHost.value, smtpPort: smtpPort.value, smtpSecure: smtpSecure.value } + : {}), + ...(showCaldav.value && caldavHost.value + ? { + caldavHost: caldavHost.value, + caldavPort: caldavPort.value, + caldavSecure: caldavSecure.value, + ...(caldavPath.value.trim() ? { caldavPath: caldavPath.value.trim() } : {}) + } : {}) } const config: AccountConfig = { @@ -155,6 +169,40 @@ const isFormValid = computed(() => imapHost.value && imapUsername.value) + +
+ +
+
+
+ + +
+
+ + +
+
+
+ +
+
+ + +
+
+
+ diff --git a/src/shared/types/account.ts b/src/shared/types/account.ts index 503fb9d..0fcfa8a 100644 --- a/src/shared/types/account.ts +++ b/src/shared/types/account.ts @@ -14,6 +14,11 @@ export interface ImapCredentials { smtpSecure?: boolean // Разрешить самоподписанные сертификаты — только для корпоративных серверов smtpAllowSelfSigned?: boolean + // CalDAV — опционально; если не указан хост, используется IMAP-хост + caldavHost?: string + caldavPort?: number + caldavSecure?: boolean + caldavPath?: string // базовый путь, например /EWS/Calendar/ (если пуст — autodiscovery) } export type AccountCredentials = ImapCredentials