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

DATA & lines starting with . (dot) #1

Closed
karel-m opened this issue Jun 27, 2016 · 4 comments
Closed

DATA & lines starting with . (dot) #1

karel-m opened this issue Jun 27, 2016 · 4 comments

Comments

@karel-m
Copy link
Contributor

karel-m commented Jun 27, 2016

send() method does not correctly handle a situation when data contains a line starting with . (dot).

According to: http://tools.ietf.org/html/rfc5321#section-4.5.2

Before sending a line of mail text, the SMTP client checks the
first character of the line.  If it is a period, one additional
period is inserted at the beginning of the line.

The current way of handling data value might be a feature. In that case I propose adding named argument data_esc which will handle the above mentioned escaping.

Here is a demonstration - in both cases the second line is missing the dot at the beginning. It also demonstrates that it cannot be "solved" by feeding data with a string created by MIME::Lite->new(..)->as_string. IMHO this escaping should happen in Mojo::SMTP::Client.

warn "A=" . $smtp->send(
        from => 'noreply@testdom.com',
        to   => 'karel@dom.com',
        data => join("\r\n", 'From: noreply@testdom.com',
                             'To: karel@dom.com',
                             'Subject: Dot test A',
                             '',
                             'first line',
                             '.second line starting with dot',
                             'last line',
                ),
        quit => 1
);

my $msg = MIME::Lite->new(
        From    => 'noreply@testdom.com',
        To      => 'karel@dom.com',
        Subject => 'Dot test B',
        Data    => join("\r\n", 
                             'first line',
                             '.second line starting with dot',
                             'last line',
                   ),
);

warn "B=" . $smtp->send(
        from => 'noreply@testdom.com',
        to   => 'karel@dom.com',
        data => $msg->as_string,
        quit => 1,
);
@olegwtf
Copy link
Owner

olegwtf commented Jun 27, 2016

I agree, data should handle this. Can you provide patch?
I haven't time to fix this now.

@karel-m
Copy link
Contributor Author

karel-m commented Jun 27, 2016

Initial idea is here: https://github.com/karel-m/p5-Mojo-SMTP-Client/commit/ea75bd07ad0650d0c3b627a4d6f29ff709832a16

After looking at https://metacpan.org/source/SHAY/libnet-3.08/lib/Net/Cmd.pm#L507 I am not sure whether we shouldn't also normalize newlines LF >> CRLF. Unfortunately straightforward replace like $line =~ s/\015?\012(\.?)/\015\012$1$1/sg; caused t/03_smtp_nb.t failure. I'll try to investigate more (basically the logic in Net::Cmd is even more complicated).

@karel-m
Copy link
Contributor Author

karel-m commented Jun 27, 2016

Another improvement: https://github.com/karel-m/p5-Mojo-SMTP-Client/commit/259918048b79524ab25a0d11afa848198f929783

Now the replacing regexp is handling . escaping as well as CRLF normalization.

It works fine when data is the scalar with actual data (all at once), however there might be troubles when data is coderef and the sequence \r\n, is not in one chunk - like blexxxxx\r\n in one chunk and .blexxx in the next chunk.

It seems like we will inevitably end up mimicing sub datasend from Net::Cmd https://metacpan.org/source/SHAY/libnet-3.08/lib/Net/Cmd.pm#L459 (see $first_ch / $last_ch kung-fu)

@olegwtf
Copy link
Owner

olegwtf commented Jun 29, 2016

Thanks
Just released version 0.11

@olegwtf olegwtf closed this as completed Jun 29, 2016
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

2 participants