Ruby IMAP library does not decrypt mail subject

I have an email with the following message in my Gmail:

"400, value, value"

Here is the code I use to capture mail:

imap = Net::IMAP.new('imap.gmail.com', 993, true, nil, false) imap.login(LOGIN, PASSWORD) imap.select("INBOX") messages = imap.search(['ALL']).map do |message_id| msg =imap.fetch(message_id, "ENVELOPE")[0].attr["ENVELOPE"] result = {:mailbox => msg.from[0].mailbox, :host => msg.from[0].host, :subject => msg.subject, :created_at => msg.date} imap.store(message_id, "+FLAGS", [:Deleted]) result end imap.expunge() imap.logout 

In msg.subject, I have the following value: "=? KOI8-R? B? MTAwLCDixc7ayc4sIDMwMDAgzMnU0s / X? ="

IMAP did not seem to decrypt it. Should I do this manually or the IMAP library for me?

+4
source share
2 answers

How about using NKF?

 require 'nkf' ... result = {... :subject => NKF.nkf("-mw", msg.subject), ...} 

-mw means MIME decoding and utf-8 output

+2
source

Mail :: Encodings are really useful here:

 require 'mail' test = "zwei plus =?ISO-8859-15?Q?zw=F6lf_ist_vierzehn?=" puts Mail::Encodings.value_decode(test) 

returns

 zwei plus zwΓΆlf ist vierzehn 
+9
source

All Articles