Function: rmail-get-new-mail-1

rmail-get-new-mail-1 is a byte-compiled function defined in rmail.el.gz.

Signature

(rmail-get-new-mail-1 FILE-NAME FILES DELETE-FILES)

Documentation

Return t if new messages are detected without error, nil otherwise.

Source Code

;; Defined in /usr/src/emacs/lisp/mail/rmail.el.gz
(defun rmail-get-new-mail-1 (file-name files delete-files)
  "Return t if new messages are detected without error, nil otherwise."
  (save-excursion
    (save-restriction
      (let ((new-messages 0)
	    (spam-filter-p (and (featurep 'rmail-spam-filter)
				rmail-use-spam-filter))
	    (blurb "")
            (mod-p (buffer-modified-p))
	    result success suffix)
	(narrow-to-region (point) (point))
	;; Read in the contents of the inbox files, renaming them as
	;; necessary, and adding to the list of files to delete
	;; eventually.
	(unwind-protect
	    (progn
	      ;; Set modified now to lock the file, so that we don't
	      ;; encounter locking problems later in the middle of
	      ;; reading the mail.
	      (set-buffer-modified-p t)
	      (if file-name
		  (rmail-insert-inbox-text files nil)
		(setq delete-files (rmail-insert-inbox-text files t))))
	  ;; If there was no new mail, or we aborted before actually
	  ;; trying to get any, mark buffer unmodified, unless it was
	  ;; modified originally.  Otherwise the buffer is correctly
	  ;; marked modified and the file locked until we save out the
	  ;; new mail.
	  (if (and (null mod-p) (= (point-min) (point-max)))
	      (set-buffer-modified-p nil)))
	;; Scan the new text and convert each message to
	;; Rmail/mbox format.
	(goto-char (point-min))
	(skip-chars-forward " \n")
	(narrow-to-region (point) (point-max))
	(unwind-protect
	    (setq new-messages (rmail-add-mbox-headers)
		  success t)
	  ;; Try to delete the garbage just inserted.
	  (or success (delete-region (point-min) (point-max)))
	  ;; If we could not convert the file's inboxes, rename the
	  ;; files we tried to read so we won't over and over again.
	  (if (and (not file-name) (not success))
	      (let ((delfiles delete-files)
		    (count 0))
		(while delfiles
		  (while (file-exists-p (format "RMAILOSE.%d" count))
		    (setq count (1+ count)))
		  (rename-file (car delfiles) (format "RMAILOSE.%d" count))
		  (setq delfiles (cdr delfiles))))))
	;; Determine if there are messages.
	(unless (zerop new-messages)
	  ;; There are.  Process them.
	  (goto-char (point-min))
	  (rmail-count-new-messages)
	  (run-hooks 'rmail-get-new-mail-hook)
	  (save-buffer))
	;; Delete the old files, now that the Rmail file is saved.
	(while delete-files
	  (condition-case ()
	      ;; First, try deleting.
	      (condition-case ()
		  (delete-file (car delete-files))
		(file-error
		 ;; If we can't delete it, truncate it.
		 (write-region (point) (point) (car delete-files))))
	    (file-error nil))
	  (setq delete-files (cdr delete-files)))
	(if (zerop new-messages)
	    (when (or file-name rmail-inbox-list)
	      (message "(No new mail has arrived)"))
	  (if spam-filter-p
	      (setq blurb (rmail-get-new-mail-filter-spam new-messages))))
	(if (rmail-summary-exists)
	    (rmail-select-summary (rmail-update-summary)))
	(setq suffix (if (= 1 new-messages) "" "s"))
	(message "%d new message%s read%s" new-messages suffix blurb)
	;; Establish the return value.
	(setq result (> new-messages 0))
	result))))