[gnu.emacs] RMAIL issues

rusty@GARNET.BERKELEY.EDU (04/06/89)

What I do to keep my rmail file to a reasonable size is start a new
one each month.  It's a bit complicated but it works.

=====> ~/.emacs <=====
(setq mail-mode-hook 'rcw-mail-mode-hook)
(setq rmail-mode-hook 'rcw-rmail-mode-hook)

(autoload 'rcw-mail-mode-hook "mail-mode-hook" nil t nil)
(autoload 'rcw-rmail-mode-hook "rmail-mode-hook" nil nil nil)

(autoload 'set-up-mail-archive-file-name "mail-stuff" nil nil nil)
(autoload 'set-up-rmail-file-name "mail-stuff" nil nil nil)

(set-up-rmail-file-name)

=====> rmail-mode-hook.el <=====
(defun rcw-rmail-mode-hook ()
  "Do this stuff when running rmail-mode."
  (progn
    (setq mail-use-rfc822 t)))

=====> mail-mode-hook.el <=====
(defun rcw-mail-mode-hook ()
  "Do this stuff when running mail-mode."
  (progn
    (setq mail-yank-ignored-headers "^via:\\|^mail-from:\\|^origin:\\|^status:\\|^remailed\\|^received:\\|^[a-z-]*message-id:\\|^summary-line:\\|^in-reply-to:\\|^return-path:")
    (set-up-mail-archive-file-name)))

=====> mail-stuff.el <=====
;; If you'd like copies of outgoing mail kept in mail-directory then
;; call this function.  Can be called by your mail-mode-hook or you can put
;; in your .emacs file.
(defun set-up-mail-archive-file-name ()
  "Set up the mail-archive-file-name variable."
  (let ((month (downcase (substring (current-time-string) 4 7)))
	(year (substring (current-time-string) 22 24)))
    (if (set-up-mail-directory)
	(progn
	  (setq mail-archive-file-name
		(expand-file-name
		  (format "%s/%s%s_out" mail-directory month year)))))))

;; If you'd like your RMAIL file kept in mail-directory instead of your
;; login directory then call this function.  Must be called in your .emacs
;; file; doesn't work if called by your rmail-mode-hook.
(defun set-up-rmail-file-name ()
  "Set up the RMAIL file name."
  (let ((month (downcase (substring (current-time-string) 4 7)))
	(year (substring (current-time-string) 22 24)))
    (if (set-up-mail-directory)
	(progn
	  (setq rmail-file-name
		(expand-file-name
		 (format "%s/rmail_%s%s" mail-directory month year)))))))

;; Set up the mail directory: in the user's login directory is a directory
;; named "mail", in that directory are directories with names of the form
;; mmmyy where "mmm" is the month (as a string) and yy is the year.  If the
;; mmmyy directory doesn't exist it is created, but first any non-directory
;; file with that name is moved out of the way.  Used by set-up-rmail-file-name
;; and set-up-mail-archive-file-name.
(defun set-up-mail-directory ()
  "Set up the name of directory where mail is kept (make it if it doesn't
exist)."
  (progn
    (setq mail-home
	  (expand-file-name
	   (format "~%s/mail" (user-real-login-name))))
    (if (not (boundp 'mail-directory))
	(if (file-directory-p mail-home)
	    (let ((month (downcase (substring (current-time-string) 4 7)))
		  (year (substring (current-time-string) 22 24)))
	      (setq mail-directory
		    (expand-file-name
		      (format "%s/%s%s" mail-home month year)))
	      (if (not (file-directory-p mail-directory))
		  (progn
		    (if (file-exists-p mail-directory)
			(rename-file mail-directory
				     (format "%s.bak" mail-directory)))
		    ;; should use call-process instead of shell-command
		    (shell-command (format "mkdir %s" mail-directory)))
		t)))
      t)))