Methods
- convert_to
- convert_to
- unquote_and_convert_to
- unquote_base64_and_convert_to
- unquote_quoted_printable_and_convert_to
Public Class methods
Not providing quoting support
[ show source ]
# File lib/action_mailer/vendor/tmail/quoting.rb, line 100
100: def convert_to(text, to, from)
101: warn "Action Mailer: iconv not loaded; ignoring conversion from #{from} to #{to} (#{__FILE__}:#{__LINE__})"
102: text
103: end
[ show source ]
# File lib/action_mailer/vendor/tmail/quoting.rb, line 86
86: def convert_to(text, to, from)
87: return text unless to && from
88: text ? Iconv.iconv(to, from, text).first : ""
89: rescue Iconv::IllegalSequence, Iconv::InvalidEncoding, Errno::EINVAL
90: # the 'from' parameter specifies a charset other than what the text
91: # actually is...not much we can do in this case but just return the
92: # unconverted text.
93: #
94: # Ditto if either parameter represents an unknown charset, like
95: # X-UNKNOWN.
96: text
97: end
[ show source ]
# File lib/action_mailer/vendor/tmail/quoting.rb, line 50
50: def unquote_and_convert_to(text, to_charset, from_charset = "iso-8859-1", preserve_underscores=false)
51: return "" if text.nil?
52: text.gsub(/(.*?)(?:(?:=\?(.*?)\?(.)\?(.*?)\?=)|$)/) do
53: before = $1
54: from_charset = $2
55: quoting_method = $3
56: text = $4
57:
58: before = convert_to(before, to_charset, from_charset) if before.length > 0
59: before + case quoting_method
60: when "q", "Q" then
61: unquote_quoted_printable_and_convert_to(text, to_charset, from_charset, preserve_underscores)
62: when "b", "B" then
63: unquote_base64_and_convert_to(text, to_charset, from_charset)
64: when nil then
65: # will be nil at the end of the string, due to the nature of
66: # the regex used.
67: ""
68: else
69: raise "unknown quoting method #{quoting_method.inspect}"
70: end
71: end
72: end
[ show source ]
# File lib/action_mailer/vendor/tmail/quoting.rb, line 80
80: def unquote_base64_and_convert_to(text, to, from)
81: convert_to(Base64.decode(text).first, to, from)
82: end
[ show source ]
# File lib/action_mailer/vendor/tmail/quoting.rb, line 74
74: def unquote_quoted_printable_and_convert_to(text, to, from, preserve_underscores=false)
75: text = text.gsub(/_/, " ") unless preserve_underscores
76: text = text.gsub(/\r\n|\r/, "\n") # normalize newlines
77: convert_to(text.unpack("M*").first, to, from)
78: end