1 ;;; elmo-imap4.el -- IMAP4 Interface for ELMO.
3 ;; Copyright (C) 1998,1999,2000 Yuuichi Teranishi <teranisi@gohome.org>
4 ;; Copyright (C) 1999,2000 Kenichi OKADA <okada@opaopa.org>
5 ;; Copyright (C) 2000 OKAZAKI Tetsurou <okazaki@be.to>
6 ;; Copyright (C) 2000 Daiki Ueno <ueno@unixuser.org>
8 ;; Author: Yuuichi Teranishi <teranisi@gohome.org>
9 ;; Kenichi OKADA <okada@opaopa.org>
10 ;; OKAZAKI Tetsurou <okazaki@be.to>
11 ;; Daiki Ueno <ueno@unixuser.org>
12 ;; Keywords: mail, net news
14 ;; This file is part of ELMO (Elisp Library for Message Orchestration).
16 ;; This program is free software; you can redistribute it and/or modify
17 ;; it under the terms of the GNU General Public License as published by
18 ;; the Free Software Foundation; either version 2, or (at your option)
21 ;; This program is distributed in the hope that it will be useful,
22 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 ;; GNU General Public License for more details.
26 ;; You should have received a copy of the GNU General Public License
27 ;; along with GNU Emacs; see the file COPYING. If not, write to the
28 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
29 ;; Boston, MA 02111-1307, USA.
34 ;; Origin of IMAP parser part is imap.el, included in Gnus.
36 ;; Copyright (C) 1998, 1999, 2000
37 ;; Free Software Foundation, Inc.
38 ;; Author: Simon Josefsson <jas@pdc.kth.se>
50 (eval-when-compile (require 'cl))
52 (defvar elmo-imap4-use-lock t
53 "USE IMAP4 with locking process.")
55 ;;; internal variables
57 (defvar elmo-imap4-seq-prefix "elmo-imap4")
58 (defvar elmo-imap4-seqno 0)
59 (defvar elmo-imap4-use-uid t
60 "Use UID as message number.")
62 (defvar elmo-imap4-current-response nil)
63 (defvar elmo-imap4-status nil)
64 (defvar elmo-imap4-reached-tag "elmo-imap40")
66 ;;; buffer local variables
68 (defvar elmo-imap4-extra-namespace-alist
69 '(("^{.*/nntp}.*$" . ".")) ; Default is for UW's remote nntp mailbox...
70 "Extra namespace alist. A list of cons cell like: (REGEXP . DELIMITER).")
71 (defvar elmo-imap4-default-hierarchy-delimiter "/")
73 (defvar elmo-imap4-server-capability nil)
74 (defvar elmo-imap4-server-namespace nil)
76 (defvar elmo-imap4-parsing nil) ; indicates parsing.
78 (defvar elmo-imap4-fetch-callback nil)
79 (defvar elmo-imap4-fetch-callback-data nil)
80 (defvar elmo-imap4-status-callback nil)
81 (defvar elmo-imap4-status-callback-data nil)
83 (defvar elmo-imap4-server-diff-async-callback nil)
84 (defvar elmo-imap4-server-diff-async-callback-data nil)
86 ;;; progress...(no use?)
87 (defvar elmo-imap4-count-progress nil)
88 (defvar elmo-imap4-count-progress-message nil)
89 (defvar elmo-imap4-progress-count nil)
91 ;;; XXX Temporal implementation
92 (defvar elmo-imap4-current-msgdb nil)
94 (defvar elmo-imap4-local-variables
96 elmo-imap4-current-response
99 elmo-imap4-reached-tag
100 elmo-imap4-count-progress
101 elmo-imap4-count-progress-message
102 elmo-imap4-progress-count
103 elmo-imap4-fetch-callback
104 elmo-imap4-fetch-callback-data
105 elmo-imap4-status-callback
106 elmo-imap4-status-callback-data
107 elmo-imap4-current-msgdb))
111 (defconst elmo-imap4-quoted-specials-list '(?\\ ?\"))
113 (defconst elmo-imap4-non-atom-char-regex
115 (concat "[^" "]!#$&'+,./0-9:;<=>?@A-Z[^_`a-z|}~-" "]")))
117 (defconst elmo-imap4-non-text-char-regex
120 "]\x01-\x09\x0b\x0c\x0e-\x1f\x7f !\"#$%&'()*+,./0-9:;<=>?@A-Z[\\^_`a-z{|}~-"
123 (defconst elmo-imap4-literal-threshold 1024
124 "Limitation of characters that can be used in a quoted string.")
127 (defvar elmo-imap4-debug nil
128 "Non-nil forces IMAP4 folder as debug mode.
129 Debug information is inserted in the buffer \"*IMAP4 DEBUG*\"")
131 (defvar elmo-imap4-debug-inhibit-logging nil)
136 (luna-define-class elmo-imap4-session (elmo-network-session)
137 (capability current-mailbox read-only))
138 (luna-define-internal-accessors 'elmo-imap4-session))
142 (defsubst elmo-imap4-spec-mailbox (spec)
145 (defsubst elmo-imap4-spec-username (spec)
148 (defsubst elmo-imap4-spec-auth (spec)
151 (defsubst elmo-imap4-spec-hostname (spec)
154 (defsubst elmo-imap4-spec-port (spec)
157 (defsubst elmo-imap4-spec-stream-type (spec)
163 (defsubst elmo-imap4-debug (message &rest args)
165 (with-current-buffer (get-buffer-create "*IMAP4 DEBUG*")
166 (goto-char (point-max))
167 (if elmo-imap4-debug-inhibit-logging
168 (insert "NO LOGGING\n")
169 (insert (apply 'format message args) "\n")))))
173 (defmacro elmo-imap4-response-continue-req-p (response)
174 "Returns non-nil if RESPONSE is '+' response."
175 (` (assq 'continue-req (, response))))
177 (defmacro elmo-imap4-response-ok-p (response)
178 "Returns non-nil if RESPONSE is an 'OK' response."
179 (` (assq 'ok (, response))))
181 (defmacro elmo-imap4-response-bye-p (response)
182 "Returns non-nil if RESPONSE is an 'BYE' response."
183 (` (assq 'bye (, response))))
185 (defmacro elmo-imap4-response-value (response symbol)
186 "Get value of the SYMBOL from RESPONSE."
187 (` (nth 1 (assq (, symbol) (, response)))))
189 (defsubst elmo-imap4-response-value-all (response symbol)
190 "Get all value of the SYMBOL from RESPONSE."
193 (if (eq (car (car response)) symbol)
194 (setq matched (nconc matched (nth 1 (car response)))))
195 (setq response (cdr response)))
198 (defmacro elmo-imap4-response-error-text (response)
199 "Returns text of NO, BAD, BYE response."
200 (` (nth 1 (or (elmo-imap4-response-value (, response) 'no)
201 (elmo-imap4-response-value (, response) 'bad)
202 (elmo-imap4-response-value (, response) 'bye)))))
204 (defmacro elmo-imap4-response-bodydetail-text (response)
205 "Returns text of BODY[section]<partial>."
206 (` (nth 3 (assq 'bodydetail (, response)))))
208 ;;; Session commands.
210 ; (defun elmo-imap4-send-command-wait (session command)
211 ; "Send COMMAND to the SESSION and wait for response.
212 ; Returns RESPONSE (parsed lisp object) of IMAP session."
213 ; (elmo-imap4-read-response session
214 ; (elmo-imap4-send-command
218 (defun elmo-imap4-send-command-wait (session command)
219 "Send COMMAND to the SESSION.
220 Returns RESPONSE (parsed lisp object) of IMAP session.
221 If response is not `OK', causes error with IMAP response text."
222 (elmo-imap4-accept-ok session
223 (elmo-imap4-send-command
227 (defun elmo-imap4-send-command (session command)
228 "Send COMMAND to the SESSION.
229 Returns a TAG string which is assigned to the COMAND."
230 (let* ((command-args (if (listp command)
233 (process (elmo-network-session-process-internal session))
234 cmdstr tag token kind)
235 (with-current-buffer (process-buffer process)
236 (setq tag (concat elmo-imap4-seq-prefix
238 (setq elmo-imap4-seqno (+ 1 elmo-imap4-seqno)))))
239 (setq cmdstr (concat tag " "))
240 ;; (erase-buffer) No need.
241 (goto-char (point-min))
242 (if (elmo-imap4-response-bye-p elmo-imap4-current-response)
243 (signal 'elmo-imap4-bye-error
244 (list (elmo-imap4-response-error-text
245 elmo-imap4-current-response))))
246 (setq elmo-imap4-current-response nil)
247 (if elmo-imap4-parsing
248 (error "IMAP process is running. Please wait (or plug again.)"))
249 (setq elmo-imap4-parsing t)
250 (elmo-imap4-debug "<-(%s)- %s" tag command)
251 (while (setq token (car command-args))
252 (cond ((stringp token) ; formatted
253 (setq cmdstr (concat cmdstr token)))
254 ((listp token) ; unformatted
255 (setq kind (car token))
256 (cond ((eq kind 'atom)
257 (setq cmdstr (concat cmdstr (nth 1 token))))
261 (elmo-imap4-format-quoted (nth 1 token)))))
263 (setq cmdstr (concat cmdstr
264 (format "{%d}" (nth 2 token))))
265 (process-send-string process cmdstr)
266 (process-send-string process "\r\n")
268 (elmo-imap4-accept-continue-req session)
269 (cond ((stringp (nth 1 token))
270 (setq cmdstr (nth 1 token)))
271 ((bufferp (nth 1 token))
272 (with-current-buffer (nth 1 token)
276 (+ (point-min) (nth 2 token)))))
278 (error "Wrong argument for literal"))))
280 (error "Unknown token kind %s" kind))))
282 (error "Invalid argument")))
283 (setq command-args (cdr command-args)))
285 (process-send-string process cmdstr))
286 (process-send-string process "\r\n")
289 (defun elmo-imap4-send-string (session string)
290 "Send STRING to the SESSION."
291 (with-current-buffer (process-buffer
292 (elmo-network-session-process-internal session))
293 (setq elmo-imap4-current-response nil)
294 (goto-char (point-min))
295 (elmo-imap4-debug "<-- %s" string)
296 (process-send-string (elmo-network-session-process-internal session)
298 (process-send-string (elmo-network-session-process-internal session)
301 (defun elmo-imap4-read-response (session tag)
302 "Read parsed response from SESSION.
303 TAG is the tag of the command"
304 (with-current-buffer (process-buffer
305 (elmo-network-session-process-internal session))
306 (while (not (or (string= tag elmo-imap4-reached-tag)
307 (elmo-imap4-response-bye-p elmo-imap4-current-response)))
308 (when (memq (process-status
309 (elmo-network-session-process-internal session))
311 (accept-process-output (elmo-network-session-process-internal session)
313 (elmo-imap4-debug "=>%s" (prin1-to-string elmo-imap4-current-response))
314 (setq elmo-imap4-parsing nil)
315 elmo-imap4-current-response))
317 (defsubst elmo-imap4-read-untagged (process)
318 (with-current-buffer (process-buffer process)
319 (while (not elmo-imap4-current-response)
320 (accept-process-output process 1))
321 (elmo-imap4-debug "=>%s" (prin1-to-string elmo-imap4-current-response))
322 elmo-imap4-current-response))
324 (defun elmo-imap4-read-continue-req (session)
325 "Returns a text following to continue-req in SESSION.
326 If response is not `+' response, returns nil."
327 (elmo-imap4-response-value
328 (elmo-imap4-read-untagged
329 (elmo-network-session-process-internal session))
332 (defun elmo-imap4-accept-continue-req (session)
333 "Returns non-nil if `+' (continue-req) response is arrived in SESSION.
334 If response is not `+' response, cause an error."
337 (elmo-imap4-read-untagged
338 (elmo-network-session-process-internal session)))
339 (or (elmo-imap4-response-continue-req-p response)
340 (error "IMAP error: %s"
341 (or (elmo-imap4-response-error-text response)
342 "No continut-req from server.")))))
344 (defun elmo-imap4-read-ok (session tag)
345 "Returns non-nil if `OK' response of the command with TAG is arrived
346 in SESSION. If response is not `OK' response, returns nil."
347 (elmo-imap4-response-ok-p
348 (elmo-imap4-read-response session tag)))
350 (defun elmo-imap4-accept-ok (session tag)
351 "Accept only `OK' response from SESSION.
352 If response is not `OK' response, causes error with IMAP response text."
353 (let ((response (elmo-imap4-read-response session tag)))
354 (if (elmo-imap4-response-ok-p response)
356 (if (elmo-imap4-response-bye-p response)
357 (signal 'elmo-imap4-bye-error
358 (list (elmo-imap4-response-error-text response)))
359 (error "IMAP error: %s"
360 (or (elmo-imap4-response-error-text response)
361 "No `OK' response from server."))))))
364 (defun elmo-imap4-session-check (session)
365 (elmo-imap4-send-command-wait session "check"))
367 (defun elmo-imap4-atom-p (string)
368 "Return t if STRING is an atom defined in rfc2060."
369 (if (string= string "")
372 (not (string-match elmo-imap4-non-atom-char-regex string)))))
374 (defun elmo-imap4-quotable-p (string)
375 "Return t if STRING can be formatted as a quoted defined in rfc2060."
377 (not (string-match elmo-imap4-non-text-char-regex string))))
379 (defun elmo-imap4-nil (string)
380 "Return a list represents the special atom \"NIL\" defined in rfc2060, \
382 Otherwise return nil."
386 (defun elmo-imap4-atom (string)
387 "Return a list represents STRING as an atom defined in rfc2060.
388 Return nil if STRING is not an atom. See `elmo-imap4-atom-p'."
389 (if (elmo-imap4-atom-p string)
390 (list 'atom string)))
392 (defun elmo-imap4-quoted (string)
393 "Return a list represents STRING as a quoted defined in rfc2060.
394 Return nil if STRING can not be formatted as a quoted. See `elmo-imap4-quotable-p'."
395 (if (elmo-imap4-quotable-p string)
396 (list 'quoted string)))
398 (defun elmo-imap4-literal-1 (string-or-buffer length)
399 "Internal function for `elmo-imap4-literal' and `elmo-imap4-buffer-literal'.
400 Return a list represents STRING-OR-BUFFER as a literal defined in rfc2060.
401 STRING-OR-BUFFER must be an encoded string or a single-byte string or a single-byte buffer.
402 LENGTH must be the number of octets for STRING-OR-BUFFER."
403 (list 'literal string-or-buffer length))
405 (defun elmo-imap4-literal (string)
406 "Return a list represents STRING as a literal defined in rfc2060.
407 STRING must be an encoded or a single-byte string."
408 (elmo-imap4-literal-1 string (length string)))
410 (defun elmo-imap4-buffer-literal (buffer)
411 "Return a list represents BUFFER as a literal defined in rfc2060.
412 BUFFER must be a single-byte buffer."
413 (elmo-imap4-literal-1 buffer (with-current-buffer buffer
416 (defun elmo-imap4-string-1 (string length)
417 "Internal function for `elmo-imap4-string' and `elmo-imap4-buffer-string'.
418 Return a list represents STRING as a string defined in rfc2060.
419 STRING must be an encoded or a single-byte string.
420 LENGTH must be the number of octets for STRING."
421 (or (elmo-imap4-quoted string)
422 (elmo-imap4-literal-1 string length)))
424 (defun elmo-imap4-string (string)
425 "Return a list represents STRING as a string defined in rfc2060.
426 STRING must be an encoded or a single-byte string."
427 (let ((length (length string)))
428 (if (< elmo-imap4-literal-threshold length)
429 (elmo-imap4-literal-1 string length)
430 (elmo-imap4-string-1 string length))))
432 (defun elmo-imap4-buffer-string (buffer)
433 "Return a list represents BUFFER as a string defined in rfc2060.
434 BUFFER must be a single-byte buffer."
435 (let ((length (with-current-buffer buffer
437 (if (< elmo-imap4-literal-threshold length)
438 (elmo-imap4-literal-1 buffer length)
439 (elmo-imap4-string-1 (with-current-buffer buffer
443 (defun elmo-imap4-astring-1 (string length)
444 "Internal function for `elmo-imap4-astring' and `elmo-imap4-buffer-astring'.
445 Return a list represents STRING as an astring defined in rfc2060.
446 STRING must be an encoded or a single-byte string.
447 LENGTH must be the number of octets for STRING."
448 (or (elmo-imap4-atom string)
449 (elmo-imap4-string-1 string length)))
451 (defun elmo-imap4-astring (string)
452 "Return a list represents STRING as an astring defined in rfc2060.
453 STRING must be an encoded or a single-byte string."
454 (let ((length (length string)))
455 (if (< elmo-imap4-literal-threshold length)
456 (elmo-imap4-literal-1 string length)
457 (elmo-imap4-astring-1 string length))))
459 (defun elmo-imap4-buffer-astring (buffer)
460 "Return a list represents BUFFER as an astring defined in rfc2060.
461 BUFFER must be a single-byte buffer."
462 (let ((length (with-current-buffer buffer
464 (if (< elmo-imap4-literal-threshold length)
465 (elmo-imap4-literal-1 buffer length)
466 (elmo-imap4-astring-1 (with-current-buffer buffer
470 (defun elmo-imap4-nstring (string)
471 "Return a list represents STRING as a nstring defined in rfc2060.
472 STRING must be an encoded or a single-byte string."
473 (or (elmo-imap4-nil string)
474 (elmo-imap4-string string)))
476 (defun elmo-imap4-buffer-nstring (buffer)
477 "Return a list represents BUFFER as a nstring defined in rfc2060.
478 BUFFER must be a single-byte buffer."
479 (or (elmo-imap4-nil buffer)
480 (elmo-imap4-buffer-string buffer)))
482 (defalias 'elmo-imap4-mailbox 'elmo-imap4-astring)
483 (defalias 'elmo-imap4-field-body 'elmo-imap4-astring)
484 (defalias 'elmo-imap4-userid 'elmo-imap4-astring)
485 (defalias 'elmo-imap4-password 'elmo-imap4-astring)
487 (defun elmo-imap4-format-quoted (string)
488 "Return STRING in a form of the quoted-string defined in rfc2060."
490 (std11-wrap-as-quoted-pairs string elmo-imap4-quoted-specials-list)
493 (defsubst elmo-imap4-response-get-selectable-mailbox-list (response)
497 (if (and (eq 'list (car entry))
498 (not (member "\\NoSelect" (nth 1 (nth 1 entry)))))
499 (car (nth 1 entry))))
503 (defun elmo-imap4-list-folders (spec &optional hierarchy)
504 (let* ((root (elmo-imap4-spec-mailbox spec))
505 (session (elmo-imap4-get-session spec))
508 (elmo-string-matched-assoc
510 (with-current-buffer (elmo-network-session-buffer session)
511 elmo-imap4-server-namespace)))
512 elmo-imap4-default-hierarchy-delimiter))
513 result append-serv type)
516 (not (string= root ""))
517 (not (string-match (concat "\\(.*\\)"
521 (setq root (concat root delim)))
522 (setq result (elmo-imap4-response-get-selectable-mailbox-list
523 (elmo-imap4-send-command-wait
525 (list "list " (elmo-imap4-mailbox root) " *"))))
526 (unless (string= (elmo-imap4-spec-username spec)
527 elmo-default-imap4-user)
528 (setq append-serv (concat ":" (elmo-imap4-spec-username spec))))
529 (unless (eq (elmo-imap4-spec-auth spec)
530 elmo-default-imap4-authenticate-type)
532 (concat append-serv "/" (symbol-name (elmo-imap4-spec-auth spec)))))
533 (unless (string= (elmo-imap4-spec-hostname spec)
534 elmo-default-imap4-server)
535 (setq append-serv (concat append-serv "@" (elmo-imap4-spec-hostname
537 (unless (eq (elmo-imap4-spec-port spec)
538 elmo-default-imap4-port)
539 (setq append-serv (concat append-serv ":"
541 (elmo-imap4-spec-port spec)))))
542 (setq type (elmo-imap4-spec-stream-type spec))
543 (unless (eq (elmo-network-stream-type-symbol type)
544 elmo-default-imap4-stream-type)
546 (setq append-serv (concat append-serv
547 (elmo-network-stream-type-spec-string
550 (let (folder folders ret)
551 (while (setq folders (car result))
554 (concat "^\\(" root "[^" delim "]" "+\\)" delim)
556 (setq folder (match-string 1 folders)))
559 (append ret (list (list
560 (concat "%" (elmo-imap4-decode-folder-string folder)
562 (eval append-serv)))))))
565 (mapcar '(lambda (fld)
568 (concat "^" (regexp-quote folder))
572 (setq ret (append ret (list
573 (concat "%" (elmo-imap4-decode-folder-string folders)
575 (eval append-serv))))))
576 (setq result (cdr result))))
578 (mapcar (lambda (fld)
579 (concat "%" (elmo-imap4-decode-folder-string fld)
581 (eval append-serv))))
584 (defun elmo-imap4-folder-exists-p (spec)
585 (let ((session (elmo-imap4-get-session spec)))
587 (elmo-imap4-session-current-mailbox-internal session)
588 (elmo-imap4-spec-mailbox spec))
590 (elmo-imap4-session-select-mailbox
592 (elmo-imap4-spec-mailbox spec)
595 (defun elmo-imap4-folder-creatable-p (spec)
598 (defun elmo-imap4-create-folder-maybe (spec dummy)
599 (unless (elmo-imap4-folder-exists-p spec)
600 (elmo-imap4-create-folder spec)))
602 (defun elmo-imap4-create-folder (spec)
603 (elmo-imap4-send-command-wait
604 (elmo-imap4-get-session spec)
605 (list "create " (elmo-imap4-mailbox
606 (elmo-imap4-spec-mailbox spec)))))
608 (defun elmo-imap4-delete-folder (spec)
609 (let ((session (elmo-imap4-get-session spec))
611 (when (elmo-imap4-spec-mailbox spec)
612 (when (setq msgs (elmo-imap4-list-folder spec))
613 (elmo-imap4-delete-msgs spec msgs))
614 (elmo-imap4-send-command-wait session "close")
615 (elmo-imap4-send-command-wait
618 (elmo-imap4-mailbox (elmo-imap4-spec-mailbox spec)))))))
620 (defun elmo-imap4-rename-folder (old-spec new-spec)
621 (let ((session (elmo-imap4-get-session old-spec)))
622 (elmo-imap4-send-command-wait session "close")
623 (elmo-imap4-send-command-wait
627 (elmo-imap4-spec-mailbox old-spec))
630 (elmo-imap4-spec-mailbox new-spec))))))
632 (defun elmo-imap4-max-of-folder (spec)
633 (let ((session (elmo-imap4-get-session spec))
634 (killed (and elmo-use-killed-list
635 (elmo-msgdb-killed-list-load
636 (elmo-msgdb-expand-path spec))))
638 (with-current-buffer (elmo-network-session-buffer session)
639 (setq elmo-imap4-status-callback nil)
640 (setq elmo-imap4-status-callback-data nil))
641 (setq status (elmo-imap4-response-value
642 (elmo-imap4-send-command-wait
646 (elmo-imap4-spec-mailbox spec))
647 " (uidnext messages)"))
650 (- (elmo-imap4-response-value status 'uidnext) 1)
653 (elmo-imap4-response-value status 'messages)
654 (elmo-msgdb-killed-list-length killed))
655 (elmo-imap4-response-value status 'messages)))))
657 (defun elmo-imap4-folder-diff (spec folder &optional number-list)
658 (if elmo-use-server-diff
659 (elmo-imap4-server-diff spec)
660 (elmo-generic-folder-diff spec folder number-list)))
662 (defun elmo-imap4-get-session (spec &optional if-exists)
663 (elmo-network-get-session
666 (elmo-imap4-spec-hostname spec)
667 (elmo-imap4-spec-port spec)
668 (elmo-imap4-spec-username spec)
669 (elmo-imap4-spec-auth spec)
670 (elmo-imap4-spec-stream-type spec)
673 (defun elmo-imap4-commit (spec)
674 (if (elmo-imap4-plugged-p spec)
675 (let ((session (elmo-imap4-get-session spec 'if-exists)))
678 (elmo-imap4-session-current-mailbox-internal session)
679 (elmo-imap4-spec-mailbox spec))
680 (if elmo-imap4-use-select-to-update-status
681 (elmo-imap4-session-select-mailbox
683 (elmo-imap4-spec-mailbox spec)
685 (elmo-imap4-session-check session)))))))
687 (defun elmo-imap4-session-select-mailbox (session mailbox
688 &optional force no-error)
689 "Select MAILBOX in SESSION.
690 If optional argument FORCE is non-nil, select mailbox even if current mailbox
692 If second optional argument NO-ERROR is non-nil, don't cause an error when
693 selecting folder was failed.
694 Returns response value if selecting folder succeed. "
697 (elmo-imap4-session-current-mailbox-internal session)
699 (let (response result)
702 (elmo-imap4-read-response
704 (elmo-imap4-send-command
708 (elmo-imap4-mailbox mailbox)))))
709 (if (setq result (elmo-imap4-response-ok-p response))
711 (elmo-imap4-session-set-current-mailbox-internal session mailbox)
712 (elmo-imap4-session-set-read-only-internal
714 (nth 1 (assq 'read-only (assq 'ok response)))))
715 (elmo-imap4-session-set-current-mailbox-internal session nil)
718 (elmo-imap4-response-error-text response)
719 (format "Select %s failed" mailbox))))))
720 (and result response))))
722 (defun elmo-imap4-check-validity (spec validity-file)
724 ;;;(elmo-imap4-send-command-wait
725 ;;;(elmo-imap4-get-session spec)
727 ;;; (elmo-imap4-mailbox
728 ;;; (elmo-imap4-spec-mailbox spec))
729 ;;; " (uidvalidity)")))
732 (defun elmo-imap4-sync-validity (spec validity-file)
736 (defun elmo-imap4-list (spec flag)
737 (let ((session (elmo-imap4-get-session spec)))
738 (elmo-imap4-session-select-mailbox session
739 (elmo-imap4-spec-mailbox spec))
740 (elmo-imap4-response-value
741 (elmo-imap4-send-command-wait
743 (format (if elmo-imap4-use-uid "uid search %s"
747 (defun elmo-imap4-list-folder (spec)
748 (let ((killed (and elmo-use-killed-list
749 (elmo-msgdb-killed-list-load
750 (elmo-msgdb-expand-path spec))))
752 (setq numbers (elmo-imap4-list spec "all"))
753 (elmo-living-messages numbers killed)))
755 (defun elmo-imap4-list-folder-unread (spec number-alist mark-alist
757 (if (and (elmo-imap4-plugged-p spec)
758 (elmo-imap4-use-flag-p spec))
759 (elmo-imap4-list spec "unseen")
760 (elmo-generic-list-folder-unread spec number-alist mark-alist
763 (defun elmo-imap4-list-folder-important (spec number-alist)
764 (if (and (elmo-imap4-plugged-p spec)
765 (elmo-imap4-use-flag-p spec))
766 (elmo-imap4-list spec "flagged")))
768 (defmacro elmo-imap4-detect-search-charset (string)
771 (detect-mime-charset-region (point-min) (point-max)))))
773 (defun elmo-imap4-search-internal-primitive (spec session filter from-msgs)
774 (let ((search-key (elmo-filter-key filter))
775 (imap-search-keys '("bcc" "body" "cc" "from" "subject" "to"))
778 ((string= "last" search-key)
779 (let ((numbers (or from-msgs (elmo-imap4-list-folder spec))))
780 (nthcdr (max (- (length numbers)
781 (string-to-int (elmo-filter-value filter)))
784 ((string= "first" search-key)
785 (let* ((numbers (or from-msgs (elmo-imap4-list-folder spec)))
786 (rest (nthcdr (string-to-int (elmo-filter-value filter) )
788 (mapcar '(lambda (x) (delete x numbers)) rest)
790 ((or (string= "since" search-key)
791 (string= "before" search-key))
792 (setq search-key (concat "sent" search-key))
793 (elmo-imap4-response-value
794 (elmo-imap4-send-command-wait session
796 (if elmo-imap4-use-uid
797 "uid search %s%s%s %s"
801 (if elmo-imap4-use-uid "uid ")
804 (elmo-imap4-make-number-set-list
808 (if (eq (elmo-filter-type filter)
812 (elmo-date-get-description
813 (elmo-date-get-datevec
814 (elmo-filter-value filter)))))
818 (if (eq (length (elmo-filter-value filter)) 0)
819 (setq charset 'us-ascii)
820 (elmo-imap4-detect-search-charset
821 (elmo-filter-value filter))))
822 (elmo-imap4-response-value
823 (elmo-imap4-send-command-wait session
825 (if elmo-imap4-use-uid "uid ")
829 (symbol-name charset))
833 (if elmo-imap4-use-uid "uid ")
836 (elmo-imap4-make-number-set-list
840 (if (eq (elmo-filter-type filter)
845 (elmo-filter-key filter)
849 (elmo-filter-key filter))
851 (encode-mime-charset-string
852 (elmo-filter-value filter) charset))))
855 (defun elmo-imap4-search-internal (spec session condition from-msgs)
859 (setq result (elmo-imap4-search-internal-primitive
860 spec session condition from-msgs)))
861 ((eq (car condition) 'and)
862 (setq result (elmo-imap4-search-internal spec session (nth 1 condition)
864 result (elmo-list-filter result
865 (elmo-imap4-search-internal
866 spec session (nth 2 condition)
868 ((eq (car condition) 'or)
869 (setq result (elmo-imap4-search-internal
870 spec session (nth 1 condition) from-msgs)
871 result (elmo-uniq-list
873 (elmo-imap4-search-internal
874 spec session (nth 2 condition) from-msgs)))
875 result (sort result '<))))))
878 (defun elmo-imap4-search (spec condition &optional from-msgs)
880 (let ((session (elmo-imap4-get-session spec)))
881 (elmo-imap4-session-select-mailbox
883 (elmo-imap4-spec-mailbox spec))
884 (elmo-imap4-search-internal spec session condition from-msgs))))
886 (defun elmo-imap4-use-flag-p (spec)
887 (not (string-match elmo-imap4-disuse-server-flag-mailbox-regexp
888 (elmo-imap4-spec-mailbox spec))))
892 ;; Emacs can parse dot symbol.
893 (defvar elmo-imap4-rfc822-size "RFC822\.SIZE")
894 (defvar elmo-imap4-rfc822-text "RFC822\.TEXT")
895 (defvar elmo-imap4-rfc822-header "RFC822\.HEADER")
896 (defvar elmo-imap4-rfc822-size "RFC822\.SIZE")
897 (defvar elmo-imap4-header-fields "HEADER\.FIELDS")
898 (defmacro elmo-imap4-replace-dot-symbols ()) ;; noop
899 (defalias 'elmo-imap4-fetch-read 'read)
903 ;; Cannot parse dot symbol.
904 (defvar elmo-imap4-rfc822-size "RFC822_SIZE")
905 (defvar elmo-imap4-header-fields "HEADER_FIELDS")
906 (defvar elmo-imap4-rfc822-size "RFC822_SIZE")
907 (defvar elmo-imap4-rfc822-text "RFC822_TEXT")
908 (defvar elmo-imap4-rfc822-header "RFC822_HEADER")
909 (defvar elmo-imap4-header-fields "HEADER_FIELDS")
910 (defun elmo-imap4-fetch-read (buffer)
911 (with-current-buffer buffer
914 (when (re-search-forward "[[ ]" nil t)
915 (goto-char (match-beginning 0))
916 (setq token (buffer-substring beg (point)))
917 (cond ((string= token "RFC822.SIZE")
918 (intern elmo-imap4-rfc822-size))
919 ((string= token "RFC822.HEADER")
920 (intern elmo-imap4-rfc822-header))
921 ((string= token "RFC822.TEXT")
922 (intern elmo-imap4-rfc822-text))
923 ((string= token "HEADER\.FIELDS")
924 (intern elmo-imap4-header-fields))
926 (elmo-read (current-buffer))))))))))
928 (defun elmo-imap4-make-number-set-list (msg-list &optional chop-length)
929 "Make RFC2060's message set specifier from MSG-LIST.
930 Returns a list of (NUMBER . SET-STRING).
931 SET-STRING is the message set specifier described in RFC2060.
932 NUMBER is contained message number in SET-STRING.
933 Every SET-STRING does not contain number of messages longer than CHOP-LENGTH.
934 If CHOP-LENGTH is not specified, message set is not chopped."
935 (let (count cont-list set-list)
936 (setq msg-list (sort (copy-sequence msg-list) '<))
941 (setq chop-length (length msg-list)))
942 (while (and (not (null msg-list))
943 (< count chop-length))
945 (elmo-number-set-append
946 cont-list (car msg-list)))
948 (setq msg-list (cdr msg-list)))
956 (format "%s:%s" (car x) (cdr x)))
962 (nreverse set-list)))
966 ;; read-mark -> "\\Seen"
967 ;; important -> "\\Flagged"
969 ;; (delete -> \\Deleted)
970 (defun elmo-imap4-mark-set-on-msgs (spec msgs mark &optional unmark no-expunge)
971 "SET flag of MSGS as MARK.
972 If optional argument UNMARK is non-nil, unmark."
973 (let ((session (elmo-imap4-get-session spec))
975 (elmo-imap4-session-select-mailbox session
976 (elmo-imap4-spec-mailbox spec))
977 (setq set-list (elmo-imap4-make-number-set-list msgs))
979 (with-current-buffer (elmo-network-session-buffer session)
980 (setq elmo-imap4-fetch-callback nil)
981 (setq elmo-imap4-fetch-callback-data nil))
982 (elmo-imap4-send-command-wait
985 (if elmo-imap4-use-uid
986 "uid store %s %sflags.silent (%s)"
987 "store %s %sflags.silent (%s)")
992 (elmo-imap4-send-command-wait session "expunge")))
995 (defun elmo-imap4-mark-as-important (spec msgs)
996 (and (elmo-imap4-use-flag-p spec)
997 (elmo-imap4-mark-set-on-msgs spec msgs "\\Flagged" nil 'no-expunge)))
999 (defun elmo-imap4-mark-as-read (spec msgs)
1000 (and (elmo-imap4-use-flag-p spec)
1001 (elmo-imap4-mark-set-on-msgs spec msgs "\\Seen" nil 'no-expunge)))
1003 (defun elmo-imap4-unmark-important (spec msgs)
1004 (and (elmo-imap4-use-flag-p spec)
1005 (elmo-imap4-mark-set-on-msgs spec msgs "\\Flagged" 'unmark
1008 (defun elmo-imap4-mark-as-unread (spec msgs)
1009 (and (elmo-imap4-use-flag-p spec)
1010 (elmo-imap4-mark-set-on-msgs spec msgs "\\Seen" 'unmark 'no-expunge)))
1012 (defun elmo-imap4-delete-msgs (spec msgs)
1013 (elmo-imap4-mark-set-on-msgs spec msgs "\\Deleted"))
1015 (defun elmo-imap4-delete-msgs-no-expunge (spec msgs)
1016 (elmo-imap4-mark-set-on-msgs spec msgs "\\Deleted" nil 'no-expunge))
1018 (defun elmo-imap4-msgdb-create-as-numlist (spec numlist new-mark already-mark
1019 seen-mark important-mark
1021 "Create msgdb for SPEC for NUMLIST."
1022 (elmo-imap4-msgdb-create spec numlist new-mark already-mark
1023 seen-mark important-mark seen-list t))
1025 ;; Current buffer is process buffer.
1026 (defun elmo-imap4-fetch-callback (element app-data)
1027 (funcall elmo-imap4-fetch-callback
1029 (insert (or (elmo-imap4-response-bodydetail-text element)
1032 (goto-char (point-min))
1033 (while (search-forward "\r\n" nil t)
1034 (replace-match "\n"))
1035 (elmo-msgdb-create-overview-from-buffer
1036 (elmo-imap4-response-value element 'uid)
1037 (elmo-imap4-response-value element 'rfc822size)))
1038 (elmo-imap4-response-value element 'flags)
1043 ;; 0: new-mark 1: already-mark 2: seen-mark 3: important-mark
1044 ;; 4: seen-list 5: as-number
1045 (defun elmo-imap4-fetch-callback-1 (entity flags app-data)
1046 "A msgdb entity callback function."
1047 (let ((seen (member (car entity) (nth 4 app-data)))
1049 (if (member "\\Flagged" flags)
1050 (elmo-msgdb-global-mark-set (car entity) (nth 3 app-data)))
1051 (setq mark (or (elmo-msgdb-global-mark-get (car entity))
1052 (if (elmo-cache-exists-p (car entity)) ;; XXX
1053 (if (or (member "\\Seen" flags) seen)
1056 (if (or (member "\\Seen" flags) seen)
1057 (if elmo-imap4-use-cache
1059 (nth 0 app-data)))))
1060 (setq elmo-imap4-current-msgdb
1062 elmo-imap4-current-msgdb
1064 (list (cons (elmo-msgdb-overview-entity-get-number entity)
1068 (list (elmo-msgdb-overview-entity-get-number entity)
1071 (defun elmo-imap4-msgdb-create (spec numlist &rest args)
1072 "Create msgdb for SPEC."
1074 (let ((session (elmo-imap4-get-session spec))
1077 '("Subject" "From" "To" "Cc" "Date"
1078 "Message-Id" "References" "In-Reply-To")
1079 elmo-msgdb-extra-fields))
1081 (length (length numlist))
1083 (setq rfc2060 (memq 'imap4rev1
1084 (elmo-imap4-session-capability-internal
1086 (message "Getting overview...")
1087 (elmo-imap4-session-select-mailbox session
1088 (elmo-imap4-spec-mailbox spec))
1089 (setq set-list (elmo-imap4-make-number-set-list
1091 elmo-imap4-overview-fetch-chop-length))
1093 (with-current-buffer (elmo-network-session-buffer session)
1094 (setq elmo-imap4-current-msgdb nil
1095 elmo-imap4-fetch-callback 'elmo-imap4-fetch-callback-1
1096 elmo-imap4-fetch-callback-data args)
1098 (elmo-imap4-send-command-wait
1100 ;; get overview entity from IMAP4
1101 (format "%sfetch %s (%s rfc822.size flags)"
1102 (if elmo-imap4-use-uid "uid " "")
1103 (cdr (car set-list))
1105 (format "body.peek[header.fields %s]" headers)
1106 (format "%s" headers))))
1107 (when (> length elmo-display-progress-threshold)
1108 (setq total (+ total (car (car set-list))))
1109 (elmo-display-progress
1110 'elmo-imap4-msgdb-create "Getting overview..."
1111 (/ (* total 100) length)))
1112 (setq set-list (cdr set-list)))
1113 (message "Getting overview...done")
1114 elmo-imap4-current-msgdb))))
1116 (defun elmo-imap4-parse-capability (string)
1117 (if (string-match "^\\*\\(.*\\)$" string)
1119 (concat "(" (downcase (elmo-match-string 1 string)) ")"))))
1121 (defun elmo-imap4-login (session)
1122 (let ((elmo-imap4-debug-inhibit-logging t))
1126 (elmo-imap4-send-command
1129 (elmo-imap4-userid (elmo-network-session-user-internal session))
1131 (elmo-imap4-password
1132 (elmo-get-passwd (elmo-network-session-password-key session))))))
1133 (signal 'elmo-authenticate-error '(login)))))
1136 elmo-network-initialize-session-buffer :after ((session
1137 elmo-imap4-session) buffer)
1138 (with-current-buffer buffer
1139 (mapcar 'make-variable-buffer-local elmo-imap4-local-variables)
1140 (setq elmo-imap4-seqno 0)
1141 (setq elmo-imap4-status 'initial)))
1143 (luna-define-method elmo-network-initialize-session ((session
1144 elmo-imap4-session))
1145 (let ((process (elmo-network-session-process-internal session)))
1146 (with-current-buffer (process-buffer process)
1147 ;; Skip garbage output from process before greeting.
1148 (while (and (memq (process-status process) '(open run))
1149 (goto-char (point-max))
1151 (not (elmo-imap4-parse-greeting)))
1152 (accept-process-output process 1))
1153 (set-process-filter process 'elmo-imap4-arrival-filter)
1154 (set-process-sentinel process 'elmo-imap4-sentinel)
1155 ;;; (while (and (memq (process-status process) '(open run))
1156 ;;; (eq elmo-imap4-status 'initial))
1157 ;;; (message "Waiting for server response...")
1158 ;;; (accept-process-output process 1))
1160 (unless (memq elmo-imap4-status '(nonauth auth))
1161 (signal 'elmo-open-error
1162 (list 'elmo-network-initialize-session)))
1163 (elmo-imap4-session-set-capability-internal
1165 (elmo-imap4-response-value
1166 (elmo-imap4-send-command-wait session "capability")
1168 (when (eq (elmo-network-stream-type-symbol
1169 (elmo-network-session-stream-type-internal session))
1172 (elmo-imap4-session-capability-internal session))
1173 (signal 'elmo-open-error
1174 '(elmo-imap4-starttls-error)))
1175 (elmo-imap4-send-command-wait session "starttls")
1176 (starttls-negotiate process)))))
1178 (luna-define-method elmo-network-authenticate-session ((session
1179 elmo-imap4-session))
1180 (with-current-buffer (process-buffer
1181 (elmo-network-session-process-internal session))
1182 (let* ((auth (elmo-network-session-auth-internal session))
1183 (auth (if (listp auth) auth (list auth))))
1184 (unless (or (eq elmo-imap4-status 'auth)
1186 (if (eq 'plain (car auth))
1187 (elmo-imap4-login session)
1188 (let* ((elmo-imap4-debug-inhibit-logging t)
1193 (if (string-match "^auth=\\(.*\\)$"
1195 (match-string 1 (upcase (symbol-name cap)))))
1196 (elmo-imap4-session-capability-internal session))))
1198 (sasl-find-mechanism
1200 (mapcar '(lambda (cap) (upcase (symbol-name cap)))
1204 client name step response tag
1205 sasl-read-passphrase)
1207 (if (or elmo-imap4-force-login
1210 "There's no %s capability in server. continue?"
1211 (elmo-list-to-string
1212 (elmo-network-session-auth-internal session)))))
1213 (setq mechanism (sasl-find-mechanism
1215 (signal 'elmo-authenticate-error
1216 '(elmo-imap4-auth-no-mechanisms))))
1220 (elmo-network-session-user-internal session)
1222 (elmo-network-session-host-internal session)))
1223 ;;; (if elmo-imap4-auth-user-realm
1224 ;;; (sasl-client-set-property client 'realm elmo-imap4-auth-user-realm))
1225 (setq name (sasl-mechanism-name mechanism)
1226 step (sasl-next-step client nil))
1227 (elmo-network-session-set-auth-internal
1229 (intern (downcase name)))
1230 (setq sasl-read-passphrase
1234 (elmo-network-session-password-key session)))))
1236 (elmo-imap4-send-command
1238 (concat "AUTHENTICATE " name
1239 (and (sasl-step-data step)
1242 (elmo-base64-encode-string
1243 (sasl-step-data step)
1244 'no-lin-break)))))) ;)
1248 (elmo-imap4-read-untagged
1249 (elmo-network-session-process-internal session)))
1250 (if (elmo-imap4-response-continue-req-p response)
1251 (unless (sasl-next-step client step)
1252 ;; response is '+' but there's no next step.
1253 (signal 'elmo-authenticate-error
1255 (concat "elmo-imap4-auth-"
1256 (downcase name))))))
1258 (if (elmo-imap4-response-ok-p response)
1259 (throw 'done nil) ; finished.
1260 ;; response is NO or BAD.
1261 (signal 'elmo-authenticate-error
1263 (concat "elmo-imap4-auth-"
1264 (downcase name)))))))
1267 (elmo-base64-decode-string
1268 (elmo-imap4-response-value response 'continue-req)))
1269 (setq step (sasl-next-step client step))
1271 (elmo-imap4-send-string
1273 (if (sasl-step-data step)
1274 (elmo-base64-encode-string (sasl-step-data step)
1278 (luna-define-method elmo-network-setup-session ((session
1279 elmo-imap4-session))
1280 (with-current-buffer (elmo-network-session-buffer session)
1281 (when (memq 'namespace (elmo-imap4-session-capability-internal session))
1282 (setq elmo-imap4-server-namespace
1283 (elmo-imap4-response-value
1284 (elmo-imap4-send-command-wait session "namespace")
1287 (defun elmo-imap4-setup-send-buffer (string)
1288 (let ((tmp-buf (get-buffer-create " *elmo-imap4-setup-send-buffer*")))
1291 (set-buffer tmp-buf)
1293 (elmo-set-buffer-multibyte nil)
1295 (goto-char (point-min))
1296 (if (eq (re-search-forward "^$" nil t)
1299 (goto-char (point-min))
1300 (while (search-forward "\n" nil t)
1301 (replace-match "\r\n"))))
1304 (defun elmo-imap4-read-part (folder msg part)
1305 (let* ((spec (elmo-folder-get-spec folder))
1306 (session (elmo-imap4-get-session spec)))
1307 (elmo-imap4-session-select-mailbox session
1308 (elmo-imap4-spec-mailbox spec))
1309 (with-current-buffer (elmo-network-session-buffer session)
1310 (setq elmo-imap4-fetch-callback nil)
1311 (setq elmo-imap4-fetch-callback-data nil))
1313 (elmo-imap4-response-bodydetail-text
1314 (elmo-imap4-response-value-all
1315 (elmo-imap4-send-command-wait session
1317 (if elmo-imap4-use-uid
1318 "uid fetch %s body.peek[%s]"
1319 "fetch %s body.peek[%s]")
1323 (defun elmo-imap4-prefetch-msg (spec msg outbuf)
1324 (elmo-imap4-read-msg spec msg outbuf 'unseen))
1326 (defun elmo-imap4-read-msg (spec msg outbuf
1327 &optional leave-seen-flag-untouched)
1328 (let ((session (elmo-imap4-get-session spec))
1330 (elmo-imap4-session-select-mailbox session
1331 (elmo-imap4-spec-mailbox spec))
1332 (with-current-buffer (elmo-network-session-buffer session)
1333 (setq elmo-imap4-fetch-callback nil)
1334 (setq elmo-imap4-fetch-callback-data nil))
1336 (elmo-imap4-send-command-wait session
1338 (if elmo-imap4-use-uid
1339 "uid fetch %s rfc822%s"
1340 "fetch %s rfc822%s")
1342 (if leave-seen-flag-untouched
1344 (and (setq response (elmo-imap4-response-value
1345 (elmo-imap4-response-value-all
1348 (with-current-buffer outbuf
1351 (elmo-delete-cr-get-content-type)))))
1353 (defun elmo-imap4-setup-send-buffer-from-file (file)
1354 (let ((tmp-buf (get-buffer-create
1355 " *elmo-imap4-setup-send-buffer-from-file*")))
1358 (set-buffer tmp-buf)
1360 (as-binary-input-file
1361 (insert-file-contents file))
1362 (goto-char (point-min))
1363 (if (eq (re-search-forward "^$" nil t)
1366 (goto-char (point-min))
1367 (while (search-forward "\n" nil t)
1368 (replace-match "\r\n"))))
1371 (defun elmo-imap4-delete-msgids (spec msgids)
1372 "If actual message-id is matched, then delete it."
1373 (let ((message-ids msgids)
1375 (num (length msgids)))
1378 (message "Deleting message...%d/%d" i num)
1379 (elmo-imap4-delete-msg-by-id spec (car message-ids))
1380 (setq message-ids (cdr message-ids)))
1381 (elmo-imap4-send-command-wait (elmo-imap4-get-session spec) "expunge")))
1383 (defun elmo-imap4-delete-msg-by-id (spec msgid)
1384 (let ((session (elmo-imap4-get-session spec)))
1385 (elmo-imap4-session-select-mailbox session
1386 (elmo-imap4-spec-mailbox spec))
1387 (elmo-imap4-delete-msgs-no-expunge
1389 (elmo-imap4-response-value
1390 (elmo-imap4-send-command-wait session
1392 (if elmo-imap4-use-uid
1393 "uid search header message-id "
1394 "search header message-id ")
1395 (elmo-imap4-field-body msgid)))
1398 (defun elmo-imap4-append-msg-by-id (spec msgid)
1399 (let ((session (elmo-imap4-get-session spec))
1401 (elmo-imap4-session-select-mailbox session
1402 (elmo-imap4-spec-mailbox spec))
1403 (setq send-buf (elmo-imap4-setup-send-buffer-from-file
1404 (elmo-cache-get-path msgid)))
1406 (elmo-imap4-send-command-wait
1410 (elmo-imap4-mailbox (elmo-imap4-spec-mailbox spec))
1412 (elmo-imap4-buffer-literal send-buf)))
1413 (kill-buffer send-buf)))
1416 (defun elmo-imap4-append-msg (spec string &optional msg no-see)
1417 (let ((session (elmo-imap4-get-session spec))
1419 (elmo-imap4-session-select-mailbox session
1420 (elmo-imap4-spec-mailbox spec))
1421 (setq send-buf (elmo-imap4-setup-send-buffer string))
1423 (elmo-imap4-send-command-wait
1427 (elmo-imap4-mailbox (elmo-imap4-spec-mailbox spec))
1428 (if no-see " " " (\\Seen) ")
1429 (elmo-imap4-buffer-literal send-buf)))
1430 (kill-buffer send-buf)))
1433 (defun elmo-imap4-copy-msgs (dst-spec
1434 msgs src-spec &optional expunge-it same-number)
1435 "Equivalence of hostname, username is assumed."
1436 (let ((session (elmo-imap4-get-session src-spec)))
1437 (elmo-imap4-session-select-mailbox session
1438 (elmo-imap4-spec-mailbox src-spec))
1440 (elmo-imap4-send-command-wait session
1443 (if elmo-imap4-use-uid
1448 (elmo-imap4-spec-mailbox dst-spec))))
1449 (setq msgs (cdr msgs)))
1451 (elmo-imap4-send-command-wait session "expunge"))
1454 (defun elmo-imap4-server-diff-async-callback-1 (status data)
1455 (funcall elmo-imap4-server-diff-async-callback
1456 (cons (elmo-imap4-response-value status 'unseen)
1457 (elmo-imap4-response-value status 'messages))
1460 (defun elmo-imap4-server-diff-async (spec)
1461 (let ((session (elmo-imap4-get-session spec)))
1463 ;; (elmo-imap4-commit spec)
1464 (with-current-buffer (elmo-network-session-buffer session)
1465 (setq elmo-imap4-status-callback
1466 'elmo-imap4-server-diff-async-callback-1)
1467 (setq elmo-imap4-status-callback-data
1468 elmo-imap4-server-diff-async-callback-data))
1469 (elmo-imap4-send-command session
1473 (elmo-imap4-spec-mailbox spec))
1474 " (unseen messages)"))))
1476 (defun elmo-imap4-server-diff (spec)
1478 (let ((session (elmo-imap4-get-session spec))
1481 ;;; (elmo-imap4-commit spec)
1482 (with-current-buffer (elmo-network-session-buffer session)
1483 (setq elmo-imap4-status-callback nil)
1484 (setq elmo-imap4-status-callback-data nil))
1486 (elmo-imap4-send-command-wait session
1490 (elmo-imap4-spec-mailbox spec))
1491 " (unseen messages)")))
1492 (setq response (elmo-imap4-response-value response 'status))
1493 (cons (elmo-imap4-response-value response 'unseen)
1494 (elmo-imap4-response-value response 'messages))))
1496 (defun elmo-imap4-use-cache-p (spec number)
1497 elmo-imap4-use-cache)
1499 (defun elmo-imap4-local-file-p (spec number)
1502 (defun elmo-imap4-port-label (spec)
1504 (if (elmo-imap4-spec-stream-type spec)
1505 (concat "!" (symbol-name
1506 (elmo-network-stream-type-symbol
1507 (elmo-imap4-spec-stream-type spec)))))))
1510 (defsubst elmo-imap4-portinfo (spec)
1511 (list (elmo-imap4-spec-hostname spec) (elmo-imap4-spec-port spec)))
1513 (defun elmo-imap4-plugged-p (spec)
1514 (apply 'elmo-plugged-p
1515 (append (elmo-imap4-portinfo spec)
1516 (list nil (quote (elmo-imap4-port-label spec))))))
1518 (defun elmo-imap4-set-plugged (spec plugged add)
1519 (apply 'elmo-set-plugged plugged
1520 (append (elmo-imap4-portinfo spec)
1521 (list nil nil (quote (elmo-imap4-port-label spec)) add))))
1523 (defalias 'elmo-imap4-sync-number-alist 'elmo-generic-sync-number-alist)
1527 (defvar elmo-imap4-server-eol "\r\n"
1528 "The EOL string sent from the server.")
1530 (defvar elmo-imap4-client-eol "\r\n"
1531 "The EOL string we send to the server.")
1533 (defun elmo-imap4-find-next-line ()
1534 "Return point at end of current line, taking into account literals.
1535 Return nil if no complete line has arrived."
1536 (when (re-search-forward (concat elmo-imap4-server-eol "\\|{\\([0-9]+\\)}"
1537 elmo-imap4-server-eol)
1539 (if (match-string 1)
1540 (if (< (point-max) (+ (point) (string-to-number (match-string 1))))
1542 (goto-char (+ (point) (string-to-number (match-string 1))))
1543 (elmo-imap4-find-next-line))
1546 (defun elmo-imap4-sentinel (process string)
1547 (delete-process process))
1549 (defun elmo-imap4-arrival-filter (proc string)
1550 "IMAP process filter."
1551 (with-current-buffer (process-buffer proc)
1552 (elmo-imap4-debug "-> %s" string)
1553 (goto-char (point-max))
1556 (goto-char (point-min))
1557 (while (setq end (elmo-imap4-find-next-line))
1559 (narrow-to-region (point-min) end)
1560 (delete-backward-char (length elmo-imap4-server-eol))
1561 (goto-char (point-min))
1563 (cond ((eq elmo-imap4-status 'initial)
1564 (setq elmo-imap4-current-response
1566 (list 'greeting (elmo-imap4-parse-greeting)))))
1567 ((or (eq elmo-imap4-status 'auth)
1568 (eq elmo-imap4-status 'nonauth)
1569 (eq elmo-imap4-status 'selected)
1570 (eq elmo-imap4-status 'examine))
1571 (setq elmo-imap4-current-response
1573 (elmo-imap4-parse-response)
1574 elmo-imap4-current-response)))
1576 (message "Unknown state %s in arrival filter"
1577 elmo-imap4-status))))
1578 (delete-region (point-min) (point-max)))))))
1582 (defsubst elmo-imap4-forward ()
1583 (or (eobp) (forward-char 1)))
1585 (defsubst elmo-imap4-parse-number ()
1586 (when (looking-at "[0-9]+")
1588 (string-to-number (match-string 0))
1589 (goto-char (match-end 0)))))
1591 (defsubst elmo-imap4-parse-literal ()
1592 (when (looking-at "{\\([0-9]+\\)}\r\n")
1593 (let ((pos (match-end 0))
1594 (len (string-to-number (match-string 1))))
1595 (if (< (point-max) (+ pos len))
1597 (goto-char (+ pos len))
1598 (buffer-substring pos (+ pos len))))))
1599 ;;; (list ' pos (+ pos len))))))
1601 (defsubst elmo-imap4-parse-string ()
1602 (cond ((eq (char-after (point)) ?\")
1604 (let ((p (point)) (name ""))
1605 (skip-chars-forward "^\"\\\\")
1606 (setq name (buffer-substring p (point)))
1607 (while (eq (char-after (point)) ?\\)
1608 (setq p (1+ (point)))
1610 (skip-chars-forward "^\"\\\\")
1611 (setq name (concat name (buffer-substring p (point)))))
1614 ((eq (char-after (point)) ?{)
1615 (elmo-imap4-parse-literal))))
1617 (defsubst elmo-imap4-parse-nil ()
1618 (if (looking-at "NIL")
1619 (goto-char (match-end 0))))
1621 (defsubst elmo-imap4-parse-nstring ()
1622 (or (elmo-imap4-parse-string)
1623 (and (elmo-imap4-parse-nil)
1626 (defsubst elmo-imap4-parse-astring ()
1627 (or (elmo-imap4-parse-string)
1628 (buffer-substring (point)
1629 (if (re-search-forward "[(){ \r\n%*\"\\]" nil t)
1630 (goto-char (1- (match-end 0)))
1634 (defsubst elmo-imap4-parse-address ()
1636 (when (eq (char-after (point)) ?\()
1637 (elmo-imap4-forward)
1638 (setq address (vector (prog1 (elmo-imap4-parse-nstring)
1639 (elmo-imap4-forward))
1640 (prog1 (elmo-imap4-parse-nstring)
1641 (elmo-imap4-forward))
1642 (prog1 (elmo-imap4-parse-nstring)
1643 (elmo-imap4-forward))
1644 (elmo-imap4-parse-nstring)))
1645 (when (eq (char-after (point)) ?\))
1646 (elmo-imap4-forward)
1649 (defsubst elmo-imap4-parse-address-list ()
1650 (if (eq (char-after (point)) ?\()
1651 (let (address addresses)
1652 (elmo-imap4-forward)
1653 (while (and (not (eq (char-after (point)) ?\)))
1654 ;; next line for MS Exchange bug
1655 (progn (and (eq (char-after (point)) ? ) (elmo-imap4-forward)) t)
1656 (setq address (elmo-imap4-parse-address)))
1657 (setq addresses (cons address addresses)))
1658 (when (eq (char-after (point)) ?\))
1659 (elmo-imap4-forward)
1660 (nreverse addresses)))
1661 (assert (elmo-imap4-parse-nil))))
1663 (defsubst elmo-imap4-parse-mailbox ()
1664 (let ((mailbox (elmo-imap4-parse-astring)))
1665 (if (string-equal "INBOX" (upcase mailbox))
1669 (defun elmo-imap4-parse-greeting ()
1670 "Parse a IMAP greeting."
1671 (cond ((looking-at "\\* OK ")
1672 (setq elmo-imap4-status 'nonauth))
1673 ((looking-at "\\* PREAUTH ")
1674 (setq elmo-imap4-status 'auth))
1675 ((looking-at "\\* BYE ")
1676 (setq elmo-imap4-status 'closed))))
1678 (defun elmo-imap4-parse-response ()
1679 "Parse a IMAP command response."
1681 (case (setq token (elmo-read (current-buffer)))
1683 (skip-chars-forward " ")
1684 (list 'continue-req (buffer-substring (point) (point-max)))))
1685 (* (case (prog1 (setq token (elmo-read (current-buffer)))
1686 (elmo-imap4-forward))
1687 (OK (elmo-imap4-parse-resp-text-code))
1688 (NO (elmo-imap4-parse-resp-text-code))
1689 (BAD (elmo-imap4-parse-resp-text-code))
1690 (BYE (elmo-imap4-parse-bye))
1692 (elmo-imap4-parse-flag-list)))
1693 (LIST (list 'list (elmo-imap4-parse-data-list)))
1694 (LSUB (list 'lsub (elmo-imap4-parse-data-list)))
1697 (elmo-read (concat "("
1698 (buffer-substring (point) (point-max))
1700 (STATUS (elmo-imap4-parse-status))
1702 (NAMESPACE (elmo-imap4-parse-namespace))
1703 (CAPABILITY (list 'capability
1705 (concat "(" (downcase (buffer-substring
1706 (point) (point-max)))
1708 (ACL (elmo-imap4-parse-acl))
1709 (t (case (prog1 (elmo-read (current-buffer))
1710 (elmo-imap4-forward))
1711 (EXISTS (list 'exists token))
1712 (RECENT (list 'recent token))
1713 (EXPUNGE (list 'expunge token))
1714 (FETCH (elmo-imap4-parse-fetch token))
1715 (t (list 'garbage (buffer-string)))))))
1716 (t (if (not (string-match elmo-imap4-seq-prefix (symbol-name token)))
1717 (list 'garbage (buffer-string))
1718 (case (prog1 (elmo-read (current-buffer))
1719 (elmo-imap4-forward))
1721 (setq elmo-imap4-parsing nil)
1722 (setq token (symbol-name token))
1723 (elmo-unintern token)
1724 (elmo-imap4-debug "*%s* OK arrived" token)
1725 (setq elmo-imap4-reached-tag token)
1726 (list 'ok (elmo-imap4-parse-resp-text-code))))
1728 (setq elmo-imap4-parsing nil)
1729 (setq token (symbol-name token))
1730 (elmo-unintern token)
1731 (elmo-imap4-debug "*%s* NO arrived" token)
1732 (setq elmo-imap4-reached-tag token)
1734 (when (eq (char-after (point)) ?\[)
1735 (setq code (buffer-substring (point)
1736 (search-forward "]")))
1737 (elmo-imap4-forward))
1738 (setq text (buffer-substring (point) (point-max)))
1739 (list 'no (list code text)))))
1741 (setq elmo-imap4-parsing nil)
1742 (elmo-imap4-debug "*%s* BAD arrived" token)
1743 (setq token (symbol-name token))
1744 (elmo-unintern token)
1745 (setq elmo-imap4-reached-tag token)
1747 (when (eq (char-after (point)) ?\[)
1748 (setq code (buffer-substring (point)
1749 (search-forward "]")))
1750 (elmo-imap4-forward))
1751 (setq text (buffer-substring (point) (point-max)))
1752 (list 'bad (list code text)))))
1753 (t (list 'garbage (buffer-string)))))))))
1755 (defun elmo-imap4-parse-bye ()
1757 (when (eq (char-after (point)) ?\[)
1758 (setq code (buffer-substring (point)
1759 (search-forward "]")))
1760 (elmo-imap4-forward))
1761 (setq text (buffer-substring (point) (point-max)))
1762 (list 'bye (list code text))))
1764 (defun elmo-imap4-parse-text ()
1765 (goto-char (point-min))
1766 (when (search-forward "[" nil t)
1767 (search-forward "]")
1768 (elmo-imap4-forward))
1769 (list 'text (buffer-substring (point) (point-max))))
1771 (defun elmo-imap4-parse-resp-text-code ()
1772 (when (eq (char-after (point)) ?\[)
1773 (elmo-imap4-forward)
1774 (cond ((search-forward "PERMANENTFLAGS " nil t)
1775 (list 'permanentflags (elmo-imap4-parse-flag-list)))
1776 ((search-forward "UIDNEXT " nil t)
1777 (list 'uidnext (elmo-read (current-buffer))))
1778 ((search-forward "UNSEEN " nil t)
1779 (list 'unseen (elmo-read (current-buffer))))
1780 ((looking-at "UIDVALIDITY \\([0-9]+\\)")
1781 (list 'uidvalidity (match-string 1)))
1782 ((search-forward "READ-ONLY" nil t)
1783 (list 'read-only t))
1784 ((search-forward "READ-WRITE" nil t)
1785 (list 'read-write t))
1786 ((search-forward "NEWNAME " nil t)
1787 (let (oldname newname)
1788 (setq oldname (elmo-imap4-parse-string))
1789 (elmo-imap4-forward)
1790 (setq newname (elmo-imap4-parse-string))
1791 (list 'newname newname oldname)))
1792 ((search-forward "TRYCREATE" nil t)
1793 (list 'trycreate t))
1794 ((looking-at "APPENDUID \\([0-9]+\\) \\([0-9]+\\)")
1796 (list (match-string 1)
1797 (string-to-number (match-string 2)))))
1798 ((looking-at "COPYUID \\([0-9]+\\) \\([0-9,:]+\\) \\([0-9,:]+\\)")
1799 (list 'copyuid (list (match-string 1)
1802 ((search-forward "ALERT] " nil t)
1803 (message "IMAP server information: %s"
1804 (buffer-substring (point) (point-max))))
1805 (t (list 'unknown)))))
1807 (defun elmo-imap4-parse-data-list ()
1808 (let (flags delimiter mailbox)
1809 (setq flags (elmo-imap4-parse-flag-list))
1810 (when (looking-at " NIL\\| \"\\\\?\\(.\\)\"")
1811 (setq delimiter (match-string 1))
1812 (goto-char (1+ (match-end 0)))
1813 (when (setq mailbox (elmo-imap4-parse-mailbox))
1814 (list mailbox flags delimiter)))))
1816 (defsubst elmo-imap4-parse-header-list ()
1817 (when (eq (char-after (point)) ?\()
1819 (while (not (eq (char-after (point)) ?\)))
1820 (elmo-imap4-forward)
1821 (push (elmo-imap4-parse-astring) strlist))
1822 (elmo-imap4-forward)
1823 (nreverse strlist))))
1825 (defsubst elmo-imap4-parse-fetch-body-section ()
1827 (buffer-substring (point)
1829 (progn (re-search-forward "[] ]" nil t)
1831 (if (eq (char-before) ? )
1833 (mapconcat 'identity
1834 (cons section (elmo-imap4-parse-header-list)) " ")
1835 (search-forward "]" nil t))
1838 (defun elmo-imap4-parse-fetch (response)
1839 (when (eq (char-after (point)) ?\()
1841 (while (not (eq (char-after (point)) ?\)))
1842 (elmo-imap4-forward)
1843 (let ((token (elmo-imap4-fetch-read (current-buffer))))
1844 (elmo-imap4-forward)
1846 (cond ((eq token 'UID)
1847 (list 'uid (condition-case nil
1848 (elmo-read (current-buffer))
1851 (list 'flags (elmo-imap4-parse-flag-list)))
1852 ((eq token 'ENVELOPE)
1853 (list 'envelope (elmo-imap4-parse-envelope)))
1854 ((eq token 'INTERNALDATE)
1855 (list 'internaldate (elmo-imap4-parse-string)))
1857 (list 'rfc822 (elmo-imap4-parse-nstring)))
1858 ((eq token (intern elmo-imap4-rfc822-header))
1859 (list 'rfc822header (elmo-imap4-parse-nstring)))
1860 ((eq token (intern elmo-imap4-rfc822-text))
1861 (list 'rfc822text (elmo-imap4-parse-nstring)))
1862 ((eq token (intern elmo-imap4-rfc822-size))
1863 (list 'rfc822size (elmo-read (current-buffer))))
1865 (if (eq (char-before) ?\[)
1868 (upcase (elmo-imap4-parse-fetch-body-section))
1870 (eq (char-after (point)) ?<)
1871 (buffer-substring (1+ (point))
1873 (search-forward ">" nil t)
1875 (progn (elmo-imap4-forward)
1876 (elmo-imap4-parse-nstring)))
1877 (list 'body (elmo-imap4-parse-body))))
1878 ((eq token 'BODYSTRUCTURE)
1879 (list 'bodystructure (elmo-imap4-parse-body)))))
1880 (setq list (cons element list))))
1881 (and elmo-imap4-fetch-callback
1882 (elmo-imap4-fetch-callback list elmo-imap4-fetch-callback-data))
1883 (list 'fetch list))))
1885 (defun elmo-imap4-parse-status ()
1886 (let ((mailbox (elmo-imap4-parse-mailbox))
1888 (when (and mailbox (search-forward "(" nil t))
1889 (while (not (eq (char-after (point)) ?\)))
1892 (let ((token (elmo-read (current-buffer))))
1893 (cond ((eq token 'MESSAGES)
1894 (list 'messages (elmo-read (current-buffer))))
1896 (list 'recent (elmo-read (current-buffer))))
1897 ((eq token 'UIDNEXT)
1898 (list 'uidnext (elmo-read (current-buffer))))
1899 ((eq token 'UIDVALIDITY)
1900 (and (looking-at " \\([0-9]+\\)")
1901 (prog1 (list 'uidvalidity (match-string 1))
1902 (goto-char (match-end 1)))))
1904 (list 'unseen (elmo-read (current-buffer))))
1907 "Unknown status data %s in mailbox %s ignored"
1910 (and elmo-imap4-status-callback
1911 (funcall elmo-imap4-status-callback
1913 elmo-imap4-status-callback-data))
1914 (list 'status status)))
1917 (defmacro elmo-imap4-value (value)
1918 (` (if (eq (, value) 'NIL) nil
1921 (defmacro elmo-imap4-nth (pos list)
1922 (` (let ((value (nth (, pos) (, list))))
1923 (elmo-imap4-value value))))
1925 (defun elmo-imap4-parse-namespace ()
1928 (copy-sequence elmo-imap4-extra-namespace-alist)
1929 (elmo-imap4-parse-namespace-subr
1930 (elmo-read (concat "(" (buffer-substring
1931 (point) (point-max))
1934 (defun elmo-imap4-parse-namespace-subr (ns)
1935 (let (prefix delim namespace-alist default-delim)
1936 ;; 0: personal, 1: other, 2: shared
1938 (setq namespace-alist
1939 (nconc namespace-alist
1943 (setq prefix (elmo-imap4-nth 0 namespace)
1944 delim (elmo-imap4-nth 1 namespace))
1945 (if (and prefix delim
1947 (concat (regexp-quote delim) "\\'")
1949 (setq prefix (substring prefix 0
1950 (match-beginning 0))))
1951 (if (eq (length prefix) 0)
1952 (progn (setq default-delim delim) nil)
1955 (if (string= (downcase prefix) "inbox")
1956 "[Ii][Nn][Bb][Oo][Xx]"
1957 (regexp-quote prefix))
1960 (elmo-imap4-nth i ns))))))
1962 (setq namespace-alist
1963 (nconc namespace-alist
1964 (list (cons "^.*$" default-delim)))))
1967 (defun elmo-imap4-parse-acl ()
1968 (let ((mailbox (elmo-imap4-parse-mailbox))
1969 identifier rights acl)
1970 (while (eq (char-after (point)) ?\ )
1971 (elmo-imap4-forward)
1972 (setq identifier (elmo-imap4-parse-astring))
1973 (elmo-imap4-forward)
1974 (setq rights (elmo-imap4-parse-astring))
1975 (setq acl (append acl (list (cons identifier rights)))))
1976 (list 'acl acl mailbox)))
1978 (defun elmo-imap4-parse-flag-list ()
1979 (let ((str (buffer-substring (+ (point) 1)
1980 (progn (search-forward ")" nil t)
1982 (unless (eq (length str) 0)
1983 (split-string str))))
1985 (defun elmo-imap4-parse-envelope ()
1986 (when (eq (char-after (point)) ?\()
1987 (elmo-imap4-forward)
1988 (vector (prog1 (elmo-imap4-parse-nstring);; date
1989 (elmo-imap4-forward))
1990 (prog1 (elmo-imap4-parse-nstring);; subject
1991 (elmo-imap4-forward))
1992 (prog1 (elmo-imap4-parse-address-list);; from
1993 (elmo-imap4-forward))
1994 (prog1 (elmo-imap4-parse-address-list);; sender
1995 (elmo-imap4-forward))
1996 (prog1 (elmo-imap4-parse-address-list);; reply-to
1997 (elmo-imap4-forward))
1998 (prog1 (elmo-imap4-parse-address-list);; to
1999 (elmo-imap4-forward))
2000 (prog1 (elmo-imap4-parse-address-list);; cc
2001 (elmo-imap4-forward))
2002 (prog1 (elmo-imap4-parse-address-list);; bcc
2003 (elmo-imap4-forward))
2004 (prog1 (elmo-imap4-parse-nstring);; in-reply-to
2005 (elmo-imap4-forward))
2006 (prog1 (elmo-imap4-parse-nstring);; message-id
2007 (elmo-imap4-forward)))))
2009 (defsubst elmo-imap4-parse-string-list ()
2010 (cond ((eq (char-after (point)) ?\();; body-fld-param
2012 (elmo-imap4-forward)
2013 (while (setq str (elmo-imap4-parse-string))
2015 (elmo-imap4-forward))
2016 (nreverse strlist)))
2017 ((elmo-imap4-parse-nil)
2020 (defun elmo-imap4-parse-body-extension ()
2021 (if (eq (char-after (point)) ?\()
2023 (elmo-imap4-forward)
2024 (push (elmo-imap4-parse-body-extension) b-e)
2025 (while (eq (char-after (point)) ?\ )
2026 (elmo-imap4-forward)
2027 (push (elmo-imap4-parse-body-extension) b-e))
2028 (assert (eq (char-after (point)) ?\)))
2029 (elmo-imap4-forward)
2031 (or (elmo-imap4-parse-number)
2032 (elmo-imap4-parse-nstring))))
2034 (defsubst elmo-imap4-parse-body-ext ()
2036 (when (eq (char-after (point)) ?\ );; body-fld-dsp
2037 (elmo-imap4-forward)
2039 (if (eq (char-after (point)) ?\()
2041 (elmo-imap4-forward)
2042 (push (elmo-imap4-parse-string) dsp)
2043 (elmo-imap4-forward)
2044 (push (elmo-imap4-parse-string-list) dsp)
2045 (elmo-imap4-forward))
2046 (assert (elmo-imap4-parse-nil)))
2047 (push (nreverse dsp) ext))
2048 (when (eq (char-after (point)) ?\ );; body-fld-lang
2049 (elmo-imap4-forward)
2050 (if (eq (char-after (point)) ?\()
2051 (push (elmo-imap4-parse-string-list) ext)
2052 (push (elmo-imap4-parse-nstring) ext))
2053 (while (eq (char-after (point)) ?\ );; body-extension
2054 (elmo-imap4-forward)
2055 (setq ext (append (elmo-imap4-parse-body-extension) ext)))))
2058 (defun elmo-imap4-parse-body ()
2060 (when (eq (char-after (point)) ?\()
2061 (elmo-imap4-forward)
2062 (if (eq (char-after (point)) ?\()
2064 (while (and (eq (char-after (point)) ?\()
2065 (setq subbody (elmo-imap4-parse-body)))
2066 (push subbody body))
2067 (elmo-imap4-forward)
2068 (push (elmo-imap4-parse-string) body);; media-subtype
2069 (when (eq (char-after (point)) ?\ );; body-ext-mpart:
2070 (elmo-imap4-forward)
2071 (if (eq (char-after (point)) ?\();; body-fld-param
2072 (push (elmo-imap4-parse-string-list) body)
2073 (push (and (elmo-imap4-parse-nil) nil) body))
2075 (append (elmo-imap4-parse-body-ext) body)));; body-ext-...
2076 (assert (eq (char-after (point)) ?\)))
2077 (elmo-imap4-forward)
2080 (push (elmo-imap4-parse-string) body);; media-type
2081 (elmo-imap4-forward)
2082 (push (elmo-imap4-parse-string) body);; media-subtype
2083 (elmo-imap4-forward)
2084 ;; next line for Sun SIMS bug
2085 (and (eq (char-after (point)) ? ) (elmo-imap4-forward))
2086 (if (eq (char-after (point)) ?\();; body-fld-param
2087 (push (elmo-imap4-parse-string-list) body)
2088 (push (and (elmo-imap4-parse-nil) nil) body))
2089 (elmo-imap4-forward)
2090 (push (elmo-imap4-parse-nstring) body);; body-fld-id
2091 (elmo-imap4-forward)
2092 (push (elmo-imap4-parse-nstring) body);; body-fld-desc
2093 (elmo-imap4-forward)
2094 (push (elmo-imap4-parse-string) body);; body-fld-enc
2095 (elmo-imap4-forward)
2096 (push (elmo-imap4-parse-number) body);; body-fld-octets
2098 ;; ok, we're done parsing the required parts, what comes now is one
2101 ;; envelope (then we're parsing body-type-msg)
2102 ;; body-fld-lines (then we're parsing body-type-text)
2103 ;; body-ext-1part (then we're parsing body-type-basic)
2105 ;; the problem is that the two first are in turn optionally followed
2106 ;; by the third. So we parse the first two here (if there are any)...
2108 (when (eq (char-after (point)) ?\ )
2109 (elmo-imap4-forward)
2111 (cond ((eq (char-after (point)) ?\();; body-type-msg:
2112 (push (elmo-imap4-parse-envelope) body);; envelope
2113 (elmo-imap4-forward)
2114 (push (elmo-imap4-parse-body) body);; body
2115 (elmo-imap4-forward)
2116 (push (elmo-imap4-parse-number) body));; body-fld-lines
2117 ((setq lines (elmo-imap4-parse-number));; body-type-text:
2118 (push lines body));; body-fld-lines
2120 (backward-char)))));; no match...
2122 ;; ...and then parse the third one here...
2124 (when (eq (char-after (point)) ?\ );; body-ext-1part:
2125 (elmo-imap4-forward)
2126 (push (elmo-imap4-parse-nstring) body);; body-fld-md5
2128 (append (elmo-imap4-parse-body-ext) body)));; body-ext-1part..
2130 (assert (eq (char-after (point)) ?\)))
2131 (elmo-imap4-forward)
2135 (product-provide (provide 'elmo-imap4) (require 'elmo-version))
2137 ;;; elmo-imap4.el ends here