mh-e. Node: Customizing Organizing

PREV Customizing Deleting UP Customizing Moving Mail NEXT Customizing Printing

3.4.3: Organizing Your Mail with Folders

By default, operations on folders work only one level at a time. Set mh-recursive-folders to non-nil to operate on all folders. This mostly means that you'll be able to see all your folders when you press TAB when prompted for a folder name. The variable mh-auto-folder-collect is normally turned on to generate a list of folder names in the background as soon as mh-e is loaded. Otherwise, the list is generated when you need a folder name the first time (as with o (mh-refile-msg)). If you have a lot of folders and you have mh-recursive-folders set, this could take a while, which is why it's nice to do the folder collection in the background.

The function mh-default-folder-for-message-function is used by o (mh-refile-msg) and C-c C-f C-f (mh-to-fcc) to generate a default folder. The generated folder name should be a string with a `+' before it. For each of my correspondents, I use the same name for both an alias and a folder. So, I wrote a function that takes the address in the `From:' header field, finds it in my alias file, and returns the alias, which is used as a default folder name. This is the most complicated example given here, and it demonstrates several features of Emacs Lisp programming. You should be able to drop this into `~/.emacs', however. If you use this to store messages in a subfolder of your Mail directory, you can modify the line that starts `(format +%s...' and insert your subfolder after the folder symbol `+'.

Creating useful default folder for refiling via mh-default-folder-for-message-function

(defun my-mh-folder-from-address ()
  "Determine folder name from address.
Takes the address in the From: header field, and returns its corresponding
alias from the user's personal aliases file. Returns nil if the address
was not found."
  (require 'rfc822)                         ; for the rfc822 functions
  (search-forward-regexp "^From: \\(.*\\)") ; grab header field contents
  (save-excursion                     ; save state
    (let ((addr (car (rfc822-addresses  ; get address
                      (buffer-substring (match-beginning 1)
                                        (match-end 1)))))
          (buffer (get-buffer-create " *temp*")) ; set local variables
      (set-buffer buffer)             ; jump to temporary buffer
      (unwind-protect                 ; run kill-buffer when done
          (progn                      ; function grouping construct
            (insert-file-contents (expand-file-name "aliases"
            (goto-char (point-min))   ; grab aliases file and go to start
            (setq folder
                  ;; Search for the given address, even commented-out
                  ;; addresses are found!
                  ;; The function search-forward-regexp sets values that are
                  ;; later used by match-beginning and match-end.
                  (if (search-forward-regexp (format "^;*\\(.*\\):.*%s"
                                                     addr) nil t)
                      ;; NOTE WELL: this is what the return value looks like.
                      ;; You can modify the format string to match your own
                      ;; Mail hierarchy.
                      (format "+%s" (buffer-substring (match-beginning 1)
                                                      (match-end 1))))))
        (kill-buffer buffer))          ; get rid of our temporary buffer
      folder)))                        ; function's return value

(setq mh-default-folder-for-message-function 'my-mh-folder-from-address)

The hook mh-refile-msg-hook is called after a message is marked to be refiled.

The variable mh-sortm-args holds extra arguments to pass on to the sortm command. Note: this variable is only consulted when a prefix argument is given to M-x mh-sort-folder. It is used to override any arguments given in a sortm: entry in your MH profile (`~/.mh_profile').

  • Customizing Scan Line Formats
  • PREV Customizing Deleting UP Customizing Moving Mail NEXT Customizing Printing