Function: mh-sub-folders-parse

mh-sub-folders-parse is a byte-compiled function defined in mh-utils.el.gz.

Signature

(mh-sub-folders-parse FOLDER CURRENT-FOLDER)

Documentation

Parse the results of "folders FOLDER" and return a list of sub-folders.

CURRENT-FOLDER is the result of "folder -fast". FOLDER will be nil or start with '+'; CURRENT-FOLDER will end with '+'. This function is a testable helper of mh-sub-folders-actual.

Source Code

;; Defined in /usr/src/emacs/lisp/mh-e/mh-utils.el.gz
(defun mh-sub-folders-parse (folder current-folder)
  "Parse the results of \"folders FOLDER\" and return a list of sub-folders.
CURRENT-FOLDER is the result of \"folder -fast\".
FOLDER will be nil or start with '+'; CURRENT-FOLDER will end with '+'.
This function is a testable helper of `mh-sub-folders-actual'."
  (let ((results ()))
    (goto-char (point-min))
    (while (not (and (eolp) (bolp)))
      (goto-char (line-end-position))
      (let ((start-pos (line-beginning-position))
            (has-pos (search-backward " has "
                                      (line-beginning-position) t)))
        (when (integerp has-pos)
          (while (equal (char-after has-pos) ? )
            (cl-decf has-pos))
          (cl-incf has-pos)
          (while (equal (char-after start-pos) ? )
            (cl-incf start-pos))
          (let* ((name (buffer-substring start-pos has-pos))
                 (first-char (aref name 0))
                 (second-char (and (length> name 1) (aref name 1)))
                 (last-char (aref name (1- (length name)))))
            (unless (member first-char '(?. ?# ?,))
              (when (and (equal last-char ?+) (equal name current-folder))
                (setq name (substring name 0 (1- (length name)))))
              ;; nmh outputs double slash in root folder, e.g., "//tmp"
              (when (and (equal first-char ?/) (equal second-char ?/))
                (setq name (substring name 1)))
              (push
               (cons name
                     (search-forward "(others)" (line-end-position) t))
               results))))
        (forward-line 1)))
    (setq results (nreverse results))
    (when (stringp folder)
      (setq results (cdr results))
      (let ((folder-name-len (length (format "%s/" (substring folder 1)))))
        (when (equal "+/" folder)
          ;; folder "+/" includes a trailing slash
          (cl-decf folder-name-len))
        (setq results (mapcar (lambda (f)
                                (cons (substring (car f) folder-name-len)
                                      (cdr f)))
                              results))))
    results))