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

Folding not reversible #23

Open
dlucredativ opened this issue Dec 16, 2021 · 0 comments
Open

Folding not reversible #23

dlucredativ opened this issue Dec 16, 2021 · 0 comments

Comments

@dlucredativ
Copy link

RFC2822 and RFC5322 define folding as

wherever this standard allows for folding white space (not simply WSP characters), a CRLF may be inserted before any WSP

and unfolding as

Unfolding is accomplished by simply removing any CRLF that is immediately followed by WSP

By the above definition, it is unfold(fold(input)) = input. However, sub __fold_objless replaces the original WSP by $indent. What is its use case?

sub __fold_objless {
my ($self, $line, $limit, $indent, $crlf) = @_;
# We know it will not contain any new lines at present
my $folded = "";
while (length $line) {
if ($line =~ s/^(.{0,$limit})(\s|\z)//) {
$folded .= $1 . $crlf;
$folded .= $indent if length $line;
} else {
# Basically nothing we can do. :(
$folded .= $line . $crlf;
last;
}
}
return $folded;
}

Consider

diff --git a/t/folding.t b/t/folding.t
index 9ef51cb..4e0d652 100644
--- a/t/folding.t
+++ b/t/folding.t
@@ -43,3 +43,3 @@ END
 
-  my $subject = 'A ' x 50; # Long enough to need to be folded
+  my $subject = "A\t" x 50; # Long enough to need to be folded
 
@@ -54,2 +54,3 @@ END
   unlike($email_1->as_string, qr/\Q$subject/, "we fold the 50-A line");
+  like($email_1->as_string =~ s/\r\n(?=[ \t])//gr, qr/\Q$subject/, "we fold the 50-A line reversibly");
 }

The additional test fails. I think the correct thing to do is along the lines of

diff --git a/lib/Email/Simple/Header.pm b/lib/Email/Simple/Header.pm
index 0709687..b7a3f38 100644
--- a/lib/Email/Simple/Header.pm
+++ b/lib/Email/Simple/Header.pm
@@ -434,4 +434,3 @@ sub __fold_objless {
     if ($line =~ s/^(.{0,$limit})(\s|\z)//) {
-      $folded .= $1 . $crlf;
-      $folded .= $indent if length $line;
+      $folded .= $1 . $crlf . $2;
     } else {
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