From: Mathias Tausig on 10 Sep 2009 10:09 Hy! I want to write an after-queue content filter for my postfix installation which is invoked by spawn (according to the FILTER_README from postfix.org). My problem is, that the input/output part simply does not work. I am sending a "220 localhost SMTP foo" to STDOUT at the beginning of the script, but somehow, this never reaches the SMTP client in a correct way. Has anyone ever managed to accomplish such a soultion? cheers Mathias P.S.: I am using posstfix 2.4.5 and php-5.1.2
From: Wietse Venema on 10 Sep 2009 10:18 Mathias Tausig: > Hy! > > I want to write an after-queue content filter for my postfix > installation which is invoked by spawn (according to the FILTER_README > from postfix.org). > > My problem is, that the input/output part simply does not work. I am > sending a "220 localhost SMTP foo" to STDOUT at the beginning of the > script, but somehow, this never reaches the SMTP client in a correct > way. Has anyone ever managed to accomplish such a soultion? This is an output buffering problem. You need to flush output after each reply, perhaps by calling the flush() function. Wietse
From: Thomas Gelf on 10 Sep 2009 10:26 Mathias Tausig wrote: > I want to write an after-queue content filter for my postfix > installation which is invoked by spawn (according to the FILTER_README > from postfix.org). > > My problem is, that the input/output part simply does not work. I am > sending a "220 localhost SMTP foo" to STDOUT at the beginning of the > script, but somehow, this never reaches the SMTP client in a correct > way. Has anyone ever managed to accomplish such a soultion? You should provide some more details, code samples, whatever. Or sniff on your lookback to see what's going on. Stream handling in PHP can be a mess ;-) Cheers, Thomas -- mail: thomas(a)gelf.net web: http://thomas.gelf.net/
From: Thomas Gelf on 10 Sep 2009 10:30 Wietse Venema wrote: > This is an output buffering problem. You need to flush output > after each reply, perhaps by calling the flush() function. Good catch, I guess this could most likely be his problem! -- mail: thomas(a)gelf.net web: http://thomas.gelf.net/
From: Mathias Tausig on 11 Sep 2009 04:14
Am Donnerstag, den 10.09.2009, 10:18 -0400 schrieb Wietse Venema: [...] > This is an output buffering problem. You need to flush output > after each reply, perhaps by calling the flush() function. > Hy! No, I am afraid that this is not the problem. I am sendig you a few details of my setup Here is my php script test.php: <?php error_reporting(E_ALL); fprintf(STDOUT, "220 localhost SMTP foo test\n"); fflush(STDOUT); fprintf($log, "Sent opening string (220 localhost SMTP ...)\n"); fprintf(STDOUT, "250 Hello client.example.org, nice to meet you\n"); fflush(STDOUT); flush(); fprintf(STDOUT, "250 Sender OK\n"); fflush(STDOUT); flush(); fprintf(STDOUT, "250 Recipient OK\n"); fflush(STDOUT); flush(); fprintf(STDOUT, "354 End data with <CR><LF>.<CR><LF>\n"); fflush(STDOUT); flush(); fprintf(STDOUT, "250 Message accepted for delivery\n"); fflush(STDOUT); flush(); fprintf(STDOUT, "221 See you later\n"); fflush(STDOUT); flush(); exit(0); ?> which is activated in master.cf by 127.0.0.1:10025 inet n n n - 20 spawn user=nobody argv=/tmp/test.php (yes, I tried a different user as well) I am testing this setup with a simple perl script #!/usr/bin/perl use strict; use Net::SMTP; my $smtp = Net::SMTP->new('localhost:10025', Debug => 1); exit 0; which fails and does not receive any input data. Here is the output of "tcpdump -nA -i any port 10025" upon calling this smtp client: tcpdump: WARNING: Promiscuous mode not supported on the "any" device tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on any, link-type LINUX_SLL (Linux cooked), capture size 96 bytes 10:11:34.917815 IP 127.0.0.1.42745 > 127.0.0.1.10025: S 1684489309:1684489309(0) win 32767 <mss 16396,sackOK,timestamp 1853261109 0,nop,wscale 2> E..<.h@.@.{Q..........')dgD]........%.....@.... nv.5........ 10:11:34.917864 IP 127.0.0.1.10025 > 127.0.0.1.42745: S 1696242199:1696242199(0) ack 1684489310 win 32767 <mss 16396,sackOK,timestamp 1853261109 1853261109,nop,wscale 2> E..<..@.@.<.........')..e...dgD^....2)....@.... nv.5nv.5.... 10:11:34.917897 IP 127.0.0.1.42745 > 127.0.0.1.10025: . ack 1 win 8192 <nop,nop,timestamp 1853261109 1853261109> E..4.i@.@.{X..........')dgD^e..... ..G..... nv.5nv.5 10:11:34.957172 IP 127.0.0.1.10025 > 127.0.0.1.42745: P 1:2(1) ack 1 win 8192 <nop,nop,timestamp 1853261119 1853261109> E..5.-@.@...........')..e...dgD^.. ..)..... nv.?nv.5 10:11:34.957228 IP 127.0.0.1.42745 > 127.0.0.1.10025: . ack 2 win 8192 <nop,nop,timestamp 1853261119 1853261119> E..4.j@.@.{W..........')dgD^e..... ..2..... nv.?nv.? 10:11:34.958317 IP 127.0.0.1.42745 > 127.0.0.1.10025: F 1:1(0) ack 2 win 8192 <nop,nop,timestamp 1853261119 1853261119> E..4.k@.@.{V..........')dgD^e..... ..1..... nv.?nv.? 10:11:34.961625 IP 127.0.0.1.10025 > 127.0.0.1.42745: P 2:30(28) ack 2 win 8192 <nop,nop,timestamp 1853261120 1853261119> E..P..@.@..x........')..e...dgD_.. ..D..... nv.(a)nv.?220 localhost SMTP foo test 10:11:34.961686 IP 127.0.0.1.42745 > 127.0.0.1.10025: R 1684489311:1684489311(0) win 0 E..(..@.@.<...........')dgD_....P...:... Which means, that at least the opening string is somehow sent to client, but obviously not in a correct way. If I substitute the php script with a simple c++ programm: #include <iostream> #include <fstream> using std::endl; using std::cout; int main(int argc, char** argv) { cout<<"220 localhost SMTP foo test"<<endl; cout <<"250 Hello client.example.org, nice to meet you"<<endl; cout <<"250 Sender OK"<<endl; cout <<"250 Recipient OK"<<endl; cout <<"354 End data with <CR><LF>.<CR><LF>"<<endl; cout <<"250 Message accepted for delivery"<<endl; cout <<"221 See you later"<<endl; return 0; } everything works fine. Well, I hope you can find any flaws in this setup to save my day ... cheers Mathias |