From 11dbedfaad4a9a9521ece2198a8dc491678b1902 Mon Sep 17 00:00:00 2001 From: shyouhei Date: Wed, 29 Aug 2007 04:06:12 +0000 Subject: add tag v1_8_6_5001 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/tags/v1_8_6_5001@13304 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ruby_1_8_6/sample/from.rb | 98 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 ruby_1_8_6/sample/from.rb (limited to 'ruby_1_8_6/sample/from.rb') diff --git a/ruby_1_8_6/sample/from.rb b/ruby_1_8_6/sample/from.rb new file mode 100644 index 0000000000..59cc387792 --- /dev/null +++ b/ruby_1_8_6/sample/from.rb @@ -0,0 +1,98 @@ +#! /usr/local/bin/ruby + +require "parsedate" +require "kconv" +require "mailread" + +include ParseDate +include Kconv + +class String + + def kconv(code = Kconv::EUC) + Kconv.kconv(self, code, Kconv::AUTO) + end + + def kjust(len) + len += 1 + me = self[0, len].ljust(len) + if me =~ /.$/ and $&.size == 2 + me[-2..-1] = ' ' + me[-2, 2] = ' ' + end + me.chop! + end + +end + +if ARGV[0] == '-w' + wait = TRUE + ARGV.shift +end + +if ARGV.length == 0 + file = ENV['MAIL'] + user = ENV['USER'] || ENV['USERNAME'] || ENV['LOGNAME'] +else + file = user = ARGV[0] + ARGV.clear +end + +if file == nil or !File.exist? file + [ENV['SPOOLDIR'], '/usr/spool', '/var/spool', '/usr', '/var'].each do |m| + if File.exist? f = "#{m}/mail/#{user}" + file = f + break + end + end +end + +$outcount = 0; +def fromout(date, from, subj) + return if !date + y, m, d = parsedate(date) if date + y ||= 0; m ||= 0; d ||= 0 + if from + from.gsub! /\n/, "" + else + from = "sombody@somewhere" + end + if subj + subj.gsub! /\n/, "" + else + subj = "(nil)" + end + if ENV['LANG'] =~ /sjis/i + lang = Kconv::SJIS + else + lang = Kconv::EUC + end + from = from.kconv(lang).kjust(28) + subj = subj.kconv(lang).kjust(40) + printf "%02d/%02d/%02d [%s] %s\n",y%100,m,d,from,subj + $outcount += 1 +end + +if File.exist?(file) + atime = File.atime(file) + mtime = File.mtime(file) + f = open(file, "r") + begin + until f.eof? + mail = Mail.new(f) + fromout mail.header['Date'],mail.header['From'],mail.header['Subject'] + end + ensure + f.close + File.utime(atime, mtime, file) + end +end + +if $outcount == 0 + print "You have no mail.\n" + sleep 2 if wait +elsif wait + system "stty cbreak -echo" + getc() + system "stty cooked echo" +end -- cgit v1.2.3