mirror of
https://github.com/ruby/ruby.git
synced 2025-09-17 09:33:59 +02:00

* ext/tk/*: Support new features of Tcl/Tk8.6b1 and minor bug fixes. ( [KNOWN BUG] Ruby/Tk on Ruby 1.9 will not work on Cygwin. ) * ext/tk/*: Unify sources between Ruby 1.8 & 1.9. Improve default_widget_set handling. * ext/tk/*: Multi-TkInterpreter (multi-tk.rb) works on Ruby 1.8 & 1.9. ( [KNOWN BUG] On Ruby 1.8, join to a long term Thread on Tk callbacks may freeze. On Ruby 1.9, cannot create a second master interpreter (creating slaves are OK); supported master interpreter is the default master interpreter only. ) * ext/tk/lib/tkextlib/*: Update supported versions of Tk extensions. Tcllib 1.8/Tklib 0.4.1 ==> Tcllib 1.11.1/Tklib 0.5 BWidgets 1.7 ==> BWidgets 1.8 TkTable 2.9 ==> TkTable 2.10 TkTreeCtrl 2005-12-02 ==> TkTreeCtrl 2.2.9 Tile 0.8.0/8.5.1 ==> Tile 0.8.3/8.6b1 IncrTcl 2005-02-14 ==> IncrTcl 2008-12-15 TclX 2005-02-07 ==> TclX 2008-12-15 Trofs 0.4.3 ==> Trofs 0.4.4 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@24064 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
132 lines
2.4 KiB
Ruby
132 lines
2.4 KiB
Ruby
#!/usr/bin/env ruby
|
|
|
|
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 = []
|
|
while line = f.gets()
|
|
$_.chop!
|
|
next if /^From / =~ line # skip From-line
|
|
break if /^$/ =~ line # end of header
|
|
if /^(\S+):\s*(.*)/ =~ line
|
|
@header[attr = $1.capitalize] = $2
|
|
elsif attr
|
|
sub(/^\s*/, '')
|
|
@header[attr] += "\n" + $_
|
|
end
|
|
end
|
|
|
|
return unless $_
|
|
|
|
while line = f.gets()
|
|
break if /^From / =~ line
|
|
@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']
|
|
ARGV[0] = '/var/spool/mail/' + ENV['USER']
|
|
elsif ENV['LOGNAME']
|
|
ARGV[0] = '/var/spool/mail/' + ENV['LOGNAME']
|
|
end
|
|
end
|
|
|
|
require "tk"
|
|
list = scroll = nil
|
|
TkFrame.new{|f|
|
|
list = TkListbox.new(f) {
|
|
yscroll proc{|*idx|
|
|
scroll.set *idx
|
|
}
|
|
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
|
|
next unless File.exist?(file)
|
|
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
|