require 'net/telnet' require 'kconv' cache_file = "/home/kazane/opt/tmp/rbiff.cache" mail_spool = "/home/kazane/Mail/inbox/" class Rbiff def initialize(cache, spool) @cache = cache @spool = spool @spool_result = [] @subjects = "" end def check_file @file_cache = open(@cache).read @file_result = @file_cache.chomp.split(":") end def check_spool Dir.foreach(@spool) { |@mail_num| if @mail_num =~ /[\d*]/ @spool_result << @mail_num end } open(@cache, "w").write @spool_result.join(":") end def rbiff_check check_file check_spool @result = @spool_result - @file_result if @result.to_s == "" @script = "\\0\\s0Rbiffからの報告です。\\n\\w9\\w9新しいMailはありません.......\\w9だそーです。\\w9\\w5\\n\\s4寂しいねぇ.......\\w9\\1 そう言うなよ。 \\e" rbiff_sstp else rbiff_result_put end end def rbiff_result_put @mails = @result.nitems subject_print @script = "\\0\\s0Rbiffからの報告です。\\n\\w9\\w9\\s5新しいMailが #{@mails}件、あります。\\n\\w9\\s0\\w5Subjectを読み上げます。\\n\\n\\w9\\w5#{@subjects} \\w5\\n ....以上です。\\e" rbiff_sstp #subject_print end def subject_print @result.each { |@mail| @str = "" @str = open("#{@spool}#{@mail}","r").read @str.each { |@str2| if @str2 =~ /^Subject\:/i @subjects << @str2.chomp end if @str2 =~ /.*=\?iso-2022-jp.*==\?=/i @subjects << @str2.gsub("\t","") #.gsub("\s","") end } } @subjects.gsub!(/Subject:/i," :").gsub!("\n","\\w9\\n") end def rbiff_sstp @send_str = <<"NANIKA" SEND SSTP/1.1 Sender: System Script: #{@script} Charset: shift_jis NANIKA @t = Net::Telnet.new({"Port" => 9801}) @t.print(@send_str.tosjis) end end #--main--# rbiff = Rbiff.new(cache_file, mail_spool) rbiff.rbiff_check