]> code.delx.au - gnu-emacs-elpa/blobdiff - packages/excorporate/excorporate.el
* cl-generic/cl-generic.el (cl-defmethod): Improve compatibility
[gnu-emacs-elpa] / packages / excorporate / excorporate.el
index 80f3c33bdcb1390ba2743d310a6b72a3af2f7227..9f9f5047cab04e673cf20765b686e03e5ada120e 100644 (file)
@@ -5,10 +5,10 @@
 ;; Author: Thomas Fitzsimmons <fitzsim@fitzsim.org>
 ;; Maintainer: Thomas Fitzsimmons <fitzsim@fitzsim.org>
 ;; Created: 2014-09-19
-;; Version: 0.7.0
+;; Version: 0.7.5
 ;; Keywords: calendar
 ;; Homepage: https://www.fitzsim.org/blog/
-;; Package-Requires: ((emacs "24.1") (fsm "0.2") (soap-client "3.0.2") (url-http-ntlm "2.0.2"))
+;; Package-Requires: ((emacs "24.1") (fsm "0.2") (soap-client "3.1.1") (url-http-ntlm "2.0.2"))
 
 ;; This program is free software: you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
@@ -96,6 +96,9 @@
 ;; Wilfred Hughes <me@wilfred.me.uk> tested on Exchange 2007 and
 ;; suggested documentation improvements.
 
+;; Erik Hetzner <egh@e6h.org> tested on Office 365 and helped debug
+;; Office 365 support.
+
 ;;; Code:
 \f
 ;; Implementation-visible functions and variables.
@@ -451,8 +454,10 @@ the FSM should transition to on success."
     (:unrecoverable-error
      (list :shutting-down-on-error state-data nil))
     (:retrieve-xml
-     (let ((service-url (plist-get state-data :service-url)))
-       (url-retrieve (concat service-url "?wsdl")
+     (let* ((service-url (plist-get state-data :service-url))
+           (wsdl-url (replace-regexp-in-string "/[^/]*$" "/Services.wsdl"
+                                               service-url)))
+       (url-retrieve wsdl-url
                     (lambda (status)
                       (let ((data-buffer (current-buffer)))
                         (unwind-protect
@@ -460,7 +465,7 @@ the FSM should transition to on success."
                                 (progn
                                   (plist-put state-data :failure-message
                                              (format "Failed to retrieve %s"
-                                                     service-url))
+                                                     wsdl-url))
                                   (fsm-send fsm :unrecoverable-error))
                               (plist-put state-data
                                          :service-xml
@@ -495,18 +500,27 @@ the FSM should transition to on success."
 
 (defun exco--get-server-version (wsdl)
   "Extract server version from WSDL."
-  (catch 'found
-    (dolist (attribute
-            (soap-xs-type-attributes
-             (soap-xs-element-type
-              (soap-wsdl-get
-               '("http://schemas.microsoft.com/exchange/services/2006/types"
-                 . "RequestServerVersion")
-               wsdl 'soap-xs-element-p))))
-      (when (equal (soap-xs-attribute-name attribute) "Version")
-       (throw 'found (soap-xs-attribute-default attribute))))
-    (warn "Excorporate: Failed to determine server version")
-    nil))
+  (let ((warning-message "Excorporate: Failed to determine server version")
+       (namespace "http://schemas.microsoft.com/exchange/services/2006/types")
+       (name "RequestServerVersion")
+       (found-version nil))
+    (unwind-protect
+       (setq found-version
+             (catch 'found
+               (dolist (attribute
+                        (soap-xs-type-attributes
+                         (soap-xs-element-type (soap-wsdl-get
+                                                `(,namespace . ,name)
+                                                wsdl 'soap-xs-element-p))))
+                 (when (equal (soap-xs-attribute-name attribute) "Version")
+                   (throw 'found (car (soap-xs-simple-type-enumeration
+                                       (soap-xs-attribute-type attribute))))))
+               (warn warning-message)
+               nil))
+      (if found-version
+         found-version
+       (warn warning-message)
+       nil))))
 
 (define-enter-state exco--fsm :retrieving-data
   (_fsm state-data)
@@ -649,7 +663,9 @@ OPTIONAL-INVITEES, a list of strings representing optional participants."
                                   end 'dateTime)))
             (location (cdr (assoc 'Location calendar-item)))
             (to-invitees (cdr (assoc 'DisplayTo calendar-item)))
-            (main-invitees (mapcar 'org-trim (split-string to-invitees ";")))
+            (main-invitees (when to-invitees
+                             (mapcar 'org-trim
+                                     (split-string to-invitees ";"))))
             (cc-invitees (cdr (assoc 'DisplayCc calendar-item)))
             (optional-invitees (when cc-invitees
                                  (mapcar 'org-trim
@@ -695,7 +711,12 @@ arguments, IDENTIFIER and the server's response."
      identifier
      "FindItem"
      `(;; Main arguments.
-       ((Traversal . "Shallow")
+       (;; RequestVersion is usually overridden by a fixed value in
+       ;; the WSDL (the RequestServerVersion element); provide the
+       ;; maximally-compatible Exchange2007 if the fixed value isn't
+       ;; present.
+       (RequestVersion (Version . "Exchange2007"))
+       (Traversal . "Shallow")
        (ItemShape
         (BaseShape . "AllProperties"))
        ;; To aid productivity, excorporate-calfw automatically prunes your
@@ -706,16 +727,13 @@ arguments, IDENTIFIER and the server's response."
        (ParentFolderIds
         (DistinguishedFolderId (Id . "calendar"))))
        ;; Empty arguments.
-       ,@(let ((server-major-version
-               (string-to-number
-                (substring (exco-server-version identifier) 8 12))))
-          (cond
-           ((<= server-major-version 2007)
-            '(nil nil nil nil))
-           ((< server-major-version 2013)
-            '(nil nil nil nil nil))
-           (t
-            '(nil nil nil nil nil nil)))))
+       ,@(let* ((wsdl (exco--with-fsm identifier
+                                     (plist-get (fsm-get-state-data fsm)
+                                                :service-wsdl)))
+               (arity (soap-operation-arity wsdl
+                                           "ExchangeServicePort"
+                                           "FindItem")))
+          (make-list (- arity 1) nil)))
      callback)))
 
 (defun exco-connection-iterate (initialize-function