In my Perl program, I am fetching an encrypted email, decoding it and processing it further. I am facing a problem since the data contains: %localappdata%
I could not use the qw() function directly since the data is being fetched from the mailbox. Is there a way to apply this function?
How do I use it so that special characters are not recognized as special characters but normal characters? Or is there a regex to do so?
Update: The processing that I am doing is converting the data to HTML and sending it to REST API using Curl.
Update 2: Here is the code: https://gist.github.com/8cd801fedeb90a5ca7fc
$description contains %localappdata%
OK thank you for showing your complete code. The problem is that you are passing the contents of
$bodyas a URL parameter, and so the HTTP protocl needs various characters escaping to pass them through properly.You can achieve this with the
URI::Escapemodule, and you will no longer have to do the sanitizing that you do on line 125 and the lines following# clean the body.This program uses a string containing all the problem characters you have identified, and translates it using the module. If you use
uri_escapeon the contents of$bodybefore appending it to the URL for Curl then everything should work.output
Update
For manipulating URLs in general it is best to use the
URImodule which will do all necessary escaping for you in both the path and the query part of the URL.The program below shows how to generate the URL you need to pass to
$curl->setoptusing this methodoutput
(Note that this method uses
+instead of%20for space characters. Either is acceptable in the query portion of a URL.)This URL can be set as a Curl option directly by writing