# followup.rb - followup descriptor # # Copyright (C) 2002 Yoshinori K. Okuji # # This file is part of BugCommunicator. # # BugCommunicator is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # BugCommunicator is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with BugCommunicator; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA require 'iconv' require 'rmail/parser' require 'rmail/utils' module BugCommunicator class Followup def initialize(f_id, message) @f_id = f_id @raw_message = message parser = RMail::Parser.new() @message = parser.parse(message.gsub(/\r\n/, "\n")) @header = @message.header() end def from() Utils.decode_encoded_words(@header['from']) end def subject() Utils.decode_encoded_words(@header['subject']) end def date() @header['date'] || 'unknown' end def find_first_part(msg, re) if msg.multipart? msg.each_part do |part| tmp = find_first_part(part, re) return tmp if tmp end elsif re =~ msg.header.content_type('text/plain') res = msg.decode() charset = msg.header.param('content-type', 'charset', 'US-ASCII').upcase if charset == 'US-ASCII' or charset == 'UTF-8' return res else begin return Iconv.iconv('UTF-8', charset, res) rescue end end end nil end def text() find_first_part(@message, %r!^text/plain$!) or find_first_part(@message, %r!^text/!) or @message.to_s.sub(/\A.*?\n\n/m, '') end attr_reader :f_id, :raw_message, :message end end