I am trying to use the following code, which I have not been able to test yet, because I get the following errors:
#!/usr/bin/perl use warnings; use strict; use Text::Wrap; use Mail::Box::Manager; use HTML::Obliterate qw(extirpate_html); open (MYFILE, '>>data.txt'); binmode(MYFILE, ':encoding(UTF-8)'); my $file = shift || $ENV{MAIL}; my $mgr = Mail::Box::Manager->new( access => 'r', ); my $folder = $mgr->open( folder => $file ) or die '$file: Unable to open: $!\n'; for my $msg ( sort { $a->timestamp <=> $b->timestamp } $folder->messages) { my $to = join( ', ', map { $_->format } $msg->to ); my $from = join( ', ', map { $_->format } $msg->from ); my $date = localtime( $msg->timestamp ); my $subject = $msg->subject; my $body = $msg->decoded->string; if ( $msg->isMultipart ) { foreach my $part ( $msg->parts ) { if ( $part->contentType eq 'text/html' ) { my $nohtml = extirpate_html( $msg ); $body =~ s/^>.*$//msg; $Text::Wrap::columns=80; print MYFILE wrap('', '', <<''); \n From: $from To: $to Date: $date Subject: $subject \n $body } else { $body =~ s/^>.*$//msg; $Text::Wrap::columns=80; print MYFILE wrap('', '', <<''); \n From: $from To: $to Date: $date Subject: $subject \n $body } }}
All the braces seem to match up, so I am unsure what the problem is
syntax error at x.pl line 46, near 'else' (Might be a runaway multi-line << string starting on line 36) Missing right curly or square bracket at x.pl line 63, at end of line syntax error at x.pl line 63, at EOF Execution of x.pl aborted due to compilation errors.
edit:
it now works, but the html is not striped: instead a few emails with stuff like
>
> interlaced throughout, causing it to be many more pages than it should. Is there a better way to do this
So line 36 seems to be
which means perl will wrap the following text until there is terminator
''(I never use confusing item like this, I always use END or UNTIL_END for simplicity.)That terminator is then found on line 45 (the empty line), meaning next thing it processes is line 46:
which doesn’t make sense, since the previous
ifhasn’t closed yet (the line 44 which has } is before the terminator''so its treated as text for wrapping. Perl notices this and kindly suggest you this might be the culprit:You need to swap lines 44 and 45 to first have terminator
''(empty line), then close the if with}. The second wrap in your example does this correctly.