The following command returns the raw source of an email, as a string:
set myselection to selection
source of item 1 of myselection as string
end tell
In the result box, that string is properly escaped. Quotes have \ before them, it looks ready to be used.
HOWEVER when I try to use that string in safari to submit it into a form field (specifically a textarea), the escaping disappears and I get javascript errors.
tell application "Safari"
set JSCommand to "document.getElementsByName('spam')[0].value = '" & MailSource & "';"
do JavaScript JSCommand in document 1
end tell
What gets sent to Safari is no longer escaped, and I end up getting javascript errors because the first apostrophe prematurely ends the string and the rest of the string immediately throws an error, as you would expect.
WHO exactly is un-escaping the string? How can I prevent that?