1998-01-16 07:13:05 -05:00
|
|
|
#! /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
|
1999-08-13 01:45:20 -04:00
|
|
|
me[-2..-1] = ' '
|
1998-01-16 07:13:05 -05:00
|
|
|
me[-2, 2] = ' '
|
|
|
|
end
|
|
|
|
me.chop!
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
if ARGV[0] == '-w'
|
|
|
|
wait = TRUE
|
|
|
|
ARGV.shift
|
|
|
|
end
|
|
|
|
|
|
|
|
if ARGV.length == 0
|
1999-01-19 23:59:39 -05:00
|
|
|
file = ENV['MAIL']
|
|
|
|
user = ENV['USER'] || ENV['USERNAME'] || ENV['LOGNAME']
|
1998-01-16 07:13:05 -05:00
|
|
|
else
|
1999-01-19 23:59:39 -05:00
|
|
|
file = user = ARGV[0]
|
|
|
|
ARGV.clear
|
1998-01-16 07:13:05 -05:00
|
|
|
end
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
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
|
1998-01-16 07:13:05 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
$outcount = 0;
|
|
|
|
def fromout(date, from, subj)
|
|
|
|
return if !date
|
|
|
|
y = m = d = 0
|
|
|
|
y, m, d = parsedate(date) if date
|
|
|
|
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)
|
1999-01-19 23:59:39 -05:00
|
|
|
printf "%02d/%02d/%02d [%s] %s\n",y%100,m,d,from,subj
|
1998-01-16 07:13:05 -05:00
|
|
|
$outcount += 1
|
|
|
|
end
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
if File.exist?(file)
|
|
|
|
atime = File.atime(file)
|
|
|
|
mtime = File.mtime(file)
|
1998-01-16 07:13:05 -05:00
|
|
|
f = open(file, "r")
|
1999-01-19 23:59:39 -05:00
|
|
|
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)
|
1998-01-16 07:13:05 -05:00
|
|
|
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
|