Hello!
I created a couple of scripts that manage mailing lists. I use a dedicated Mac (a server) which means that I can run the main script ("Script A", below) at 10s intervals. (This is to avoid the script interrupting the user, but I suppose you could use a mail rule that processes all incoming mail instead.)
The principle is this:
Script A: Gets all unread incoming mail and compares the sender's domain to a domain list that's maintained by Script B. If there's a match, each message is moved to the "Lists" subfolder.
Script B: Gets the sender domains of all messages in the "Lists" subfolder. If a new domain is found, it's added to the domain list. The list is written-out to disk. (This means that if I identify a message from a new domain that I want to be moved automatically in future, I can move it manually once and the scripts will do it for me in future.)
I can provide more information if this is of interest, but I think that the scripts as written are too specific to my setup to be of much use. Perhaps you can explain what it is you want to do?