Commit cb7b9bf
committed
fix: resolve CalDAV UID consistency and VTIMEZONE generation for Fastmail (#9485)
Fixes two of the three root causes of duplicate/erroneous invitation emails
when using Cal.com's CalDAV integration with Fastmail (and other RFC 6638
compliant CalDAV servers).
Bug Fix #1 (SCHEDULE-AGENT=CLIENT) was already fixed in main via the
`injectScheduleAgent()` function. This PR completes the remaining fixes.
## Bug Fix #2: Inconsistent Event UIDs (RFC 5545 §3.8.4.7)
**Problem:** `createEvent()` always generated a fresh `uuidv4()` for the
CalDAV event, regardless of the booking's canonical UID. This caused a mismatch
between:
- The CalDAV event PUT to the server (fresh UUID)
- The .ics attachment in Cal.com's confirmation email (booking.uid from DB)
RFC 5545 §3.8.4.7 requires the UID to be identical across all representations
of the same event. Fastmail treats differing UIDs as separate events, creating
duplicates in the attendee's calendar.
**Fix:** Use `event.uid || uuidv4()` — the booking's canonical UID is used
when available, falling back to a generated UUID for backward compatibility.
## Bug Fix #3: Missing VTIMEZONE Component (RFC 5545 §3.6.5)
**Problem:** The `ics` library generates UTC times:
```
DTSTART:20240115T140000Z
```
with no VTIMEZONE block. When Fastmail's CalDAV server processes this event,
it interprets the time as UTC and sends its scheduling email in UTC, confusing
attendees in non-UTC timezones.
RFC 5545 §3.6.5 requires that when DTSTART uses a TZID parameter, a matching
VTIMEZONE component MUST be included in the iCalendar object.
**Fix:** Added `injectVTimezone()` function that:
1. Builds a VTIMEZONE block for the organizer's IANA timezone using dayjs
2. Inserts it before BEGIN:VEVENT
3. Rewrites `DTSTART:...Z` (UTC) to `DTSTART;TZID=<zone>:<local-time>`
4. Handles DST-observing timezones (DAYLIGHT + STANDARD components)
5. Handles non-DST timezones (STANDARD component only)
No new dependencies required — uses `dayjs` (already imported) for timezone
conversion.
## Files Changed
- `packages/lib/CalendarService.ts` — Core fixes
- `packages/lib/CalendarService.test.ts` — Added tests for Bug 2 and Bug 3
## Testing
See PR description for full testing instructions.
Closes #94851 parent 38b43f7 commit cb7b9bf
2 files changed
+451
-148
lines changed
0 commit comments