Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > sending data from one program to a perl prog

Reply
Thread Tools

sending data from one program to a perl prog

 
 
Andrew Wheeler
Guest
Posts: n/a
 
      04-26-2004
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
 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      04-26-2004
Andrew Wheeler wrote:
> 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.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      04-26-2004
Gunnar Hjalmarsson wrote:
>
> 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.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

 
Reply With Quote
 
Joe Smith
Guest
Posts: n/a
 
      04-27-2004
Gunnar Hjalmarsson wrote:

> Gunnar Hjalmarsson wrote:
>
>>
>> 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'};
 
Reply With Quote
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      04-27-2004
Joe Smith wrote:
> Gunnar Hjalmarsson wrote:
>>
>> 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!

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

 
Reply With Quote
 
Andrew Wheeler
Guest
Posts: n/a
 
      04-27-2004
On Mon, 26 Apr 2004 23:42:43 +0200, Gunnar Hjalmarsson wrote:

> my $maxsize = 131072;


what is the significance of 131072 as a max size ?
 
Reply With Quote
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      04-27-2004
Andrew Wheeler wrote:
> Gunnar Hjalmarsson wrote:
>>
>>my $maxsize = 131072;

>
> 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).

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

 
Reply With Quote
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      04-27-2004
Gunnar Hjalmarsson wrote:
> Andrew Wheeler wrote:
>> Gunnar Hjalmarsson wrote:
>>>
>>> my $maxsize = 131072;

>>
>> 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).


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

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

 
Reply With Quote
 
Walter Roberson
Guest
Posts: n/a
 
      04-27-2004
In article <(E-Mail Removed) ain>,
Andrew Wheeler <(E-Mail Removed)> wrote:
:On Mon, 26 Apr 2004 23:42:43 +0200, Gunnar Hjalmarsson wrote:

:> 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.
--
"Meme" is self-referential; memes exist if and only if the "meme" meme
exists. "Meme" is thus logically a meta-meme; but until the existance
of meta-memes is more widely recognized, "meta-meme" is not a meme.
-- A Child's Garden Of Memes
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading binary file created a C++ program inside a Perl prog freesoft12@gmail.com Perl Misc 6 02-10-2010 07:03 AM
Starting and stopping a prog. from another prog. andoni.oconchubhair@ie.fid-intl.com Java 1 10-22-2006 10:43 PM
Piping ping into perl-prog bernd wegener Perl 3 09-22-2004 06:32 PM
c prog socket connect to java program Mei Li Java 3 07-20-2004 10:01 AM
How can I pass C prog output to parent java program Nishi Bhonsle Java 3 01-12-2004 10:29 PM



Advertisments