diff --git a/src/main/providers/caldav.provider.ts b/src/main/providers/caldav.provider.ts index 341a656..ab2666a 100644 --- a/src/main/providers/caldav.provider.ts +++ b/src/main/providers/caldav.provider.ts @@ -219,7 +219,8 @@ export class CalDavProvider { this.port = creds.caldavPort ?? (calSecure ? 443 : 80) this.username = creds.username this.password = creds.password - this.allowSelfSigned = creds.smtpAllowSelfSigned ?? false + // caldavAllowSelfSigned takes precedence; fall back to smtpAllowSelfSigned for legacy configs + this.allowSelfSigned = creds.caldavAllowSelfSigned ?? creds.smtpAllowSelfSigned ?? false // If a static CalDAV path is configured, skip autodiscovery this.staticBasePath = creds.caldavPath?.trim() || null @@ -244,11 +245,11 @@ export class CalDavProvider { } this.basePath = await this.discoverBasePath() + // discoverBasePath throws on TLS/network errors; returning null means all paths gave 404/403 if (!this.basePath) { throw new Error( - `CalDAV endpoint not found on ${this.hostname}. ` + - `Tried: /.well-known/caldav, /EWS/Calendar/. ` + - `Set the CalDAV URL explicitly in account settings, or ensure Exchange CalDAV is enabled (Exchange 2013+).` + `CalDAV not found on ${this.hostname} — all candidate paths returned 404/403.\n` + + `Set the CalDAV path explicitly in account settings (e.g. /EWS/Calendar/).` ) } } @@ -265,6 +266,9 @@ export class CalDavProvider { '/dav/', ] + // Collect errors so we can surface the most useful one if all paths fail + const errors: string[] = [] + for (const path of candidates) { try { const result = await this.req('PROPFIND', path, { Depth: '0' }) @@ -275,10 +279,31 @@ export class CalDavProvider { try { return new URL(location, `${this.protocol}://${this.hostname}`).pathname } catch { /* skip */ } } } - } catch { - // Try next candidate + // Record non-successful status for diagnostics (skip common "not found" ones) + if (result.status !== 404 && result.status !== 403) { + errors.push(`${path} → HTTP ${result.status}`) + } + } catch (err) { + const msg = (err as Error).message ?? String(err) + // TLS errors: surface immediately — retrying other paths won't help + if (isTlsError(msg)) { + throw new Error( + `TLS certificate error connecting to ${this.hostname}: ${msg}\n` + + `Enable "Разрешить самоподписанные сертификаты" in CalDAV settings.` + ) + } + errors.push(`${path} → ${msg}`) } } + + if (errors.length > 0) { + throw new Error( + `CalDAV endpoint not found on ${this.hostname}.\n` + + errors.map((e) => ` • ${e}`).join('\n') + '\n' + + `Set the CalDAV path explicitly in account settings (e.g. /EWS/Calendar/).` + ) + } + return null } @@ -480,6 +505,10 @@ export class CalDavProvider { // ── Utility ──────────────────────────────────────────────────────────────────── +function isTlsError(msg: string): boolean { + return /self.signed|UNABLE_TO_VERIFY|CERT_|certificate|SSL|TLS/i.test(msg) +} + function toUtcString(d: Date): string { const p = (n: number) => String(n).padStart(2, '0') return `${d.getUTCFullYear()}${p(d.getUTCMonth() + 1)}${p(d.getUTCDate())}T${p(d.getUTCHours())}${p(d.getUTCMinutes())}${p(d.getUTCSeconds())}Z` diff --git a/src/renderer/src/components/accounts/AddAccountDialog.vue b/src/renderer/src/components/accounts/AddAccountDialog.vue index af568bb..ed2bb9f 100644 --- a/src/renderer/src/components/accounts/AddAccountDialog.vue +++ b/src/renderer/src/components/accounts/AddAccountDialog.vue @@ -34,11 +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) +const caldavHost = ref('') +const caldavPort = ref(443) +const caldavSecure = ref(true) +const caldavPath = ref('') +const caldavAllowSelfSigned = ref(false) +const showCaldav = ref(false) function generateId(): string { return `${Date.now()}-${Math.random().toString(36).slice(2, 9)}` @@ -69,7 +70,8 @@ async function handleSubmit(): Promise { caldavHost: caldavHost.value, caldavPort: caldavPort.value, caldavSecure: caldavSecure.value, - ...(caldavPath.value.trim() ? { caldavPath: caldavPath.value.trim() } : {}) + ...(caldavPath.value.trim() ? { caldavPath: caldavPath.value.trim() } : {}), + ...(caldavAllowSelfSigned.value ? { caldavAllowSelfSigned: true } : {}) } : {}) } @@ -218,6 +220,12 @@ 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 56dbd55..10b8bc4 100644 --- a/src/renderer/src/components/accounts/EditAccountDialog.vue +++ b/src/renderer/src/components/accounts/EditAccountDialog.vue @@ -32,11 +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) +const caldavHost = ref(creds.caldavHost ?? '') +const caldavPort = ref(creds.caldavPort ?? 443) +const caldavSecure = ref(creds.caldavSecure ?? true) +const caldavPath = ref(creds.caldavPath ?? '') +const caldavAllowSelfSigned = ref(creds.caldavAllowSelfSigned ?? false) +const showCaldav = ref(!!creds.caldavHost) async function handleSubmit(): Promise { testing.value = true @@ -57,7 +58,8 @@ async function handleSubmit(): Promise { caldavHost: caldavHost.value, caldavPort: caldavPort.value, caldavSecure: caldavSecure.value, - ...(caldavPath.value.trim() ? { caldavPath: caldavPath.value.trim() } : {}) + ...(caldavPath.value.trim() ? { caldavPath: caldavPath.value.trim() } : {}), + ...(caldavAllowSelfSigned.value ? { caldavAllowSelfSigned: true } : {}) } : {}) } @@ -200,6 +202,12 @@ const isFormValid = computed(() => imapHost.value && imapUsername.value) +
+ +
diff --git a/src/shared/types/account.ts b/src/shared/types/account.ts index 0fcfa8a..530824e 100644 --- a/src/shared/types/account.ts +++ b/src/shared/types/account.ts @@ -18,7 +18,8 @@ export interface ImapCredentials { caldavHost?: string caldavPort?: number caldavSecure?: boolean - caldavPath?: string // базовый путь, например /EWS/Calendar/ (если пуст — autodiscovery) + caldavPath?: string // базовый путь, например /EWS/Calendar/ (если пуст — autodiscovery) + caldavAllowSelfSigned?: boolean // разрешить самоподписанные/недоверенные сертификаты } export type AccountCredentials = ImapCredentials