By setting mu4e-refile-folder to a function, you can dynamically
determine where messages are to be refiled.
If you want to do this based on the subject of a message, you could use a function that matches the message subject against a list of regular expressions, and choose the refile-folder based on that; for example:
(defun my-mu4e-refile-folder-function (msg)
"Set the refile folder for MSG."
(or (cdr-safe
(seq-find (lambda(cell)
(mu4e-matches-subject-p msg (car cell)))
'(("soccer\\|football" . "/football")
("school" . "/school")
("homepage\\|website" . "/website"))))
"/general")) ;; default; must always return a valid folder
(setq mu4e-refile-folder #'my-mu4e-refile-folder-function)
Note the "/general" folder: it is the default folder in case the subject
does not match any of the regular expressions. If you have multiple accounts,
you can accommodate them as well, for example with the following. It shows how
you can use flexible, account-specific strategies to determine the
refile-folder.
(defun my-mu4e-refile-folder-function (msg)
"Set the refile folder for MSG, multiple accounts.
Assume all message for some account arrive in some account-specific
folder, e.g. \"Account1\", \"Account2\"."
(let ((maildir (mu4e-message-field msg :maildir)))
(cond
;; for account1, we refile based on the address a message
;; was sent to (mailing lists)
((string-match-p "Account1" maildir)
(or (cdr-safe
(seq-find (lambda(cell)
(mu4e-contact-matches-p msg :recip (car cell)))
'(("mu-discuss@googlegroups.com" . "/Account1/mu4e")
("pandoc-discuss@googlegroups.com" . "/Account1/Pandoc")
("auctex@gnu.org" . "/Account1/AUCTeX"))))
"/Account1/archive"))
;; account2
((string-match-p "Account2" maildir)
(or (cdr-safe
(seq-find (lambda(cell)
(mu4e-matches-subject-p msg (car cell)))
'(("soccer\\|football" . "/Account2/football")
("school" . "/Account2/school")
("homepage\\|website" . "/Account2/website"))))
"/Account2/archive"))
;; default, catch-all
(t "/archive"))))
It is an error for mu4e-refile-folder to return anything but a valid
folder.