1

The Mail application in macOS allows creation of rules, such as Sender X and keyword Y in subject -> mark as read and move to archive. I am looking for something similar in mu4e.

Smart refiling has a similar feature:

you can select some messages in the headers view, then press r, and have them all marked for refiling to their particular folders.

What I'm looking for is that result without having to see the message or press r to refile it.

Does it exist?

  • See smart refiling. – jagrg Feb 19 at 0:33
  • @jagrg Smart refiling still requires user input, I'd like the messages to be refiled without even seeing them. I updated the question. – miguelmorin Feb 19 at 10:33
1

I don't think so. In any case, the function that does the refiling is called mu4e~proc-move, so all you need is the message's docid and target folder. But how do you know which messages are new during the indexing process? One way around this is to find messages flagged unread using the mu find command (see below).

(defvar mu4e-find-new-messages-command
  "mu find maildir:/YOUR_INBOX_FOLDER flag:unread --format=sexp 2>/dev/null")

(defun mu4e-refile-messages ()
  (let* ((cmd mu4e-find-new-messages-command)
         (res (concat "(list" (shell-command-to-string cmd) ")"))
         (msgs (car (read-from-string res))))
    (unless (equal '(list) msgs)
      (dolist (msg msgs)
        (when-let ((docid (mu4e-message-field msg :docid))
                   (maildir (funcall mu4e-refile-folder msg)))
          (mu4e~proc-move docid maildir))))))

(add-to-list 'mu4e-index-updated-hook 'mu4e-refile-messages)
| improve this answer | |
  • Is the logic that I would create smart refiling rules as in the manual, and your function and hook applies them each time the mu4e index is updated? – miguelmorin Feb 20 at 14:19
  • That's the logic, yes. – jagrg Feb 20 at 16:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.