Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICloud calendar support #305

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions org-caldav.el
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,27 @@ default namespace."
(while (re-search-forward "</?" nil t)
(insert "DAV:")))))))

(defun org-caldav-icloud-empty-props-workaround (buffer)
"Workaraound for icloud implementation which returns empty prop in propstat"
(with-current-buffer buffer
(save-excursion
;; Remove the blocks with <status>HTTP/1.1 404 Not Found</status>
(goto-char (point-min))
(while (re-search-forward
"^[[:space:]]*<propstat>[[:space:]\n]*<prop>[[:space:]\n]*<resourcetype xmlns=\"DAV:\"/>[[:space:]\n]*</prop>[[:space:]\n]*<status>HTTP/1\\.1 404 Not Found</status>[[:space:]\n]*</propstat>[[:space:]\n]*"
nil t)
(replace-match ""))

(goto-char (point-min))
(while (re-search-forward
"^[[:space:]]*<propstat>[[:space:]\n]*<prop>[[:space:]\n]*</prop>[[:space:]\n]*<status>HTTP/1\\.1 200 OK</status>[[:space:]\n]*</propstat>[[:space:]\n]*"
nil t)
(replace-match " <propstat>\n <prop>\n\n <resourcetype xmlns=\"DAV:\"/>\n\n </prop>\n <status>HTTP/1.1 200 OK</status>\n </propstat>"))

(goto-char (point-min))
(while (re-search-forward "<propstat>" nil t)
(replace-match "<propstat xmlns=\"DAV:\">")))))

(defun org-caldav-url-dav-get-properties (url property)
"Retrieve PROPERTY from URL.
Output is the same as `url-dav-get-properties'. This switches to
Expand Down Expand Up @@ -608,6 +629,7 @@ OAuth2 if necessary."
(switch-to-buffer resultbuf)
(error "Error while doing PROPFIND for '%s' at URL %s: %s" property url response))))
(org-caldav-namespace-bug-workaround resultbuf)
(org-caldav-icloud-empty-props-workaround resultbuf)
(url-dav-process-response resultbuf url))))

(defun org-caldav-check-connection ()
Expand All @@ -619,6 +641,8 @@ Also sets `org-caldav-empty-calendar' if calendar is empty."
(let* ((output (org-caldav-url-dav-get-properties
(org-caldav-events-url) "resourcetype"))
(status (plist-get (cdar output) 'DAV:status)))
(when (and (stringp status) (string= status ""))
(setq status 404))
;; We accept any 2xx status. Since some CalDAV servers return 404
;; for a newly created and not yet used calendar, we accept it as
;; well.
Expand Down