aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2018-01-23 14:13:50 -0500
committerStefan Monnier2018-01-23 14:13:50 -0500
commite41c1dc99e631886fafc5595d4f4c048f294af33 (patch)
treef68ee0f8139a2310cc3b25f073535013b2d469e9
parent5ed5f548aaa1f3fa7941895d48f97ad970b38ff1 (diff)
downloademacs-e41c1dc99e631886fafc5595d4f4c048f294af33.tar.gz
emacs-e41c1dc99e631886fafc5595d4f4c048f294af33.zip
* lisp/net/imap.el: Use lexical-binding and cl-lib
Require packages instead of autoloading their functions. (imap-send-command): Remove unused vars 'stream' and 'eol'. (imap-parse-response): Use pcase. (imap-parse-fetch): Remove unused arg 'response'. * lisp/format-spec.el: Don't require CL.
-rw-r--r--lisp/format-spec.el2
-rw-r--r--lisp/net/imap.el170
2 files changed, 82 insertions, 90 deletions
diff --git a/lisp/format-spec.el b/lisp/format-spec.el
index 31caf931edb..38ce69b6c4d 100644
--- a/lisp/format-spec.el
+++ b/lisp/format-spec.el
@@ -24,8 +24,6 @@
24 24
25;;; Code: 25;;; Code:
26 26
27(eval-when-compile (require 'cl))
28
29(defun format-spec (format specification) 27(defun format-spec (format specification)
30 "Return a string based on FORMAT and SPECIFICATION. 28 "Return a string based on FORMAT and SPECIFICATION.
31FORMAT is a string containing `format'-like specs like \"bash %u %k\", 29FORMAT is a string containing `format'-like specs like \"bash %u %k\",
diff --git a/lisp/net/imap.el b/lisp/net/imap.el
index 3d2a4f948bc..36b96ca10af 100644
--- a/lisp/net/imap.el
+++ b/lisp/net/imap.el
@@ -1,4 +1,4 @@
1;;; imap.el --- imap library 1;;; imap.el --- imap library -*- lexical-binding:t -*-
2 2
3;; Copyright (C) 1998-2018 Free Software Foundation, Inc. 3;; Copyright (C) 1998-2018 Free Software Foundation, Inc.
4 4
@@ -135,20 +135,16 @@
135 135
136;;; Code: 136;;; Code:
137 137
138(eval-when-compile (require 'cl)) 138(eval-when-compile (require 'cl-lib))
139(eval-and-compile 139(require 'format-spec)
140 ;; For Emacs <22.2 and XEmacs. 140(require 'utf7)
141 (unless (fboundp 'declare-function) (defmacro declare-function (&rest _r))) 141(require 'rfc2104)
142 (autoload 'sasl-find-mechanism "sasl") 142;; Hmm... digest-md5 is not part of Emacs.
143 (autoload 'digest-md5-parse-digest-challenge "digest-md5") 143;; FIXME: Should/can we use sasl-digest.el instead?
144 (autoload 'digest-md5-digest-response "digest-md5") 144(declare-function digest-md5-parse-digest-challenge "digest-md5")
145 (autoload 'digest-md5-digest-uri "digest-md5") 145(declare-function digest-md5-digest-response "digest-md5")
146 (autoload 'digest-md5-challenge "digest-md5") 146(declare-function digest-md5-digest-uri "digest-md5")
147 (autoload 'rfc2104-hash "rfc2104") 147(declare-function digest-md5-challenge "digest-md5")
148 (autoload 'utf7-encode "utf7")
149 (autoload 'utf7-decode "utf7")
150 (autoload 'format-spec "format-spec")
151 (autoload 'format-spec-make "format-spec"))
152 148
153;; User variables. 149;; User variables.
154 150
@@ -1900,9 +1896,7 @@ on failure."
1900 (setq cmdstr nil) 1896 (setq cmdstr nil)
1901 (if (not (eq (imap-wait-for-tag tag) 'INCOMPLETE)) 1897 (if (not (eq (imap-wait-for-tag tag) 'INCOMPLETE))
1902 (setq command nil) ;; abort command if no cont-req 1898 (setq command nil) ;; abort command if no cont-req
1903 (let ((process imap-process) 1899 (let ((process imap-process))
1904 (stream imap-stream)
1905 (eol imap-client-eol))
1906 (with-current-buffer cmd 1900 (with-current-buffer cmd
1907 (imap-log cmd) 1901 (imap-log cmd)
1908 (process-send-region process (point-min) 1902 (process-send-region process (point-min)
@@ -1956,7 +1950,7 @@ on failure."
1956 'INCOMPLETE 1950 'INCOMPLETE
1957 'OK)))))) 1951 'OK))))))
1958 1952
1959(defun imap-sentinel (process string) 1953(defun imap-sentinel (process _string)
1960 (delete-process process)) 1954 (delete-process process))
1961 1955
1962(defun imap-find-next-line () 1956(defun imap-find-next-line ()
@@ -2145,7 +2139,7 @@ Return nil if no complete line has arrived."
2145 (imap-forward) 2139 (imap-forward)
2146 (nreverse addresses))) 2140 (nreverse addresses)))
2147 ;; With assert, the code might not be eval'd. 2141 ;; With assert, the code might not be eval'd.
2148 ;; (assert (imap-parse-nil) t "In imap-parse-address-list") 2142 ;; (cl-assert (imap-parse-nil) t "In imap-parse-address-list")
2149 (imap-parse-nil))) 2143 (imap-parse-nil)))
2150 2144
2151;; mailbox = "INBOX" / astring 2145;; mailbox = "INBOX" / astring
@@ -2218,72 +2212,72 @@ Return nil if no complete line has arrived."
2218(defun imap-parse-response () 2212(defun imap-parse-response ()
2219 "Parse an IMAP command response." 2213 "Parse an IMAP command response."
2220 (let (token) 2214 (let (token)
2221 (case (setq token (read (current-buffer))) 2215 (pcase (setq token (read (current-buffer)))
2222 (+ (setq imap-continuation 2216 ('+ (setq imap-continuation
2223 (or (buffer-substring (min (point-max) (1+ (point))) 2217 (or (buffer-substring (min (point-max) (1+ (point)))
2224 (point-max)) 2218 (point-max))
2225 t))) 2219 t)))
2226 (* (case (prog1 (setq token (read (current-buffer))) 2220 ('* (pcase (prog1 (setq token (read (current-buffer)))
2227 (imap-forward)) 2221 (imap-forward))
2228 (OK (imap-parse-resp-text)) 2222 ('OK (imap-parse-resp-text))
2229 (NO (imap-parse-resp-text)) 2223 ('NO (imap-parse-resp-text))
2230 (BAD (imap-parse-resp-text)) 2224 ('BAD (imap-parse-resp-text))
2231 (BYE (imap-parse-resp-text)) 2225 ('BYE (imap-parse-resp-text))
2232 (FLAGS (imap-mailbox-put 'flags (imap-parse-flag-list))) 2226 ('FLAGS (imap-mailbox-put 'flags (imap-parse-flag-list)))
2233 (LIST (imap-parse-data-list 'list)) 2227 ('LIST (imap-parse-data-list 'list))
2234 (LSUB (imap-parse-data-list 'lsub)) 2228 ('LSUB (imap-parse-data-list 'lsub))
2235 (SEARCH (imap-mailbox-put 2229 ('SEARCH (imap-mailbox-put
2236 'search 2230 'search
2237 (read (concat "(" (buffer-substring (point) (point-max)) ")")))) 2231 (read (concat "(" (buffer-substring (point) (point-max)) ")"))))
2238 (STATUS (imap-parse-status)) 2232 ('STATUS (imap-parse-status))
2239 (CAPABILITY (setq imap-capability 2233 ('CAPABILITY (setq imap-capability
2240 (read (concat "(" (upcase (buffer-substring 2234 (read (concat "(" (upcase (buffer-substring
2241 (point) (point-max))) 2235 (point) (point-max)))
2242 ")")))) 2236 ")"))))
2243 (ID (setq imap-id (read (buffer-substring (point) 2237 ('ID (setq imap-id (read (buffer-substring (point)
2244 (point-max))))) 2238 (point-max)))))
2245 (ACL (imap-parse-acl)) 2239 ('ACL (imap-parse-acl))
2246 (t (case (prog1 (read (current-buffer)) 2240 (_ (pcase (prog1 (read (current-buffer))
2247 (imap-forward)) 2241 (imap-forward))
2248 (EXISTS (imap-mailbox-put 'exists token)) 2242 ('EXISTS (imap-mailbox-put 'exists token))
2249 (RECENT (imap-mailbox-put 'recent token)) 2243 ('RECENT (imap-mailbox-put 'recent token))
2250 (EXPUNGE t) 2244 ('EXPUNGE t)
2251 (FETCH (imap-parse-fetch token)) 2245 ('FETCH (imap-parse-fetch))
2252 (t (message "Garbage: %s" (buffer-string))))))) 2246 (_ (message "Garbage: %s" (buffer-string)))))))
2253 (t (let (status) 2247 (_ (let (status)
2254 (if (not (integerp token)) 2248 (if (not (integerp token))
2255 (message "Garbage: %s" (buffer-string)) 2249 (message "Garbage: %s" (buffer-string))
2256 (case (prog1 (setq status (read (current-buffer))) 2250 (pcase (prog1 (setq status (read (current-buffer)))
2257 (imap-forward)) 2251 (imap-forward))
2258 (OK (progn 2252 ('OK (progn
2259 (setq imap-reached-tag (max imap-reached-tag token)) 2253 (setq imap-reached-tag (max imap-reached-tag token))
2260 (imap-parse-resp-text))) 2254 (imap-parse-resp-text)))
2261 (NO (progn 2255 ('NO (progn
2262 (setq imap-reached-tag (max imap-reached-tag token)) 2256 (setq imap-reached-tag (max imap-reached-tag token))
2263 (save-excursion 2257 (save-excursion
2264 (imap-parse-resp-text)) 2258 (imap-parse-resp-text))
2265 (let (code text) 2259 (let (code text)
2266 (when (eq (char-after) ?\[) 2260 (when (eq (char-after) ?\[)
2267 (setq code (buffer-substring (point) 2261 (setq code (buffer-substring (point)
2268 (search-forward "]"))) 2262 (search-forward "]")))
2269 (imap-forward)) 2263 (imap-forward))
2270 (setq text (buffer-substring (point) (point-max))) 2264 (setq text (buffer-substring (point) (point-max)))
2271 (push (list token status code text) 2265 (push (list token status code text)
2272 imap-failed-tags)))) 2266 imap-failed-tags))))
2273 (BAD (progn 2267 ('BAD (progn
2274 (setq imap-reached-tag (max imap-reached-tag token)) 2268 (setq imap-reached-tag (max imap-reached-tag token))
2275 (save-excursion 2269 (save-excursion
2276 (imap-parse-resp-text)) 2270 (imap-parse-resp-text))
2277 (let (code text) 2271 (let (code text)
2278 (when (eq (char-after) ?\[) 2272 (when (eq (char-after) ?\[)
2279 (setq code (buffer-substring (point) 2273 (setq code (buffer-substring (point)
2280 (search-forward "]"))) 2274 (search-forward "]")))
2281 (imap-forward)) 2275 (imap-forward))
2282 (setq text (buffer-substring (point) (point-max))) 2276 (setq text (buffer-substring (point) (point-max)))
2283 (push (list token status code text) imap-failed-tags) 2277 (push (list token status code text) imap-failed-tags)
2284 (error "Internal error, tag %s status %s code %s text %s" 2278 (error "Internal error, tag %s status %s code %s text %s"
2285 token status code text)))) 2279 token status code text))))
2286 (t (message "Garbage: %s" (buffer-string)))) 2280 (_ (message "Garbage: %s" (buffer-string))))
2287 (when (assq token imap-callbacks) 2281 (when (assq token imap-callbacks)
2288 (funcall (cdr (assq token imap-callbacks)) token status) 2282 (funcall (cdr (assq token imap-callbacks)) token status)
2289 (setq imap-callbacks 2283 (setq imap-callbacks
@@ -2459,7 +2453,7 @@ Return nil if no complete line has arrived."
2459 (search-forward "]" nil t)) 2453 (search-forward "]" nil t))
2460 section))) 2454 section)))
2461 2455
2462(defun imap-parse-fetch (response) 2456(defun imap-parse-fetch ()
2463 (when (eq (char-after) ?\() 2457 (when (eq (char-after) ?\()
2464 (let (uid flags envelope internaldate rfc822 rfc822header rfc822text 2458 (let (uid flags envelope internaldate rfc822 rfc822header rfc822text
2465 rfc822size body bodydetail bodystructure flags-empty) 2459 rfc822size body bodydetail bodystructure flags-empty)
@@ -2593,7 +2587,7 @@ Return nil if no complete line has arrived."
2593 2587
2594(defun imap-parse-flag-list () 2588(defun imap-parse-flag-list ()
2595 (let (flag-list start) 2589 (let (flag-list start)
2596 (assert (eq (char-after) ?\() nil "In imap-parse-flag-list 1") 2590 (cl-assert (eq (char-after) ?\() nil "In imap-parse-flag-list 1")
2597 (while (and (not (eq (char-after) ?\))) 2591 (while (and (not (eq (char-after) ?\)))
2598 (setq start (progn 2592 (setq start (progn
2599 (imap-forward) 2593 (imap-forward)
@@ -2602,7 +2596,7 @@ Return nil if no complete line has arrived."
2602 (point))) 2596 (point)))
2603 (> (skip-chars-forward "^ )" (point-at-eol)) 0)) 2597 (> (skip-chars-forward "^ )" (point-at-eol)) 0))
2604 (push (buffer-substring start (point)) flag-list)) 2598 (push (buffer-substring start (point)) flag-list))
2605 (assert (eq (char-after) ?\)) nil "In imap-parse-flag-list 2") 2599 (cl-assert (eq (char-after) ?\)) nil "In imap-parse-flag-list 2")
2606 (imap-forward) 2600 (imap-forward)
2607 (nreverse flag-list))) 2601 (nreverse flag-list)))
2608 2602
@@ -2687,7 +2681,7 @@ Return nil if no complete line has arrived."
2687 (while (eq (char-after) ?\ ) 2681 (while (eq (char-after) ?\ )
2688 (imap-forward) 2682 (imap-forward)
2689 (push (imap-parse-body-extension) b-e)) 2683 (push (imap-parse-body-extension) b-e))
2690 (assert (eq (char-after) ?\)) nil "In imap-parse-body-extension") 2684 (cl-assert (eq (char-after) ?\)) nil "In imap-parse-body-extension")
2691 (imap-forward) 2685 (imap-forward)
2692 (nreverse b-e)) 2686 (nreverse b-e))
2693 (or (imap-parse-number) 2687 (or (imap-parse-number)
@@ -2716,7 +2710,7 @@ Return nil if no complete line has arrived."
2716 (push (imap-parse-string-list) dsp) 2710 (push (imap-parse-string-list) dsp)
2717 (imap-forward)) 2711 (imap-forward))
2718 ;; With assert, the code might not be eval'd. 2712 ;; With assert, the code might not be eval'd.
2719 ;; (assert (imap-parse-nil) t "In imap-parse-body-ext") 2713 ;; (cl-assert (imap-parse-nil) t "In imap-parse-body-ext")
2720 (imap-parse-nil)) 2714 (imap-parse-nil))
2721 (push (nreverse dsp) ext)) 2715 (push (nreverse dsp) ext))
2722 (when (eq (char-after) ?\ ) ;; body-fld-lang 2716 (when (eq (char-after) ?\ ) ;; body-fld-lang
@@ -2813,7 +2807,7 @@ Return nil if no complete line has arrived."
2813 (push (and (imap-parse-nil) nil) body)) 2807 (push (and (imap-parse-nil) nil) body))
2814 (setq body 2808 (setq body
2815 (append (imap-parse-body-ext) body))) ;; body-ext-... 2809 (append (imap-parse-body-ext) body))) ;; body-ext-...
2816 (assert (eq (char-after) ?\)) nil "In imap-parse-body") 2810 (cl-assert (eq (char-after) ?\)) nil "In imap-parse-body")
2817 (imap-forward) 2811 (imap-forward)
2818 (nreverse body)) 2812 (nreverse body))
2819 2813
@@ -2879,7 +2873,7 @@ Return nil if no complete line has arrived."
2879 (push (imap-parse-nstring) body) ;; body-fld-md5 2873 (push (imap-parse-nstring) body) ;; body-fld-md5
2880 (setq body (append (imap-parse-body-ext) body))) ;; body-ext-1part.. 2874 (setq body (append (imap-parse-body-ext) body))) ;; body-ext-1part..
2881 2875
2882 (assert (eq (char-after) ?\)) nil "In imap-parse-body 2") 2876 (cl-assert (eq (char-after) ?\)) nil "In imap-parse-body 2")
2883 (imap-forward) 2877 (imap-forward)
2884 (nreverse body))))) 2878 (nreverse body)))))
2885 2879