procmail
[Top] [All Lists]

Re: Procmail and Variables and PHP

2001-01-18 03:10:23
At 12:32 2001-01-17 -0500, Brian C. Doyle wrote:

IE: RP="info about RP" like put into brackets or quotes or something so that when i echo out RP in php it is seen as "info about RP" and not info.

Uhm, have you tried to echo it out into the PHP that you're creating by encapsulating the string in quotes _at the time_, a shell command would be like:

        echo \"$ENVVAR\"

Better yet have procmail replace all spaces " " with an underscore "_"

Clearly, you should be using sed (which is _not_ part of procmail, but procmail can easily make use of it).

to escape doublequotes:

        sed s/\"/\\\"/g

switch spaces to underscores:

        sed s/\ /_/g

If you elect to insert quotes into the string, you should so so AFTER escaping in-string quotes. Further, you should probably be aware of language-specific syntax - for instance, the difference with handling "" and '' strings, and also variable names found within the string (so you should escape $ as well, just to be safe)

        sed s/\$/\\\$/g

        sed 's/\(.*\)/\"\1\"/'

To amalgamate these into an expression which sed can execute at one invocation:

        sed 's/\(["\$]\)/\\\1/g'\;s/\ /_/g\;'s/\(.*\)/\"\1\"/'


I suggest if the above doesn't make clear sense to you that you read up on regular expressions. There are two applicable ORA (O'Reilly & Associates) books pertinent here: _Mastering_Regular_Expressions_ and _sed_&_awk_


an example of using that sed regexp in your procmail filter:

:0h
SUBJECT=|(formail -zxSubject:|sed 's/\(["\$]\)/\\\1/g'\;
s/\ /_/g\;'s/\(.*\)/\"\1\"/')

(the regexp should be all on one line)


If you want to test the regexp, construct yourself a text file with different message strings in it, and then run

        sed regexp filename

The escaped sequences will appear out on the terminal.


Disclaimer: there are likely a number of other things which you should take care to escape and preprocess before emitting material from email into a script, either for security or mere syntax reasons -- it is your responsibility to evaluate the scripting syntax - I have merely identified for you a tool that can do the job, and a script that can specifically handle what you indicated needed to be converted -- anything further is your own responsibility, and I specificall disclaim any responsibility for ill effects you may have from employing anything I have described or suggested. I only make Warranties for advice given under a consulting contract with appropriate retainer fees.


---
 Please DO NOT carbon me on list replies.  I'll get my copy from the list.

 Sean B. Straw / Professional Software Engineering
 Post Box 2395 / San Rafael, CA  94912-2395

_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

<Prev in Thread] Current Thread [Next in Thread>