in reply to Re^4: Again on SOAP::Lite, MIME::Entity and SOAP::Packager
in thread Again on SOAP::Lite, MIME::Entity and SOAP::Packager

Oh, sorry - I misled you in my untested reply about monkey patching. The monkeypatch should simply use $old_stringify_body. You now have the (IMO better) approach of patching the module directly, but for completeness, the following should allow you to replace just that subroutine:

use MIME::Entity; my $old_stringify_body = \&MIME::Entity::stringify_body; *MIME::Entity::stringify_body = sub { my( $self ) = @_; my $body = $old_stringify_body(); $body =~ s!\n!\r\n!g; return $body };

Replies are listed 'Best First'.
Re^6: Again on SOAP::Lite, MIME::Entity and SOAP::Packager
by ray.rick.mini (Sexton) on Dec 29, 2016 at 11:27 UTC

    SUCCESS! Your code works great.. this actually fix the wrong behaviour:

    my $old_stringify_body = \&MIME::Entity::stringify_body; *MIME::Entity::stringify_body = sub { my( $self ) = @_; my $body = &$old_stringify_body; $body =~ s!\n!\r\n!g; return $body };

      Thanks for confirming this. I'm not sure whether patching ->stringify_body is the best approach in general. I've looked through the test suite and the test suite caters in various locations for output being different sizes depending on whether Perl uses \n or \r\n when writing text files without binmode. This makes me feel that the whole test suite would also need an overhaul together with the module to produce identical output regardless of where it is run.

      As I don't have a (direct) use case for MIME::tools beyond MIME::Parser and thus don't know what the applicable RFCs say, it's hard to tell (and fix) the situations where \n is used wrongly. Hopefully your investigations and findings here help others encountering SOAP problems address these issues.

        I just modified the sub only to change multipart boundaries. There is the case where binary encoded data are in the body with '\n' char and I don't want to mess with those
        my $old_stringify_body = \&MIME::Entity::stringify_body; *MIME::Entity::stringify_body = sub { my( $self ) = @_; my $body = &$old_stringify_body; $body=~/(----+=_\d+-\d+-\d)/; my $boundary=$1; $body =~ s!\n$boundary\n!\r\n$boundary\r\n!g; return $body };
        Great thanks Corion for the help!