[Mailmunge] MIME::Entity->body

Dianne Skoll dianne at skollsoft.com
Mon Aug 2 16:19:17 EDT 2021


On Mon, 02 Aug 2021 15:59:10 -0400
postfix--- via Mailmunge <mailmunge at lists.mailmunge.org> wrote:

> I obviously am not understanding how to use MIME::Entity, and it
> feels like im missing something simple. I get the parts from the
> entity, i get the body from the part. The MIME::Entity docs says the
> body "Returns an array reference. Each array entry is a
> newline-terminated line." I can Dumper($part->body) and see the email
> body as an array of lines.

You almost certainly do not want to use $entity->body.  That gives you
the *encoded* body, not the decoded body.  This distinction is mentioned
in the MIME::Entity man page.

What you want to do is get the bodyhandle, like this:

     my $body = $part->bodyhandle;

And then you can read the decoded body line-by-line like this:

    my $io = $body->open('r');
    while (defined($_ = $io->getline)) {
        # Do stuff with $_
    }

See "man MIME::Body"

Regards,

Dianne.


More information about the Mailmunge mailing list