Class: TMail::Unquoter
Class Method Summary collapse
- .unquote_and_convert_to(text, to_charset, from_charset = "iso-8859-1", preserve_underscores = false) ⇒ Object
- .unquote_base64_and_convert_to(text, to, from) ⇒ Object
- .unquote_quoted_printable_and_convert_to(text, to, from, preserve_underscores = false) ⇒ Object
Class Method Details
.unquote_and_convert_to(text, to_charset, from_charset = "iso-8859-1", preserve_underscores = false) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/tmail/quoting.rb', line 67 def unquote_and_convert_to(text, to_charset, from_charset = "iso-8859-1", preserve_underscores=false) return "" if text.nil? text.gsub!(/\?=(\s*)=\?/, '?==?') # Remove whitespaces between 'encoded-word's text.gsub(/(.*?)(?:(?:=\?(.*?)\?(.)\?(.*?)\?=)|$)/) do before = $1 from_charset = $2 quoting_method = $3 text = $4 before = convert_to(before, to_charset, from_charset) if before.length > 0 before + case quoting_method when "q", "Q" then unquote_quoted_printable_and_convert_to(text, to_charset, from_charset, preserve_underscores) when "b", "B" then unquote_base64_and_convert_to(text, to_charset, from_charset) when nil then # will be nil at the end of the string, due to the nature of # the regex used. "" else raise "unknown quoting method #{quoting_method.inspect}" end end end |
.unquote_base64_and_convert_to(text, to, from) ⇒ Object
98 99 100 |
# File 'lib/tmail/quoting.rb', line 98 def unquote_base64_and_convert_to(text, to, from) convert_to(Base64.decode(text), to, from) end |
.unquote_quoted_printable_and_convert_to(text, to, from, preserve_underscores = false) ⇒ Object
92 93 94 95 96 |
# File 'lib/tmail/quoting.rb', line 92 def unquote_quoted_printable_and_convert_to(text, to, from, preserve_underscores=false) text = text.gsub(/_/, " ") unless preserve_underscores text = text.gsub(/\r\n|\r/, "\n") # normalize newlines convert_to(text.unpack("M*").first, to, from) end |