Class: TMail::Unquoter

Inherits:
Object
  • Object
show all
Defined in:
lib/action_mailer/vendor/tmail/quoting.rb

Class Method Summary collapse

Class Method Details

.unquote_and_convert_to(text, to_charset, from_charset = "iso-8859-1") ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/action_mailer/vendor/tmail/quoting.rb', line 50

def unquote_and_convert_to(text, to_charset, from_charset = "iso-8859-1")
  return "" if text.nil?
  if text =~ /^=\?(.*?)\?(.)\?(.*)\?=$/
    from_charset = $1
    quoting_method = $2
    text = $3
    case quoting_method.upcase
      when "Q" then
        unquote_quoted_printable_and_convert_to(text, to_charset, from_charset)
      when "B" then
        unquote_base64_and_convert_to(text, to_charset, from_charset)
      else
        raise "unknown quoting method #{quoting_method.inspect}"
    end
  else
    convert_to(text, to_charset, from_charset)
  end
end

.unquote_base64_and_convert_to(text, to, from) ⇒ Object



73
74
75
# File 'lib/action_mailer/vendor/tmail/quoting.rb', line 73

def unquote_base64_and_convert_to(text, to, from)
  convert_to(Base64.decode(text).first, to, from)
end

.unquote_quoted_printable_and_convert_to(text, to, from) ⇒ Object



69
70
71
# File 'lib/action_mailer/vendor/tmail/quoting.rb', line 69

def unquote_quoted_printable_and_convert_to(text, to, from)
  convert_to(text.gsub(/_/," ").unpack("M*").first, to, from)
end