Skip to content

Instantly share code, notes, and snippets.

@chrisfinne
Created February 15, 2012 11:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisfinne/1835150 to your computer and use it in GitHub Desktop.
Save chrisfinne/1835150 to your computer and use it in GitHub Desktop.
Ruby TMail detect HTML in plain text or escaped HTML
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 =~ /&lt;\/(p|a|span|div|style|head|html)&gt;/im }
else
return true if body =~ /&lt;\/(p|a|span|div|style|head|html)&gt;/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