In Gmail, unfortunately, this is not possible.
I returned to my email client, Gnus (due to its amazing flexibility and ease) to do this. Details are explained in the section โ6.3.3 Client-side IMAP Splittingโ in its manual.
It was surprisingly easy. In my ".gnus.el" file, I put (I use the nnimap server for Gmail) something like this:
(setq nnimap-split-methods '(("mail-list-folder" "Return-Path: mail-list-address") ("INBOX" ""))
You will need to adapt the parts "mail-list-folder" (label) and "Return-Path: mail-list-address" accordingly. A string containing "Return-Path: ..." is a regular expression, so you can use wildcards such as. * And even groups. For example, to filter out some of the lists that I subscribed to, I have:
(setq nnimap-split-methods '(("list.\\1" "^Return-Path: <\\(.*\\)-bounces.*@gnu.org>") ("INBOX" ""))
Pay attention to the capture group \\ (. * \\), which is used to form my label, as well as the adaptations necessary to match the return path generated by the mailing list program.
If you want to try, I can suggest the following wiki to get started: https://www.emacswiki.org/emacs/GnusGmail .
source share