sending data from one program to a perl prog

A

Andrew Wheeler

Hello everyone,

I want to write a Perl program to edit an email then sent the email back
to the sender automatically.

My email program allows me to filter emails and send the email to a
program (As I already have done with Spam-Assassin)

However as this is my first real Perl Program and I need a little help:)

Can anyone point me to any documentation on how Perl handles a large block
of text (the email) when it is piped directly to a shell command (the Perl
program).
I need to replace all occurrences of [ ] with [ X ] so is it best to
treat the email as one block or break it into chunks and process the
chunks separately.

And what would happen if evolution pipes two separate messages the Perl
program? will the system start 2 separate programs or crash ?

Any comments gratefully received

Andrew
 
G

Gunnar Hjalmarsson

Andrew said:
Can anyone point me to any documentation on how Perl handles a
large block of text (the email) when it is piped directly to a
shell command (the Perl program).

Well, it depends on the code in the Perl program. ;-)

Such a message is made available in STDIN, and this is an (untested)
example code fragment for storing it in a variable:

my $msg;
my $maxsize = 131072;
unless ($ENV{CONTENT_LENGTH} > $maxsize) {
$msg = do {local $/; <STDIN>};
} else {
print "Requested action aborted:\n",
"Message too large.\n\n";
exit;
}

There are suitable modules at CPAN for parsing the message, so you'd
better take a look there.
I need to replace all occurrences of [ ] with [ X ] so is it best
to treat the email as one block or break it into chunks and process
the chunks separately.

It sounds to me as if you can make a global substitution to the whole
message body at one time.

Then, so send the revised message, I recommend that you pay another
visit at CPAN for a mail sending module. There are quite a few of
them; my personal favorite is Mail::Sender.
And what would happen if evolution pipes two separate messages the
Perl program? will the system start 2 separate programs or crash ?

Two processes; shouldn't cause a problem.
 
G

Gunnar Hjalmarsson

Gunnar said:
my $msg;
my $maxsize = 131072;
unless ($ENV{CONTENT_LENGTH} > $maxsize) {
$msg = do {local $/; <STDIN>};

I'd better add that such a check of message size does not always work.
For instance, the sendmail configuration on my own brand new server is
so 'secure' so that no %ENV variable at all is present when a process
is run as the mail program. Perl's stat() function, i.e.
(stat STDIN)[7], does not contain the size either...

Oh, well.
 
J

Joe Smith

Gunnar said:
Gunnar said:
my $msg;
my $maxsize = 131072;
unless ($ENV{CONTENT_LENGTH} > $maxsize) {
$msg = do {local $/; <STDIN>};


I'd better add that such a check of message size does not always work.
For instance, the sendmail configuration on my own brand new server is
so 'secure' so that no %ENV variable at all is present when a process is
run as the mail program. Perl's stat() function, i.e.
(stat STDIN)[7], does not contain the size either...

Oh, well.

What about something like
my $bytes_read = read STDIN,$msg,$maxsize;
unless eof(STDIN) { return 'error'};
 
G

Gunnar Hjalmarsson

Joe said:
Gunnar said:
my $msg;
my $maxsize = 131072;
unless ($ENV{CONTENT_LENGTH} > $maxsize) {
$msg = do {local $/; <STDIN>};

I'd better add that such a check of message size does not always
work. For instance, the sendmail configuration on my own brand
new server is so 'secure' so that no %ENV variable at all is
present when a process is run as the mail program. Perl's stat()
function, i.e. (stat STDIN)[7], does not contain the size
either...

Oh, well.

What about something like
my $bytes_read = read STDIN,$msg,$maxsize;
unless eof(STDIN) { return 'error'};

Yes, that's it. (But you don't need $bytes_read, do you?) Thanks, Joe!
 
G

Gunnar Hjalmarsson

Andrew said:
what is the significance of 131072 as a max size ?

None, AFAIK. It's up to you to decide what's a reasonable value (if
you want to include such a check).
 
G

Gunnar Hjalmarsson

Gunnar said:
None, AFAIK. It's up to you to decide what's a reasonable value (if
you want to include such a check).

Besides the obvious, of course, i.e. prevent that your program
processes and forwards an unreasonably large message.
 
W

Walter Roberson

:> my $maxsize = 131072;

:what is the significance of 131072 as a max size ?

128 kilobytes = 131072 bytes.

64 Kb is one of the magic numbers in TCP, I seem to recall;
128 Kb allows for two buffer's worth of the maximum size.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top