I use this to parse email topics:
You can try the following:
str = "=?UTF-8?Q?J=2E_Pablo_Fern=C3=A1ndez?=" if m = /=\?([A-Za-z0-9\-]+)\?(B|Q)\?([!->@-~]+)\?=/i.match(str) case m[2] when "B" # Base64 encoded decoded = Base64.decode64(m[3]) when "Q" # Q encoded decoded = m[3].unpack("M").first.gsub('_',' ') else p "Could not find keyword!!!" end Iconv.conv('utf-8',m[1],decoded) # to convert to utf-8 end
ankimal
source share