X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/0cb3c82ac7c780c1588c495a36d725c1ca2a5c76..4c9ad9f4f44521d7eae9ea1e8277cf7f8b577d20:/docs/contrib/replyfilter diff --git a/docs/contrib/replyfilter b/docs/contrib/replyfilter index 193dd40b..36facd5f 100755 --- a/docs/contrib/replyfilter +++ b/docs/contrib/replyfilter @@ -160,15 +160,28 @@ sub process_text (*$$;$) # if ($encoding eq '7bit' || $encoding eq '8bit') { + # + # Switch the character set to whatever is specified by + # the MIME message + # + binmode($input, ":encoding($charset)"); while (<$input>) { $ret = match_boundary($_, $boundary); if (defined $ret) { + binmode($input, ':encoding(us-ascii)'); return $ret; } print $quoteprefix, $_; } return 'EOF'; } else { + # + # If we've got some other encoding, the input text is almost + # certainly US-ASCII + # + + binmode($input, ':encoding(us-ascii)'); + $decoder = find_decoder($encoding); if (! defined $decoder) { return 'EOF'; @@ -180,23 +193,31 @@ sub process_text (*$$;$) # to filter it. Read it in; if it's too long, filter it. # + my $chardecode = find_encoding($charset); + while (<$input>) { - my $line, $len; + my @lines, $len; last if ($ret = match_boundary($_, $boundary)); - $line = decode($charset, &$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'; } @@ -205,7 +226,9 @@ sub process_text (*$$;$) # # These are short enough; just output it now as-is # - print STDOUT @text; + foreach my $line (@text) { + print STDOUT $quoteprefix, $line; + } return $ret; } @@ -627,6 +650,8 @@ sub match_boundary($$) { my ($_, $boundary) = @_; + return if ! defined $boundary; + if (substr($_, 0, 2) eq '--') { s/[ \t\r\n]+\Z//; if ($_ eq "--$boundary") {