fix: surface CalDAV TLS/network errors and add caldavAllowSelfSigned option
- discoverBasePath now throws on TLS errors immediately instead of silently swallowing them as "endpoint not found" - TLS errors include a hint to enable the new self-signed cert option - Other errors (network, auth) are collected and shown in the final message - Added caldavAllowSelfSigned field to ImapCredentials and both account dialogs - CalDavProvider prefers caldavAllowSelfSigned, falls back to smtpAllowSelfSigned Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
360d389a87
commit
d47b30bbb0
4 changed files with 65 additions and 19 deletions
|
|
@ -219,7 +219,8 @@ export class CalDavProvider {
|
||||||
this.port = creds.caldavPort ?? (calSecure ? 443 : 80)
|
this.port = creds.caldavPort ?? (calSecure ? 443 : 80)
|
||||||
this.username = creds.username
|
this.username = creds.username
|
||||||
this.password = creds.password
|
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
|
// If a static CalDAV path is configured, skip autodiscovery
|
||||||
this.staticBasePath = creds.caldavPath?.trim() || null
|
this.staticBasePath = creds.caldavPath?.trim() || null
|
||||||
|
|
@ -244,11 +245,11 @@ export class CalDavProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.basePath = await this.discoverBasePath()
|
this.basePath = await this.discoverBasePath()
|
||||||
|
// discoverBasePath throws on TLS/network errors; returning null means all paths gave 404/403
|
||||||
if (!this.basePath) {
|
if (!this.basePath) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`CalDAV endpoint not found on ${this.hostname}. ` +
|
`CalDAV not found on ${this.hostname} — all candidate paths returned 404/403.\n` +
|
||||||
`Tried: /.well-known/caldav, /EWS/Calendar/. ` +
|
`Set the CalDAV path explicitly in account settings (e.g. /EWS/Calendar/).`
|
||||||
`Set the CalDAV URL explicitly in account settings, or ensure Exchange CalDAV is enabled (Exchange 2013+).`
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -265,6 +266,9 @@ export class CalDavProvider {
|
||||||
'/dav/',
|
'/dav/',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
// Collect errors so we can surface the most useful one if all paths fail
|
||||||
|
const errors: string[] = []
|
||||||
|
|
||||||
for (const path of candidates) {
|
for (const path of candidates) {
|
||||||
try {
|
try {
|
||||||
const result = await this.req('PROPFIND', path, { Depth: '0' })
|
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 */ }
|
try { return new URL(location, `${this.protocol}://${this.hostname}`).pathname } catch { /* skip */ }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch {
|
// Record non-successful status for diagnostics (skip common "not found" ones)
|
||||||
// Try next candidate
|
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
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -480,6 +505,10 @@ export class CalDavProvider {
|
||||||
|
|
||||||
// ── Utility ────────────────────────────────────────────────────────────────────
|
// ── Utility ────────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
function isTlsError(msg: string): boolean {
|
||||||
|
return /self.signed|UNABLE_TO_VERIFY|CERT_|certificate|SSL|TLS/i.test(msg)
|
||||||
|
}
|
||||||
|
|
||||||
function toUtcString(d: Date): string {
|
function toUtcString(d: Date): string {
|
||||||
const p = (n: number) => String(n).padStart(2, '0')
|
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`
|
return `${d.getUTCFullYear()}${p(d.getUTCMonth() + 1)}${p(d.getUTCDate())}T${p(d.getUTCHours())}${p(d.getUTCMinutes())}${p(d.getUTCSeconds())}Z`
|
||||||
|
|
|
||||||
|
|
@ -34,11 +34,12 @@ const smtpSecure = ref(false)
|
||||||
const smtpAllowSelfSigned = ref(false)
|
const smtpAllowSelfSigned = ref(false)
|
||||||
const showSmtp = ref(false)
|
const showSmtp = ref(false)
|
||||||
|
|
||||||
const caldavHost = ref('')
|
const caldavHost = ref('')
|
||||||
const caldavPort = ref(443)
|
const caldavPort = ref(443)
|
||||||
const caldavSecure = ref(true)
|
const caldavSecure = ref(true)
|
||||||
const caldavPath = ref('')
|
const caldavPath = ref('')
|
||||||
const showCaldav = ref(false)
|
const caldavAllowSelfSigned = ref(false)
|
||||||
|
const showCaldav = ref(false)
|
||||||
|
|
||||||
function generateId(): string {
|
function generateId(): string {
|
||||||
return `${Date.now()}-${Math.random().toString(36).slice(2, 9)}`
|
return `${Date.now()}-${Math.random().toString(36).slice(2, 9)}`
|
||||||
|
|
@ -69,7 +70,8 @@ async function handleSubmit(): Promise<void> {
|
||||||
caldavHost: caldavHost.value,
|
caldavHost: caldavHost.value,
|
||||||
caldavPort: caldavPort.value,
|
caldavPort: caldavPort.value,
|
||||||
caldavSecure: caldavSecure.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
|
||||||
<label>Путь CalDAV (необязательно)</label>
|
<label>Путь CalDAV (необязательно)</label>
|
||||||
<input v-model="caldavPath" type="text" placeholder="/EWS/Calendar/ (пусто = автоопределение)" />
|
<input v-model="caldavPath" type="text" placeholder="/EWS/Calendar/ (пусто = автоопределение)" />
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="checkbox-label">
|
||||||
|
<input v-model="caldavAllowSelfSigned" type="checkbox" />
|
||||||
|
Разрешить самоподписанные сертификаты
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,11 +32,12 @@ const smtpPort = ref(creds.smtpPort ?? 587)
|
||||||
const smtpSecure = ref(creds.smtpSecure ?? false)
|
const smtpSecure = ref(creds.smtpSecure ?? false)
|
||||||
const showSmtp = ref(!!creds.smtpHost)
|
const showSmtp = ref(!!creds.smtpHost)
|
||||||
|
|
||||||
const caldavHost = ref(creds.caldavHost ?? '')
|
const caldavHost = ref(creds.caldavHost ?? '')
|
||||||
const caldavPort = ref(creds.caldavPort ?? 443)
|
const caldavPort = ref(creds.caldavPort ?? 443)
|
||||||
const caldavSecure = ref(creds.caldavSecure ?? true)
|
const caldavSecure = ref(creds.caldavSecure ?? true)
|
||||||
const caldavPath = ref(creds.caldavPath ?? '')
|
const caldavPath = ref(creds.caldavPath ?? '')
|
||||||
const showCaldav = ref(!!creds.caldavHost)
|
const caldavAllowSelfSigned = ref(creds.caldavAllowSelfSigned ?? false)
|
||||||
|
const showCaldav = ref(!!creds.caldavHost)
|
||||||
|
|
||||||
async function handleSubmit(): Promise<void> {
|
async function handleSubmit(): Promise<void> {
|
||||||
testing.value = true
|
testing.value = true
|
||||||
|
|
@ -57,7 +58,8 @@ async function handleSubmit(): Promise<void> {
|
||||||
caldavHost: caldavHost.value,
|
caldavHost: caldavHost.value,
|
||||||
caldavPort: caldavPort.value,
|
caldavPort: caldavPort.value,
|
||||||
caldavSecure: caldavSecure.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)
|
||||||
<label>Путь CalDAV (необязательно)</label>
|
<label>Путь CalDAV (необязательно)</label>
|
||||||
<input v-model="caldavPath" type="text" placeholder="/EWS/Calendar/ (пусто = автоопределение)" />
|
<input v-model="caldavPath" type="text" placeholder="/EWS/Calendar/ (пусто = автоопределение)" />
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="checkbox-label">
|
||||||
|
<input v-model="caldavAllowSelfSigned" type="checkbox" />
|
||||||
|
Разрешить самоподписанные сертификаты
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,8 @@ export interface ImapCredentials {
|
||||||
caldavHost?: string
|
caldavHost?: string
|
||||||
caldavPort?: number
|
caldavPort?: number
|
||||||
caldavSecure?: boolean
|
caldavSecure?: boolean
|
||||||
caldavPath?: string // базовый путь, например /EWS/Calendar/ (если пуст — autodiscovery)
|
caldavPath?: string // базовый путь, например /EWS/Calendar/ (если пуст — autodiscovery)
|
||||||
|
caldavAllowSelfSigned?: boolean // разрешить самоподписанные/недоверенные сертификаты
|
||||||
}
|
}
|
||||||
|
|
||||||
export type AccountCredentials = ImapCredentials
|
export type AccountCredentials = ImapCredentials
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue