One of my personal use-cases for this is to automatically parse payment receipts received from Twitch and enter the corresponding transactions into my accounting software.
In the end this software provides you with a possibility to match any mail you receive by their headers and execute a script which is able to act on those mails. The script is provided with a JSON representation of the mail on `stdin` and can yield commands (for example "mark as read", "move to mailbox", ...) to `stdout` which then will be executed on the mail.