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>
54 ;; silence byte compiler.
62 (defun-maybe sasl-cram-md5 (username passphrase challenge))
63 (defun-maybe sasl-digest-md5-digest-response
64 (digest-challenge username passwd serv-type host &optional realm))
65 (defun-maybe starttls-negotiate (a))
66 (defun-maybe elmo-generic-list-folder-unread (spec number-alist mark-alist unread-marks))
67 (defun-maybe elmo-generic-folder-diff (spec folder number-list))
68 (defsubst-maybe utf7-decode-string (string &optional imap) string))
70 (defvar elmo-imap4-use-lock t
71 "USE IMAP4 with locking process.")
73 ;;; internal variables
75 (defvar elmo-imap4-seq-prefix "elmo-imap4")
76 (defvar elmo-imap4-seqno 0)
77 (defvar elmo-imap4-use-uid t
78 "Use UID as message number.")
80 (defvar elmo-imap4-current-response nil)
81 (defvar elmo-imap4-status nil)
82 (defvar elmo-imap4-reached-tag "elmo-imap40")
84 ;;; buffer local variables
86 (defvar elmo-imap4-extra-namespace-alist
87 '(("^{.*/nntp}.*$" . ".")) ; Default is for UW's remote nntp mailbox...
88 "Extra namespace alist. A list of cons cell like: (REGEXP . DELIMITER).")
89 (defvar elmo-imap4-default-hierarchy-delimiter "/")
91 (defvar elmo-imap4-server-capability nil)
92 (defvar elmo-imap4-server-namespace nil)
94 (defvar elmo-imap4-parsing nil) ; indicates parsing.
96 (defvar elmo-imap4-fetch-callback nil)
97 (defvar elmo-imap4-fetch-callback-data nil)
98 (defvar elmo-imap4-status-callback nil)
99 (defvar elmo-imap4-status-callback-data nil)
101 (defvar elmo-imap4-server-diff-async-callback nil)
102 (defvar elmo-imap4-server-diff-async-callback-data nil)
104 ;;; progress...(no use?)
105 (defvar elmo-imap4-count-progress nil)
106 (defvar elmo-imap4-count-progress-message nil)
107 (defvar elmo-imap4-progress-count nil)
109 ;;; XXX Temporal implementation
110 (defvar elmo-imap4-current-msgdb nil)
112 (defvar elmo-imap4-local-variables
114 elmo-imap4-current-response
117 elmo-imap4-reached-tag
118 elmo-imap4-count-progress
119 elmo-imap4-count-progress-message
120 elmo-imap4-progress-count
121 elmo-imap4-fetch-callback
122 elmo-imap4-fetch-callback-data
123 elmo-imap4-status-callback
124 elmo-imap4-status-callback-data
125 elmo-imap4-current-msgdb))
127 (defvar elmo-imap4-authenticator-alist
128 '((login elmo-imap4-auth-login)
129 (cram-md5 elmo-imap4-auth-cram-md5)
130 (digest-md5 elmo-imap4-auth-digest-md5)
131 (plain elmo-imap4-login))
132 "Definition of authenticators.")
136 (defconst elmo-imap4-quoted-specials-list '(?\\ ?\"))
138 (defconst elmo-imap4-non-atom-char-regex
140 (concat "[^" "]!#$&'+,./0-9:;<=>?@A-Z[^_`a-z|}~-" "]")))
142 (defconst elmo-imap4-non-text-char-regex
145 "]\x01-\x09\x0b\x0c\x0e-\x1f\x7f !\"#$%&'()*+,./0-9:;<=>?@A-Z[\\^_`a-z{|}~-"
148 (defconst elmo-imap4-literal-threshold 1024
149 "Limitation of characters that can be used in a quoted string.")
152 (defvar elmo-imap4-debug nil
153 "Non-nil forces IMAP4 folder as debug mode.
154 Debug information is inserted in the buffer \"*IMAP4 DEBUG*\"")
156 (defvar elmo-imap4-debug-inhibit-logging nil)
161 (luna-define-class elmo-imap4-session (elmo-network-session)
162 (capability current-mailbox read-only))
163 (luna-define-internal-accessors 'elmo-imap4-session))
167 (defsubst elmo-imap4-spec-mailbox (spec)
170 (defsubst elmo-imap4-spec-username (spec)
173 (defsubst elmo-imap4-spec-auth (spec)
176 (defsubst elmo-imap4-spec-hostname (spec)
179 (defsubst elmo-imap4-spec-port (spec)
182 (defsubst elmo-imap4-spec-stream-type (spec)
188 (defsubst elmo-imap4-debug (message &rest args)
190 (with-current-buffer (get-buffer-create "*IMAP4 DEBUG*")
191 (goto-char (point-max))
192 (if elmo-imap4-debug-inhibit-logging
193 (insert "NO LOGGING\n")
194 (insert (apply 'format message args) "\n")))))
198 (defmacro elmo-imap4-response-continue-req-p (response)
199 "Returns non-nil if RESPONSE is '+' response."
200 (` (assq 'continue-req (, response))))
202 (defmacro elmo-imap4-response-ok-p (response)
203 "Returns non-nil if RESPONSE is an 'OK' response."
204 (` (assq 'ok (, response))))
206 (defmacro elmo-imap4-response-bye-p (response)
207 "Returns non-nil if RESPONSE is an 'BYE' response."
208 (` (assq 'bye (, response))))
210 (defmacro elmo-imap4-response-value (response symbol)
211 "Get value of the SYMBOL from RESPONSE."
212 (` (nth 1 (assq (, symbol) (, response)))))
214 (defsubst elmo-imap4-response-value-all (response symbol)
215 "Get all value of the SYMBOL from RESPONSE."
218 (if (eq (car (car response)) symbol)
219 (setq matched (nconc matched (nth 1 (car response)))))
220 (setq response (cdr response)))
223 (defmacro elmo-imap4-response-error-text (response)
224 "Returns text of NO, BAD, BYE response."
225 (` (nth 1 (or (elmo-imap4-response-value (, response) 'no)
226 (elmo-imap4-response-value (, response) 'bad)
227 (elmo-imap4-response-value (, response) 'bye)))))
229 (defmacro elmo-imap4-response-bodydetail-text (response)
230 "Returns text of BODY[section]<partial>."
231 (` (nth 3 (assq 'bodydetail (, response)))))
233 ;;; Session commands.
235 ; (defun elmo-imap4-send-command-wait (session command)
236 ; "Send COMMAND to the SESSION and wait for response.
237 ; Returns RESPONSE (parsed lisp object) of IMAP session."
238 ; (elmo-imap4-read-response session
239 ; (elmo-imap4-send-command
243 (defun elmo-imap4-send-command-wait (session command)
244 "Send COMMAND to the SESSION.
245 Returns RESPONSE (parsed lisp object) of IMAP session.
246 If response is not `OK', causes error with IMAP response text."
247 (elmo-imap4-accept-ok session
248 (elmo-imap4-send-command
252 (defun elmo-imap4-send-command (session command)
253 "Send COMMAND to the SESSION.
254 Returns a TAG string which is assigned to the COMAND."
255 (let* ((command-args (if (listp command)
258 (process (elmo-network-session-process-internal session))
259 cmdstr tag token kind)
260 (with-current-buffer (process-buffer process)
261 (setq tag (concat elmo-imap4-seq-prefix
263 (setq elmo-imap4-seqno (+ 1 elmo-imap4-seqno)))))
264 (setq cmdstr (concat tag " "))
265 ;; (erase-buffer) No need.
266 (goto-char (point-min))
267 (if (elmo-imap4-response-bye-p elmo-imap4-current-response)
268 (signal 'elmo-imap4-bye-error
269 (list (elmo-imap4-response-error-text
270 elmo-imap4-current-response))))
271 (setq elmo-imap4-current-response nil)
272 (if elmo-imap4-parsing
273 (error "IMAP process is running. Please wait (or plug again.)"))
274 (setq elmo-imap4-parsing t)
275 (elmo-imap4-debug "<-(%s)- %s" tag command)
276 (while (setq token (car command-args))
277 (cond ((stringp token) ; formatted
278 (setq cmdstr (concat cmdstr token)))
279 ((listp token) ; unformatted
280 (setq kind (car token))
281 (cond ((eq kind 'atom)
282 (setq cmdstr (concat cmdstr (nth 1 token))))
286 (elmo-imap4-format-quoted (nth 1 token)))))
288 (setq cmdstr (concat cmdstr
289 (format "{%d}" (nth 2 token))))
290 (process-send-string process cmdstr)
291 (process-send-string process "\r\n")
293 (elmo-imap4-accept-continue-req session)
294 (cond ((stringp (nth 1 token))
295 (setq cmdstr (nth 1 token)))
296 ((bufferp (nth 1 token))
297 (with-current-buffer (nth 1 token)
301 (+ (point-min) (nth 2 token)))))
303 (error "Wrong argument for literal"))))
305 (error "Unknown token kind %s" kind))))
307 (error "Invalid argument")))
308 (setq command-args (cdr command-args)))
310 (process-send-string process cmdstr))
311 (process-send-string process "\r\n")
314 (defun elmo-imap4-send-string (session string)
315 "Send STRING to the SESSION."
316 (with-current-buffer (process-buffer
317 (elmo-network-session-process-internal session))
318 (setq elmo-imap4-current-response nil)
319 (goto-char (point-min))
320 (elmo-imap4-debug "<-- %s" string)
321 (process-send-string (elmo-network-session-process-internal session)
323 (process-send-string (elmo-network-session-process-internal session)
326 (defun elmo-imap4-read-response (session tag)
327 "Read parsed response from SESSION.
328 TAG is the tag of the command"
329 (with-current-buffer (process-buffer
330 (elmo-network-session-process-internal session))
331 (while (not (or (string= tag elmo-imap4-reached-tag)
332 (elmo-imap4-response-bye-p elmo-imap4-current-response)))
333 (when (memq (process-status
334 (elmo-network-session-process-internal session))
336 (accept-process-output (elmo-network-session-process-internal session)
338 (elmo-imap4-debug "=>%s" (prin1-to-string elmo-imap4-current-response))
339 (setq elmo-imap4-parsing nil)
340 elmo-imap4-current-response))
342 (defsubst elmo-imap4-read-untagged (process)
343 (with-current-buffer (process-buffer process)
344 (while (not elmo-imap4-current-response)
345 (accept-process-output process 1))
346 (elmo-imap4-debug "=>%s" (prin1-to-string elmo-imap4-current-response))
347 elmo-imap4-current-response))
349 (defun elmo-imap4-read-continue-req (session)
350 "Returns a text following to continue-req in SESSION.
351 If response is not `+' response, returns nil."
352 (elmo-imap4-response-value
353 (elmo-imap4-read-untagged
354 (elmo-network-session-process-internal session))
357 (defun elmo-imap4-accept-continue-req (session)
358 "Returns non-nil if `+' (continue-req) response is arrived in SESSION.
359 If response is not `+' response, cause an error."
362 (elmo-imap4-read-untagged
363 (elmo-network-session-process-internal session)))
364 (or (elmo-imap4-response-continue-req-p response)
365 (error "IMAP error: %s"
366 (or (elmo-imap4-response-error-text response)
367 "No continut-req from server.")))))
369 (defun elmo-imap4-read-ok (session tag)
370 "Returns non-nil if `OK' response of the command with TAG is arrived
371 in SESSION. If response is not `OK' response, returns nil."
372 (elmo-imap4-response-ok-p
373 (elmo-imap4-read-response session tag)))
375 (defun elmo-imap4-accept-ok (session tag)
376 "Accept only `OK' response from SESSION.
377 If response is not `OK' response, causes error with IMAP response text."
378 (let ((response (elmo-imap4-read-response session tag)))
379 (if (elmo-imap4-response-ok-p response)
381 (if (elmo-imap4-response-bye-p response)
382 (signal 'elmo-imap4-bye-error
383 (list (elmo-imap4-response-error-text response)))
384 (error "IMAP error: %s"
385 (or (elmo-imap4-response-error-text response)
386 "No `OK' response from server."))))))
389 (defun elmo-imap4-session-check (session)
390 (elmo-imap4-send-command-wait session "check"))
392 (defun elmo-imap4-atom-p (string)
393 "Return t if STRING is an atom defined in rfc2060."
394 (if (string= string "")
397 (not (string-match elmo-imap4-non-atom-char-regex string)))))
399 (defun elmo-imap4-quotable-p (string)
400 "Return t if STRING can be formatted as a quoted defined in rfc2060."
402 (not (string-match elmo-imap4-non-text-char-regex string))))
404 (defun elmo-imap4-nil (string)
405 "Return a list represents the special atom \"NIL\" defined in rfc2060, \
407 Otherwise return nil."
411 (defun elmo-imap4-atom (string)
412 "Return a list represents STRING as an atom defined in rfc2060.
413 Return nil if STRING is not an atom. See `elmo-imap4-atom-p'."
414 (if (elmo-imap4-atom-p string)
415 (list 'atom string)))
417 (defun elmo-imap4-quoted (string)
418 "Return a list represents STRING as a quoted defined in rfc2060.
419 Return nil if STRING can not be formatted as a quoted. See `elmo-imap4-quotable-p'."
420 (if (elmo-imap4-quotable-p string)
421 (list 'quoted string)))
423 (defun elmo-imap4-literal-1 (string-or-buffer length)
424 "Internal function for `elmo-imap4-literal' and `elmo-imap4-buffer-literal'.
425 Return a list represents STRING-OR-BUFFER as a literal defined in rfc2060.
426 STRING-OR-BUFFER must be an encoded string or a single-byte string or a single-byte buffer.
427 LENGTH must be the number of octets for STRING-OR-BUFFER."
428 (list 'literal string-or-buffer length))
430 (defun elmo-imap4-literal (string)
431 "Return a list represents STRING as a literal defined in rfc2060.
432 STRING must be an encoded or a single-byte string."
433 (elmo-imap4-literal-1 string (length string)))
435 (defun elmo-imap4-buffer-literal (buffer)
436 "Return a list represents BUFFER as a literal defined in rfc2060.
437 BUFFER must be a single-byte buffer."
438 (elmo-imap4-literal-1 buffer (with-current-buffer buffer
441 (defun elmo-imap4-string-1 (string length)
442 "Internal function for `elmo-imap4-string' and `elmo-imap4-buffer-string'.
443 Return a list represents STRING as a string defined in rfc2060.
444 STRING must be an encoded or a single-byte string.
445 LENGTH must be the number of octets for STRING."
446 (or (elmo-imap4-quoted string)
447 (elmo-imap4-literal-1 string length)))
449 (defun elmo-imap4-string (string)
450 "Return a list represents STRING as a string defined in rfc2060.
451 STRING must be an encoded or a single-byte string."
452 (let ((length (length string)))
453 (if (< elmo-imap4-literal-threshold length)
454 (elmo-imap4-literal-1 string length)
455 (elmo-imap4-string-1 string length))))
457 (defun elmo-imap4-buffer-string (buffer)
458 "Return a list represents BUFFER as a string defined in rfc2060.
459 BUFFER must be a single-byte buffer."
460 (let ((length (with-current-buffer buffer
462 (if (< elmo-imap4-literal-threshold length)
463 (elmo-imap4-literal-1 buffer length)
464 (elmo-imap4-string-1 (with-current-buffer buffer
468 (defun elmo-imap4-astring-1 (string length)
469 "Internal function for `elmo-imap4-astring' and `elmo-imap4-buffer-astring'.
470 Return a list represents STRING as an astring defined in rfc2060.
471 STRING must be an encoded or a single-byte string.
472 LENGTH must be the number of octets for STRING."
473 (or (elmo-imap4-atom string)
474 (elmo-imap4-string-1 string length)))
476 (defun elmo-imap4-astring (string)
477 "Return a list represents STRING as an astring defined in rfc2060.
478 STRING must be an encoded or a single-byte string."
479 (let ((length (length string)))
480 (if (< elmo-imap4-literal-threshold length)
481 (elmo-imap4-literal-1 string length)
482 (elmo-imap4-astring-1 string length))))
484 (defun elmo-imap4-buffer-astring (buffer)
485 "Return a list represents BUFFER as an astring defined in rfc2060.
486 BUFFER must be a single-byte buffer."
487 (let ((length (with-current-buffer buffer
489 (if (< elmo-imap4-literal-threshold length)
490 (elmo-imap4-literal-1 buffer length)
491 (elmo-imap4-astring-1 (with-current-buffer buffer
495 (defun elmo-imap4-nstring (string)
496 "Return a list represents STRING as a nstring defined in rfc2060.
497 STRING must be an encoded or a single-byte string."
498 (or (elmo-imap4-nil string)
499 (elmo-imap4-string string)))
501 (defun elmo-imap4-buffer-nstring (buffer)
502 "Return a list represents BUFFER as a nstring defined in rfc2060.
503 BUFFER must be a single-byte buffer."
504 (or (elmo-imap4-nil buffer)
505 (elmo-imap4-buffer-string buffer)))
507 (defalias 'elmo-imap4-mailbox 'elmo-imap4-astring)
508 (defalias 'elmo-imap4-field-body 'elmo-imap4-astring)
509 (defalias 'elmo-imap4-userid 'elmo-imap4-astring)
510 (defalias 'elmo-imap4-password 'elmo-imap4-astring)
512 (defun elmo-imap4-format-quoted (string)
513 "Return STRING in a form of the quoted-string defined in rfc2060."
515 (std11-wrap-as-quoted-pairs string elmo-imap4-quoted-specials-list)
518 (defsubst elmo-imap4-response-get-selectable-mailbox-list (response)
522 (if (and (eq 'list (car entry))
523 (not (member "\\NoSelect" (nth 1 (nth 1 entry)))))
524 (car (nth 1 entry))))
528 (defun elmo-imap4-list-folders (spec &optional hierarchy)
529 (let* ((root (elmo-imap4-spec-mailbox spec))
530 (session (elmo-imap4-get-session spec))
533 (elmo-string-matched-assoc
535 (with-current-buffer (elmo-network-session-buffer session)
536 elmo-imap4-server-namespace)))
537 elmo-imap4-default-hierarchy-delimiter))
538 result append-serv type)
541 (not (string= root ""))
542 (not (string-match (concat "\\(.*\\)"
546 (setq root (concat root delim)))
547 (setq result (elmo-imap4-response-get-selectable-mailbox-list
548 (elmo-imap4-send-command-wait
550 (list "list " (elmo-imap4-mailbox root) " *"))))
551 (unless (string= (elmo-imap4-spec-username spec)
552 elmo-default-imap4-user)
553 (setq append-serv (concat ":" (elmo-imap4-spec-username spec))))
554 (unless (eq (elmo-imap4-spec-auth spec)
555 elmo-default-imap4-authenticate-type)
557 (concat append-serv "/" (symbol-name (elmo-imap4-spec-auth spec)))))
558 (unless (string= (elmo-imap4-spec-hostname spec)
559 elmo-default-imap4-server)
560 (setq append-serv (concat append-serv "@" (elmo-imap4-spec-hostname
562 (unless (eq (elmo-imap4-spec-port spec)
563 elmo-default-imap4-port)
564 (setq append-serv (concat append-serv ":"
566 (elmo-imap4-spec-port spec)))))
567 (setq type (elmo-imap4-spec-stream-type spec))
568 (unless (eq (elmo-network-stream-type-symbol type)
569 elmo-default-imap4-stream-type)
571 (setq append-serv (concat append-serv
572 (elmo-network-stream-type-spec-string
575 (let (folder folders ret)
576 (while (setq folders (car result))
579 (concat "^\\(" root "[^" delim "]" "+\\)" delim)
581 (setq folder (match-string 1 folders)))
584 (append ret (list (list
585 (concat "%" (elmo-imap4-decode-folder-string folder)
587 (eval append-serv)))))))
590 (mapcar '(lambda (fld)
593 (concat "^" (regexp-quote folder))
597 (setq ret (append ret (list
598 (concat "%" (elmo-imap4-decode-folder-string folders)
600 (eval append-serv))))))
601 (setq result (cdr result))))
603 (mapcar (lambda (fld)
604 (concat "%" (elmo-imap4-decode-folder-string fld)
606 (eval append-serv))))
609 (defun elmo-imap4-folder-exists-p (spec)
610 (let ((session (elmo-imap4-get-session spec)))
612 (elmo-imap4-session-current-mailbox-internal session)
613 (elmo-imap4-spec-mailbox spec))
615 (elmo-imap4-session-select-mailbox
617 (elmo-imap4-spec-mailbox spec)
620 (defun elmo-imap4-folder-creatable-p (spec)
623 (defun elmo-imap4-create-folder-maybe (spec dummy)
624 (unless (elmo-imap4-folder-exists-p spec)
625 (elmo-imap4-create-folder spec)))
627 (defun elmo-imap4-create-folder (spec)
628 (elmo-imap4-send-command-wait
629 (elmo-imap4-get-session spec)
630 (list "create " (elmo-imap4-mailbox
631 (elmo-imap4-spec-mailbox spec)))))
633 (defun elmo-imap4-delete-folder (spec)
634 (let ((session (elmo-imap4-get-session spec))
636 (when (elmo-imap4-spec-mailbox spec)
637 (when (setq msgs (elmo-imap4-list-folder spec))
638 (elmo-imap4-delete-msgs spec msgs))
639 ;; (elmo-imap4-send-command-wait session "close")
640 (elmo-imap4-send-command-wait
643 (elmo-imap4-mailbox (elmo-imap4-spec-mailbox spec)))))))
645 (defun elmo-imap4-rename-folder (old-spec new-spec)
646 ;;;(elmo-imap4-send-command-wait session "close")
647 (elmo-imap4-send-command-wait
648 (elmo-imap4-get-session old-spec)
651 (elmo-imap4-spec-mailbox old-spec))
654 (elmo-imap4-spec-mailbox new-spec)))))
656 (defun elmo-imap4-max-of-folder (spec)
657 (let ((session (elmo-imap4-get-session spec))
658 (killed (and elmo-use-killed-list
659 (elmo-msgdb-killed-list-load
660 (elmo-msgdb-expand-path spec))))
662 (with-current-buffer (elmo-network-session-buffer session)
663 (setq elmo-imap4-status-callback nil)
664 (setq elmo-imap4-status-callback-data nil))
665 (setq status (elmo-imap4-response-value
666 (elmo-imap4-send-command-wait
670 (elmo-imap4-spec-mailbox spec))
671 " (uidnext messages)"))
674 (- (elmo-imap4-response-value status 'uidnext) 1)
677 (elmo-imap4-response-value status 'messages)
678 (elmo-msgdb-killed-list-length killed))
679 (elmo-imap4-response-value status 'messages)))))
681 (defun elmo-imap4-folder-diff (spec folder &optional number-list)
682 (if elmo-use-server-diff
683 (elmo-imap4-server-diff spec)
684 (elmo-generic-folder-diff spec folder number-list)))
686 (defun elmo-imap4-get-session (spec &optional if-exists)
687 (elmo-network-get-session
690 (elmo-imap4-spec-hostname spec)
691 (elmo-imap4-spec-port spec)
692 (elmo-imap4-spec-username spec)
693 (elmo-imap4-spec-auth spec)
694 (elmo-imap4-spec-stream-type spec)
697 (defun elmo-imap4-commit (spec)
698 (if (elmo-imap4-plugged-p spec)
699 (let ((session (elmo-imap4-get-session spec 'if-exists)))
702 (elmo-imap4-session-current-mailbox-internal session)
703 (elmo-imap4-spec-mailbox spec))
704 (if elmo-imap4-use-select-to-update-status
705 (elmo-imap4-session-select-mailbox
707 (elmo-imap4-spec-mailbox spec)
709 (elmo-imap4-session-check session)))))))
711 (defun elmo-imap4-session-select-mailbox (session mailbox
712 &optional force no-error)
713 "Select MAILBOX in SESSION.
714 If optional argument FORCE is non-nil, select mailbox even if current mailbox
716 If second optional argument NO-ERROR is non-nil, don't cause an error when
717 selecting folder was failed.
718 Returns response value if selecting folder succeed. "
721 (elmo-imap4-session-current-mailbox-internal session)
723 (let (response result)
726 (elmo-imap4-read-response
728 (elmo-imap4-send-command
732 (elmo-imap4-mailbox mailbox)))))
733 (if (setq result (elmo-imap4-response-ok-p response))
735 (elmo-imap4-session-set-current-mailbox-internal session mailbox)
736 (elmo-imap4-session-set-read-only-internal
738 (nth 1 (assq 'read-only (assq 'ok response)))))
739 (elmo-imap4-session-set-current-mailbox-internal session nil)
742 (elmo-imap4-response-error-text response)
743 (format "Select %s failed" mailbox))))))
744 (and result response))))
746 (defun elmo-imap4-check-validity (spec validity-file)
748 ;;;(elmo-imap4-send-command-wait
749 ;;;(elmo-imap4-get-session spec)
751 ;;; (elmo-imap4-mailbox
752 ;;; (elmo-imap4-spec-mailbox spec))
753 ;;; " (uidvalidity)")))
756 (defun elmo-imap4-sync-validity (spec validity-file)
760 (defun elmo-imap4-list (spec flag)
761 (let ((session (elmo-imap4-get-session spec)))
762 (elmo-imap4-session-select-mailbox session
763 (elmo-imap4-spec-mailbox spec))
764 (elmo-imap4-response-value
765 (elmo-imap4-send-command-wait
767 (format (if elmo-imap4-use-uid "uid search %s"
771 (defun elmo-imap4-list-folder (spec)
772 (let ((killed (and elmo-use-killed-list
773 (elmo-msgdb-killed-list-load
774 (elmo-msgdb-expand-path spec))))
776 (setq numbers (elmo-imap4-list spec "all"))
777 (elmo-living-messages numbers killed)))
779 (defun elmo-imap4-list-folder-unread (spec number-alist mark-alist
781 (if (and (elmo-imap4-plugged-p spec)
782 (elmo-imap4-use-flag-p spec))
783 (elmo-imap4-list spec "unseen")
784 (elmo-generic-list-folder-unread spec number-alist mark-alist
787 (defun elmo-imap4-list-folder-important (spec number-alist)
788 (if (and (elmo-imap4-plugged-p spec)
789 (elmo-imap4-use-flag-p spec))
790 (elmo-imap4-list spec "flagged")))
792 (defmacro elmo-imap4-detect-search-charset (string)
795 (detect-mime-charset-region (point-min) (point-max)))))
797 (defun elmo-imap4-search-internal-primitive (spec session filter from-msgs)
798 (let ((search-key (elmo-filter-key filter))
799 (imap-search-keys '("bcc" "body" "cc" "from" "subject" "to"))
802 ((string= "last" search-key)
803 (let ((numbers (or from-msgs (elmo-imap4-list-folder spec))))
804 (nthcdr (max (- (length numbers)
805 (string-to-int (elmo-filter-value filter)))
808 ((string= "first" search-key)
809 (let* ((numbers (or from-msgs (elmo-imap4-list-folder spec)))
810 (rest (nthcdr (string-to-int (elmo-filter-value filter) )
812 (mapcar '(lambda (x) (delete x numbers)) rest)
814 ((or (string= "since" search-key)
815 (string= "before" search-key))
816 (setq search-key (concat "sent" search-key))
817 (elmo-imap4-response-value
818 (elmo-imap4-send-command-wait session
820 (if elmo-imap4-use-uid
821 "uid search %s%s%s %s"
825 (if elmo-imap4-use-uid "uid ")
828 (elmo-imap4-make-number-set-list
832 (if (eq (elmo-filter-type filter)
836 (elmo-date-get-description
837 (elmo-date-get-datevec
838 (elmo-filter-value filter)))))
842 (if (eq (length (elmo-filter-value filter)) 0)
843 (setq charset 'us-ascii)
844 (elmo-imap4-detect-search-charset
845 (elmo-filter-value filter))))
846 (elmo-imap4-response-value
847 (elmo-imap4-send-command-wait session
849 (if elmo-imap4-use-uid "uid ")
853 (symbol-name charset))
857 (if elmo-imap4-use-uid "uid ")
860 (elmo-imap4-make-number-set-list
864 (if (eq (elmo-filter-type filter)
869 (elmo-filter-key filter)
873 (elmo-filter-key filter))
875 (encode-mime-charset-string
876 (elmo-filter-value filter) charset))))
879 (defun elmo-imap4-search-internal (spec session condition from-msgs)
883 (setq result (elmo-imap4-search-internal-primitive
884 spec session condition from-msgs)))
885 ((eq (car condition) 'and)
886 (setq result (elmo-imap4-search-internal spec session (nth 1 condition)
888 result (elmo-list-filter result
889 (elmo-imap4-search-internal
890 spec session (nth 2 condition)
892 ((eq (car condition) 'or)
893 (setq result (elmo-imap4-search-internal
894 spec session (nth 1 condition) from-msgs)
895 result (elmo-uniq-list
897 (elmo-imap4-search-internal
898 spec session (nth 2 condition) from-msgs)))
899 result (sort result '<))))))
902 (defun elmo-imap4-search (spec condition &optional from-msgs)
904 (let ((session (elmo-imap4-get-session spec)))
905 (elmo-imap4-session-select-mailbox
907 (elmo-imap4-spec-mailbox spec))
908 (elmo-imap4-search-internal spec session condition from-msgs))))
910 (defun elmo-imap4-use-flag-p (spec)
911 (not (string-match elmo-imap4-disuse-server-flag-mailbox-regexp
912 (elmo-imap4-spec-mailbox spec))))
916 ;; Emacs can parse dot symbol.
917 (defvar elmo-imap4-rfc822-size "RFC822\.SIZE")
918 (defvar elmo-imap4-rfc822-text "RFC822\.TEXT")
919 (defvar elmo-imap4-rfc822-header "RFC822\.HEADER")
920 (defvar elmo-imap4-rfc822-size "RFC822\.SIZE")
921 (defvar elmo-imap4-header-fields "HEADER\.FIELDS")
922 (defmacro elmo-imap4-replace-dot-symbols ()) ;; noop
923 (defalias 'elmo-imap4-fetch-read 'read)
927 ;; Cannot parse dot symbol.
928 (defvar elmo-imap4-rfc822-size "RFC822_SIZE")
929 (defvar elmo-imap4-header-fields "HEADER_FIELDS")
930 (defvar elmo-imap4-rfc822-size "RFC822_SIZE")
931 (defvar elmo-imap4-rfc822-text "RFC822_TEXT")
932 (defvar elmo-imap4-rfc822-header "RFC822_HEADER")
933 (defvar elmo-imap4-header-fields "HEADER_FIELDS")
934 (defun elmo-imap4-fetch-read (buffer)
935 (with-current-buffer buffer
938 (when (re-search-forward "[[ ]" nil t)
939 (goto-char (match-beginning 0))
940 (setq token (buffer-substring beg (point)))
941 (cond ((string= token "RFC822.SIZE")
942 (intern elmo-imap4-rfc822-size))
943 ((string= token "RFC822.HEADER")
944 (intern elmo-imap4-rfc822-header))
945 ((string= token "RFC822.TEXT")
946 (intern elmo-imap4-rfc822-text))
947 ((string= token "HEADER\.FIELDS")
948 (intern elmo-imap4-header-fields))
950 (elmo-read (current-buffer))))))))))
952 (defun elmo-imap4-make-number-set-list (msg-list &optional chop-length)
953 "Make RFC2060's message set specifier from MSG-LIST.
954 Returns a list of (NUMBER . SET-STRING).
955 SET-STRING is the message set specifier described in RFC2060.
956 NUMBER is contained message number in SET-STRING.
957 Every SET-STRING does not contain number of messages longer than CHOP-LENGTH.
958 If CHOP-LENGTH is not specified, message set is not chopped."
959 (let (count cont-list set-list)
960 (setq msg-list (sort (copy-sequence msg-list) '<))
965 (setq chop-length (length msg-list)))
966 (while (and (not (null msg-list))
967 (< count chop-length))
969 (elmo-number-set-append
970 cont-list (car msg-list)))
972 (setq msg-list (cdr msg-list)))
980 (format "%s:%s" (car x) (cdr x)))
986 (nreverse set-list)))
990 ;; read-mark -> "\\Seen"
991 ;; important -> "\\Flagged"
993 ;; (delete -> \\Deleted)
994 (defun elmo-imap4-mark-set-on-msgs (spec msgs mark &optional unmark no-expunge)
995 "SET flag of MSGS as MARK.
996 If optional argument UNMARK is non-nil, unmark."
997 (let ((session (elmo-imap4-get-session spec))
999 (elmo-imap4-session-select-mailbox session
1000 (elmo-imap4-spec-mailbox spec))
1001 (setq set-list (elmo-imap4-make-number-set-list msgs))
1003 (with-current-buffer (elmo-network-session-buffer session)
1004 (setq elmo-imap4-fetch-callback nil)
1005 (setq elmo-imap4-fetch-callback-data nil))
1006 (elmo-imap4-send-command-wait
1009 (if elmo-imap4-use-uid
1010 "uid store %s %sflags.silent (%s)"
1011 "store %s %sflags.silent (%s)")
1012 (cdr (car set-list))
1016 (elmo-imap4-send-command-wait session "expunge")))
1019 (defun elmo-imap4-mark-as-important (spec msgs)
1020 (and (elmo-imap4-use-flag-p spec)
1021 (elmo-imap4-mark-set-on-msgs spec msgs "\\Flagged" nil 'no-expunge)))
1023 (defun elmo-imap4-mark-as-read (spec msgs)
1024 (and (elmo-imap4-use-flag-p spec)
1025 (elmo-imap4-mark-set-on-msgs spec msgs "\\Seen" nil 'no-expunge)))
1027 (defun elmo-imap4-unmark-important (spec msgs)
1028 (and (elmo-imap4-use-flag-p spec)
1029 (elmo-imap4-mark-set-on-msgs spec msgs "\\Flagged" 'unmark
1032 (defun elmo-imap4-mark-as-unread (spec msgs)
1033 (and (elmo-imap4-use-flag-p spec)
1034 (elmo-imap4-mark-set-on-msgs spec msgs "\\Seen" 'unmark 'no-expunge)))
1036 (defun elmo-imap4-delete-msgs (spec msgs)
1037 (elmo-imap4-mark-set-on-msgs spec msgs "\\Deleted"))
1039 (defun elmo-imap4-delete-msgs-no-expunge (spec msgs)
1040 (elmo-imap4-mark-set-on-msgs spec msgs "\\Deleted" nil 'no-expunge))
1042 (defun elmo-imap4-msgdb-create-as-numlist (spec numlist new-mark already-mark
1043 seen-mark important-mark
1045 "Create msgdb for SPEC for NUMLIST."
1046 (elmo-imap4-msgdb-create spec numlist new-mark already-mark
1047 seen-mark important-mark seen-list t))
1049 ;; Current buffer is process buffer.
1050 (defun elmo-imap4-fetch-callback (element app-data)
1051 (funcall elmo-imap4-fetch-callback
1053 (insert (or (elmo-imap4-response-bodydetail-text element)
1056 (goto-char (point-min))
1057 (while (search-forward "\r\n" nil t)
1058 (replace-match "\n"))
1059 (elmo-msgdb-create-overview-from-buffer
1060 (elmo-imap4-response-value element 'uid)
1061 (elmo-imap4-response-value element 'rfc822size)))
1062 (elmo-imap4-response-value element 'flags)
1067 ;; 0: new-mark 1: already-mark 2: seen-mark 3: important-mark
1068 ;; 4: seen-list 5: as-number
1069 (defun elmo-imap4-fetch-callback-1 (entity flags app-data)
1070 "A msgdb entity callback function."
1071 (let ((seen (member (car entity) (nth 4 app-data)))
1073 (if (member "\\Flagged" flags)
1074 (elmo-msgdb-global-mark-set (car entity) (nth 3 app-data)))
1075 (setq mark (or (elmo-msgdb-global-mark-get (car entity))
1076 (if (elmo-cache-exists-p (car entity)) ;; XXX
1077 (if (or (member "\\Seen" flags) seen)
1080 (if (or (member "\\Seen" flags) seen)
1081 (if elmo-imap4-use-cache
1083 (nth 0 app-data)))))
1084 (setq elmo-imap4-current-msgdb
1086 elmo-imap4-current-msgdb
1088 (list (cons (elmo-msgdb-overview-entity-get-number entity)
1092 (list (elmo-msgdb-overview-entity-get-number entity)
1095 (defun elmo-imap4-msgdb-create (spec numlist &rest args)
1096 "Create msgdb for SPEC."
1098 (let ((session (elmo-imap4-get-session spec))
1101 '("Subject" "From" "To" "Cc" "Date"
1102 "Message-Id" "References" "In-Reply-To")
1103 elmo-msgdb-extra-fields))
1105 (length (length numlist))
1107 (setq rfc2060 (memq 'imap4rev1
1108 (elmo-imap4-session-capability-internal
1110 (message "Getting overview...")
1111 (elmo-imap4-session-select-mailbox session
1112 (elmo-imap4-spec-mailbox spec))
1113 (setq set-list (elmo-imap4-make-number-set-list
1115 elmo-imap4-overview-fetch-chop-length))
1117 (with-current-buffer (elmo-network-session-buffer session)
1118 (setq elmo-imap4-current-msgdb nil
1119 elmo-imap4-fetch-callback 'elmo-imap4-fetch-callback-1
1120 elmo-imap4-fetch-callback-data args)
1122 (elmo-imap4-send-command-wait
1124 ;; get overview entity from IMAP4
1125 (format "%sfetch %s (%s rfc822.size flags)"
1126 (if elmo-imap4-use-uid "uid " "")
1127 (cdr (car set-list))
1129 (format "body.peek[header.fields %s]" headers)
1130 (format "%s" headers))))
1131 (when (> length elmo-display-progress-threshold)
1132 (setq total (+ total (car (car set-list))))
1133 (elmo-display-progress
1134 'elmo-imap4-msgdb-create "Getting overview..."
1135 (/ (* total 100) length)))
1136 (setq set-list (cdr set-list)))
1137 (message "Getting overview...done")
1138 elmo-imap4-current-msgdb))))
1140 (defun elmo-imap4-parse-capability (string)
1141 (if (string-match "^\\*\\(.*\\)$" string)
1143 (concat "(" (downcase (elmo-match-string 1 string)) ")"))))
1145 ;; Current buffer is process buffer.
1146 (defun elmo-imap4-auth-login (session)
1147 (let ((tag (elmo-imap4-send-command session "authenticate login"))
1148 (elmo-imap4-debug-inhibit-logging t))
1149 (or (elmo-imap4-read-continue-req session)
1150 (signal 'elmo-authenticate-error '(elmo-imap4-auth-login)))
1151 (elmo-imap4-send-string session
1152 (elmo-base64-encode-string
1153 (elmo-network-session-user-internal session)))
1154 (or (elmo-imap4-read-continue-req session)
1155 (signal 'elmo-authenticate-error '(elmo-imap4-auth-login)))
1156 (elmo-imap4-send-string session
1157 (elmo-base64-encode-string
1159 (elmo-network-session-password-key session))))
1160 (or (elmo-imap4-read-ok session tag)
1161 (signal 'elmo-authenticate-error '(elmo-imap4-auth-login)))
1162 (setq elmo-imap4-status 'auth)))
1164 (defun elmo-imap4-auth-cram-md5 (session)
1165 (let ((tag (elmo-imap4-send-command session "authenticate cram-md5"))
1166 (elmo-imap4-debug-inhibit-logging t)
1168 (or (setq response (elmo-imap4-read-continue-req session))
1169 (signal 'elmo-authenticate-error
1170 '(elmo-imap4-auth-cram-md5)))
1171 (elmo-imap4-send-string
1173 (elmo-base64-encode-string
1174 (sasl-cram-md5 (elmo-network-session-user-internal session)
1176 (elmo-network-session-password-key session))
1177 (elmo-base64-decode-string response))))
1178 (or (elmo-imap4-read-ok session tag)
1179 (signal 'elmo-authenticate-error '(elmo-imap4-auth-cram-md5)))))
1181 (defun elmo-imap4-auth-digest-md5 (session)
1182 (let ((tag (elmo-imap4-send-command session "authenticate digest-md5"))
1183 (elmo-imap4-debug-inhibit-logging t)
1185 (or (setq response (elmo-imap4-read-continue-req session))
1186 (signal 'elmo-authenticate-error '(elmo-imap4-auth-digest-md5)))
1187 (elmo-imap4-send-string
1189 (elmo-base64-encode-string
1190 (sasl-digest-md5-digest-response
1191 (elmo-base64-decode-string response)
1192 (elmo-network-session-user-internal session)
1193 (elmo-get-passwd (elmo-network-session-password-key session))
1195 (elmo-network-session-password-key session))
1197 (or (setq response (elmo-imap4-read-continue-req session))
1198 (signal 'elmo-authenticate-error '(elmo-imap4-auth-digest-md5)))
1199 (elmo-imap4-send-string session "")
1200 (or (elmo-imap4-read-ok session tag)
1201 (signal 'elmo-authenticate-error '(elmo-imap4-auth-digest-md5)))))
1203 (defun elmo-imap4-login (session)
1204 (let ((elmo-imap4-debug-inhibit-logging t))
1208 (elmo-imap4-send-command
1211 (elmo-imap4-userid (elmo-network-session-user-internal session))
1213 (elmo-imap4-password
1214 (elmo-get-passwd (elmo-network-session-password-key session))))))
1215 (signal 'elmo-authenticate-error '(login)))))
1218 elmo-network-initialize-session-buffer :after ((session
1219 elmo-imap4-session) buffer)
1220 (with-current-buffer buffer
1221 (mapcar 'make-variable-buffer-local elmo-imap4-local-variables)
1222 (setq elmo-imap4-seqno 0)
1223 (setq elmo-imap4-status 'initial)))
1225 (luna-define-method elmo-network-initialize-session ((session
1226 elmo-imap4-session))
1227 (let ((process (elmo-network-session-process-internal session)))
1228 (with-current-buffer (process-buffer process)
1229 ;; Skip garbage output from process before greeting.
1230 (while (and (memq (process-status process) '(open run))
1231 (goto-char (point-max))
1233 (not (elmo-imap4-parse-greeting)))
1234 (accept-process-output process 1))
1235 (set-process-filter process 'elmo-imap4-arrival-filter)
1236 (set-process-sentinel process 'elmo-imap4-sentinel)
1237 ;;; (while (and (memq (process-status process) '(open run))
1238 ;;; (eq elmo-imap4-status 'initial))
1239 ;;; (message "Waiting for server response...")
1240 ;;; (accept-process-output process 1))
1242 (unless (memq elmo-imap4-status '(nonauth auth))
1243 (signal 'elmo-open-error
1244 (list 'elmo-network-initialize-session)))
1245 (elmo-imap4-session-set-capability-internal
1247 (elmo-imap4-response-value
1248 (elmo-imap4-send-command-wait session "capability")
1250 (when (eq (elmo-network-stream-type-symbol
1251 (elmo-network-session-stream-type-internal session))
1254 (elmo-imap4-session-capability-internal session))
1255 (signal 'elmo-open-error
1256 '(elmo-imap4-starttls-error)))
1257 (elmo-imap4-send-command-wait session "starttls")
1258 (starttls-negotiate process)))))
1260 (luna-define-method elmo-network-authenticate-session ((session
1261 elmo-imap4-session))
1262 (with-current-buffer (process-buffer
1263 (elmo-network-session-process-internal session))
1264 (unless (eq elmo-imap4-status 'auth)
1265 (unless (or (not (elmo-network-session-auth-internal session))
1266 (eq (elmo-network-session-auth-internal session) 'plain)
1269 (elmo-network-session-auth-internal
1271 (elmo-imap4-session-capability-internal session))
1273 (elmo-network-session-auth-internal session)
1274 elmo-imap4-authenticator-alist)))
1275 (if (or elmo-imap4-force-login
1278 "There's no %s capability in server. continue?"
1279 (elmo-network-session-auth-internal session))))
1280 (elmo-network-session-set-auth-internal session nil)
1281 (signal 'elmo-open-error
1282 '(elmo-network-initialize-session))))
1283 (let ((authenticator
1284 (if (elmo-network-session-auth-internal session)
1286 (elmo-network-session-auth-internal session)
1287 elmo-imap4-authenticator-alist))
1288 'elmo-imap4-login)))
1289 (funcall authenticator session)))))
1291 (luna-define-method elmo-network-setup-session ((session
1292 elmo-imap4-session))
1293 (with-current-buffer (elmo-network-session-buffer session)
1294 (when (memq 'namespace (elmo-imap4-session-capability-internal session))
1295 (setq elmo-imap4-server-namespace
1296 (elmo-imap4-response-value
1297 (elmo-imap4-send-command-wait session "namespace")
1300 (defun elmo-imap4-setup-send-buffer (string)
1301 (let ((tmp-buf (get-buffer-create " *elmo-imap4-setup-send-buffer*")))
1304 (set-buffer tmp-buf)
1306 (elmo-set-buffer-multibyte nil)
1308 (goto-char (point-min))
1309 (if (eq (re-search-forward "^$" nil t)
1312 (goto-char (point-min))
1313 (while (search-forward "\n" nil t)
1314 (replace-match "\r\n"))))
1317 (defun elmo-imap4-read-part (folder msg part)
1318 (let* ((spec (elmo-folder-get-spec folder))
1319 (session (elmo-imap4-get-session spec)))
1320 (elmo-imap4-session-select-mailbox session
1321 (elmo-imap4-spec-mailbox spec))
1322 (with-current-buffer (elmo-network-session-buffer session)
1323 (setq elmo-imap4-fetch-callback nil)
1324 (setq elmo-imap4-fetch-callback-data nil))
1326 (elmo-imap4-response-bodydetail-text
1327 (elmo-imap4-response-value-all
1328 (elmo-imap4-send-command-wait session
1330 (if elmo-imap4-use-uid
1331 "uid fetch %s body.peek[%s]"
1332 "fetch %s body.peek[%s]")
1336 (defun elmo-imap4-prefetch-msg (spec msg outbuf)
1337 (elmo-imap4-read-msg spec msg outbuf 'unseen))
1339 (defun elmo-imap4-read-msg (spec msg outbuf
1340 &optional leave-seen-flag-untouched)
1341 (let ((session (elmo-imap4-get-session spec))
1343 (elmo-imap4-session-select-mailbox session
1344 (elmo-imap4-spec-mailbox spec))
1345 (with-current-buffer (elmo-network-session-buffer session)
1346 (setq elmo-imap4-fetch-callback nil)
1347 (setq elmo-imap4-fetch-callback-data nil))
1349 (elmo-imap4-send-command-wait session
1351 (if elmo-imap4-use-uid
1352 "uid fetch %s rfc822%s"
1353 "fetch %s rfc822%s")
1355 (if leave-seen-flag-untouched
1357 (and (setq response (elmo-imap4-response-value
1358 (elmo-imap4-response-value-all
1361 (with-current-buffer outbuf
1364 (elmo-delete-cr-get-content-type)))))
1366 (defun elmo-imap4-setup-send-buffer-from-file (file)
1367 (let ((tmp-buf (get-buffer-create
1368 " *elmo-imap4-setup-send-buffer-from-file*")))
1371 (set-buffer tmp-buf)
1373 (as-binary-input-file
1374 (insert-file-contents file))
1375 (goto-char (point-min))
1376 (if (eq (re-search-forward "^$" nil t)
1379 (goto-char (point-min))
1380 (while (search-forward "\n" nil t)
1381 (replace-match "\r\n"))))
1384 (defun elmo-imap4-delete-msgids (spec msgids)
1385 "If actual message-id is matched, then delete it."
1386 (let ((message-ids msgids)
1388 (num (length msgids)))
1391 (message "Deleting message...%d/%d" i num)
1392 (elmo-imap4-delete-msg-by-id spec (car message-ids))
1393 (setq message-ids (cdr message-ids)))
1394 (elmo-imap4-send-command-wait (elmo-imap4-get-session spec) "expunge")))
1396 (defun elmo-imap4-delete-msg-by-id (spec msgid)
1397 (let ((session (elmo-imap4-get-session spec)))
1398 (elmo-imap4-session-select-mailbox session
1399 (elmo-imap4-spec-mailbox spec))
1400 (elmo-imap4-delete-msgs-no-expunge
1402 (elmo-imap4-response-value
1403 (elmo-imap4-send-command-wait session
1405 (if elmo-imap4-use-uid
1406 "uid search header message-id "
1407 "search header message-id ")
1408 (elmo-imap4-field-body msgid)))
1411 (defun elmo-imap4-append-msg-by-id (spec msgid)
1412 (let ((session (elmo-imap4-get-session spec))
1414 (elmo-imap4-session-select-mailbox session
1415 (elmo-imap4-spec-mailbox spec))
1416 (setq send-buf (elmo-imap4-setup-send-buffer-from-file
1417 (elmo-cache-get-path msgid)))
1419 (elmo-imap4-send-command-wait
1423 (elmo-imap4-mailbox (elmo-imap4-spec-mailbox spec))
1425 (elmo-imap4-buffer-literal send-buf)))
1426 (kill-buffer send-buf)))
1429 (defun elmo-imap4-append-msg (spec string &optional msg no-see)
1430 (let ((session (elmo-imap4-get-session spec))
1432 (elmo-imap4-session-select-mailbox session
1433 (elmo-imap4-spec-mailbox spec))
1434 (setq send-buf (elmo-imap4-setup-send-buffer string))
1436 (elmo-imap4-send-command-wait
1440 (elmo-imap4-mailbox (elmo-imap4-spec-mailbox spec))
1441 (if no-see " " " (\\Seen) ")
1442 (elmo-imap4-buffer-literal send-buf)))
1443 (kill-buffer send-buf)))
1446 (defun elmo-imap4-copy-msgs (dst-spec
1447 msgs src-spec &optional expunge-it same-number)
1448 "Equivalence of hostname, username is assumed."
1449 (let ((session (elmo-imap4-get-session src-spec)))
1450 (elmo-imap4-session-select-mailbox session
1451 (elmo-imap4-spec-mailbox src-spec))
1453 (elmo-imap4-send-command-wait session
1456 (if elmo-imap4-use-uid
1461 (elmo-imap4-spec-mailbox dst-spec))))
1462 (setq msgs (cdr msgs)))
1464 (elmo-imap4-send-command-wait session "expunge"))
1467 (defun elmo-imap4-server-diff-async-callback-1 (status data)
1468 (funcall elmo-imap4-server-diff-async-callback
1469 (cons (elmo-imap4-response-value status 'unseen)
1470 (elmo-imap4-response-value status 'messages))
1473 (defun elmo-imap4-server-diff-async (spec)
1474 (let ((session (elmo-imap4-get-session spec)))
1476 ;; (elmo-imap4-commit spec)
1477 (with-current-buffer (elmo-network-session-buffer session)
1478 (setq elmo-imap4-status-callback
1479 'elmo-imap4-server-diff-async-callback-1)
1480 (setq elmo-imap4-status-callback-data
1481 elmo-imap4-server-diff-async-callback-data))
1482 (elmo-imap4-send-command session
1486 (elmo-imap4-spec-mailbox spec))
1487 " (unseen messages)"))))
1489 (defun elmo-imap4-server-diff (spec)
1491 (let ((session (elmo-imap4-get-session spec))
1494 ;;; (elmo-imap4-commit spec)
1495 (with-current-buffer (elmo-network-session-buffer session)
1496 (setq elmo-imap4-status-callback nil)
1497 (setq elmo-imap4-status-callback-data nil))
1499 (elmo-imap4-send-command-wait session
1503 (elmo-imap4-spec-mailbox spec))
1504 " (unseen messages)")))
1505 (setq response (elmo-imap4-response-value response 'status))
1506 (cons (elmo-imap4-response-value response 'unseen)
1507 (elmo-imap4-response-value response 'messages))))
1509 (defun elmo-imap4-use-cache-p (spec number)
1510 elmo-imap4-use-cache)
1512 (defun elmo-imap4-local-file-p (spec number)
1515 (defun elmo-imap4-port-label (spec)
1517 (if (elmo-imap4-spec-stream-type spec)
1518 (concat "!" (symbol-name
1519 (elmo-network-stream-type-symbol
1520 (elmo-imap4-spec-stream-type spec)))))))
1523 (defsubst elmo-imap4-portinfo (spec)
1524 (list (elmo-imap4-spec-hostname spec) (elmo-imap4-spec-port spec)))
1526 (defun elmo-imap4-plugged-p (spec)
1527 (apply 'elmo-plugged-p
1528 (append (elmo-imap4-portinfo spec)
1529 (list nil (quote (elmo-imap4-port-label spec))))))
1531 (defun elmo-imap4-set-plugged (spec plugged add)
1532 (apply 'elmo-set-plugged plugged
1533 (append (elmo-imap4-portinfo spec)
1534 (list nil nil (quote (elmo-imap4-port-label spec)) add))))
1536 (defalias 'elmo-imap4-sync-number-alist 'elmo-generic-sync-number-alist)
1540 (defvar elmo-imap4-server-eol "\r\n"
1541 "The EOL string sent from the server.")
1543 (defvar elmo-imap4-client-eol "\r\n"
1544 "The EOL string we send to the server.")
1546 (defun elmo-imap4-find-next-line ()
1547 "Return point at end of current line, taking into account literals.
1548 Return nil if no complete line has arrived."
1549 (when (re-search-forward (concat elmo-imap4-server-eol "\\|{\\([0-9]+\\)}"
1550 elmo-imap4-server-eol)
1552 (if (match-string 1)
1553 (if (< (point-max) (+ (point) (string-to-number (match-string 1))))
1555 (goto-char (+ (point) (string-to-number (match-string 1))))
1556 (elmo-imap4-find-next-line))
1559 (defun elmo-imap4-sentinel (process string)
1560 (delete-process process))
1562 (defun elmo-imap4-arrival-filter (proc string)
1563 "IMAP process filter."
1564 (with-current-buffer (process-buffer proc)
1565 (elmo-imap4-debug "-> %s" string)
1566 (goto-char (point-max))
1569 (goto-char (point-min))
1570 (while (setq end (elmo-imap4-find-next-line))
1572 (narrow-to-region (point-min) end)
1573 (delete-backward-char (length elmo-imap4-server-eol))
1574 (goto-char (point-min))
1576 (cond ((eq elmo-imap4-status 'initial)
1577 (setq elmo-imap4-current-response
1579 (list 'greeting (elmo-imap4-parse-greeting)))))
1580 ((or (eq elmo-imap4-status 'auth)
1581 (eq elmo-imap4-status 'nonauth)
1582 (eq elmo-imap4-status 'selected)
1583 (eq elmo-imap4-status 'examine))
1584 (setq elmo-imap4-current-response
1586 (elmo-imap4-parse-response)
1587 elmo-imap4-current-response)))
1589 (message "Unknown state %s in arrival filter"
1590 elmo-imap4-status))))
1591 (delete-region (point-min) (point-max)))))))
1595 (defsubst elmo-imap4-forward ()
1596 (or (eobp) (forward-char 1)))
1598 (defsubst elmo-imap4-parse-number ()
1599 (when (looking-at "[0-9]+")
1601 (string-to-number (match-string 0))
1602 (goto-char (match-end 0)))))
1604 (defsubst elmo-imap4-parse-literal ()
1605 (when (looking-at "{\\([0-9]+\\)}\r\n")
1606 (let ((pos (match-end 0))
1607 (len (string-to-number (match-string 1))))
1608 (if (< (point-max) (+ pos len))
1610 (goto-char (+ pos len))
1611 (buffer-substring pos (+ pos len))))))
1612 ;;; (list ' pos (+ pos len))))))
1614 (defsubst elmo-imap4-parse-string ()
1615 (cond ((eq (char-after (point)) ?\")
1617 (let ((p (point)) (name ""))
1618 (skip-chars-forward "^\"\\\\")
1619 (setq name (buffer-substring p (point)))
1620 (while (eq (char-after (point)) ?\\)
1621 (setq p (1+ (point)))
1623 (skip-chars-forward "^\"\\\\")
1624 (setq name (concat name (buffer-substring p (point)))))
1627 ((eq (char-after (point)) ?{)
1628 (elmo-imap4-parse-literal))))
1630 (defsubst elmo-imap4-parse-nil ()
1631 (if (looking-at "NIL")
1632 (goto-char (match-end 0))))
1634 (defsubst elmo-imap4-parse-nstring ()
1635 (or (elmo-imap4-parse-string)
1636 (and (elmo-imap4-parse-nil)
1639 (defsubst elmo-imap4-parse-astring ()
1640 (or (elmo-imap4-parse-string)
1641 (buffer-substring (point)
1642 (if (re-search-forward "[(){ \r\n%*\"\\]" nil t)
1643 (goto-char (1- (match-end 0)))
1647 (defsubst elmo-imap4-parse-address ()
1649 (when (eq (char-after (point)) ?\()
1650 (elmo-imap4-forward)
1651 (setq address (vector (prog1 (elmo-imap4-parse-nstring)
1652 (elmo-imap4-forward))
1653 (prog1 (elmo-imap4-parse-nstring)
1654 (elmo-imap4-forward))
1655 (prog1 (elmo-imap4-parse-nstring)
1656 (elmo-imap4-forward))
1657 (elmo-imap4-parse-nstring)))
1658 (when (eq (char-after (point)) ?\))
1659 (elmo-imap4-forward)
1662 (defsubst elmo-imap4-parse-address-list ()
1663 (if (eq (char-after (point)) ?\()
1664 (let (address addresses)
1665 (elmo-imap4-forward)
1666 (while (and (not (eq (char-after (point)) ?\)))
1667 ;; next line for MS Exchange bug
1668 (progn (and (eq (char-after (point)) ? ) (elmo-imap4-forward)) t)
1669 (setq address (elmo-imap4-parse-address)))
1670 (setq addresses (cons address addresses)))
1671 (when (eq (char-after (point)) ?\))
1672 (elmo-imap4-forward)
1673 (nreverse addresses)))
1674 (assert (elmo-imap4-parse-nil))))
1676 (defsubst elmo-imap4-parse-mailbox ()
1677 (let ((mailbox (elmo-imap4-parse-astring)))
1678 (if (string-equal "INBOX" (upcase mailbox))
1682 (defun elmo-imap4-parse-greeting ()
1683 "Parse a IMAP greeting."
1684 (cond ((looking-at "\\* OK ")
1685 (setq elmo-imap4-status 'nonauth))
1686 ((looking-at "\\* PREAUTH ")
1687 (setq elmo-imap4-status 'auth))
1688 ((looking-at "\\* BYE ")
1689 (setq elmo-imap4-status 'closed))))
1691 (defun elmo-imap4-parse-response ()
1692 "Parse a IMAP command response."
1694 (case (setq token (elmo-read (current-buffer)))
1696 (skip-chars-forward " ")
1697 (list 'continue-req (buffer-substring (point) (point-max)))))
1698 (* (case (prog1 (setq token (elmo-read (current-buffer)))
1699 (elmo-imap4-forward))
1700 (OK (elmo-imap4-parse-resp-text-code))
1701 (NO (elmo-imap4-parse-resp-text-code))
1702 (BAD (elmo-imap4-parse-resp-text-code))
1703 (BYE (elmo-imap4-parse-bye))
1705 (elmo-imap4-parse-flag-list)))
1706 (LIST (list 'list (elmo-imap4-parse-data-list)))
1707 (LSUB (list 'lsub (elmo-imap4-parse-data-list)))
1710 (elmo-read (concat "("
1711 (buffer-substring (point) (point-max))
1713 (STATUS (elmo-imap4-parse-status))
1715 (NAMESPACE (elmo-imap4-parse-namespace))
1716 (CAPABILITY (list 'capability
1718 (concat "(" (downcase (buffer-substring
1719 (point) (point-max)))
1721 (ACL (elmo-imap4-parse-acl))
1722 (t (case (prog1 (elmo-read (current-buffer))
1723 (elmo-imap4-forward))
1724 (EXISTS (list 'exists token))
1725 (RECENT (list 'recent token))
1726 (EXPUNGE (list 'expunge token))
1727 (FETCH (elmo-imap4-parse-fetch token))
1728 (t (list 'garbage (buffer-string)))))))
1729 (t (if (not (string-match elmo-imap4-seq-prefix (symbol-name token)))
1730 (list 'garbage (buffer-string))
1731 (case (prog1 (elmo-read (current-buffer))
1732 (elmo-imap4-forward))
1734 (setq elmo-imap4-parsing nil)
1735 (setq token (symbol-name token))
1736 (elmo-unintern token)
1737 (elmo-imap4-debug "*%s* OK arrived" token)
1738 (setq elmo-imap4-reached-tag token)
1739 (list 'ok (elmo-imap4-parse-resp-text-code))))
1741 (setq elmo-imap4-parsing nil)
1742 (setq token (symbol-name token))
1743 (elmo-unintern token)
1744 (elmo-imap4-debug "*%s* NO arrived" 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 'no (list code text)))))
1754 (setq elmo-imap4-parsing nil)
1755 (elmo-imap4-debug "*%s* BAD arrived" token)
1756 (setq token (symbol-name token))
1757 (elmo-unintern token)
1758 (setq elmo-imap4-reached-tag token)
1760 (when (eq (char-after (point)) ?\[)
1761 (setq code (buffer-substring (point)
1762 (search-forward "]")))
1763 (elmo-imap4-forward))
1764 (setq text (buffer-substring (point) (point-max)))
1765 (list 'bad (list code text)))))
1766 (t (list 'garbage (buffer-string)))))))))
1768 (defun elmo-imap4-parse-bye ()
1770 (when (eq (char-after (point)) ?\[)
1771 (setq code (buffer-substring (point)
1772 (search-forward "]")))
1773 (elmo-imap4-forward))
1774 (setq text (buffer-substring (point) (point-max)))
1775 (list 'bye (list code text))))
1777 (defun elmo-imap4-parse-text ()
1778 (goto-char (point-min))
1779 (when (search-forward "[" nil t)
1780 (search-forward "]")
1781 (elmo-imap4-forward))
1782 (list 'text (buffer-substring (point) (point-max))))
1784 (defun elmo-imap4-parse-resp-text-code ()
1785 (when (eq (char-after (point)) ?\[)
1786 (elmo-imap4-forward)
1787 (cond ((search-forward "PERMANENTFLAGS " nil t)
1788 (list 'permanentflags (elmo-imap4-parse-flag-list)))
1789 ((search-forward "UIDNEXT " nil t)
1790 (list 'uidnext (elmo-read (current-buffer))))
1791 ((search-forward "UNSEEN " nil t)
1792 (list 'unseen (elmo-read (current-buffer))))
1793 ((looking-at "UIDVALIDITY \\([0-9]+\\)")
1794 (list 'uidvalidity (match-string 1)))
1795 ((search-forward "READ-ONLY" nil t)
1796 (list 'read-only t))
1797 ((search-forward "READ-WRITE" nil t)
1798 (list 'read-write t))
1799 ((search-forward "NEWNAME " nil t)
1800 (let (oldname newname)
1801 (setq oldname (elmo-imap4-parse-string))
1802 (elmo-imap4-forward)
1803 (setq newname (elmo-imap4-parse-string))
1804 (list 'newname newname oldname)))
1805 ((search-forward "TRYCREATE" nil t)
1806 (list 'trycreate t))
1807 ((looking-at "APPENDUID \\([0-9]+\\) \\([0-9]+\\)")
1809 (list (match-string 1)
1810 (string-to-number (match-string 2)))))
1811 ((looking-at "COPYUID \\([0-9]+\\) \\([0-9,:]+\\) \\([0-9,:]+\\)")
1812 (list 'copyuid (list (match-string 1)
1815 ((search-forward "ALERT] " nil t)
1816 (message "IMAP server information: %s"
1817 (buffer-substring (point) (point-max))))
1818 (t (list 'unknown)))))
1820 (defun elmo-imap4-parse-data-list ()
1821 (let (flags delimiter mailbox)
1822 (setq flags (elmo-imap4-parse-flag-list))
1823 (when (looking-at " NIL\\| \"\\\\?\\(.\\)\"")
1824 (setq delimiter (match-string 1))
1825 (goto-char (1+ (match-end 0)))
1826 (when (setq mailbox (elmo-imap4-parse-mailbox))
1827 (list mailbox flags delimiter)))))
1829 (defsubst elmo-imap4-parse-header-list ()
1830 (when (eq (char-after (point)) ?\()
1832 (while (not (eq (char-after (point)) ?\)))
1833 (elmo-imap4-forward)
1834 (push (elmo-imap4-parse-astring) strlist))
1835 (elmo-imap4-forward)
1836 (nreverse strlist))))
1838 (defsubst elmo-imap4-parse-fetch-body-section ()
1840 (buffer-substring (point)
1842 (progn (re-search-forward "[] ]" nil t)
1844 (if (eq (char-before) ? )
1846 (mapconcat 'identity
1847 (cons section (elmo-imap4-parse-header-list)) " ")
1848 (search-forward "]" nil t))
1851 (defun elmo-imap4-parse-fetch (response)
1852 (when (eq (char-after (point)) ?\()
1854 (while (not (eq (char-after (point)) ?\)))
1855 (elmo-imap4-forward)
1856 (let ((token (elmo-imap4-fetch-read (current-buffer))))
1857 (elmo-imap4-forward)
1859 (cond ((eq token 'UID)
1860 (list 'uid (condition-case nil
1861 (elmo-read (current-buffer))
1864 (list 'flags (elmo-imap4-parse-flag-list)))
1865 ((eq token 'ENVELOPE)
1866 (list 'envelope (elmo-imap4-parse-envelope)))
1867 ((eq token 'INTERNALDATE)
1868 (list 'internaldate (elmo-imap4-parse-string)))
1870 (list 'rfc822 (elmo-imap4-parse-nstring)))
1871 ((eq token (intern elmo-imap4-rfc822-header))
1872 (list 'rfc822header (elmo-imap4-parse-nstring)))
1873 ((eq token (intern elmo-imap4-rfc822-text))
1874 (list 'rfc822text (elmo-imap4-parse-nstring)))
1875 ((eq token (intern elmo-imap4-rfc822-size))
1876 (list 'rfc822size (elmo-read (current-buffer))))
1878 (if (eq (char-before) ?\[)
1881 (upcase (elmo-imap4-parse-fetch-body-section))
1883 (eq (char-after (point)) ?<)
1884 (buffer-substring (1+ (point))
1886 (search-forward ">" nil t)
1888 (progn (elmo-imap4-forward)
1889 (elmo-imap4-parse-nstring)))
1890 (list 'body (elmo-imap4-parse-body))))
1891 ((eq token 'BODYSTRUCTURE)
1892 (list 'bodystructure (elmo-imap4-parse-body)))))
1893 (setq list (cons element list))))
1894 (and elmo-imap4-fetch-callback
1895 (elmo-imap4-fetch-callback list elmo-imap4-fetch-callback-data))
1896 (list 'fetch list))))
1898 (defun elmo-imap4-parse-status ()
1899 (let ((mailbox (elmo-imap4-parse-mailbox))
1901 (when (and mailbox (search-forward "(" nil t))
1902 (while (not (eq (char-after (point)) ?\)))
1905 (let ((token (elmo-read (current-buffer))))
1906 (cond ((eq token 'MESSAGES)
1907 (list 'messages (elmo-read (current-buffer))))
1909 (list 'recent (elmo-read (current-buffer))))
1910 ((eq token 'UIDNEXT)
1911 (list 'uidnext (elmo-read (current-buffer))))
1912 ((eq token 'UIDVALIDITY)
1913 (and (looking-at " \\([0-9]+\\)")
1914 (prog1 (list 'uidvalidity (match-string 1))
1915 (goto-char (match-end 1)))))
1917 (list 'unseen (elmo-read (current-buffer))))
1920 "Unknown status data %s in mailbox %s ignored"
1923 (and elmo-imap4-status-callback
1924 (funcall elmo-imap4-status-callback
1926 elmo-imap4-status-callback-data))
1927 (list 'status status)))
1930 (defmacro elmo-imap4-value (value)
1931 (` (if (eq (, value) 'NIL) nil
1934 (defmacro elmo-imap4-nth (pos list)
1935 (` (let ((value (nth (, pos) (, list))))
1936 (elmo-imap4-value value))))
1938 (defun elmo-imap4-parse-namespace ()
1941 (copy-sequence elmo-imap4-extra-namespace-alist)
1942 (elmo-imap4-parse-namespace-subr
1943 (elmo-read (concat "(" (buffer-substring
1944 (point) (point-max))
1947 (defun elmo-imap4-parse-namespace-subr (ns)
1948 (let (prefix delim namespace-alist default-delim)
1949 ;; 0: personal, 1: other, 2: shared
1951 (setq namespace-alist
1952 (nconc namespace-alist
1956 (setq prefix (elmo-imap4-nth 0 namespace)
1957 delim (elmo-imap4-nth 1 namespace))
1958 (if (and prefix delim
1960 (concat (regexp-quote delim) "\\'")
1962 (setq prefix (substring prefix 0
1963 (match-beginning 0))))
1964 (if (eq (length prefix) 0)
1965 (progn (setq default-delim delim) nil)
1968 (if (string= (downcase prefix) "inbox")
1969 "[Ii][Nn][Bb][Oo][Xx]"
1970 (regexp-quote prefix))
1973 (elmo-imap4-nth i ns))))))
1975 (setq namespace-alist
1976 (nconc namespace-alist
1977 (list (cons "^.*$" default-delim)))))
1980 (defun elmo-imap4-parse-acl ()
1981 (let ((mailbox (elmo-imap4-parse-mailbox))
1982 identifier rights acl)
1983 (while (eq (char-after (point)) ?\ )
1984 (elmo-imap4-forward)
1985 (setq identifier (elmo-imap4-parse-astring))
1986 (elmo-imap4-forward)
1987 (setq rights (elmo-imap4-parse-astring))
1988 (setq acl (append acl (list (cons identifier rights)))))
1989 (list 'acl acl mailbox)))
1991 (defun elmo-imap4-parse-flag-list ()
1992 (let ((str (buffer-substring (+ (point) 1)
1993 (progn (search-forward ")" nil t)
1995 (unless (eq (length str) 0)
1996 (split-string str))))
1998 (defun elmo-imap4-parse-envelope ()
1999 (when (eq (char-after (point)) ?\()
2000 (elmo-imap4-forward)
2001 (vector (prog1 (elmo-imap4-parse-nstring);; date
2002 (elmo-imap4-forward))
2003 (prog1 (elmo-imap4-parse-nstring);; subject
2004 (elmo-imap4-forward))
2005 (prog1 (elmo-imap4-parse-address-list);; from
2006 (elmo-imap4-forward))
2007 (prog1 (elmo-imap4-parse-address-list);; sender
2008 (elmo-imap4-forward))
2009 (prog1 (elmo-imap4-parse-address-list);; reply-to
2010 (elmo-imap4-forward))
2011 (prog1 (elmo-imap4-parse-address-list);; to
2012 (elmo-imap4-forward))
2013 (prog1 (elmo-imap4-parse-address-list);; cc
2014 (elmo-imap4-forward))
2015 (prog1 (elmo-imap4-parse-address-list);; bcc
2016 (elmo-imap4-forward))
2017 (prog1 (elmo-imap4-parse-nstring);; in-reply-to
2018 (elmo-imap4-forward))
2019 (prog1 (elmo-imap4-parse-nstring);; message-id
2020 (elmo-imap4-forward)))))
2022 (defsubst elmo-imap4-parse-string-list ()
2023 (cond ((eq (char-after (point)) ?\();; body-fld-param
2025 (elmo-imap4-forward)
2026 (while (setq str (elmo-imap4-parse-string))
2028 (elmo-imap4-forward))
2029 (nreverse strlist)))
2030 ((elmo-imap4-parse-nil)
2033 (defun elmo-imap4-parse-body-extension ()
2034 (if (eq (char-after (point)) ?\()
2036 (elmo-imap4-forward)
2037 (push (elmo-imap4-parse-body-extension) b-e)
2038 (while (eq (char-after (point)) ?\ )
2039 (elmo-imap4-forward)
2040 (push (elmo-imap4-parse-body-extension) b-e))
2041 (assert (eq (char-after (point)) ?\)))
2042 (elmo-imap4-forward)
2044 (or (elmo-imap4-parse-number)
2045 (elmo-imap4-parse-nstring))))
2047 (defsubst elmo-imap4-parse-body-ext ()
2049 (when (eq (char-after (point)) ?\ );; body-fld-dsp
2050 (elmo-imap4-forward)
2052 (if (eq (char-after (point)) ?\()
2054 (elmo-imap4-forward)
2055 (push (elmo-imap4-parse-string) dsp)
2056 (elmo-imap4-forward)
2057 (push (elmo-imap4-parse-string-list) dsp)
2058 (elmo-imap4-forward))
2059 (assert (elmo-imap4-parse-nil)))
2060 (push (nreverse dsp) ext))
2061 (when (eq (char-after (point)) ?\ );; body-fld-lang
2062 (elmo-imap4-forward)
2063 (if (eq (char-after (point)) ?\()
2064 (push (elmo-imap4-parse-string-list) ext)
2065 (push (elmo-imap4-parse-nstring) ext))
2066 (while (eq (char-after (point)) ?\ );; body-extension
2067 (elmo-imap4-forward)
2068 (setq ext (append (elmo-imap4-parse-body-extension) ext)))))
2071 (defun elmo-imap4-parse-body ()
2073 (when (eq (char-after (point)) ?\()
2074 (elmo-imap4-forward)
2075 (if (eq (char-after (point)) ?\()
2077 (while (and (eq (char-after (point)) ?\()
2078 (setq subbody (elmo-imap4-parse-body)))
2079 (push subbody body))
2080 (elmo-imap4-forward)
2081 (push (elmo-imap4-parse-string) body);; media-subtype
2082 (when (eq (char-after (point)) ?\ );; body-ext-mpart:
2083 (elmo-imap4-forward)
2084 (if (eq (char-after (point)) ?\();; body-fld-param
2085 (push (elmo-imap4-parse-string-list) body)
2086 (push (and (elmo-imap4-parse-nil) nil) body))
2088 (append (elmo-imap4-parse-body-ext) body)));; body-ext-...
2089 (assert (eq (char-after (point)) ?\)))
2090 (elmo-imap4-forward)
2093 (push (elmo-imap4-parse-string) body);; media-type
2094 (elmo-imap4-forward)
2095 (push (elmo-imap4-parse-string) body);; media-subtype
2096 (elmo-imap4-forward)
2097 ;; next line for Sun SIMS bug
2098 (and (eq (char-after (point)) ? ) (elmo-imap4-forward))
2099 (if (eq (char-after (point)) ?\();; body-fld-param
2100 (push (elmo-imap4-parse-string-list) body)
2101 (push (and (elmo-imap4-parse-nil) nil) body))
2102 (elmo-imap4-forward)
2103 (push (elmo-imap4-parse-nstring) body);; body-fld-id
2104 (elmo-imap4-forward)
2105 (push (elmo-imap4-parse-nstring) body);; body-fld-desc
2106 (elmo-imap4-forward)
2107 (push (elmo-imap4-parse-string) body);; body-fld-enc
2108 (elmo-imap4-forward)
2109 (push (elmo-imap4-parse-number) body);; body-fld-octets
2111 ;; ok, we're done parsing the required parts, what comes now is one
2114 ;; envelope (then we're parsing body-type-msg)
2115 ;; body-fld-lines (then we're parsing body-type-text)
2116 ;; body-ext-1part (then we're parsing body-type-basic)
2118 ;; the problem is that the two first are in turn optionally followed
2119 ;; by the third. So we parse the first two here (if there are any)...
2121 (when (eq (char-after (point)) ?\ )
2122 (elmo-imap4-forward)
2124 (cond ((eq (char-after (point)) ?\();; body-type-msg:
2125 (push (elmo-imap4-parse-envelope) body);; envelope
2126 (elmo-imap4-forward)
2127 (push (elmo-imap4-parse-body) body);; body
2128 (elmo-imap4-forward)
2129 (push (elmo-imap4-parse-number) body));; body-fld-lines
2130 ((setq lines (elmo-imap4-parse-number));; body-type-text:
2131 (push lines body));; body-fld-lines
2133 (backward-char)))));; no match...
2135 ;; ...and then parse the third one here...
2137 (when (eq (char-after (point)) ?\ );; body-ext-1part:
2138 (elmo-imap4-forward)
2139 (push (elmo-imap4-parse-nstring) body);; body-fld-md5
2141 (append (elmo-imap4-parse-body-ext) body)));; body-ext-1part..
2143 (assert (eq (char-after (point)) ?\)))
2144 (elmo-imap4-forward)
2148 (product-provide (provide 'elmo-imap4) (require 'elmo-version))
2150 ;;; elmo-imap4.el ends here