Mu4e documentation has an example of smart refiling, whereby you can choose which maildir to refile an email based on the properties of that email. I'd like to do that, except the destination maildir's name is a property of the email (specifically the :to property).
Probably easiest to explain in an example. In the documentation:
(setq mu4e-refile-folderIn this example all emails to a google groups mu-di...@googlegroups.com end up in the /mu maildir. I'd like to go one further. I'd like %anything%@googlegroups.com to go to the maildir /googlegroups/%anything%, for any value of %anything%.
(setq mu4e-refile-folder
(lambda (msg)
(let* ((to (split-string (cdar (mu4e-message-field msg :to)) "@"))
(user (car to))
(domain (cadr to)))
(when (eq domain "googlegroups.com")
(concat "/groups/" user)))))