while (<$input>) {
$ret = match_boundary($_, $boundary);
if (defined $ret) {
+ binmode($input, ':encoding(us-ascii)');
return $ret;
}
print $quoteprefix, $_;
# certainly US-ASCII
#
- binmode($input, ":encoding(us-ascii)");
+ binmode($input, ':encoding(us-ascii)');
$decoder = find_decoder($encoding);
if (! defined $decoder) {
my $chardecode = find_encoding($charset);
while (<$input>) {
- my $line, $len;
+ my @lines, $len;
last if ($ret = match_boundary($_, $boundary));
- $line = $chardecode->decode(&$decoder($_));
+ @lines = split(/^/, $chardecode->decode(&$decoder($_)));
if (substr($text[$#text], -1, 1) eq "\n") {
- push @text, $line;
+ push @text, shift @lines;
} else {
- $text[$#text] .= $line;
+ $text[$#text] .= shift @lines;
}
if (($len = length($text[$#text])) > $maxline) {
$maxline = $len;
}
+
+ if ($#lines > -1) {
+ push @text, @lines;
+ }
}
+ binmode($input, ':encoding(us-ascii)');
+
if (! defined $ret) {
$ret = 'EOF';
}
#
# These are short enough; just output it now as-is
#
- print STDOUT @text;
+ foreach my $line (@text) {
+ print STDOUT $quoteprefix, $line;
+ }
return $ret;
}
{
my ($_, $boundary) = @_;
+ return if ! defined $boundary;
+
if (substr($_, 0, 2) eq '--') {
s/[ \t\r\n]+\Z//;
if ($_ eq "--$boundary") {