Created
February 15, 2012 11:20
-
-
Save chrisfinne/1835150 to your computer and use it in GitHub Desktop.
Ruby TMail detect HTML in plain text or escaped HTML
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TMail::Mail | |
def bad_html? | |
if multipart? | |
return true if parts.detect{|p| p.content_type.include?('text/plain') && p.to_s =~ /<(html|head)/im } | |
return true if parts.detect{|p| p.to_s =~ /<\/(p|a|span|div|style|head|html)>/im } | |
else | |
return true if body =~ /<\/(p|a|span|div|style|head|html)>/im | |
return true if content_type.include?('text/plain') && body =~ /<(html|head)/im | |
end | |
false | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment