IN Usermin mail ( default port 20000) you can use / set some rules / filters. ( for mail… a kind of wizard / wildcards also)
Maybe that suits you?
or as base starting point.
Further the if using postfix / dovecot / procmail you can have a look at those programms to.
Here some >
https://doc.dovecot.org/configuration_manual/push_notification/
Please post also you solution while that is this forum for!
don’t know about dovecot http api’s https://doc.dovecot.org/admin_manual/doveadm_http_api/