Function: nnheader-parse-head

nnheader-parse-head is a byte-compiled function defined in nnheader.el.gz.

Signature

(nnheader-parse-head &optional NAKED TEMP)

Documentation

Parse data of type header in the current buffer and return a mail header.

Modify the buffer contents in the process. The buffer is assumed to begin each header with an "Article retrieved" line with an article number; if NAKED is non-nil this line is assumed absent, and the buffer should contain a single header's worth of data. If TEMP is non-nil the data is first copied to a temporary buffer leaving the original buffer untouched.

Source Code

;; Defined in /usr/src/emacs/lisp/gnus/nnheader.el.gz
(defun nnheader-parse-head (&optional naked temp)
  "Parse data of type `header' in the current buffer and return a mail header.
Modify the buffer contents in the process.  The buffer is assumed
to begin each header with an \"Article retrieved\" line with an
article number; if NAKED is non-nil this line is assumed absent,
and the buffer should contain a single header's worth of data.
If TEMP is non-nil the data is first copied to a temporary buffer
leaving the original buffer untouched."
  (let ((cur (current-buffer))
	(num 0)
	(beg (point-min))
	(end (point-max))
	buf)
    (when (or naked
	      ;; Search to the beginning of the next header.  Error
	      ;; messages do not begin with 2 or 3.
	      (when (re-search-forward "^[23][0-9]+ " nil t)
		(setq num (read cur)
		      beg (point)
		      end (if (search-forward "\n.\n" nil t)
                              (goto-char (- (point) 2))
			    (point)))))
      ;; When TEMP copy the data to a temporary buffer.
      (if temp
	  (progn
	    (set-buffer (setq buf (generate-new-buffer " *nnheader-temp*")))
	    (insert-buffer-substring cur beg end))
        ;; Otherwise just narrow to the data.
	(narrow-to-region beg end))
      (let ((case-fold-search t)
	    (buffer-read-only nil)
	    header)
	(nnheader-remove-cr-followed-by-lf)
	(ietf-drums-unfold-fws)
        (subst-char-in-region (point-min) (point-max) ?\t ?\s t)
        (subst-char-in-region (point-min) (point-max) ?\r ?\s t)
	(goto-char (point-min))
	(insert "\n")
	(setq header (nnheader-head-make-header num))
	(goto-char (point-min))
	(delete-char 1)
	(if temp
	    (kill-buffer buf)
	  (goto-char (point-max))
	  (widen))
	(when gnus-alter-header-function
	  (funcall gnus-alter-header-function header))
	header))))