You'd have to be able to read PHP and write Python to get it done. You can look at the code in the RoundCube plugin that allows you to create filters in order to see what has to be done on the server and then transfer that into the Python-based Mail-in-a-Box Daemon in order to add this feature to the API offered there.
The code that you wanna read is located here on a Mail-in-a-Box server:
or here directly from the RoundCube Git:
The code that serves the API can be found here:
I'm not an active dev of this project, so I'm sure someone else can give you more in-depth pointers if you need them.