Subject: Re: [nnir] (invalid-read-syntax "#")

From: Andrew Cohen <[email-masked]>
Date: Thu, 11 Aug 2011 13:06:27 -0400

I don't think this is a bug in nnir. It looks like its a bug in
`nnimap-transform-headers'. If I read the RFC correctly the parsing of a
bodystructure is special for a bodytype of "MESSAGE" and subtype of
"RFC822".  Can you try evaluating the modified version of
`nnimap-transform-headers' below and see if it fixes the problem?

(defun nnimap-transform-headers ()
  (goto-char (point-min))
  (let (article bytes lines size string)
    (block nil
      (while (not (eobp))
	(while (not (looking-at "\\* [0-9]+ FETCH.+UID \\([0-9]+\\)"))
	  (delete-region (point) (progn (forward-line 1) (point)))
	  (when (eobp)
	    (return)))
	(setq article (match-string 1))
	;; Unfold quoted {number} strings.
	(while (re-search-forward "[^]][ (]{\\([0-9]+\\)}\r?\n"
				  (1+ (line-end-position)) t)
	  (setq size (string-to-number (match-string 1)))
	  (delete-region (+ (match-beginning 0) 2) (point))
	  (setq string (buffer-substring (point) (+ (point) size)))
	  (delete-region (point) (+ (point) size))
	  (insert (format "%S" string)))
	(setq bytes (nnimap-get-length)
	      lines nil)
	(beginning-of-line)
	(setq size
	      (and (re-search-forward "RFC822.SIZE \\([0-9]+\\)"
				      (line-end-position)
				      t)
		   (match-string 1)))
	(beginning-of-line)
	(when (search-forward "BODYSTRUCTURE" (line-end-position) t)
	  (let ((structure (ignore-errors
			     (read (current-buffer)))))
	    (while (and (consp structure)
			(not (stringp (car structure))))
	      (setq structure (car structure)))
	    (setq lines (if (and 
			     (equal (nth 0 structure) "MESSAGE") 
			     (equal (nth 1 structure) "RFC822"))
			    (nth 9 structure)
			  (nth 7 structure)))))
	(delete-region (line-beginning-position) (line-end-position))
	(insert (format "211 %s Article retrieved." article))
	(forward-line 1)
	(when size
	  (insert (format "Chars: %s\n" size)))
	(when lines
	  (insert (format "Lines: %s\n" lines)))
	(unless (re-search-forward "^\r$" nil t)
	  (goto-char (point-max)))
	(delete-region (line-beginning-position) (line-end-position))
	(insert ".")
	(forward-line 1)))))