feat: add separate CalDAV endpoint settings per account

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 <noreply@anthropic.com>
This commit is contained in:
Aero Mail Dev 2026-04-16 03:13:16 +00:00
parent adbf8b8e49
commit 42093ed8f3
4 changed files with 127 additions and 5 deletions

View file

@ -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<void> {
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+).`
)
}
}

View file

@ -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<void> {
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
</div>
</div>
<!-- CalDAV (опционально) -->
<div class="smtp-section">
<button type="button" class="smtp-toggle" @click="showCaldav = !showCaldav">
<svg :style="{ transform: showCaldav ? 'rotate(90deg)' : 'none', transition: 'transform 0.18s' }"
width="12" height="12" viewBox="0 0 24 24" fill="none"
stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
<polyline points="9 18 15 12 9 6"/>
</svg>
Настройки CalDAV (для календаря)
</button>
<div v-if="showCaldav" class="smtp-fields">
<div class="form-row">
<div class="form-group flex-1">
<label>CalDAV сервер</label>
<input v-model="caldavHost" type="text" placeholder="mailsrv.example.com" />
</div>
<div class="form-group" style="width: 80px">
<label>Порт</label>
<input v-model.number="caldavPort" type="number" />
</div>
</div>
<div class="form-group">
<label class="checkbox-label">
<input v-model="caldavSecure" type="checkbox" />
SSL/TLS (HTTPS)
</label>
</div>
<div class="form-group">
<label>Путь CalDAV (необязательно)</label>
<input v-model="caldavPath" type="text" placeholder="/EWS/Calendar/ (пусто = автоопределение)" />
</div>
</div>
</div>
<button type="submit" class="submit-btn" :disabled="!isFormValid || testing">
{{ testing ? 'Подключение...' : 'Добавить аккаунт' }}
</button>

View file

@ -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<void> {
testing.value = true
error.value = ''
@ -45,6 +51,14 @@ async function handleSubmit(): Promise<void> {
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)
</div>
</div>
<!-- CalDAV (опционально) -->
<div class="smtp-section">
<button type="button" class="smtp-toggle" @click="showCaldav = !showCaldav">
<svg :style="{ transform: showCaldav ? 'rotate(90deg)' : 'none', transition: 'transform 0.18s' }"
width="12" height="12" viewBox="0 0 24 24" fill="none"
stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
<polyline points="9 18 15 12 9 6"/>
</svg>
Настройки CalDAV (для календаря)
</button>
<div v-if="showCaldav" class="smtp-fields">
<div class="form-row">
<div class="form-group flex-1">
<label>CalDAV сервер</label>
<input v-model="caldavHost" type="text" placeholder="mailsrv.example.com" />
</div>
<div class="form-group" style="width: 80px">
<label>Порт</label>
<input v-model.number="caldavPort" type="number" />
</div>
</div>
<div class="form-group">
<label class="checkbox-label">
<input v-model="caldavSecure" type="checkbox" />
SSL/TLS (HTTPS)
</label>
</div>
<div class="form-group">
<label>Путь CalDAV (необязательно)</label>
<input v-model="caldavPath" type="text" placeholder="/EWS/Calendar/ (пусто = автоопределение)" />
</div>
</div>
</div>
<button type="submit" class="submit-btn" :disabled="!isFormValid || testing">
{{ testing ? 'Сохранение...' : 'Сохранить изменения' }}
</button>

View file

@ -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