diff options
author | Yukihiro Matsumoto <[email protected]> | 1995-02-24 13:15:43 +0900 |
---|---|---|
committer | Takashi Kokubun <[email protected]> | 2019-08-17 22:09:31 +0900 |
commit | 881c5a9c320c637ee0f6526b40cf70c1379ab656 (patch) | |
tree | 3c0327fc9bdef8f056563ceee400226ac572535b /sample/from.rb | |
parent | 2f106ab85c4f4e171374aee261f5a12bdd923c41 (diff) |
version 0.68v0_68
https://cache.ruby-lang.org/pub/ruby/1.0/ruby-0.67-0.68.diff.gz
Fri Feb 24 13:15:43 1995 Yukihiro Matsumoto (matz@ix-02)
* version 0.68
Thu Feb 23 11:19:19 1995 Yukihiro Matsumoto (matz@ix-02)
* eval.c: resque節のselfの値が間違っていた.
* eval.c(rb_clear_cache): キャッシュのクリアし忘れがあった.
* eval.c: 定数のスコープをクラス内の静的スコープに変更した.これに
よって,特異メソッドからは参照される定数は,レシーバのクラスでは
なく,定義されたスコープのクラスの定数となる.
Wed Feb 22 00:51:38 1995 Yukihiro Matsumoto (matz@dyna)
* regex.c: ignorecaseを正規表現のコンパイル前に指定しないと正しく
動作しない.修正.
* string.c(toupper,tolower): bug fix.
* ENV,VERSION: readonly変数から定数へ.
Diffstat (limited to 'sample/from.rb')
-rw-r--r-- | sample/from.rb | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/sample/from.rb b/sample/from.rb new file mode 100644 index 0000000000..f6602943af --- /dev/null +++ b/sample/from.rb @@ -0,0 +1,100 @@ +#! /usr/local/bin/ruby + +$= = TRUE + +module ParseDate + MONTHS = { + 'jan' => 1, 'feb' => 2, 'mar' => 3, 'apr' => 4, + 'may' => 5, 'jun' => 6, 'jul' => 7, 'aug' => 8, + 'sep' => 9, 'oct' =>10, 'nov' =>11, 'dec' =>12 } + MONTHPAT = MONTHS.keys.join('|') + DAYPAT = 'mon|tue|wed|thu|fri|sat|sun' + + def ParseDate.parsedate(date) + if date.sub(/(#{DAYPAT})/i, ' ') + dayofweek = $1 + end + if date.sub(/\s+(\d+:\d+(:\d+)?)/, ' ') + time = $1 + end + if date =~ /19\d\d/ + year = $& + end + if date.sub(/\s*(\d+)\s+(#{MONTHPAT})\S*\s+/, ' ') + dayofmonth = $1 + monthname = $2 + elsif date.sub(/\s*(#{MONTHPAT})\S*\s+(\d+)\s+/, ' ') + monthname = $1 + dayofmonth = $2 + elsif date.sub(/\s*(#{MONTHPAT})\S*\s+(\d+)\D+/, ' ') + monthname = $1 + dayofmonth = $2 + elsif date.sub(/\s*(\d\d?)\/(\d\d?)/, ' ') + month = $1 + dayofmonth = $2 + end + if monthname + month = MONTHS[monthname.tolower] + end + if ! year && date =~ /\d\d/ + year = $& + end + return year, month, dayofmonth + end + +end + + def parsedate(date) + ParseDate.parsedate(date) + end + +# include ParseDate + +if $ARGV[0] == '-w' + wait = TRUE + $ARGV.shift +end + +$ARGV[0] = '/usr/spool/mail/' + ENV['USER'] if $ARGV.length == 0 + +$outcount = 0; +def fromout(date, from, subj) + y, m, d = parsedate(date) + printf "%-2d/%02d/%02d [%.28s] %.40s\n", y, m, d, from, subj + $outcount += 1 +end + +while TRUE + fields = {} + while gets() + $_.chop + continue if /^From / # skip From-line + break if /^[ \t]*$/ # end of header + if /^(\S+):\s*(.*)/ + fields[attr = $1] = $2 + elsif attr + sub(/^\s*/, '') + fields[attr] += "\n" + $_ + end + end + + break if ! $_ + + fromout fields['Date'], fields['From'], fields['Subject'] + + while gets() +# print $_ + break if /^From / + end + + break if ! $_ +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 |