-
- (let ((state (or (assoc gnus-command-method gnus-opened-servers)
- (car (setq gnus-opened-servers
- (cons (list gnus-command-method nil)
- gnus-opened-servers))))))
- (cond ((eq (nth 1 state) 'denied)
- ;; If this method was previously denied, we just return nil.
-
- (gnus-message 1 "Denied server")
- nil)
- ((eq (nth 1 state) 'offline)
- ;; If this method was previously opened offline, we just return t.
- t)
- ((not gnus-plugged)
- ;; I'm opening servers while unplugged. Set the status to
- ;; either 'offline or 'denied without asking (I'm assuming
- ;; that the user wants to go 'offline on every agentized
- ;; server when opening while unplugged.)
- (setcar (cdr state) (if (and gnus-agent
- (gnus-agent-method-p gnus-command-method))
- (or gnus-server-unopen-status
- 'offline)
- 'denied))
-
- (if (eq (nth 1 state) 'offline)
- ;; Invoke the agent's backend to open the offline server.
- (funcall (gnus-get-function gnus-command-method 'open-server)
- (nth 1 gnus-command-method)
- (nthcdr 2 gnus-command-method))))
- ((condition-case err
- ;; Open the server.
- (funcall (gnus-get-function gnus-command-method 'open-server)
- (nth 1 gnus-command-method)
- (nthcdr 2 gnus-command-method))
- (error
- (gnus-message 1 (format
- "Unable to open server due to: %s"
- (error-message-string err)))
- nil)
- (quit
- (gnus-message 1 "Quit trying to open server")
- nil))
- ;; I successfully opened the server.
- (setcar (cdr state) 'ok))
- (t
- ;; I couldn't open the server so decide whether to mark it
- ;; 'denied or to open it 'offline.
- (setcar (cdr state)
- (if (and gnus-agent
- (not (eq (cadr state) 'offline))
- (gnus-agent-method-p gnus-command-method))
- (or gnus-server-unopen-status
- (if (gnus-y-or-n-p
- (format "Unable to open %s:%s, go offline? "
- (car gnus-command-method)
- (cadr gnus-command-method)))
- 'offline
- 'denied))
- 'denied))
- (if (eq (nth 1 state) 'offline)
- ;; Invoke the agent's backend to open the offline server.
- (funcall (gnus-get-function gnus-command-method 'open-server)
- (nth 1 gnus-command-method)
- (nthcdr 2 gnus-command-method)))))))
+ (when gnus-backend-trace
+ (with-current-buffer (get-buffer-create "*gnus trace*")
+ (buffer-disable-undo)
+ (goto-char (point-max))
+ (insert (format-time-string "%H:%M:%S")
+ (format " %S\n" gnus-command-method))))
+ (let ((elem (assoc gnus-command-method gnus-opened-servers))
+ (server (gnus-method-to-server-name gnus-command-method)))
+ ;; If this method was previously denied, we just return nil.
+ (if (eq (nth 1 elem) 'denied)
+ (progn
+ (gnus-message 1 "Denied server %s" server)
+ nil)
+ ;; Open the server.
+ (let* ((open-server-function
+ (gnus-get-function gnus-command-method 'open-server))
+ (result
+ (condition-case err
+ (funcall open-server-function
+ (nth 1 gnus-command-method)
+ (nthcdr 2 gnus-command-method))
+ (error
+ (gnus-message 1 "Unable to open server %s due to: %s"
+ server (error-message-string err))
+ nil)
+ (quit
+ (gnus-message 1 "Quit trying to open server %s" server)
+ nil)))
+ open-offline)
+ ;; If this hasn't been opened before, we add it to the list.
+ (unless elem
+ (setq elem (list gnus-command-method nil)
+ gnus-opened-servers (cons elem gnus-opened-servers)))
+ ;; Set the status of this server.
+ (setcar
+ (cdr elem)
+ (cond (result
+ (if (eq open-server-function #'nnagent-open-server)
+ ;; The agent's backend has a "special" status
+ 'offline
+ 'ok))
+ ((and gnus-agent
+ (gnus-agent-method-p gnus-command-method))
+ (cond
+ (gnus-server-unopen-status
+ ;; Set the server's status to the unopen
+ ;; status. If that status is offline,
+ ;; recurse to open the agent's backend.
+ (setq open-offline (eq gnus-server-unopen-status 'offline))
+ gnus-server-unopen-status)
+ ((not gnus-batch-mode)
+ (setq open-offline t)
+ 'offline)
+ (t
+ ;; This agentized server was still denied
+ 'denied)))
+ (t
+ ;; This unagentized server must be denied
+ 'denied)))
+
+ ;; NOTE: I MUST set the server's status to offline before this
+ ;; recursive call as this status will drive the
+ ;; gnus-get-function (called above) to return the agent's
+ ;; backend.
+ (if open-offline
+ ;; Recursively open this offline server to perform the
+ ;; open-server function of the agent's backend.
+ (let ((gnus-server-unopen-status 'denied))
+ ;; Bind gnus-server-unopen-status to avoid recursively
+ ;; prompting with "go offline?". This is only a concern
+ ;; when the agent's backend fails to open the server.
+ (gnus-open-server gnus-command-method))
+ (when (and (eq (cadr elem) 'ok) gnus-agent
+ (gnus-agent-method-p gnus-command-method))
+ (save-excursion
+ (gnus-agent-possibly-synchronize-flags-server
+ gnus-command-method)))
+ result)))))