Function: nnimap-parse-flags

nnimap-parse-flags is a byte-compiled function defined in nnimap.el.gz.

Signature

(nnimap-parse-flags SEQUENCES)

Source Code

;; Defined in /usr/src/emacs/lisp/gnus/nnimap.el.gz
(defun nnimap-parse-flags (sequences)
  (goto-char (point-min))
  ;; Change \Delete etc to %Delete, so that the Emacs Lisp reader can
  ;; read it.
  (subst-char-in-region (point-min) (point-max)
			?\\ ?% t)
  (let (start end articles groups uidnext elems permanent-flags
	      uidvalidity vanished highestmodseq)
    (dolist (elem sequences)
      (cl-destructuring-bind (group-sequence flag-sequence totalp group command)
	  elem
	(setq start (point))
	(when (and
	       ;; The EXAMINE was successful.
	       (search-forward (format "\n%d OK " group-sequence) nil t)
	       (progn
		 (forward-line 1)
		 (setq end (point))
		 (goto-char start)
		 (setq permanent-flags
		       (if (equal command "SELECT")
			   (and (search-forward "PERMANENTFLAGS " end t)
				(read (current-buffer)))
			 'not-scanned))
		 (goto-char start)
		 (setq uidnext
		       (and (search-forward "UIDNEXT " end t)
			    (read (current-buffer))))
		 (goto-char start)
		 (setq uidvalidity
		       (and (re-search-forward "UIDVALIDITY \\([0-9]+\\)"
					       end t)
			    ;; Store UIDVALIDITY as a string; before bignums,
			    ;; it was usually too big for 32-bit Emacsen,
			    ;; and we don't want to change the format now.
			    (match-string 1)))
		 (goto-char start)
		 (setq vanished
		       (and (eq flag-sequence 'qresync)
			    (re-search-forward "^\\* VANISHED .*? \\([0-9:,]+\\)"
					       end t)
			    (match-string 1)))
		 (goto-char start)
		 (setq highestmodseq
		       (and (re-search-forward "HIGHESTMODSEQ \\([0-9]+\\)"
					       end t)
			    (match-string 1)))
		 (goto-char end)
		 (forward-line -1))
	       ;; The UID FETCH FLAGS was successful.
	       (or (eq flag-sequence 'qresync)
		   (search-forward (format "\n%d OK " flag-sequence) nil t)))
	  (if (eq flag-sequence 'qresync)
	      (progn
		(goto-char start)
		(setq start end))
	    (setq start (point))
	    (goto-char end))
	  (while (re-search-forward "^\\* [0-9]+ FETCH " start t)
	    (progn
	      (setq elems (read (current-buffer)))
	      (push (cons (cadr (memq 'UID elems))
			  (cadr (memq 'FLAGS elems)))
		    articles)))
	  (push (nconc (list group uidnext totalp permanent-flags uidvalidity
			     vanished highestmodseq)
		       articles)
		groups)
	  (if (eq flag-sequence 'qresync)
	      (goto-char end)
	    (setq end (point)))
	  (setq articles nil))))
    groups))