in reply to Re^5: Is it possible to force MIME::Parser to extract text-files on a Windows system without the extra CR's on the end of lines?
in thread Is it possible to force MIME::Parser to extract text-files on a Windows system without the extra CR's on the end of lines?

Not sure what you mean, my anonymous friend. Would you please explain further?

Can you guess? ... some Body object or something has a mutator called binary that controls whether or not to use newline translation ...

  • Comment on Re^6: Is it possible to force MIME::Parser to extract text-files on a Windows system without the extra CR's on the end of lines?

Replies are listed 'Best First'.
Re^7: Is it possible to force MIME::Parser to extract text-files on a Windows system without the extra CR's on the end of lines?
by WilliamDee (Initiate) on Feb 12, 2014 at 20:50 UTC

    Gotcha, yes, I dug around in the Parser.pm to have a look at that sort of stuff. For example, here is the part dealing with binary attachments:

    $bin_ent->head->mime_attr('Content-type.x-unix-mode' => "0$mode"); $bin_ent->bodyhandle($self->new_body_for($bin_ent->head)); $bin_ent->bodyhandle->binmode(1) or die "$ME: can't set to binmode: $! +"; my $io = $bin_ent->bodyhandle->open("w") or die "$ME: can't create: $! +"; $io->print($bin_data) or die "$ME: can't print: $!"; $io->close or die "$ME: can't close: $!";

    And here is the part dealing with text attachments:

    $txt_ent->bodyhandle($self->new_body_for($txt_ent->head)); my $io = $txt_ent->bodyhandle->open("w") or die "$ME: can't create: $! +"; $io->print(@$preamble) or die "$ME: can't print: $!"; $io->close or die "$ME: can't close: $!";

    So it occurred to me: "Hmm! If I add in code to force the text to use binary like this..."

    $txt_ent->bodyhandle($self->new_body_for($txt_ent->head)); $txt_ent->bodyhandle->binmode(1) or die "$ME: can't set to binmode: $! +"; my $io = $txt_ent->bodyhandle->open("w") or die "$ME: can't create: $! +";

    Unfortunately it didn't work, leading me to conclude that I don't know enough about the code at this time to be dealing with changing the guts of an existing perl module.

    Technically I could copy and recreate it under the name of MIME::MyParser and see if I could manage to hack that into submission - however it seemed more than I was capable of managing if I couldn't even change the existing code. It was at this point that I decided it was easier to hack the input-file to trick the parser into doing what I want it to do.

    Cheers,
    William

      I think the idea is to try calling methods on $entity , not editing Parser.pm ... parse_open gives you entity ...not sure if it work but that would be the approach I would investigate, not editing the module :)