diff options
author | Byron Jones <bjones@mozilla.com> | 2012-10-04 07:04:17 +0200 |
---|---|---|
committer | Byron Jones <bjones@mozilla.com> | 2012-10-04 07:04:17 +0200 |
commit | e9b93e7519656a29da28a859ffee69667b7a440a (patch) | |
tree | 5b62df4b6bc5afd63688c06a8801fdbb0eb15e2b /extensions | |
parent | 736334e67b3b0f6fe50bd1a513c08dc98d53c2c8 (diff) | |
download | bugzilla-e9b93e7519656a29da28a859ffee69667b7a440a.tar.gz bugzilla-e9b93e7519656a29da28a859ffee69667b7a440a.tar.xz |
Bug 790697: Profanivore causes broken HTML main by creating very long lines
Diffstat (limited to 'extensions')
-rw-r--r-- | extensions/Profanivore/Extension.pm | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/extensions/Profanivore/Extension.pm b/extensions/Profanivore/Extension.pm index 87a35a3f7..cdec6e1c6 100644 --- a/extensions/Profanivore/Extension.pm +++ b/extensions/Profanivore/Extension.pm @@ -87,13 +87,23 @@ sub mailer_before_send { } _fix_encoding($part); my $body = $part->body_str; + my $new_body; if ($part->content_type =~ /^text\/html/) { - $body = _filter_html($body); + $new_body = _filter_html($body); + if ($new_body ne $body) { + # HTML::Tree removes unnecessary whitespace, + # resulting in very long lines. We need to use + # quoted-printable encoding to avoid exceeding + # email's maximum line length. + $part->encoding_set('quoted-printable'); + } } elsif ($part->content_type =~ /^text\/plain/) { - $body = _filter_text($body); + $new_body = _filter_text($body); + } + if ($new_body && $new_body ne $body) { + $part->body_str_set($new_body); } - $part->body_str_set($body); }); } # Single part email @@ -133,23 +143,27 @@ sub _filter_html { my $comments_div = $tree->look_down( _tag => 'div', id => 'comments' ); return $html if !$comments_div; my @comments = $comments_div->look_down( _tag => 'pre' ); + my $dirty = 0; foreach my $comment (@comments) { - _filter_html_node($comment); + _filter_html_node($comment, \$dirty); } - return $tree->as_HTML; + return $dirty ? $tree->as_HTML : $html; } sub _filter_html_node { - my $node = shift; + my ($node, $dirty) = @_; my $content = [ $node->content_list ]; foreach my $item_r ($node->content_refs_list) { if (ref $$item_r) { _filter_html_node($$item_r); } else { - $$item_r = _filter_text($$item_r); + my $new_text = _filter_text($$item_r); + if ($new_text ne $$item_r) { + $$item_r = $new_text; + $$dirty = 1; + } } } - return $node; } __PACKAGE__->NAME; |