[32603] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 3876 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Feb 7 14:09:20 2013

Date: Thu, 7 Feb 2013 11:09:06 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 7 Feb 2013     Volume: 11 Number: 3876

Today's topics:
    Re: A little help with Perl & Email Messages artmerar@gmail.com
    Re: A little help with Perl & Email Messages <news@lawshouse.org>
    Re: A little help with Perl & Email Messages <jurgenex@hotmail.com>
    Re: A little help with Perl & Email Messages <news@lawshouse.org>
    Re: A little help with Perl & Email Messages artmerar@gmail.com
    Re: A little help with Perl & Email Messages <jurgenex@hotmail.com>
    Re: A little help with Perl & Email Messages artmerar@gmail.com
    Re: A little help with Perl & Email Messages <ben@morrow.me.uk>
    Re: A little help with Perl & Email Messages <ben@morrow.me.uk>
    Re: A little help with Perl & Email Messages artmerar@gmail.com
    Re: A little help with Perl & Email Messages <news@lawshouse.org>
    Re: A little help with Perl & Email Messages artmerar@gmail.com
    Re: A little help with Perl & Email Messages <news@lawshouse.org>
    Re: A little help with Perl & Email Messages <jurgenex@hotmail.com>
        help with regexp <marc.girod@gmail.com>
    Re: help with regexp <ben@morrow.me.uk>
    Re: help with regexp <rweikusat@mssgmbh.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Wed, 6 Feb 2013 08:18:02 -0800 (PST)
From: artmerar@gmail.com
Subject: Re: A little help with Perl & Email Messages
Message-Id: <93afcfa1-cbb1-4c80-88ac-63676d51b38b@googlegroups.com>

On Wednesday, February 6, 2013 9:32:03 AM UTC-6, Henry Law wrote:
> On 05/02/13 21:33, artmerar@gmail.com wrote:
> 
> > So, we can take the incoming messages and forward them to a script:
> 
> >
> 
> > | /home/johndoe/filter.pl
> 
> 
> 
> When you say "forward them to a script", what do you mean?  What exactly 
> 
> will the system do with the message and the program?  My guess would be 
> 
> that, as instructed by this ".qmail" file, the mail client program will 
> 
> invoke filter.pl and *pass it the text of the message* in some 
> 
> well-defined way, most likely via STDIN.
> 
> 
> 
> > When I use Email::Filter I start like this:  my $mail = Email::Filter->new();
> 
> > That gives some type of Hash Array:  Email::Filter=HASH(0x1f220730)
> 
> 
> 
> Er yes, that's a Perl object of type "Email::Filter".   I sense that you 
> 
> need to read up on how to use Perl objects such as that one.
> 
> 
> 
> > It is not STDIN, it is not a file, it was forwarded via the .qmail file:  | /home/johndoe/filter.pl
> 
> 
> 
> See my earlier question: are you sure?  From what you've written I do 
> 
> think it is STDIN.  If that's the case then you merely open STDIN inside 
> 
> "filter.pl", read in the text and pass it to your Email::Filter object.
> 
> 
> 
> I've no idea about Email::Filter but someone else suggested Email::MIME 
> 
> which I do know a bit about, having used it.  If you use that module 
> 
> then something like this might be a place to start:
> 
> 
> 
> #!/usr/bin/perl
> 
> use strict;
> 
> use warnings;
> 
> my $msg;
> 
> $msg .= $_ while <>;
> 
> chomp $msg;
> 
> 
> 
> my $email = Email::MIME->new($msg);
> 
> # ... etc
> 
> 
> 
> There are better ways of slurping in the whole of a STDIN stream but I 
> 
> don't have time to look them up right now; sorry.  I hope this helps.
> 
> 
> 
> 
> 
> -- 
> 
> 
> 
> Henry Law            Manchester, England


I tried the following code:

use MIME::Parser;
my $parser = new MIME::Parser;
$parser->decode_headers(1);
my $mail = $parser->parse(\*STDIN) or die "parse failed\n";

$mail = MIME::Entity=HASH(0x12d4f420)

Not sure what that means......




------------------------------

Date: Wed, 06 Feb 2013 18:29:01 +0000
From: Henry Law <news@lawshouse.org>
Subject: Re: A little help with Perl & Email Messages
Message-Id: <rr6dnSRx6r9wPY_MnZ2dnUVZ8tmdnZ2d@giganews.com>

On 06/02/13 16:18, artmerar@gmail.com wrote:
> use MIME::Parser;
> my $parser = new MIME::Parser;
> $parser->decode_headers(1);
> my $mail = $parser->parse(\*STDIN) or die "parse failed\n";
>
> $mail = MIME::Entity=HASH(0x12d4f420)
>
> Not sure what that means......

Please make a clear distinction between Perl code (down as far as "my 
$mail =") and comment, that is, your last two lines.

You're nearly there!  You've got a MIME::Entity object containing the 
text of your email.  You can do with it anything that the methods of 
MIME::Entity allow you to do.  Read it up.  Try perldoc MIME::Entity, or 
find the same material on the web.  Look; I've done a little bit for 
you, starting with your code above:

$ cat tryout
#!/usr/bin/perl
use strict;
use warnings;
use 5.010;

use MIME::Parser;

my $parser = new MIME::Parser;
$parser->decode_headers(1);
my $mail = $parser->parse(\*STDIN) or die "parse failed\n";

$mail->dump_skeleton;

$ cat TestEmail.txt | ./tryout
Content-type: text/plain
Effective-type: text/plain
Body-file: ./msg-7497-1.txt
Subject: This is a test email

--
henry@eris:~/Perl/tryout$

-- 

Henry Law            Manchester, England


------------------------------

Date: Wed, 06 Feb 2013 11:04:48 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: A little help with Perl & Email Messages
Message-Id: <q4a5h81va4neilc5qgtfs7lm2784b3o1sl@4ax.com>

[using full-quote to demonstrate my point]
artmerar@gmail.com wrote:
>On Wednesday, February 6, 2013 9:32:03 AM UTC-6, Henry Law wrote:
>> On 05/02/13 21:33, artmerar@gmail.com wrote:
>> 
>> > So, we can take the incoming messages and forward them to a script:
>> 
>> >
>> 
>> > | /home/johndoe/filter.pl
>> 
>> 
>> 
>> When you say "forward them to a script", what do you mean?  What exactly 
>> 
>> will the system do with the message and the program?  My guess would be 
>> 
>> that, as instructed by this ".qmail" file, the mail client program will 
>> 
>> invoke filter.pl and *pass it the text of the message* in some 
>> 
>> well-defined way, most likely via STDIN.
>> 
>> 
>> 
>> > When I use Email::Filter I start like this:  my $mail = Email::Filter->new();
>> 
>> > That gives some type of Hash Array:  Email::Filter=HASH(0x1f220730)
>> 
>> 
>> 
>> Er yes, that's a Perl object of type "Email::Filter".   I sense that you 
>> 
>> need to read up on how to use Perl objects such as that one.
>> 
>> 
>> 
>> > It is not STDIN, it is not a file, it was forwarded via the .qmail file:  | /home/johndoe/filter.pl
>> 
>> 
>> 
>> See my earlier question: are you sure?  From what you've written I do 
>> 
>> think it is STDIN.  If that's the case then you merely open STDIN inside 
>> 
>> "filter.pl", read in the text and pass it to your Email::Filter object.
>> 
>> 
>> 
>> I've no idea about Email::Filter but someone else suggested Email::MIME 
>> 
>> which I do know a bit about, having used it.  If you use that module 
>> 
>> then something like this might be a place to start:
>> 
>> 
>> 
>> #!/usr/bin/perl
>> 
>> use strict;
>> 
>> use warnings;
>> 
>> my $msg;
>> 
>> $msg .= $_ while <>;
>> 
>> chomp $msg;
>> 
>> 
>> 
>> my $email = Email::MIME->new($msg);
>> 
>> # ... etc
>> 
>> 
>> 
>> There are better ways of slurping in the whole of a STDIN stream but I 
>> 
>> don't have time to look them up right now; sorry.  I hope this helps.
>> 
>> 
>> 
>> 
>> 
>> -- 
>> 
>> 
>> 
>> Henry Law            Manchester, England
>
>
>I tried the following code:
>
>use MIME::Parser;
>my $parser = new MIME::Parser;
>$parser->decode_headers(1);
>my $mail = $parser->parse(\*STDIN) or die "parse failed\n";
>
>$mail = MIME::Entity=HASH(0x12d4f420)
>
>Not sure what that means......
>

Would you mind stopping to add an additional blank line after every
single line that you quoted and claiming the previous poster wrote
those? This really does not improve readability one bit....

jue


------------------------------

Date: Wed, 06 Feb 2013 19:28:47 +0000
From: Henry Law <news@lawshouse.org>
Subject: Re: A little help with Perl & Email Messages
Message-Id: <Z--dnXxW3O9yM4_MnZ2dnUVZ8mWdnZ2d@giganews.com>

On 06/02/13 19:04, Jürgen Exner wrote:

> Would you mind stopping to add an additional blank line after every
> single line that you quoted and claiming the previous poster wrote
> those? This really does not improve readability one bit....

You're right, of course, and I'll do that.

But don't you have something more useful to add to the discussion?  I 
know from previous history that you know orders of magnitude more Perl 
than I do; I should have thought that your time might have been better 
spent advising the OP.

-- 

Henry Law            Manchester, England


------------------------------

Date: Wed, 6 Feb 2013 11:41:35 -0800 (PST)
From: artmerar@gmail.com
Subject: Re: A little help with Perl & Email Messages
Message-Id: <1b34e162-eb93-4767-adcf-fb7d5e036d94@googlegroups.com>

On Wednesday, February 6, 2013 12:29:01 PM UTC-6, Henry Law wrote:
> On 06/02/13 16:18, artmerar@gmail.com wrote:
> 
> > use MIME::Parser;
> 
> > my $parser = new MIME::Parser;
> 
> > $parser->decode_headers(1);
> 
> > my $mail = $parser->parse(\*STDIN) or die "parse failed\n";
> 
> >
> 
> > $mail = MIME::Entity=HASH(0x12d4f420)
> 
> >
> 
> > Not sure what that means......
> 
> 
> 
> Please make a clear distinction between Perl code (down as far as "my 
> 
> $mail =") and comment, that is, your last two lines.
> 
> 
> 
> You're nearly there!  You've got a MIME::Entity object containing the 
> 
> text of your email.  You can do with it anything that the methods of 
> 
> MIME::Entity allow you to do.  Read it up.  Try perldoc MIME::Entity, or 
> 
> find the same material on the web.  Look; I've done a little bit for 
> 
> you, starting with your code above:
> 
> 
> 
> $ cat tryout
> 
> #!/usr/bin/perl
> 
> use strict;
> 
> use warnings;
> 
> use 5.010;
> 
> 
> 
> use MIME::Parser;
> 
> 
> 
> my $parser = new MIME::Parser;
> 
> $parser->decode_headers(1);
> 
> my $mail = $parser->parse(\*STDIN) or die "parse failed\n";
> 
> 
> 
> $mail->dump_skeleton;
> 
> 
> 
> $ cat TestEmail.txt | ./tryout
> 
> Content-type: text/plain
> 
> Effective-type: text/plain
> 
> Body-file: ./msg-7497-1.txt
> 
> Subject: This is a test email
> 
> 
> 
> --
> 
> henry@eris:~/Perl/tryout$
> 
> 
> 
> -- 
> 
> 
> 
> Henry Law            Manchester, England

Sigh, I feel so helpless.  LOL.

I tried another example:

use MIME::Lite;
use MIME::Parser;
user MIME::Body
use Email::MIME;

my $parser = new MIME::Parser;
my $entity = $parser->parse(\*STDIN);
my $body = $entity->bodyhandle;
print LOG "HERE: $body\n";

And the log is empty......I also see a MIME::Body, do I need to reference that?



------------------------------

Date: Wed, 06 Feb 2013 11:55:07 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: A little help with Perl & Email Messages
Message-Id: <b4d5h8plmv4gbhuctmphaafau0sns45kd4@4ax.com>

Henry Law <news@lawshouse.org> wrote:
>On 06/02/13 19:04, Jürgen Exner wrote:
>
>> Would you mind stopping to add an additional blank line after every
>> single line that you quoted and claiming the previous poster wrote
>> those? This really does not improve readability one bit....
>
>You're right, of course, and I'll do that.

Henry, it's not you who is doubling the number of lines, it is artmerar.
He/she has to fix that, nothing _you_ can do about it.

>But don't you have something more useful to add to the discussion?  I 
>know from previous history that you know orders of magnitude more Perl 
>than I do; I should have thought that your time might have been better 
>spent advising the OP.

Well, thanks for the flattery, but MIME is not my strong side.

jue


------------------------------

Date: Wed, 6 Feb 2013 13:34:07 -0800 (PST)
From: artmerar@gmail.com
Subject: Re: A little help with Perl & Email Messages
Message-Id: <f3188719-ca6c-480e-be20-0a36225b81ad@googlegroups.com>

On Wednesday, February 6, 2013 1:28:47 PM UTC-6, Henry Law wrote:
> On 06/02/13 19:04, J=FCrgen Exner wrote:
>=20
>=20
>=20
> > Would you mind stopping to add an additional blank line after every
>=20
> > single line that you quoted and claiming the previous poster wrote
>=20
> > those? This really does not improve readability one bit....
>=20
>=20
>=20
> You're right, of course, and I'll do that.
>=20
>=20
>=20
> But don't you have something more useful to add to the discussion?  I=20
>=20
> know from previous history that you know orders of magnitude more Perl=20
>=20
> than I do; I should have thought that your time might have been better=20
>=20
> spent advising the OP.
>=20
>=20
>=20
> --=20
>=20
>=20
>=20
> Henry Law            Manchester, England


I tried this, and while it is dumping out the body to files on disk in msg*=
 files, it dump many of them, from all previous messages......not sure why:

my $parser =3D new MIME::Parser;
my $entity =3D $parser->parse(\*STDIN);
my $body =3D $entity->bodyhandle;
$body =3D new MIME::Body::File "/home";

my $IO =3D $body->open("r")      || die "open body: $!";
while (defined($_ =3D $IO->getline)) {
    print LOG "HERE: $_\n";
}
$IO->close                  || die "close I/O handle: $!";


------------------------------

Date: Wed, 6 Feb 2013 23:38:41 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: A little help with Perl & Email Messages
Message-Id: <156bu9-nk22.ln1@anubis.morrow.me.uk>

[Your 'newsreader' seems to be adding extra blank lines between every
line of quoted text. Please find a way to stop it from doing that.]

Quoth artmerar@gmail.com:
> On Wednesday, February 6, 2013 7:52:24 AM UTC-6, Ben Morrow wrote:
> > Quoth artmerar@gmail.com:
> > 
> > > Ok, our server runs Qmail.  In the users home directory we can ut a
> > > file, .qmail, which acts like a .forward.  So, we can take the incoming
> > > messages and forward them to a script:
> > >
> > > | /home/johndoe/filter.pl
> > >
> > > I want to take the emails and extract the From, To, Subject & Body.  I
> > > was using Email::Filter and was getting everything, but the body
> > > contains all the tags & MIME information, etc.
<snip>
> > > But all those Perl modules are expecting the input to come from
> > > 'somewhere'.  But I'm not sure in this case where 'somewhere' is.  It is
> > > not STDIN, it is not a file, it was forwarded via the .qmail file:  |
> > > /home/johndoe/filter.pl
> > 
> > Invoking a command from .qmail like that sends the mail through the
> > command's STDIN.
> 
> Example from website:
> 
>  use Email::MIME;
>   my $parsed = Email::MIME->new($message);
> 
>   my @parts = $parsed->parts; # These will be Email::MIME objects, too.
>   my $decoded = $parsed->body;
>   my $non_decoded = $parsed->body_raw;
> 
>   my $content_type = $parsed->content_type;
> 
> Now, where is $message coming from?  I do not have a variable with
> $message. 

It comes from STDIN. STDIN is a filehandle; if you want the message in a
variable, you have to read from that filehandle into a variable. For
this you can use (among other things) the <> operator; see perldoc
perlop and the explanation of $/ in perldoc perlvar.

> If I try $mail = Email::Filter->new();, that does not
> work......

What does not work?

Ben



------------------------------

Date: Wed, 6 Feb 2013 23:44:00 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: A little help with Perl & Email Messages
Message-Id: <0f6bu9-nk22.ln1@anubis.morrow.me.uk>


Quoth artmerar@gmail.com:
> 
> I tried the following code:
> 
> use MIME::Parser;

Unless you're likely to be dealing with messages that won't fit into
memory, I'd recommend Email::MIME over MIME::Parser. It's a lot easier
to work with.

> my $parser = new MIME::Parser;

Don't use that syntax; from time to time it will do something
unexpected.

    my $parser = MIME::Parser->new;

> $mail = MIME::Entity=HASH(0x12d4f420)
> 
> Not sure what that means......

perldoc perltoot or perldoc perlboot

Ben



------------------------------

Date: Wed, 6 Feb 2013 21:04:57 -0800 (PST)
From: artmerar@gmail.com
Subject: Re: A little help with Perl & Email Messages
Message-Id: <9623abcd-6093-4c92-b2a1-5a475fc85d93@googlegroups.com>

On Wednesday, February 6, 2013 5:44:00 PM UTC-6, Ben Morrow wrote:
> Quoth artmerar@gmail.com:
> 
> > 
> 
> > I tried the following code:
> 
> > 
> 
> > use MIME::Parser;
> 
> 
> 
> Unless you're likely to be dealing with messages that won't fit into
> 
> memory, I'd recommend Email::MIME over MIME::Parser. It's a lot easier
> 
> to work with.
> 
> 
> 
> > my $parser = new MIME::Parser;
> 
> 
> 
> Don't use that syntax; from time to time it will do something
> 
> unexpected.
> 
> 
> 
>     my $parser = MIME::Parser->new;
> 
> 
> 
> > $mail = MIME::Entity=HASH(0x12d4f420)
> 
> > 
> 
> > Not sure what that means......
> 
> 
> 
> perldoc perltoot or perldoc perlboot
> 
> 
> 
> Ben

I'm experiencing 3 conditions:

1)  It writes msg* files to disk, LOTS OF THEM, many of previous messages sent to that address.

2)  I get the body with all the MIME junk in it.

3)  I get nothing.

I'm looking for the text only......I've honestly tried about 30 examples with no luck.  So, either I'm a dork, or I'm just missing something.




------------------------------

Date: Thu, 07 Feb 2013 08:30:28 +0000
From: Henry Law <news@lawshouse.org>
Subject: Re: A little help with Perl & Email Messages
Message-Id: <_Lqdnao79am5-47MnZ2dnUVZ8jidnZ2d@giganews.com>

On 07/02/13 05:04, artmerar@gmail.com wrote:
> I'm experiencing 3 conditions:
>
> 1)  It writes msg* files to disk, LOTS OF THEM, many of previous messages sent to that address.
>
> 2)  I get the body with all the MIME junk in it.
>
> 3)  I get nothing.
>
> I'm looking for the text only......I've honestly tried about 30 examples with no luck.  So, either I'm a dork, or I'm just missing something.

I don't know why you're finding this so difficult.

Why don't you start with this?  As far as I can tell it does what you 
want, as you described in your original post.

$ cat art.pl
#!/usr/bin/perl
use strict;
use warnings;

use Email::Simple;  # Why not?  Your requirement is Simple.

# Read the message from STDIN
my $txt;
$txt .= $_ while <>;

# Create the message object and extract its headers
my $msg = Email::Simple->new($txt)
   or die "Couldn't create an email from that text\n";
my %headers = $msg->header_pairs();

# Now you probably have all the things you said you needed
print "This message is from '$headers{From}' to '$headers{To}'\n";
print "Here is the subject: '$headers{Subject}'.\n";
print "------BODY-------\n" , $msg->body() , "------BODY END-------\n";

$

I've done your qmail homework for you too.  Look in qmail-command(8) and 
you'll find this:
> qmail-local will, upon your request, feed each incoming mail
>      message through a program of your choice.
>
>      When a mail message arrives, qmail-local runs sh -c  command
>      in  your  home directory.  It makes the message available on
>      command's standard input.

So make your own version of my sample program the one that's named in 
the .qmail file for the user, and you'll be able to do whatever you want 
with the mail.  (Read the rest of qmail-command for details of return 
codes and their meanings).

NB: If security is any concern then you need to look carefully at 
ownership of the "forwarding" program.  I've not checked but it could 
run with elevated privileges of some kind, thus providing a back door.

-- 

Henry Law            Manchester, England


------------------------------

Date: Thu, 7 Feb 2013 08:27:14 -0800 (PST)
From: artmerar@gmail.com
Subject: Re: A little help with Perl & Email Messages
Message-Id: <33c1fa21-91bd-4f7c-b922-faa5e90bf263@googlegroups.com>

On Thursday, February 7, 2013 2:30:28 AM UTC-6, Henry Law wrote:
> On 07/02/13 05:04, artmerar@gmail.com wrote:
> 
> > I'm experiencing 3 conditions:
> 
> >
> 
> > 1)  It writes msg* files to disk, LOTS OF THEM, many of previous messages sent to that address.
> 
> >
> 
> > 2)  I get the body with all the MIME junk in it.
> 
> >
> 
> > 3)  I get nothing.
> 
> >
> 
> > I'm looking for the text only......I've honestly tried about 30 examples with no luck.  So, either I'm a dork, or I'm just missing something.
> 
> 
> 
> I don't know why you're finding this so difficult.
> 
> 
> 
> Why don't you start with this?  As far as I can tell it does what you 
> 
> want, as you described in your original post.
> 
> 
> 
> $ cat art.pl
> 
> #!/usr/bin/perl
> 
> use strict;
> 
> use warnings;
> 
> 
> 
> use Email::Simple;  # Why not?  Your requirement is Simple.
> 
> 
> 
> # Read the message from STDIN
> 
> my $txt;
> 
> $txt .= $_ while <>;
> 
> 
> 
> # Create the message object and extract its headers
> 
> my $msg = Email::Simple->new($txt)
> 
>    or die "Couldn't create an email from that text\n";
> 
> my %headers = $msg->header_pairs();
> 
> 
> 
> # Now you probably have all the things you said you needed
> 
> print "This message is from '$headers{From}' to '$headers{To}'\n";
> 
> print "Here is the subject: '$headers{Subject}'.\n";
> 
> print "------BODY-------\n" , $msg->body() , "------BODY END-------\n";
> 
> 
> 
> $
> 
> 
> 
> I've done your qmail homework for you too.  Look in qmail-command(8) and 
> 
> you'll find this:
> 
> > qmail-local will, upon your request, feed each incoming mail
> 
> >      message through a program of your choice.
> 
> >
> 
> >      When a mail message arrives, qmail-local runs sh -c  command
> 
> >      in  your  home directory.  It makes the message available on
> 
> >      command's standard input.
> 
> 
> 
> So make your own version of my sample program the one that's named in 
> 
> the .qmail file for the user, and you'll be able to do whatever you want 
> 
> with the mail.  (Read the rest of qmail-command for details of return 
> 
> codes and their meanings).
> 
> 
> 
> NB: If security is any concern then you need to look carefully at 
> 
> ownership of the "forwarding" program.  I've not checked but it could 
> 
> run with elevated privileges of some kind, thus providing a back door.
> 
> 
> 
> -- 
> 
> 
> 
> Henry Law            Manchester, England

Henry,

That does work, but is there a way to get rid of all the header information:

Here is the subject: 'TEST'.
------BODY-------
This is a multipart message in MIME format.

------=_NextPart_000_12F3_01CE045C.72E20340
Content-Type: text/plain;
        charset="us-ascii"
Content-Transfer-Encoding: 7bit

Fdsfdsasda

Fdsafdasdfas

------=_NextPart_000_12F3_01CE045C.72E20340
Content-Type: text/html;
        charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
<html xmlns:v=3D"urn:schemas-microsoft-com:vml" =
xmlns:o=3D"urn:schemas-microsoft-com:office:office" =
xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
 .
 .
 .


------------------------------

Date: Thu, 07 Feb 2013 16:42:41 +0000
From: Henry Law <news@lawshouse.org>
Subject: Re: A little help with Perl & Email Messages
Message-Id: <wridnSrrjY8cRI7MnZ2dnUVZ8oOdnZ2d@giganews.com>

On 07/02/13 16:27, artmerar@gmail.com wrote:
>
> That does work, but is there a way to get rid of all the header information:
>
> Here is the subject: 'TEST'.
> ------BODY-------
> This is a multipart message in MIME format.
>
> ------=_NextPart_000_12F3_01CE045C.72E20340
> Content-Type: text/plain;
>          charset="us-ascii"
> Content-Transfer-Encoding: 7bit

If it's in MIME format then you need Email::MIME.  It extends 
Email::Simple to allow you to separate the different MIME parts, and 
fiddle around with their Content-Type and Transfer-Encoding and so 
forth.  It will also (as I recall) return the body (with or without 
decoding), which presumably is what you want.

Please have a go at that -- write some code -- and if it doesn't do what 
you expect then you can get help here.

-- 

Henry Law            Manchester, England


------------------------------

Date: Thu, 07 Feb 2013 09:37:49 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: A little help with Perl & Email Messages
Message-Id: <2dp7h8pndgd5aocor9vjdeddk4m4dtbgu7@4ax.com>

artmerar@gmail.com wrote:
>On Thursday, February 7, 2013 2:30:28 AM UTC-6, Henry Law wrote:
>> On 07/02/13 05:04, artmerar@gmail.com wrote:
>> 
>> > I'm experiencing 3 conditions:
>> 
>> >
>> 
>> > 1)  It writes msg* files to disk, LOTS OF THEM, many of previous messages sent to that address.
>> 
>> >
>> 
>> > 2)  I get the body with all the MIME junk in it.
>> 
>> >
>> 
>> > 3)  I get nothing.
>> 
>> >
>> 
>> > I'm looking for the text only......

And so are the readers of comp.lang.perl.misc. They are not interested
in empty lines unless they contribute to the readability of the text in
a meaningful way.
And they are not interested in lines exceeding the established Usenet
standard of ~75 characters, either.

>I've honestly tried about 30 examples with no luck.  So, either I'm a dork, or I'm just missing something.

Well, go figure

*PLONK*

jue


------------------------------

Date: Thu, 7 Feb 2013 02:53:56 -0800 (PST)
From: Marc Girod <marc.girod@gmail.com>
Subject: help with regexp
Message-Id: <348c85d1-412e-4291-a2d4-b502d308d553@y9g2000vbb.googlegroups.com>

Hello,

I intend to start fixing an issue I have with a regexp of mine, but I
thought I might ask for comments even before I start myself.

I wanted to catch the text between '%[' ... ']N?l' brackets in a
'format specification' [*].
My first attempt worked well at first, with format strings such as
'%Vn %[^O13]Nl\n':

  $fmt =~ s/\%\[(.*?)\](N?)l/$ph/

The text I catch is itself a regexp, but which I process in isolation
[I extend the format specification, so that '^O13' will be used as a
filter.]

Unfortunately, later, I started to use bolder format strings, such as
e.g.:
  '%Vn %[Foo]NSa %[^O13]Nl\n'

My first regexp obviously bled over the two sets of brackets...
A first naive fix was:

  $fmt =~ s/\%\[([^\]]*?)\](N?)l/$ph/

However, I can forsee that this prevents other valid specs, such as
e.g.:
  '%Vn %[^[OE]]Nl\n'

I can also see that my strategy works only with *one* such field, but
I am willing to accept that, if I can support complex regexps inside
it.

The question I have is: am I doomed to implement a parser?
Or can I find a reasonable way out e.g. with look ahead?

Of course, I'll post what I get to myself, if I do (I won't jump to it
right away...)

Thanks!
Marc

*: I give the link to the man page for this, but I don't expect you to
need to read it:
<http://publib.boulder.ibm.com/infocenter/cchelp/v7r0m1/topic/
com.ibm.rational.clearcase.cc_ref.doc/topics/fmt_ccase.htm>


------------------------------

Date: Thu, 7 Feb 2013 14:37:58 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: help with regexp
Message-Id: <6rqcu9-uif2.ln1@anubis.morrow.me.uk>


Quoth Marc Girod <marc.girod@gmail.com>:
> 
> I wanted to catch the text between '%[' ... ']N?l' brackets in a
> 'format specification' [*].
> My first attempt worked well at first, with format strings such as
> '%Vn %[^O13]Nl\n':
> 
>   $fmt =~ s/\%\[(.*?)\](N?)l/$ph/
> 
> The text I catch is itself a regexp, but which I process in isolation
> [I extend the format specification, so that '^O13' will be used as a
> filter.]
> 
> Unfortunately, later, I started to use bolder format strings, such as
> e.g.:
>   '%Vn %[Foo]NSa %[^O13]Nl\n'
> 
> My first regexp obviously bled over the two sets of brackets...
> A first naive fix was:
> 
>   $fmt =~ s/\%\[([^\]]*?)\](N?)l/$ph/
> 
> However, I can forsee that this prevents other valid specs, such as
> e.g.:
>   '%Vn %[^[OE]]Nl\n'

I am assuming the spec here requires matching brackets inside a %[]Nl?
Can non-matching brackets be escaped?

> I can also see that my strategy works only with *one* such field, but
> I am willing to accept that, if I can support complex regexps inside
> it.
> 
> The question I have is: am I doomed to implement a parser?
> Or can I find a reasonable way out e.g. with look ahead?

You are doomed to implement a parser, but you can do so using the regex
engine :). It's not lookahead you need, it's recursion.

If you don't allow escaping of unbalanced brackets, the simple answer is
to use Regexp::Common::balanced. If you do, you will need to use 5.10,
and write out the recursion yourself:

    $fmt =~ m[
        % \[ ( 
            (?: [^][\\]     # any ordinary character
            |   \\.         # any escaped character
            |   \[ (?-1) \] # a nested set of brackets
            )*
        ) \] (N?) l
    ]x;

The trick is the (?-1) group, which says 'start again at the top of the
nearest enclosing () group'.

Ben



------------------------------

Date: Thu, 07 Feb 2013 15:40:19 +0000
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: help with regexp
Message-Id: <87a9rguo7w.fsf@sapphire.mobileactivedefense.com>

Ben Morrow <ben@morrow.me.uk> writes:
> Quoth Marc Girod <marc.girod@gmail.com>:
>> I wanted to catch the text between '%[' ... ']N?l' brackets in a
>> 'format specification' [*].
>> My first attempt worked well at first, with format strings such as
>> '%Vn %[^O13]Nl\n':
>> 
>>   $fmt =~ s/\%\[(.*?)\](N?)l/$ph/

[...]

>> The question I have is: am I doomed to implement a parser?
>> Or can I find a reasonable way out e.g. with look ahead?
>
> You are doomed to implement a parser, but you can do so using the regex
> engine :).

Not really. A 'parser' would be something which does a grammatical analysis
of a sequence of tokens. This here is a lexical analyzer.


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 3876
***************************************


home help back first fref pref prev next nref lref last post