# HG changeset patch # User HIROSE Yuuji # Date 1392868225 -32400 # Node ID 52a3c4444a4cf4cea1225300ca75da0c48f4d972 # Parent 9ed5d139232f53cb3b787013a9f79e804929ef22 Set from:comment to email if post from alien diff -r 9ed5d139232f -r 52a3c4444a4c after5.rb --- a/after5.rb Mon Dec 23 12:37:53 2013 +0900 +++ b/after5.rb Thu Feb 20 12:50:25 2014 +0900 @@ -1,10 +1,10 @@ -#!/usr/local/bin/ruby19 +#!/usr/local/bin/ruby20 # -*- coding: euc-jp -*- # # Associative Scheduling Table - after5 # (C)2003, 2004, 2006, 2008, 2012, 2013 by HIROSE Yuuji [yuujigentei.org] # $Id: after5.rb,v 1.20 2012/12/03 15:54:20 yuuji Exp $ -# Last modified Mon Dec 23 12:33:10 2013 on firestorm +# Last modified Thu Feb 20 12:49:36 2014 on firestorm # See http://www.gentei.org/~yuuji/software/after5/ # このスクリプトはEUCで保存してください。 $hgid = <<_HGID_.split[1..-2].join(" ") @@ -2801,9 +2801,13 @@ elsif /^from/i =~ hold[0] && fromhack.is_a?(String) from = hold.join.toeuc.sub(/From: */i, "").strip email, comment = parseaddress(from) - if (!comment || comment=="") && comment = @sc.ismembersemail(email) - # Reverse conversion of uname<->email - comment = @sc.nickname(comment) || "whoareyou" + if (!comment || comment=="") + if comment = @sc.ismembersemail(email) + # Reverse conversion of uname<->email + comment = @sc.nickname(comment) || "whoareyou" + else + comment = email # email from alien + end end hold = ["From: "+rewritefrom(email, comment, fromhack)+"\n"] elsif /^received:/i =~ line @@ -2822,8 +2826,36 @@ end ret + hold + body end + def recompose_multipart(string) + /(\r?)\n\r?\n/ =~ string or return string + $1 > "" ? eol = "\r\n" : eol = "\n" + head, body = $`, $' + r = Hash.new + if %r,^Content-type:\s*text/plain,i =~ head + # open("/tmp/a", "a"){|a| a.printf("str=<<<%s>>>\n\n", string)} + r["name"] = ":TEXT" + r["value"] = body.sub(Regexp.new(".*?"+eol+eol, Regexp::MULTILINE), "") + return [head, r] + elsif %r,^Content-type:\s*(multipart/(.*));\s*boundary=([\'\"])?(.*)\3,mi =~ + head + ct, boundary = $1, $4 + [head] + body.split(eol+"--"+boundary).collect {|pc| + recompose_multipart(pc) + } + elsif %r,^Content-type:\s*(.*);\s*name=([\'\"])?(\S*)\2,mi =~ head + r["name"] = $3 + %r,filename=([\'\"])?(\S+)\1,mi =~ head + r["filename"] = $2 + content = body.sub(Regexp.new(".*?"+eol+eol, Regexp::MULTILINE), "") + r['value'] = content + return [head, r] + end + end def extract_attachment(attachment) # Must return [text, href] strings to attached files + # Argument ATTACHMENT is a array of attached files. + # Each element is an Hash of a form of: + # {'filename'=>name, 'value'=>content, 'content-type'=>contentType} href = ""; text = "" dir = @attachmentdir + Time.now.strftime("/%Y%m") if %r,(https?://[^/]+), =~ @opt['url'] @@ -4262,6 +4294,15 @@ when /-(setpasswd|deluser|adduser)$/ ARGV.shift @job = $1+ " '#{ARGV[0]}'" # + exit + when "-mp" + ARGV.shift + r = recompose_multipart(ARGF.readlines.join) + open("/tmp/a", "w"){|a| + + a.printf("R:(((%s)))\n", r) + } + + exit 0 when "" end ARGV.shift