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.
(if (string-match "^\"\\(.*\\)\"$" val)
(setq val (match-string 1 val)))
(setq mailbox-list
- (append mailbox-list
+ (nconc mailbox-list
(list val)))))
mailbox-list)))
(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)
(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
(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)
(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)
(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
(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)
(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)
(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)
(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)
'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))))