2003-08-02 01:04:30 -04:00
|
|
|
#!/usr/bin/env ruby
|
1999-08-13 01:37:52 -04:00
|
|
|
|
|
|
|
require "parsedate"
|
|
|
|
require "base64"
|
|
|
|
|
|
|
|
include ParseDate
|
|
|
|
|
|
|
|
class Mail
|
|
|
|
def Mail.new(f)
|
|
|
|
if !f.kind_of?(IO)
|
|
|
|
f = open(f, "r")
|
|
|
|
me = super(f)
|
|
|
|
f.close
|
|
|
|
else
|
|
|
|
me = super
|
|
|
|
end
|
|
|
|
return me
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(f)
|
|
|
|
@header = {}
|
|
|
|
@body = []
|
2000-12-28 00:00:47 -05:00
|
|
|
while line = f.gets()
|
1999-08-13 01:37:52 -04:00
|
|
|
$_.chop!
|
2009-03-05 22:56:38 -05:00
|
|
|
next if /^From / =~ line # skip From-line
|
2004-10-11 00:51:21 -04:00
|
|
|
break if /^$/ =~ line # end of header
|
2000-12-28 00:00:47 -05:00
|
|
|
if /^(\S+):\s*(.*)/ =~ line
|
2004-10-11 00:51:21 -04:00
|
|
|
@header[attr = $1.capitalize] = $2
|
1999-08-13 01:37:52 -04:00
|
|
|
elsif attr
|
2004-10-11 00:51:21 -04:00
|
|
|
sub(/^\s*/, '')
|
|
|
|
@header[attr] += "\n" + $_
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2000-12-28 00:00:47 -05:00
|
|
|
return unless $_
|
1999-08-13 01:37:52 -04:00
|
|
|
|
2000-12-28 00:00:47 -05:00
|
|
|
while line = f.gets()
|
|
|
|
break if /^From / =~ line
|
1999-08-13 01:37:52 -04:00
|
|
|
@body.push($_)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def header
|
|
|
|
return @header
|
|
|
|
end
|
|
|
|
|
|
|
|
def body
|
|
|
|
return @body
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
if ARGV.length == 0
|
|
|
|
if ENV['MAIL']
|
|
|
|
ARGV[0] = ENV['MAIL']
|
|
|
|
elsif ENV['USER']
|
2003-07-29 04:05:30 -04:00
|
|
|
ARGV[0] = '/var/spool/mail/' + ENV['USER']
|
1999-08-13 01:37:52 -04:00
|
|
|
elsif ENV['LOGNAME']
|
2003-07-29 04:05:30 -04:00
|
|
|
ARGV[0] = '/var/spool/mail/' + ENV['LOGNAME']
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
require "tk"
|
|
|
|
list = scroll = nil
|
|
|
|
TkFrame.new{|f|
|
|
|
|
list = TkListbox.new(f) {
|
2003-07-29 04:05:30 -04:00
|
|
|
yscroll proc{|*idx|
|
2004-10-11 00:51:21 -04:00
|
|
|
scroll.set *idx
|
1999-08-13 01:37:52 -04:00
|
|
|
}
|
|
|
|
relief 'raised'
|
|
|
|
# geometry "80x5"
|
|
|
|
width 80
|
|
|
|
height 5
|
|
|
|
setgrid 'yes'
|
|
|
|
pack('side'=>'left','fill'=>'both','expand'=>'yes')
|
|
|
|
}
|
|
|
|
scroll = TkScrollbar.new(f) {
|
|
|
|
command proc{|idx|
|
|
|
|
list.yview *idx
|
|
|
|
}
|
|
|
|
pack('side'=>'right','fill'=>'y')
|
|
|
|
}
|
|
|
|
pack
|
|
|
|
}
|
|
|
|
root = Tk.root
|
|
|
|
TkButton.new(root) {
|
|
|
|
text 'Dismiss'
|
|
|
|
command proc {exit}
|
|
|
|
pack('fill'=>'both','expand'=>'yes')
|
|
|
|
}
|
|
|
|
root.bind "Control-c", proc{exit}
|
|
|
|
root.bind "Control-q", proc{exit}
|
|
|
|
root.bind "space", proc{exit}
|
|
|
|
|
|
|
|
$outcount = 0;
|
|
|
|
for file in ARGV
|
2003-07-29 04:05:30 -04:00
|
|
|
next unless File.exist?(file)
|
1999-08-13 01:37:52 -04:00
|
|
|
atime = File.atime(file)
|
|
|
|
mtime = File.mtime(file)
|
|
|
|
f = open(file, "r")
|
|
|
|
begin
|
|
|
|
until f.eof
|
|
|
|
mail = Mail.new(f)
|
|
|
|
date = mail.header['Date']
|
|
|
|
next unless date
|
|
|
|
from = mail.header['From']
|
|
|
|
subj = mail.header['Subject']
|
|
|
|
y = m = d = 0
|
|
|
|
y, m, d = parsedate(date) if date
|
|
|
|
from = "sombody@somewhere" unless from
|
|
|
|
subj = "(nil)" unless subj
|
|
|
|
from = decode_b(from)
|
|
|
|
subj = decode_b(subj)
|
|
|
|
list.insert 'end', format('%-02d/%02d/%02d [%-28.28s] %s',y,m,d,from,subj)
|
|
|
|
$outcount += 1
|
|
|
|
end
|
|
|
|
ensure
|
|
|
|
f.close
|
|
|
|
File.utime(atime, mtime, file)
|
|
|
|
list.see 'end'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
limit = 10000
|
|
|
|
if $outcount == 0
|
|
|
|
list.insert 'end', "You have no mail."
|
|
|
|
limit = 2000
|
|
|
|
end
|
|
|
|
Tk.after limit, proc{
|
|
|
|
exit
|
|
|
|
}
|
|
|
|
Tk.mainloop
|