AND THIS IS A NO-GO.
After much talking, thinking, trial and error and technical difficulties, I have decided NOT to introduce IM commands at all. As a reminder, I wanted to make the viewer execute commands received through object IMs as well as llOwnerSays, provided the object that sends IMs to you passes some very tight tests such as "its group must the same as the parcel you are on", or "its owner must be in your friends list and must be able to map you".
Well the main reason of my step back is that many people are concerned with upcoming unsolicited @version=nnnn IMs from objects that they don't even know, eventually leading them to leave public BDSM areas because of the spam. Truth is, there is no way that I know of to check whether you're using my viewer or not, except by actually asking you with that very message and adapting to the answer or lack thereof. So the reason is social.
Technically I had to adapt too, because when receiving task IMs the viewer does not have a clue about the actual UUID of the object that sent the IM. Presumably because that object could be in another sim, and not even the root prim of its link set. I don't really know why we don't get that UUID but at least we have the owner of the object, along with its position and region, so that would have been possible.
So instead of relying on IMs coming directly from cages, the user will have to wear an attachment to "relay" chat messages from the cage (or furniture, let's not forget furniture designers) to the avatar through llOwnerSay like before. That attachment would decide to relay commands by checking the object against rules very much like the ones I have been describing in pseudocode in my previous post. So basically, what I wanted to do in the viewer will be done in a script instead, which is a sane approach if you ask me.
To be honest I am not totally decided yet. But we're making progress here, and I would like to thank you all for your precious comments and discussions in-world, special thanks going to Chorazin Allen for his very detailed concerns (and also his Relay mockup) and Ariel Moonsoo for commenting here. People who know me well know how difficult it is to convince me of something, 'cause I am more stubborn than a donkey and twice as slow* :)
(* The first one who can tell me where that line comes from and who said it, receives a full shibari set for free, or something else of the same value if they already have it ^_^)