Ruby unicode mail receiving

How do i see unicode text within retrieved messages?

$require 'net/pop'
mail_server = Net::POP3.new('mail.yahoo.ru')
mail_server.start('login','pass')
mail_server.mails.each do |m|
   puts m.pop if /Superjob/.match(m.header)
end

Shows me "??????.." instead of cyrillic letters.

Upvotes: 0

Views: 131

Answers (2)

the8472
the8472

Reputation: 43042

You might want to use the mail gem, it supports multipart messages, automatic charset conversion for all fields etc.

Upvotes: 1

Sean
Sean

Reputation: 2891

I'm not completely familiar with net/pop but you probably want to use Iconv to convert it to utf-8 with something like this:

require 'net/pop'
require 'iconv'

mail_server = Net::POP3.new('mail.yahoo.ru')
mail_server.start('login','pass')
mail_server.mails.each do |m|
 m = Iconv.conv('UTF8', 'CP1251', m)
 #or m.header = Iconv.conv('UTF8', 'CP1251', m.header) ??
 puts m.pop if /Superjob/.match(m.header)
end

Upvotes: 1

Related Questions