From: okazaki Date: Mon, 24 Jul 2000 21:54:56 +0000 (+0000) Subject: * elmo-imap4.el (elmo-imap4-process-folder-list): Use `nconc' X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3271dfe0db915bdadb4eff38c550634a0030d564;p=elisp%2Fwanderlust.git * elmo-imap4.el (elmo-imap4-process-folder-list): Use `nconc' instead of `append'. (elmo-imap4-commit): Use `elmo-imap4-plugged-p' instead of `elmo-plugged-p' directly. * elmo-pop3.el (elmo-pop3-commit): Use `elmo-pop3-plugged-p' instead of `elmo-plugged-p' directly. * elmo-pop3.el (elmo-pop3-get-connection): Split temporary variable. Eliminate unused variable. Use `memq' for checking a process status. Use `cons' instead of `append' for updating the connection cache. * elmo-nntp.el (elmo-nntp-get-connection): Likewise. * elmo-imap4.el (elmo-imap4-get-connection): Likewise. --- diff --git a/elmo/elmo-imap4.el b/elmo/elmo-imap4.el index 05ff583..de13da7 100644 --- a/elmo/elmo-imap4.el +++ b/elmo/elmo-imap4.el @@ -120,7 +120,7 @@ Debug information is inserted in the buffer \"*IMAP4 DEBUG*\"") (if (string-match "^\"\\(.*\\)\"$" val) (setq val (match-string 1 val))) (setq mailbox-list - (append mailbox-list + (nconc mailbox-list (list val))))) mailbox-list))) @@ -256,36 +256,33 @@ Debug information is inserted in the buffer \"*IMAP4 DEBUG*\"") (cadr (memq 'messages response))))))) (defun elmo-imap4-get-connection (spec) + "Return opened IMAP connection for SPEC." (let* ((user (elmo-imap4-spec-username spec)) (server (elmo-imap4-spec-hostname spec)) (port (elmo-imap4-spec-port spec)) (auth (elmo-imap4-spec-auth spec)) (ssl (elmo-imap4-spec-ssl spec)) (user-at-host (format "%s@%s" user server)) - ret-val result buffer process proc-stat + entry connection result buffer process proc-stat user-at-host-on-port) (if (not (elmo-plugged-p server port)) (error "Unplugged")) (setq user-at-host-on-port (concat user-at-host ":" (int-to-string port) (if (eq ssl 'starttls) "!!" (if ssl "!")))) - (setq ret-val (assoc user-at-host-on-port - elmo-imap4-connection-cache)) - (if (and ret-val - (or (eq (setq proc-stat - (process-status (cadr (cdr ret-val)))) - 'closed) - (eq proc-stat 'exit))) + (setq entry (assoc user-at-host-on-port elmo-imap4-connection-cache)) + (if (and entry + (memq (setq proc-stat + (process-status (cadr (cdr entry)))) + '(closed exit))) ;; connection is closed... - (progn - (kill-buffer (car (cdr ret-val))) + (let ((buffer (car (cdr entry)))) + (if buffer (kill-buffer buffer)) (setq elmo-imap4-connection-cache - (delete ret-val elmo-imap4-connection-cache)) - (setq ret-val nil))) - (if ret-val - (progn - (setq ret-val (cdr ret-val)) ;; connection cache exists. - ret-val) + (delete entry elmo-imap4-connection-cache)) + (setq entry nil))) + (if entry + (cdr entry) ; connection cache exists. (setq result (elmo-imap4-open-connection server user auth port (elmo-get-passwd user-at-host) @@ -299,14 +296,15 @@ Debug information is inserted in the buffer \"*IMAP4 DEBUG*\"") (elmo-remove-passwd user-at-host) (delete-process process) (error "Login failed")) - (setq elmo-imap4-connection-cache - (append elmo-imap4-connection-cache - (list - (cons user-at-host-on-port - (setq ret-val (list buffer process - ""; current-folder.. - )))))) - ret-val))) + ;; add a new entry to the top of the cache. + (setq elmo-imap4-connection-cache + (cons + (cons user-at-host-on-port + (setq connection (list buffer process + ""; current-folder.. + ))) + elmo-imap4-connection-cache)) + connection))) (defun elmo-imap4-process-filter (process output) (save-match-data @@ -426,8 +424,7 @@ Debug information is inserted in the buffer \"*IMAP4 DEBUG*\"") (elmo-imap4-read-response buffer process)))) (defun elmo-imap4-commit (spec) - (if (elmo-plugged-p (elmo-imap4-spec-hostname spec) - (elmo-imap4-spec-port spec)) + (if (elmo-imap4-plugged-p spec) (save-excursion (let ((connection (elmo-imap4-get-connection spec)) response ret-val beg end) @@ -1094,8 +1091,8 @@ If optional argument UNMARK is non-nil, unmark." (length (car y)))))))) (defun elmo-imap4-open-connection (imap4-server user auth port passphrase ssl) - "Open Imap connection and returns -the list of (process session-buffer current-working-folder). + "Open IMAP connection to IMAP4-SERVER on PORT for USER. +Return a cons cell of (session-buffer . process). Return nil if connection failed." (let ((process nil) (host imap4-server) diff --git a/elmo/elmo-nntp.el b/elmo/elmo-nntp.el index b997204..e6dd617 100644 --- a/elmo/elmo-nntp.el +++ b/elmo/elmo-nntp.el @@ -171,41 +171,39 @@ Don't cache if nil.") (setq elmo-nntp-connection-cache nil))) (defun elmo-nntp-get-connection (server user port ssl) + "Return opened NNTP connection to SERVER on PORT for USER." (let* ((user-at-host (format "%s@%s" user server)) - (user-at-host-on-port (concat + (user-at-host-on-port (concat user-at-host ":" (int-to-string port) (if (eq ssl 'starttls) "!!" (if ssl "!")))) - ret-val result buffer process errmsg proc-stat) + entry connection result buffer process proc-stat) (if (not (elmo-plugged-p server port)) (error "Unplugged")) - (setq ret-val (assoc user-at-host-on-port elmo-nntp-connection-cache)) - (if (and ret-val - (or (eq (setq proc-stat - (process-status (cadr (cdr ret-val)))) - 'closed) - (eq proc-stat 'exit))) + (setq entry (assoc user-at-host-on-port elmo-nntp-connection-cache)) + (if (and entry + (memq (setq proc-stat + (process-status (cadr (cdr entry)))) + '(closed exit))) ;; connection is closed... - (progn - (kill-buffer (car (cdr ret-val))) - (setq elmo-nntp-connection-cache - (delete ret-val elmo-nntp-connection-cache)) - (setq ret-val nil))) - (if ret-val - (cdr ret-val) + (let ((buffer (car (cdr entry)))) + (if buffer (kill-buffer buffer)) + (setq elmo-nntp-connection-cache + (delq entry elmo-nntp-connection-cache)) + (setq entry nil))) + (if entry + (cdr entry) (setq result (elmo-nntp-open-connection server user port ssl)) (if (null result) - (progn - (if process (delete-process process)) - (if buffer (kill-buffer buffer)) - (error "Connection failed")) - (setq buffer (car result)) - (setq process (cdr result)) - (setq elmo-nntp-connection-cache - (nconc elmo-nntp-connection-cache - (list - (cons user-at-host-on-port - (setq ret-val (list buffer process nil)))))) - ret-val)))) + (error "Connection failed")) + (setq buffer (car result)) + (setq process (cdr result)) + ;; add a new entry to the top of the cache. + (setq elmo-nntp-connection-cache + (cons + (cons user-at-host-on-port + (setq connection (list buffer process nil))) + elmo-nntp-connection-cache)) + connection))) (defun elmo-nntp-process-filter (process output) (save-excursion @@ -934,8 +932,8 @@ Returns message string." (std11-field-body "Newsgroups")))) (defun elmo-nntp-open-connection (server user portnum ssl) - "Open NNTP connection and returns -the list of (process session-buffer current-working-folder). + "Open NNTP connection to SERVER on PORTNUM for USER. +Return a cons cell of (session-buffer . process). Return nil if connection failed." (let ((process nil) (host server) diff --git a/elmo/elmo-pop3.el b/elmo/elmo-pop3.el index 9a7f6d6..2886a52 100644 --- a/elmo/elmo-pop3.el +++ b/elmo/elmo-pop3.el @@ -107,36 +107,36 @@ (setq elmo-pop3-connection-cache nil))) (defun elmo-pop3-get-connection (spec &optional if-exists) + "Return opened POP3 connection for SPEC." (let* ((user (elmo-pop3-spec-username spec)) (server (elmo-pop3-spec-hostname spec)) (port (elmo-pop3-spec-port spec)) (auth (elmo-pop3-spec-auth spec)) (ssl (elmo-pop3-spec-ssl spec)) (user-at-host (format "%s@%s" user server)) - connection result buffer process errmsg proc-stat response + entry connection result buffer process proc-stat response user-at-host-on-port) (if (not (elmo-plugged-p server port)) (error "Unplugged")) - (setq user-at-host-on-port + (setq user-at-host-on-port (concat user-at-host ":" (int-to-string port) (if (eq ssl 'starttls) "!!" (if ssl "!")))) - (setq connection (assoc user-at-host-on-port elmo-pop3-connection-cache)) - (if (and connection - (or (eq (setq proc-stat - (process-status (cadr (cdr connection)))) - 'closed) - (eq proc-stat 'exit))) + (setq entry (assoc user-at-host-on-port elmo-pop3-connection-cache)) + (if (and entry + (memq (setq proc-stat + (process-status (cadr (cdr entry)))) + '(closed exit))) ;; connection is closed... - (progn - (kill-buffer (car (cdr connection))) - (setq elmo-pop3-connection-cache - (delete connection elmo-pop3-connection-cache)) - (setq connection nil))) - (if connection - (cdr connection) + (let ((buffer (car (cdr entry)))) + (if buffer (kill-buffer buffer)) + (setq elmo-pop3-connection-cache + (delete entry elmo-pop3-connection-cache)) + (setq entry nil))) + (if entry + (cdr entry) (unless if-exists (setq result - (elmo-pop3-open-connection + (elmo-pop3-open-connection server user port auth (elmo-get-passwd user-at-host) ssl)) (if (null result) @@ -147,11 +147,12 @@ (elmo-remove-passwd user-at-host) (delete-process process) (error "Login failed")) - (setq elmo-pop3-connection-cache - (append elmo-pop3-connection-cache - (list - (cons user-at-host-on-port - (setq connection (list buffer process)))))) + ;; add a new entry to the top of the cache. + (setq elmo-pop3-connection-cache + (cons + (cons user-at-host-on-port + (setq connection (list buffer process))) + elmo-pop3-connection-cache)) ;; initialization of list (with-current-buffer buffer (make-variable-buffer-local 'elmo-pop3-uidl-number-hash) @@ -240,6 +241,9 @@ (insert output))) (defun elmo-pop3-open-connection (server user port auth passphrase ssl) + "Open POP3 connection to SERVER on PORT for USER. +Return a cons cell of (session-buffer . process). +Return nil if connection failed." (let ((process nil) (host server) process-buffer ret-val response capability) @@ -819,7 +823,7 @@ 'elmo-generic-list-folder-important) (defun elmo-pop3-commit (spec) - (if (elmo-plugged-p (elmo-pop3-spec-hostname spec) (elmo-pop3-spec-port spec)) + (if (elmo-pop3-plugged-p spec) (elmo-pop3-close-connection (elmo-pop3-get-connection spec 'if-exists))))