Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 218
Robert Grezan Avatar asked Mar 18 '13 00:03

Robert Grezan


1 Answers

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).

like image 124
Robert Grezan Avatar answered Nov 15 '22 06:11

Robert Grezan