Pregunta

He conseguido el mensaje de correo con las siguientes tema en mi Gmail accout:

"400, ????????, ????????"

Este es el código que utilizo para agarrar electrónico:

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

En msg.subject Tengo siguiente valor "=? KOI8-R? B? MTAwLCDixc7ayc4sIDMwMDAgzMnU0s / X? ="

Parece que IMAP no han decodificado él. ¿Debo hacer yo manualmente o biblioteca IMAP podría hacerlo por mí?

¿Fue útil?

Solución

¿Y si uso NKF?

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

medios -mw MIME decodificar y UTF-8 salida

Otros consejos

Correo :: codificaciones es realmente útil aquí:

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

retornos

zwei plus zwölf ist vierzehn
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top