one way is from the javascript events there are before<command> and after<command> events. so something like:
rcmail.addEventListener('beformove', function() { /* do something */ });
If you want a more detailed example look at the JS in the vcard_attachments plugin shipped with roundcube.