【問題】
utf-8で書かれたメールをパースしててこうなった(抜粋)
NHK EB%F%l<br> B$,$s$P$l!*%k%k%m%m<br> BBh8BOC<br>
ちなみに mail.rb
require 'rubygems' require 'tmail' file = File.open('/home/otiai10/mbox') do |f| email = TMail::Mail.parse(f.read) puts 'body:', email.body end
るびい
【調査】
Ruby 1.8.2 には String.encode メソッドがない!?(パート2)
まーとりあえず無ぇことは分かった。
別にwindowsではないんだが、Kconvというのがあるのは分かった。
【解決】
mail.rb
require 'kconv' require 'rubygems' require 'tmail' file = File.open('/home/hiromu/mbox') do |f| email = TMail::Mail.parse(f.read) body = Kconv.toutf8(email.body) puts 'body:', body end
で、出力
NHK Eテレ<br> がんばれ!ルルロロ<br> 第8話<br>