In your JS code as in mine, there is a flaw: if the subject fields contains JS customisation (if then else) or personalisation field, the result is not given correctly, it doesn't take into account the JS code, not interpreted, so the functions return all the labels included.
Actually, the CDATA taken is common to all messages, the delivery itself.
So it should be added 2nd pass JS interpretation, a bit as in Content Management (publication templates), in order that it would be evaluated for the accurate message for 1 contact.
I am looking for the exact syntax to do it either with your solution or mine (standard xpath object).
If someone else could help, it would be appreciated.
At the end I've managed to get the subject line into a variable by doing this:
instance.vars.subjLine = sqlGetString("select substring(dl.mdata,position('<subject><![CDATA[' in dl.mdata)+18,position(']]></subject>' in dl.mdata)-position('<subject><![CDATA[' in dl.mdata)-18 ) from nmsdelivery dl where sInternalName='DM12345'")