[PHP] PHP milter SAPI: problem with smfi_getsymval
Hi, I compiled the milter sapi, the example in the distribution works well. BUT when I try to get the values of the sendmail macros with the smfi_getsymval function, i desperately get a blank string. I used strace and I do see the "i" sendmail macro in a red system call but I can no red its value in the PHP milter. Any ideas? Is this worth logging a bug? Thanks --- HERE is the code I used. It is just the distribution example with the milter_envfrom function modified by including two function calls: milter_log(smfi_getsymval("i")); milter_log(smfi_getsymval("{i}")); Example was retrieved from CVS: http://cvs.php.net/viewvc.cgi/php-src/sapi/milter/milter.php?revision=1.2&view=markup http://www.sendmail.com/partner/resources/development/milter_api/ * * for api details see * http://www.sendmail.com/partner/resources/development/milter_api/api.html * * below is a list of all callbacks, that are available through the milter sapi, * if you leave one or more out they simply won't get called (e.g. if you secify an * empty php file, the milter would do nothing :) */ /** * this function is called once on sapi startup, * here you can specify the actions the filter may take * * see http://www.sendmail.com/partner/resources/development/milter_api/smfi_register.html#flags */ function milter_log($msg) { $GLOBALS['log'] = fopen("/tmp/milter.log", "a"); fwrite($GLOBALS['log'], date("[H:i:s d.m.Y]") . "\t{$msg}\n"); fclose($GLOBALS['log']); } function milter_init() { milter_log("-- startup --"); milter_log("milter_init()"); smfi_setflags(SMFIF_ADDHDRS); } /** * is called once, at the start of each SMTP connection */ function milter_connect($connect) { milter_log("milter_connect('$connect')"); } /** * is called whenever the client sends a HELO/EHLO command. * It may therefore be called between zero and three times. */ function milter_helo($helo) { milter_log("milter_helo('$helo')"); } /** * is called once at the beginning of each message, * before milter_envrcpt. */ function milter_envfrom($args) { milter_log("milter_envfrom(args[])"); foreach ($args as $ix => $arg) { milter_log("\targs[$ix] = $arg"); } milter_log(smfi_getsymval("i")); milter_log(smfi_getsymval("{i}")); } /** * is called once per recipient, hence one or more times per message, * immediately after milter_envfrom */ function milter_envrcpt($args) { milter_log("milter_envrcpt(args[])"); foreach ($args as $ix => $arg) { milter_log("\targs[$ix] = $arg"); } } /** * is called zero or more times between milter_envrcpt and milter_eoh, * once per message header */ function milter_header($header, $value) { milter_log("milter_header('$header', '$value')"); } /** * is called once after all headers have been sent and processed. */ function milter_eoh() { milter_log("milter_eoh()"); } /** * is called zero or more times between milter_eoh and milter_eom. */ function milter_body($bodypart) { milter_log("milter_body('$bodypart')"); } /** * is called once after all calls to milter_body for a given message. * most of the api functions, that alter the message can only be called * within this callback. */ function milter_eom() { milter_log("milter_eom()"); /* add PHP header to the message */ smfi_addheader("X-PHP", phpversion()); } /** * may be called at any time during message processing * (i.e. between some message-oriented routine and milter_eom). */ function milter_abort() { milter_log("milter_abort()"); } /** * is always called once at the end of each connection. */ function milter_close() { milter_log("milter_close()"); } ?> Alex Madon http://atpic.com Webmaster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP milter SAPI: problem with smfi_getsymval
Hi, I did not get a reply to my question on this list, so I raised a bug. The bug was confirmed and fixed within 24 hours. Thank you the PHP team! FYI the bug number is 40083 http://bugs.php.net/40083 You can now start filtering spam using your favorite programming language! Thanks Alex, Atpic.com Webmaster http://atpic.com > Hi, > > I compiled the milter sapi, the example in the distribution works well. > BUT when I try to get the values of the sendmail macros with the > smfi_getsymval function, i desperately get a blank string. > I used strace and I do see the "i" sendmail macro in a red system call but > I can no red its value in the PHP milter. > Any ideas? > Is this worth logging a bug? > > Thanks > > --- > HERE is the code I used. It is just the distribution example with the > milter_envfrom function modified by including two function calls: > > milter_log(smfi_getsymval("i")); > milter_log(smfi_getsymval("{i}")); > > Example was retrieved from CVS: > > http://cvs.php.net/viewvc.cgi/php-src/sapi/milter/milter.php?revision=1.2&view=markup > > /** > * example milter script > * > * run: php-milter -D -p /path/to/sock milter.php > * > * for details on how to set up sendmail and configure the milter see > * http://www.sendmail.com/partner/resources/development/milter_api/ > * > * for api details see > * > http://www.sendmail.com/partner/resources/development/milter_api/api.html > * > * below is a list of all callbacks, that are available through the milter > sapi, > * if you leave one or more out they simply won't get called (e.g. if you > secify an > * empty php file, the milter would do nothing :) > */ > > /** > * this function is called once on sapi startup, > * here you can specify the actions the filter may take > * > * see > http://www.sendmail.com/partner/resources/development/milter_api/smfi_register.html#flags > */ > > function milter_log($msg) > { > $GLOBALS['log'] = fopen("/tmp/milter.log", "a"); > fwrite($GLOBALS['log'], date("[H:i:s d.m.Y]") . "\t{$msg}\n"); > fclose($GLOBALS['log']); > } > > function milter_init() { > milter_log("-- startup --"); > milter_log("milter_init()"); > smfi_setflags(SMFIF_ADDHDRS); > } > > /** > * is called once, at the start of each SMTP connection > */ > function milter_connect($connect) > { > milter_log("milter_connect('$connect')"); > } > > /** > * is called whenever the client sends a HELO/EHLO command. > * It may therefore be called between zero and three times. > */ > function milter_helo($helo) > { > milter_log("milter_helo('$helo')"); > } > > /** > * is called once at the beginning of each message, > * before milter_envrcpt. > */ > function milter_envfrom($args) > { > milter_log("milter_envfrom(args[])"); > foreach ($args as $ix => $arg) { > milter_log("\targs[$ix] = $arg"); > } > milter_log(smfi_getsymval("i")); > milter_log(smfi_getsymval("{i}")); > } > > /** > * is called once per recipient, hence one or more times per message, > * immediately after milter_envfrom > */ > function milter_envrcpt($args) > { > milter_log("milter_envrcpt(args[])"); > foreach ($args as $ix => $arg) { > milter_log("\targs[$ix] = $arg"); > } > } > > /** > * is called zero or more times between milter_envrcpt and milter_eoh, > * once per message header > */ > function milter_header($header, $value) > { > milter_log("milter_header('$header', '$value')"); > } > > /** > * is called once after all headers have been sent and processed. > */ > function milter_eoh() > { > milter_log("milter_eoh()"); > } > > /** > * is called zero or more times between milter_eoh and milter_eom. > */ > function milter_body($bodypart) > { > milter_log("milter_body('$bodypart')"); > } > > /** > * is called once after all calls to milter_body for a given message. > * most of the api functions, that alter the message can only be called > * within this callback. > */ > function milter_eom() > { > milter_log("milter_eom()"); > /* add PHP header to the message */ > smfi_addheader("X-PHP", phpversion()); > } > > /** > * may be called at any time during message processing > * (i.e. between some message-oriented routine and milter_eom). > */ > function milter_abort() > { > milter_log("milter_abort()"); > } > > /** > * is always called once at the end of each connection. > */ > function milter_close() > { > milter_log("milter_close()"); > } > ?> > > Alex Madon http://atpic.com Webmaster > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP milter SAPI: problem with smfi_getsymval
Hi Jochem, Well, the best known spam filtering solution is PERL based (mimedefang/spamassassin). In theory, you could do this using the PHP milter SAPI: the SAPI provides you with a way to catch the STMP commands sent by mail server to you mail server and tell your mail server want to tell to the sending server. For instance if you see the connection coming from a spammer IP, then you could temp fail the mail. In other words, there are huge spam related libraries in PERL with no equivalent in PHP but the PHP SAPI allows you to develop such libraries. The sendmail milter API is document here: http://www.sendmail.org/doc/sendmail-current/libmilter/docs/ Thanks Alex, Atpic.com Webmaster http://atpic.com > Atpic wrote: >> Hi, >> >> I did not get a reply to my question on this list, > > most likely because nobody here had much of a clue as to how to help, > I for one got my brain in a twist trying to figure what you were going on > about, > I didn't succeed :-) > >> so I raised a bug. The >> bug was confirmed and fixed within 24 hours. Thank you the PHP team! > > that is impressive :-) > >> FYI the bug number is 40083 >> http://bugs.php.net/40083 >> You can now start filtering spam using your favorite programming >> language! > > care to elaborate? I'm sure there are lots of people that would like to do > this - but silly old me can't figure out even where to start learning > about > this great sounding functionality. apologies if I am asking the blindingly > obvious :-/ > > rgds, > Jochem > >> >> Thanks >> Alex, Atpic.com Webmaster >> http://atpic.com >> >>> Hi, >>> >>> I compiled the milter sapi, the example in the distribution works >>> well. >>> BUT when I try to get the values of the sendmail macros with the >>> smfi_getsymval function, i desperately get a blank string. >>> I used strace and I do see the "i" sendmail macro in a red system call >>> but >>> I can no red its value in the PHP milter. >>> Any ideas? >>> Is this worth logging a bug? >>> >>> Thanks >>> >>> --- >>> HERE is the code I used. It is just the distribution example with the >>> milter_envfrom function modified by including two function calls: >>> >>> milter_log(smfi_getsymval("i")); >>> milter_log(smfi_getsymval("{i}")); >>> >>> Example was retrieved from CVS: >>> >>> http://cvs.php.net/viewvc.cgi/php-src/sapi/milter/milter.php?revision=1.2&view=markup >>> >>> >> /** >>> * example milter script >>> * >>> * run: php-milter -D -p /path/to/sock milter.php >>> * >>> * for details on how to set up sendmail and configure the milter see >>> * http://www.sendmail.com/partner/resources/development/milter_api/ >>> * >>> * for api details see >>> * >>> http://www.sendmail.com/partner/resources/development/milter_api/api.html >>> * >>> * below is a list of all callbacks, that are available through the >>> milter >>> sapi, >>> * if you leave one or more out they simply won't get called (e.g. if >>> you >>> secify an >>> * empty php file, the milter would do nothing :) >>> */ >>> >>> /** >>> * this function is called once on sapi startup, >>> * here you can specify the actions the filter may take >>> * >>> * see >>> http://www.sendmail.com/partner/resources/development/milter_api/smfi_register.html#flags >>> */ >>> >>> function milter_log($msg) >>> { >>> $GLOBALS['log'] = fopen("/tmp/milter.log", "a"); >>> fwrite($GLOBALS['log'], date("[H:i:s d.m.Y]") . "\t{$msg}\n"); >>> fclose($GLOBALS['log']); >>> } >>> >>> function milter_init() { >>> milter_log("-- startup --"); >>> milter_log("milter_init()"); >>> smfi_setflags(SMFIF_ADDHDRS); >>> } >>> >>> /** >>> * is called once, at the start of each SMTP connection >>> */ >>> function milter_connect($connect) >>> { >>> milter_log("milter_connect('$connect')"); >>> } >>> >>> /** >>> * is called whenever the client sends a HELO/EHLO command. >>> * It may therefore be called between zero and three times. >>> */ >>>
Re: [PHP] PHP milter SAPI: problem with smfi_getsymval
Hi Jochem, 1) yes, the milter could do some action based on the subject of the mail, the sender's address, the recipient's address, etc... Note that it is sometimes difficult to compile several SAPIs at the same time. I could get the Apache module and CLI (command line interface) SAPI in one compile, but I needed to compile the milter SAPI separately as it complained some symbols were already defined in the Apache compilation. (I may have missed something here however). 2) the milter (mail filter) is following the API defined by sendmail. Posfix also tried to provide an API which is compatible with the sendmail API, but to my knowledge Postfix implements only a subset of the API. Thanks Alex, Atpic.com Webmaster http://atpic.com > Atpic wrote: >> Hi Jochem, >> >> Well, the best known spam filtering solution is PERL based >> (mimedefang/spamassassin). > > spamassassin at least I (a little) familiar with (I usually leave the > intricacies > to someone with much more knowledge about this kind of stuff - what are > sys admins for? :-) > >> In theory, you could do this using the PHP milter SAPI: the SAPI >> provides > > the 'PHP milter SAPI' bit confuses me - like where to start with regard to > installing it properly - I'm not in need of answer regarding this ... > > first off I'm going to do a whole bunch of reading (including the link you > pointed me at - thanks for that!) > > a couple of question that I do have are (hope you don't mind the > intrusion): > > 1. based on your description I come to the conclusion > that the milter SAPI could be used to intercept incoming (reply) emails > that > related to automated information request email from a website (the idea > being to > track the complete thread of conversation related to a sales lead that was > initiated > by a person visiting a website - I would like to do this because, for one > of my clients, > there are a lot of users that make a pigs ear of managing their > leads/clients/etc - and > initial contact always via a website and related to data stored in the > websites DB), > I could do something like this with the milter SAPI? > > > 2. would I have to use sendmail as my MTA? or is it possible to use the > milter SAPI > in the 'toolchain' of any sendmail compatible MTA? (my > hoster/sysadmin/magic-geek runs > Gentoo installation with courier as the MTA, I believe courier is sendmail > compatible, > then again my believe may be completely unfounded/misguided) > >> you with a way to catch the STMP commands sent by mail server to you >> mail >> server and tell your mail server want to tell to the sending server. >> For instance if you see the connection coming from a spammer IP, then >> you >> could temp fail the mail. >> In other words, there are huge spam related libraries in PERL with no >> equivalent in PHP but the PHP SAPI allows you to develop such libraries. >> The sendmail milter API is document here: >> http://www.sendmail.org/doc/sendmail-current/libmilter/docs/ >> > > thanks again for your feedback. > > kind regards, > Jochem > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php