How to decode subject fetched via Net::IMAP which in UTF8? (ruby)
Asked Answered
G

1

8

I'm using Net::IMAP.fetch to fetch some messages from Gmail. However, when I fetch a message which has a UTF8 subject (i.e., in cyrillic) I get something like this:

=?UTF-8?B?0KHRgNC/0YHQutC4INGE0L7RgNGD0Lwg0YLRgNCw?= =?UTF-8?B?0LbQuCDQuNC30LHQvtGA0L3QuCDQvNCw0YLQtdGA0Lg=?= =?UTF-8?B?0ZjQsNC7INC4INC90LAg0ZvQuNGA0LjQu9C40YY=?= =?UTF-8?B?0LggLSBjaXJpbGFjZSB0ZXN0?=

How can I convert the above string into UTF8?

NOTE: this is for ruby 1.8.7

Guffaw answered 18/3, 2013 at 0:11 Comment(0)
G
7

The answer is:

Mail::Encodings.unquote_and_convert_to( string, 'utf-8' )

The point is that encoding of email subjects is "QUOTED-PRINTABLE" encoding (by default for Gmail).

Guffaw answered 18/3, 2013 at 0:44 Comment(1)
Note that this answer relies on having installed the mail gem first.Transonic

© 2022 - 2024 — McMap. All rights reserved.