From 54bed5e78cacc017ad95521f3a50ebcfe344895d Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Mon, 18 Nov 2019 03:41:08 +0100 Subject: pullimap: Fix mangling of data lines starting with a dot. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some LMTP servers, Dovecot's in particular, trims leading dots that are not doubled (e.g. “.foo” would become “foo”). In RFC 5322 sec. 4.5.2 explicitly says that when an RFC 5322 line starts with a '.', the character needs to be doubled. --- pullimap | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'pullimap') diff --git a/pullimap b/pullimap index fbe300e..ee2168d 100755 --- a/pullimap +++ b/pullimap @@ -175,17 +175,18 @@ sub sendmail($$) { my $length = length($$rfc822); while ((my $end = index($$rfc822, "\r\n", $offset) + 2) != 1) { my $line = substr($$rfc822, $offset, $end-$offset); - # RFC 5321 section 4.5.2: the character sequence "\r\n.\r\n" - # ends the mail text and cannot be sent by the user - $SMTP->print($line eq ".\r\n" ? "..\r\n" : $line) or die; + # RFC 5321 sec. 4.5.2: if the line starts with a dot, double it + $line = ".".$line if substr($line, 0, 1) eq "."; + $SMTP->print($line) or die; $offset = $end; } if ($offset < $length) { # the last line did not end with "\r\n"; add it in order to # have the receiving SMTP server recognize the "end of data" - # condition. See RFC 5321 section 4.1.1.4 + # condition. See RFC 5321 sec. 4.1.1.4 my $line = substr($$rfc822, $offset); - $SMTP->print(($line eq "." ? ".." : $line), "\r\n") or die; + $line = ".".$line if substr($line, 0, 1) eq "."; + $SMTP->print($line, "\r\n") or die; } $SMTP->printflush(".\r\n") or die; } -- cgit v1.2.3