Re: [Exim] transport_filter.pl

Top Pagina
Delete this message
Reply to this message
Auteur: Philip Hazel
Datum:  
Aan: Szabo Laszlo
CC: exim-users
Onderwerp: Re: [Exim] transport_filter.pl
On Mon, 10 Jan 2000, Szabo Laszlo wrote:

> Can I write an ordenary file when I running a perl script as transport_filter
> for remote_smtp and address_pipe transports?


Why not?

> - the file is writeable by exim user,


Yes, it has to be.

Your script has a typo in it, though

> === cut === a draft ===
> #!/usr/bin/perl
> $/="";
> chomp($headers = <STDIN>);
> $/='\n";

     ^^^^
Typo ^^^^     


> open(OUT, ">>/somewhere/afile");
> printf(STDOUT "%s\n\n", $headers);
> printf(OUT "%s\n\n", $headers);
> while(<STDIN>) {
> chomp;
> printf(STDOUT "%s\n", $_);
> printf(OUT "%s\n", $_);
> }
> close(OUT);
> === cut ===


Why bother with the chomping? Why not just do

#!/usr/bin/perl
open(OUT, ">>/somewhere/afile");
$/="";
$_ = <STDIN>;
$/='\n';

print STDOUT;
print OUT;
close(OUT);

print while(<STDIN>);

There are two problems with this.

(1) You are not doing any interlocking. If two messages are being
delivered at once, their data will get mixed up in the file.

(2) You are not taking precautions against /somewhere/afile failing to
open.

A way to avoid having to deal with locking would be to use a system
filter to set up an "unseen" delivery to a file, using
message_filter_file_transport to point to a special appendfile transport
that has "headers_only" set.

-- 
Philip Hazel            University of Cambridge Computing Service,
ph10@???      Cambridge, England. Phone: +44 1223 334714.