From: Kikutani Makoto Date: 1998-02-14T15:10:55+09:00 Subject: [ruby-list:6412] Re: call for scripts --az5kW0TMd/poaVZ8 Content-Type: text/plain; charset=iso-2022-jp Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=mutta03411 きくたに@ぷ〜たろ〜です。 Tue, Feb 10, 1998 at 06:04:35PM +0900 において Yukihiro Matsumoto さん曰く: > 標準ライブラリにある部分を除いて100〜200行程度以下 > # 必要な部分を標準ライブラリに追加してしまうのはアリです. > > ある程度実用上意味のあるプログラム > > 簡単な使い方の説明付き rubyを知って初めて書いたのがこれ(今手を入れたけど)。 mimeをサポートしてないメイラに、mimeのマルチパートで 送りつけられてくると困るので、これを使ってました。 こんなんでいいですか? -- 人生を背負い投げ 菊谷 誠(Kikutani Makoto) kikutani@eis.or.jp hgf03701@niftyserve.or.jp http://www.eis.or.jp/muse/kikutani/ --az5kW0TMd/poaVZ8 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=b64dec #!/usr/local/bin/ruby # decode base64encoded multpart mail for non-mime-supported mailer # usage: b64dec [file] require "base64.rb" class Body def initialize(pn) @part_num = pn @body = nil @filename = nil @method = nil end attr("filename", TRUE) attr("method", TRUE) def append(s) @body += s end def decode begin if @method == "base64" @filename = sprintf("part%d\.decoded", @part_num) unless @filename fd = open(@filename, "w") printf(fd, "%s", decode64(@body)) else @filename = sprintf("part%d", @part_num) unless @filename fd = open(@filename, "w") printf(fd, "%s", @body) end fd.close printf($stderr, "%s created\n", @filename) rescue printf($stderr, "couldn't write %s\n", @filename) end end end body = nil boundary = nil part_num = 0 while gets if /boundary=\"(.*)\"/ # multipart boundary string has double quote rex = Regexp.quote($1) boundary = /^--#{rex}/ elsif /boundary=(.*)/ rex = Regexp.quote($1) boundary = /^--#{rex}/ elsif boundary && $_ =~ boundary # beginning or end of multipart part_num += 1 if body body.decode end body = Body.new(part_num) elsif /^Content-Transfer-Encoding: (\S+)/ body.method = $1 if body && part_num > 0 elsif /^Content-Disposition:.*filename=\"(.*)\"/ body.filename = $1 if body elsif /^Content-.*:/ # do nothing else body.append($_) if body end end --az5kW0TMd/poaVZ8--