Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

MIME Errors

by Anonymous Monk
on Nov 23, 2001 at 15:16 UTC ( #127086=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi All, someone here kindly helped me with some code a few weeks ago to use when parsing emails to get the subject/from/body of an email .. I have the code, but it seems to be bringing up errors all the time, can anyone see any problems in this code?
use MIME::Parser; use Mail::Address; $parser = new MIME::Parser; eval { $MIME_entity = $parser->parse(\*STDIN); } if ($@){ print 'Trouble parsing mail:'; print $parser->results->msgs(); } $header = $MIME_entity->head(); $subject = $header->get('Subject'); my $from = $header->get('From'); my @from_addresses = Mail::Address->parse($from); my $address; if (@from_addresses) { $address = $from_addresses[0]->address(); } else { print "No address found in from line!\n"; } $bodyh = $ent->bodyhandle; } $parser->filer->purge();

Here is the errors:
syntax error at email.pl line 47, near "){" syntax error at email.pl line 50, near "}"

Any ideas on what the problem could be?, Thank you so much

Replies are listed 'Best First'.
Re: MIME Errors
by arhuman (Vicar) on Nov 23, 2001 at 15:23 UTC
    Probably the missing semi-colon after the eval block...
    I also suspect the last '}' to be unmatched (and useless) ?

    PS : Being consistent in your code layout would help finding such 'bracket error'.
    See perlstyle for good advices...
    As always : just my humble opinion..

    UPDATE : To find where to place the semi-colon see eval
    the syntax is explained and several examples given.
    And sorry but I couldn't resist : RTFM !! ;-)


    "Only Bad Coders Code Badly In Perl" (OBC2BIP)
      ?I have fixed the unmatched '}' but the two errors remain :( How do you mean semi-colon after eval block? There is on at the end of that line, is there supposed to another ?
      use MIME::Parser; use Mail::Address; $parser = new MIME::Parser; eval { $MIME_entity = $parser->parse(\*STDIN); } if ($@){ print 'Trouble parsing mail:'; print $parser->results->msgs(); } else { $header = $MIME_entity->head(); $subject = $header->get('Subject'); my $from = $header->get('From'); my @from_addresses = Mail::Address->parse($from); my $address; if (@from_addresses) { $address = $from_addresses[0]->address(); } else { print "No address found in from line!\n"; } $bodyh = $ent->bodyhandle; } $parser->filer->purge();
Re: MIME Errors
by dws (Chancellor) on Nov 23, 2001 at 15:29 UTC
    I have the code, but it seems to be bringing up errors all the time
    eval { ... }; ^ -- you need one of these
      Thanks DWS.. I dont know why but this script doesnt want to parse emails, after piping an email to it, this is what I get:
      Name "main::ent" used only once: possible typo at /script.pl line 63. Name "main::bodyh" used only once: possible typo at /script.pl line 63 +. Name "main::subject" used only once: possible typo at /script.pl line +54. Trouble parsing mail:debug: process_header warning: skipping bogus mailbox 'From ' line debug: type = multipart, subtype = alternative debug: process_multipart... debug: parsing part 1... debug: process_header debug: type = text, subtype = plain debug: process_singlepart... debug: using temp file debug: t bound: 0 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 + CPU) debug: extract uuencode? 0 debug: encoding? quoted-printable debug: effective type? text/plain debug: no filename recommended: synthesizing our own debug: planning to use 'msg-12389-1.txt' debug: outputting body to disk file: ./msg-12389-1.txt
        Hello Anonymous, I think I posted the example to you last time.

        It's hard to say for certain without more details, but here's some speculation as to the error you're seeing (not including the warnings that someone else has noted).

        First of all, the MIME Parser is blowing up while parsing the message that you piped it, and is then printing out the details, as it's coded to do.

        The question is why it's blowing up - and that's what's not clear. According to this debug, it appears to have gotten as far as selecting a disk file to hold the first MIME part of the message, then it dies.

        Could this be a file permission problem? Could the script be running as a user who does not have permission to write in the current working directory? You could solve this in multiple ways - you can tell the MIME parser to parse in core memory, or you can specify a writable directory to use for the temp files, or you can change permissions on the current working directory.

        In any of these cases, you've got a bit of work to do - and, it sounds like, a bit of reading. There's no easy answer - you need to digest the MIME-tools documentation.

        Good hunting.

        Peace,
        -McD

        anyone ? :( please.. not sure why it is doing that error

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://127086]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2022-05-28 17:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (99 votes). Check out past polls.

    Notices?