Navigation Menu

Skip to content

Commit

Permalink
fold headers from create method
Browse files Browse the repository at this point in the history
this code has grown very long in the tooth :-/
  • Loading branch information
rjbs committed Jul 4, 2015
1 parent 230efce commit d000914
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Changes
@@ -1,6 +1,8 @@
Revision history for Perl extension Email::Simple

{{$NEXT}}
- fold headers passed to header arg in create method
https://github.com/rjbs/Email-Simple/issues/7

2.206 2015-03-26 23:30:51-04:00 America/New_York
- the changes from 2.204 are back (and re-listed here), but now with
Expand Down
2 changes: 1 addition & 1 deletion lib/Email/Simple/Creator.pm
Expand Up @@ -22,7 +22,7 @@ sub _add_to_header {
Carp::carp("replaced vertical whitespace in $key header with space; this will become fatal in a future version");
}

$$header .= "$key: $value" . $class->_crlf;
$$header .= Email::Simple::Header->__fold_objless("$key: $value", 78, q{ }, $class->_crlf);
}

sub _finalize_header {
Expand Down
10 changes: 8 additions & 2 deletions lib/Email/Simple/Header.pm
Expand Up @@ -316,15 +316,21 @@ sub _fold {

my $indent = $arg->{indent} || $self->_default_fold_indent;

return $self->__fold_objless($line, $limit, $indent, $self->crlf);
}

sub __fold_objless {
my ($self, $line, $limit, $indent, $crlf) = @_;

# We know it will not contain any new lines at present
my $folded = "";
while ($line) {
if ($line =~ s/^(.{0,$limit})(\s|\z)//) {
$folded .= $1 . $self->crlf;
$folded .= $1 . $crlf;
$folded .= $indent if $line;
} else {
# Basically nothing we can do. :(
$folded .= $line . $self->crlf;
$folded .= $line . $crlf;
last;
}
}
Expand Down
19 changes: 18 additions & 1 deletion t/folding.t
@@ -1,6 +1,6 @@
#!perl -w
use strict;
use Test::More tests => 6;
use Test::More tests => 7;

# This time, with folding!

Expand Down Expand Up @@ -36,3 +36,20 @@ END
my $email = Email::Simple->new($text);
is($email->header('Fold-2'), '0 1 2', "we unfold with a false start string");
}

{
my $to = 'to@example.com';
my $from = 'from@example.com';

my $subject = 'A ' x 50; # Long enough to need to be folded

my $email_1 = Email::Simple->create(
header => [
To => $to,
From => $from,
Subject => $subject, # string specified in constructor does *not* get folded
]
);

unlike($email_1->as_string, qr/\Q$subject/, "we fold the 50-A line");
}

0 comments on commit d000914

Please sign in to comment.