Skip to content

Commit f4b8c76

Browse files
committed
Skip inlining CSS for content with over 3k tags
Email content with too many tags can cause performance issues during the inlining process. Typically, emails are not expected to contain tags more than 1k.
1 parent fa580e6 commit f4b8c76

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lib/RT/Util.pm

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ For html CONTENT, convert CSS <style> blocks to inline styles.
294294
=cut
295295

296296
our $INLINE_CSS_MAX_SIZE = 1024 * 1024;
297+
our $INLINE_CSS_MAX_TAGS = 3_000;
297298

298299
sub InlineCSS {
299300
my $content = shift // return;
@@ -308,6 +309,16 @@ sub InlineCSS {
308309
return $content;
309310
}
310311

312+
if ($INLINE_CSS_MAX_TAGS) {
313+
my $tags;
314+
while ( $content =~ /<\w+/g ) {
315+
if ( ++$tags > $INLINE_CSS_MAX_TAGS ) {
316+
RT->Logger->debug("Content exceeds max tag limit ($INLINE_CSS_MAX_TAGS), skipping");
317+
return $content;
318+
}
319+
}
320+
}
321+
311322
# HTML::Query generates a ton of warnings about unsupported
312323
# pseudoclasses. Suppress those since they don't help the person
313324
# running RT.

0 commit comments

Comments
 (0)