Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

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?

by WilliamDee (Initiate)
on Feb 12, 2014 at 19:28 UTC ( [id://1074671]=note: print w/replies, xml ) Need Help??


in reply to Re^4: 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?

Cheers,
William

PS: Have altered the documentation in my code to be properly clear, now using:

# change it to use binary extraction when MIME::Parse extracts tex +t files from the mail message $hold =~ s/text\/plain/application\/x-msexcel/g;
  • Comment on 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?
  • Download Code

Replies are listed 'Best First'.
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?
by Anonymous Monk on Feb 12, 2014 at 19:53 UTC

    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 ...

      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 :)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2024-04-23 18:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found