Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > A little help with Perl & Email Messages

Reply
Thread Tools

A little help with Perl & Email Messages

 
 
Jürgen Exner
Guest
Posts: n/a
 
      02-07-2013
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
>On Thursday, February 7, 2013 2:30:28 AM UTC-6, Henry Law wrote:
>> On 07/02/13 05:04, (E-Mail Removed) 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
 
Reply With Quote
 
 
 
 
artmerar@gmail.com
Guest
Posts: n/a
 
      02-07-2013
On Thursday, February 7, 2013 10:42:41 AM UTC-6, Henry Law wrote:
> On 07/02/13 16:27, (E-Mail Removed) 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


Henry,

Thanks for the pointer. It is almost working, but still have the MIME content:

my $txt;
$txt .= $_ while <>;

my $parsed = Email::MIME->new($txt);
my $decoded = $parsed->body;
my $non_decoded = $parsed->body_raw;

print "DECODED: $decoded\n";
print "NON: $non_decoded\n";


DECODED: This is a multipart message in MIME format.


NON: This is a multipart message in MIME format.

------=_NextPart_000_1500_01CE053E.2ADE0E30
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit

STUFF

MORE STUFF


------=_NextPart_000_1500_01CE053E.2ADE0E30
Content-Type: text/html;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
 
Reply With Quote
 
 
 
 
artmerar@gmail.com
Guest
Posts: n/a
 
      02-08-2013
On Thursday, February 7, 2013 2:47:13 PM UTC-6, Henry Law wrote:
> On 07/02/13 20:26, (E-Mail Removed) wrote:
>
> > Thanks for the pointer. It is almost working, but still have the MIME content:

>
> >

>
> > my $txt;

>
> > $txt .= $_ while <>;

>
> >

>
> > my $parsed = Email::MIME->new($txt);

>
> > my $decoded = $parsed->body;

>
> > my $non_decoded = $parsed->body_raw;

>
> >

>
> > print "DECODED: $decoded\n";

>
> > print "NON: $non_decoded\n";

>
> >

>
> >

>
> > DECODED: This is a multipart message in MIME format.

>
> >

>
> >

>
> > NON: This is a multipart message in MIME format.

>
> >

>
> > ------=_NextPart_000_1500_01CE053E.2ADE0E30

>
> > Content-Type: text/plain;

>
> > charset="us-ascii"

>
> > Content-Transfer-Encoding: 7bit

>
> <snipped>
>
>
>
> It is working perfectly. Look up the structure of multipart MIME
>
> messages and read the documentation.
>
>
>
> Hint: you'll find some help in the third line of the code snippet in the
>
> Synopsis section of the perldoc for Email::MIME. There's another broad
>
> hint in the section describing the "body" method.
>
>
>
> --
>
>
>
> Henry Law Manchester, England


Thanks for all the pointers Henry. I did the reading and changed the code. Looking at the @parts array, it contains some hashes:

PARTS: Email::MIME=HASH(0x16465de0) Email::MIME=HASH(0x164660c0)

I looked at the content type and got this:

CONTENT: multipart/alternative; boundary="----=_NextPart_000_1574_01CE0591.17983190"

Still looking to get just the text, but making some slow progress. This stuff is a bit more complex than I originally thought.

 
Reply With Quote
 
artmerar@gmail.com
Guest
Posts: n/a
 
      02-08-2013
On Thursday, February 7, 2013 2:47:13 PM UTC-6, Henry Law wrote:
> On 07/02/13 20:26, (E-Mail Removed) wrote:
>
> > Thanks for the pointer. It is almost working, but still have the MIME content:

>
> >

>
> > my $txt;

>
> > $txt .= $_ while <>;

>
> >

>
> > my $parsed = Email::MIME->new($txt);

>
> > my $decoded = $parsed->body;

>
> > my $non_decoded = $parsed->body_raw;

>
> >

>
> > print "DECODED: $decoded\n";

>
> > print "NON: $non_decoded\n";

>
> >

>
> >

>
> > DECODED: This is a multipart message in MIME format.

>
> >

>
> >

>
> > NON: This is a multipart message in MIME format.

>
> >

>
> > ------=_NextPart_000_1500_01CE053E.2ADE0E30

>
> > Content-Type: text/plain;

>
> > charset="us-ascii"

>
> > Content-Transfer-Encoding: 7bit

>
> <snipped>
>
>
>
> It is working perfectly. Look up the structure of multipart MIME
>
> messages and read the documentation.
>
>
>
> Hint: you'll find some help in the third line of the code snippet in the
>
> Synopsis section of the perldoc for Email::MIME. There's another broad
>
> hint in the section describing the "body" method.
>
>
>
> --
>
>
>
> Henry Law Manchester, England



Well, what I found out was this:

If I send the email, like from Outlook, and specifically choose Plain Text, the script works fine. But, if the email is in HTML, which is the default, I just cannot get plain text from it.

So, I give, Gonna try and loop through the content and find the info I need. Thanks for all the pointers though, it did help quite a bit.

 
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
1 little 2 little 3 little Kennedys dale Digital Photography 0 03-23-2008 01:03 PM
i have trouble to recive messages ---any ideas for a little help John Penney Computer Support 1 08-29-2006 02:10 PM
why cant i send email messages from this email Billie Jo Ames Computer Support 8 06-30-2005 12:24 PM
Problems with posting email/news messages via OE6 and working with Web-based email Alex Vinokur Computer Support 2 06-18-2004 12:56 PM
A little help had anyone used the email-dir.py Email Module Chuck Amadi Python 1 06-06-2004 04:06 AM



Advertisments