Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new() takes global $1 value as crlf character #24

Open
gbdimde opened this issue Jun 7, 2023 · 0 comments
Open

new() takes global $1 value as crlf character #24

gbdimde opened this issue Jun 7, 2023 · 0 comments

Comments

@gbdimde
Copy link

gbdimde commented Jun 7, 2023

We are using Email::MIME (Version 1.946) that inherits from Email::Simple (Version 2.216). When called like in the following code, the internal crlf character is set to the value of $1:

use Email::MIME;
use Data::Dumper;

my $x = "testvalue";
$x =~ m/^(.+)$/;

my $mime = Email::MIME->new("");

print Dumper($mime);

The output is

$VAR1 = bless( {
                 'header' => bless( {
                                      'headers' => [],
                                      'mycrlf' => 'testvalue'
                                    }, 'Email::MIME::Header' ),
                 'body' => \'',
                 'mycrlf' => 'testvalue',
                 'encode_check' => 1,
                 'ct' => {
                           'composite' => 'plain',
                           'subtype' => 'plain',
                           'attributes' => {
                                             'charset' => 'us-ascii'
                                           },
                           'type' => 'text',
                           'discrete' => 'text'
                         },
                 'body_raw' => '',
                 'parts' => []
               }, 'Email::MIME' );

Please note the entry for "myctrlf".

The problem is in the method _split_head_from_body of Email::Simple:

sub _split_head_from_body {
  my ($self, $text_ref) = @_;
 
  # For body/header division, see RFC 2822, section 2.1
  #
  # Honestly, are we *ever* going to have LFCR messages?? -- rjbs, 2015-10-11
  my $re = qr{\x0a\x0d\x0a\x0d|\x0d\x0a\x0d\x0a|\x0d\x0d|\x0a\x0a};
 
  if ($$text_ref =~ /($re)/gsm) {
    my $crlf = substr $1, 0, length($1)/2;
    return (pos($$text_ref), $crlf);
  } else {
 
    # The body is, of course, optional.
    my $re = $self->__crlf_re;
    $$text_ref =~ /($re)/gsm;
    return (undef, ($1 || "\n"));
  }
} 

In the "else" case it is not checked if the regexp is matching and an existing $1 is used instead of setting the value to "\n". It should be done something like this (the code is not tested):

    my $crlf = "\n";
    if ( $$text_ref =~ /($re)/gsm ) {
        $crlf = $1 || "\n";
    }
    return (undef, $crlf);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant