[Better text part decoding Aredridel **20061209000407] { hunk ./campingatmailbox.rb 136 - @cmessage.body = WordWrapper.wrap(imap.uid_fetch(@uid, "BODY[#{part.part_id}]").first.attr["BODY[#{part.part_id}]"]).gsub(/^/, '> ') + @cmessage.body = WordWrapper.wrap(decode(part)).gsub(/^/, '> ') hunk ./campingatmailbox.rb 201 - @parts[structure.part_id].unpack('m*') + @parts[structure.part_id].unpack('m*').first hunk ./campingatmailbox.rb 203 - @parts[structure.part_id].gsub(/\r\n/, "\n").unpack('M*') + @parts[structure.part_id].gsub(/\r\n/, "\n").unpack('M*').first hunk ./campingatmailbox.rb 1136 - pre do - capture { WordWrapper.wrap(decode(structure)).gsub(%r{(http://[^[:space:]]+)}) { |m| "#{$1}" } } + part = decode(structure) + if structure.param['CHARSET'] and structure.param['CHARSET'].downcase != 'utf-8' + part = Iconv.new('utf-8', structure.param['CHARSET'].downcase).iconv(part) + end + case structure.subtype + when 'PLAIN' + pre do + capture { WordWrapper.wrap(part).gsub(%r{(http://[^[:space:]]+)}) { |m| "#{$1}" } } + end + when 'HTML' + pre do + capture { WordWrapper.wrap(part) } + end + else + pre do + capture { WordWrapper.wrap(part).gsub(%r{(http://[^[:space:]]+)}) { |m| "#{$1}" } } + end }