calendar-invite: strip METHOD from ICS before CalDAV storage
CalDAV servers (Migadu) reject ICS files with METHOD:REQUEST/REPLY as it's an iTIP email concept, not a storage property. Strip it when saving to local calendar, for both send and reply flows.
This commit is contained in:
@@ -74,6 +74,17 @@ def _build_calendar_email(from_addr, to_addr, subject, body, ics_bytes, method="
|
||||
return msg.as_string()
|
||||
|
||||
|
||||
def _strip_method(ics_bytes):
|
||||
"""Remove METHOD property from ICS for CalDAV storage.
|
||||
|
||||
CalDAV servers reject METHOD (it's an iTIP/email concept, not a storage one).
|
||||
"""
|
||||
cal = Calendar.from_ical(ics_bytes)
|
||||
if "method" in cal:
|
||||
del cal["method"]
|
||||
return cal.to_ical()
|
||||
|
||||
|
||||
def _parse_iso_datetime(dt_str):
|
||||
"""Parse ISO 8601 datetime string to a datetime object."""
|
||||
# Handle both 2026-03-20T14:00:00 and 2026-03-20T14:00
|
||||
@@ -167,10 +178,10 @@ def cmd_send(args):
|
||||
_send_email(email_str, args.account)
|
||||
print(f"Calendar invite sent to: {args.to}")
|
||||
|
||||
# Save to local calendar
|
||||
# Save to local calendar (without METHOD for CalDAV compatibility)
|
||||
if CALENDAR_DIR.is_dir():
|
||||
dest = CALENDAR_DIR / f"{uid}.ics"
|
||||
dest.write_bytes(ics_bytes)
|
||||
dest.write_bytes(_strip_method(ics_bytes))
|
||||
print(f"Saved to local calendar: {dest}")
|
||||
_sync_calendar()
|
||||
|
||||
@@ -344,8 +355,8 @@ def cmd_reply(args):
|
||||
if CALENDAR_DIR.is_dir():
|
||||
dest = CALENDAR_DIR / f"{uid}.ics"
|
||||
if partstat in ("ACCEPTED", "TENTATIVE"):
|
||||
# Save the original event to local calendar
|
||||
dest.write_bytes(ics_path.read_bytes())
|
||||
# Save the original event to local calendar (without METHOD for CalDAV)
|
||||
dest.write_bytes(_strip_method(ics_path.read_bytes()))
|
||||
print(f"Saved to local calendar: {dest}")
|
||||
elif partstat == "DECLINED" and dest.is_file():
|
||||
dest.unlink()
|
||||
|
||||
Reference in New Issue
Block a user