Function: mh-folder-from-address

mh-folder-from-address is an autoloaded and byte-compiled function defined in mh-folder.el.gz.

Signature

(mh-folder-from-address)

Documentation

Derive folder name from sender.

The name of the folder is derived as follows:

  a) The folder name associated with the first address found in
     the list mh-default-folder-list is used. Each element in
     this list contains a "Check Recipient" item. If this item is
     turned on, then the address is checked against the recipient
     instead of the sender. This is useful for mailing lists.

  b) An alias prefixed by mh-default-folder-prefix
     corresponding to the address is used. The prefix is used to
     prevent clutter in your mail directory.

Return nil if a folder name was not derived, or if the variable mh-default-folder-must-exist-flag is t and the folder does not exist.

Source Code

;; Defined in /usr/src/emacs/lisp/mh-e/mh-folder.el.gz
;;;###mh-autoload
(defun mh-folder-from-address ()
  "Derive folder name from sender.

The name of the folder is derived as follows:

  a) The folder name associated with the first address found in
     the list `mh-default-folder-list' is used. Each element in
     this list contains a \"Check Recipient\" item. If this item is
     turned on, then the address is checked against the recipient
     instead of the sender. This is useful for mailing lists.

  b) An alias prefixed by `mh-default-folder-prefix'
     corresponding to the address is used. The prefix is used to
     prevent clutter in your mail directory.

Return nil if a folder name was not derived, or if the variable
`mh-default-folder-must-exist-flag' is t and the folder does not
exist."
  ;; Loop for all entries in mh-default-folder-list
  (save-restriction
    (goto-char (point-min))
    (re-search-forward "\n\n" nil 'limit)
    (narrow-to-region (point-min) (point))
    (let ((to/cc (concat (or (message-fetch-field "to") "") ", "
                         (or (message-fetch-field "cc") "")))
          (from (or (message-fetch-field "from") ""))
          folder-name)
      (setq folder-name
            (cl-loop for list in mh-default-folder-list
                     when (string-match (nth 0 list)
                                        (if (nth 2 list) to/cc from))
                     return (nth 1 list)
                     finally return nil))

      ;; Make sure a result from `mh-default-folder-list' begins with "+"
      ;; since 'mh-expand-file-name below depends on it
      (when (and folder-name (not (eq (aref folder-name 0) ?+)))
        (setq folder-name (concat "+" folder-name)))

      ;; If not, is there an alias for the address?
      (when (not folder-name)
        (let* ((from-header (mh-extract-from-header-value))
               (address (and from-header
                             (nth 1 (mail-extract-address-components
                                     from-header))))
               (alias (and address (mh-alias-address-to-alias address))))
          (when alias
            (setq folder-name
                  (and alias (concat "+" mh-default-folder-prefix alias))))))

      ;; If mh-default-folder-must-exist-flag set, check that folder exists.
      (if (and folder-name
               (or (not mh-default-folder-must-exist-flag)
                   (file-exists-p (mh-expand-file-name folder-name))))
          folder-name))))