diff --git a/config.el b/config.el index 1e59421..c4f73b8 100644 --- a/config.el +++ b/config.el @@ -1775,28 +1775,30 @@ current frame." (setq org-caldav-delete-org-entries 'never) (setq org-caldav-delete-calendar-entries 'never) - ;; Fix #1: Baikal stores .ics files with literal @ in filename. - ;; org-caldav-get-event uses url-hexify-string which encodes @ as %40 → HTTP 404. - ;; UIDs like ...@google.com are stored on disk as literal @, so we must not encode it. - (defadvice org-caldav-get-event (around fix-at-encoding-in-uid - (uid &optional with-headers) activate) - "Preserve @ in UID path for Baikal CalDAV compatibility." - (cl-letf* ((orig-hexify (symbol-function 'url-hexify-string)) - ((symbol-function 'url-hexify-string) - (lambda (str &optional allowed-chars) - (replace-regexp-in-string "%40" "@" (funcall orig-hexify str allowed-chars))))) - ad-do-it)) + ;; Fix #2: Events with @google.com UIDs fail retrieval (Emacs URL parser + ;; misinterprets @ in path as userinfo separator, connecting to wrong host). + ;; There are 775 such events. Mark them as 'ignored' before update-events-in-org + ;; processes them. Org-caldav natively skips 'ignored' events. + ;; Also catch any remaining nil-field or retrieval errors to keep sync alive. + (defadvice org-caldav-update-events-in-org (before ignore-google-uids activate) + "Mark @google.com UIDs as ignored to prevent URL parsing failures." + (let ((count 0)) + (dolist (event org-caldav-event-list) + (when (and (stringp (car event)) + (string-match "@google\\.com$" (car event))) + (org-caldav-event-set-status event 'ignored) + (setq count (1+ count)))) + (when (> count 0) + (message "org-caldav: marked %d @google.com UIDs as ignored" count) + (org-caldav-debug-print 1 (format "Ignored %d @google.com UIDs" count))))) - ;; Fix #2: Some CalDAV events have nil SUMMARY or missing fields, causing - ;; Wrong type argument: stringp, nil inside org-caldav-update-events-in-org. - ;; This advice catches the error and logs it so sync continues to save state. - (defadvice org-caldav-update-events-in-org (around skip-nil-field-events activate) - "Catch nil-field errors from malformed events; log and continue." + (defadvice org-caldav-update-events-in-org (around skip-failed-events activate) + "Catch errors during cal->org sync; log and return so sync state is saved." (condition-case err ad-do-it - (wrong-type-argument - (message "org-caldav: skipped event with nil field: %S" err) - (org-caldav-debug-print 1 (format "Skipped nil-field event: %S" err))))) + (error + (message "org-caldav: update-events-in-org stopped early: %S" err) + (org-caldav-debug-print 1 (format "update-events-in-org error: %S" err))))) ;; Fix #3: org-caldav-set-sequence-number calls org-caldav-get-event to read ;; the current SEQUENCE from server before pushing updates. If the GET fails