Function: nnmail-process-unix-mail-format
nnmail-process-unix-mail-format is a byte-compiled function defined in
nnmail.el.gz.
Signature
(nnmail-process-unix-mail-format FUNC ARTNUM-FUNC)
Source Code
;; Defined in /usr/src/emacs/lisp/gnus/nnmail.el.gz
(defun nnmail-process-unix-mail-format (func artnum-func)
(let ((case-fold-search t)
(count 0)
start message-id content-length end skip head-end)
(goto-char (point-min))
(if (not (and (re-search-forward "^From " nil t)
(goto-char (match-beginning 0))))
;; Possibly wrong format?
(error "Error, unknown mail format! (Possibly corrupted %s `%s'.)"
(if (buffer-file-name) "file" "buffer")
(or (buffer-file-name) (buffer-name)))
;; Carry on until the bitter end.
(while (not (eobp))
(setq start (point)
end nil)
;; Find the end of the head.
(narrow-to-region
start
(if (search-forward "\n\n" nil t)
(1- (point))
;; This will never happen, but just to be on the safe side --
;; if there is no head-body delimiter, we search a bit manually.
(while (and (looking-at "From \\|[^ \t]+:")
(not (eobp)))
(forward-line 1))
(point)))
;; Find the Message-ID header.
(goto-char (point-min))
(if (re-search-forward "^Message-ID[ \t]*:[ \n\t]*\\(<[^>]+>\\)" nil t)
(setq message-id (match-string 1))
(save-excursion
(when (re-search-forward "^Message-ID[ \t]*:" nil t)
(beginning-of-line)
(insert "Original-")))
;; There is no Message-ID here, so we create one.
(forward-line 1)
(insert "Message-ID: " (setq message-id (nnmail-message-id)) "\n"))
;; Look for a Content-Length header.
(goto-char (point-min))
(if (not (re-search-forward
"^Content-Length:[ \t]*\\([0-9]+\\)" nil t))
(setq content-length nil)
(setq content-length (string-to-number (match-string 1)))
;; We destroy the header, since none of the backends ever
;; use it, and we do not want to confuse other mailers by
;; having a (possibly) faulty header.
(beginning-of-line)
(insert "X-"))
(run-hooks 'nnmail-prepare-incoming-header-hook)
;; Find the end of this article.
(goto-char (point-max))
(widen)
(setq head-end (point))
;; We try the Content-Length value. The idea: skip over the header
;; separator, then check what happens content-length bytes into the
;; message body. This should be either the end of the buffer, the
;; message separator or a blank line followed by the separator.
;; The blank line should probably be deleted. If neither of the
;; three is met, the content-length header is probably invalid.
(when content-length
(forward-line 1)
(setq skip (+ (point) content-length))
(goto-char skip)
(cond ((or (= skip (point-max))
(= (1+ skip) (point-max)))
(setq end (point-max)))
((looking-at "From ")
(setq end skip))
((looking-at "[ \t]*\n\\(From \\)")
(setq end (match-beginning 1)))
(t (setq end nil))))
(if end
(goto-char end)
;; No Content-Length, so we find the beginning of the next
;; article or the end of the buffer.
(goto-char head-end)
(or (nnmail-search-unix-mail-delim)
(goto-char (point-max))))
;; Allow the backend to save the article.
(save-excursion
(save-restriction
(narrow-to-region start (point))
(goto-char (point-min))
(incf count)
(nnmail-check-duplication message-id func artnum-func)
(setq end (point-max))))
(goto-char end)))
count))