(defun contact-server () "Contact server." (let* ((username "damien") (password "the password") (authorization (format "Basic %s" (base64-encode-string (format "%s:%s" username password)))) (url "https://damien@some-nextcloud.foo/personal") (url-request-method "OPTIONS") (url-request-data nil) (url-request-extra-headers `(("Authorization" . ,authorization))) (buffer (url-retrieve-synchronously url))) (with-current-buffer buffer (goto-char (point-min)) (when (not (re-search-forward "^HTTP[^ ]* \\([0-9]+ .*\\)$" (point-at-eol) t)) (user-error "No valid HTTP response from URL %s" url)) (let ((response (match-string 1))) (when (not (string-match "2[0-9][0-9].*" response)) (user-error "Error while checking for OPTIONS at URL %s: %s" url response))) (mail-narrow-to-head) (let ((davheader (mail-fetch-field "dav"))) (when (not davheader) (user-error "The URL %s does not accept DAV requests" url))) (message "Success contacting server")))) (progn (message "Contacting server (1/2)") (contact-server) (message "Contacting server (2/2)") (contact-server))