module LooseMail
Constants
- ENCODED_VALUE
- VERSION
Public Class Methods
decode_data(type, data)
click to toggle source
# File lib/loose_mail.rb, line 25 def self.decode_data(type, data) case type when 'q', 'Q' then data.gsub(/_/, ' ').unpack1('M') when 'b', 'B' then data.unpack1('m') end end
decode_words(words)
click to toggle source
# File lib/loose_mail.rb, line 8 def self.decode_words(words) results = [] while (word = words.shift) if (m = word.match(ENCODED_VALUE)) charset = m[1].downcase word = decode_data(m[2], m[3]) while (m = words.first&.match(ENCODED_VALUE)) && m[1].downcase == charset word.concat decode_data(m[2], m[3]) words.shift end word = Mail::Ruby19.charset_encoder.encode(word, charset).encode(Encoding::UTF_8, undef: :replace, invalid: :replace) end results.push word end results.join end