zammad/lib/html_sanitizer/base.rb
Mantas Masalskis 752ace59f7 Fixes #5897 - Emails cannot be fetched from mailbox
Co-authored-by: Dominik Klein <dk@zammad.com>
Co-authored-by: Mantas <mm@zammad.com>
2026-01-08 16:37:31 +02:00

30 lines
845 B
Ruby

# Copyright (C) 2012-2026 Zammad Foundation, https://zammad-foundation.org/
class HtmlSanitizer
class Base
def with_timeout(string, &)
Timeout.timeout(PROCESSING_TIMEOUT, &)
rescue Timeout::Error
Rails.logger.error "Could not process string via #{self.class.name} in #{PROCESSING_TIMEOUT} seconds. Current state: #{string}"
UNPROCESSABLE_HTML_MSG
rescue => e
return UNPROCESSABLE_HTML_MSG if e.is_a?(ArgumentError) && e.message == 'Document tree depth limit exceeded'
raise e
end
def loop_string(string, scrubber)
string = ScrubHtml.new(string, scrubber).scrub!.to_html
old_string = string
loop do
string = ScrubHtml.new(string, scrubber).scrub!.to_html
break if string == old_string
old_string = string
end
string
end
end
end