# HG changeset patch # User HIROSE Yuuji # Date 1339426065 -32400 # Node ID d65174b867aaeb2a26f6b1019e362f98b44c8e6b # Parent b491a43bd5fe14428d9bfc6eac13c2f3fd079266 Add fromhack mode diff -r b491a43bd5fe -r d65174b867aa after5.rb --- a/after5.rb Mon Jun 11 23:47:35 2012 +0900 +++ b/after5.rb Mon Jun 11 23:47:45 2012 +0900 @@ -4,7 +4,7 @@ # Associative Scheduling Table - after5 # (C)2003, 2004, 2006, 2008, 2012 by HIROSE Yuuji [yuujigentei.org] # $Id: after5.rb,v 1.19 2012/04/01 11:52:25 yuuji Exp yuuji $ -# Last modified Mon Jun 11 00:12:27 2012 on firestorm +# Last modified Mon Jun 11 23:37:31 2012 on firestorm # See http://www.gentei.org/~yuuji/software/after5/ # このスクリプトはEUCで保存してください。 $hgid = <<_HGID_.split[1..-2].join(" ") @@ -414,9 +414,47 @@ map[g]['members'] << a.untaint } end + # get other attributes + Dir.foreach(d) {|attr| + next if /^\./ =~ attr + next unless /^[-_a-z]+$/i =~ attr + next if attr == "name" # already collected + attr.untaint + file = File.join(d, attr) #.untaint + next if test(?d, file) + next unless test(?s, file) && test(?r, file) + map[g][attr] = IO.readlines(file).join.toeuc.strip + } } map end + def putgroupattr(group, attr, value) + d = File.join(@groupmapdir, group).untaint + Dir.mkdir(d) unless test(?d, d) + file = File.join(d, attr) + begin + unless @groupmap[group] + @groupmap[group] = {} + end + @groupmap[group][attr] = value + if value == nil + File.unlink(file) + else + open(file, "w"){|w| w.puts @groupmap[group][attr]} + end + rescue + return nil + end + return {attr => value} + end + def getgroupattr(group, attr) + if @groupmap.has_key?(group) && @groupmap[group][attr].is_a?(String) && + @groupmap[group][attr] > '' + return @groupmap[group][attr].untaint + else + return nil + end + end def groupmap() @groupmap end @@ -1232,6 +1270,8 @@ 'it is mischief by someone else'], 'user' => ['ユーザ', 'user'], 'group' => ['グループ', 'group'], + 'fromhack' => ['ML配送時のFrom:を常にMLのアドレスにする', +'Set From: address of all ML messages to ML address.'], 'personal' => ['個人で', 'personal'], 'registas' => ['グループ予定として登録?', 'Register as group?'], 'headsched' => ['下の枠内に予定を記入: 1行以内で短めに。 @@ -1240,7 +1280,7 @@ Or, put short subject in the first line, details in latter lines.'], 'joinquit' => ['入退', 'joining/quiting'], 'of' => ['の', "'s"], - 'id' => ['ID(英単語かローマ字の1単語半角空白なしで)', 'ID(without spaces)'], + 'id' => ['ID(英単語かローマ字の分かりやすい1単語半角空白なしで)', 'ID(without spaces)'], 'name' => ['名前', 'name'], 'anystring' => ['(日本語OK)', '(any length, any characters)'], 'setto' => ['を設定 → ', 'set to '], @@ -2585,29 +2625,52 @@ exit 0 end # ML functions - def tagify_subj(body, tag, removeregexp) + def parseaddress(spec) # from catchup.rb + # Return [email, comment] + # nil if comment does not exitst. + if /(.*)\s*<(.*)>/ =~ spec then + [$2, $1.strip] + elsif /(.*)\s*\((.*)\)/ =~ spec then + [$1.strip, $2] + else + [spec.strip, nil] + end + end + def rewritefrom(email, comment, newseed) # from catchup.rb + # no need to setcomment here because if comment set, it's enough + comment.sub!(/(\"?)(.*)\1/, '\2') + comment += "/" if comment>"" + return comment.gsub(/([^\x00-\x7f]+)/){NKF.nkf('-jM', $1)} + + email.sub("@", "=")+" <"+newseed+">" + # end + end + + def tagify_subj(body, tag, removeregexp, fromhack = nil) # This method should be generic for other headers than `Subject'? hold = [] ret = [] skip = false - regexp = /^Subject: / while line = body.shift case line.toeuc when /^$/ hold << "\n" break - when regexp - skip = true + when /^(subject|from): /i + skip = $1.downcase ret += hold hold = [line] when /^\s/ # continued line hold << line else - if skip then + if skip=="subject" sj = hold.join.toeuc.sub("Subject: ", "").gsub(tag, "").strip sj.gsub!(removeregexp, "") sj = sj.sub(/^(re: *)+/i, "Re: ").gsub("\n", "") ret << "Subject: "+NKF.nkf('-jM', tag+" "+sj).strip+"\n" + elsif skip=="from" && fromhack.is_a?(String) + from = hold.join.toeuc.sub(/From: */i, "").strip + email, comment = parseaddress(from) + ret << "From: "+rewritefrom(email, comment, fromhack)+"\n" else ret += hold end @@ -2642,6 +2705,7 @@ from = sprintf("%s <%s>", nick, @params['user']) body = @params['body'].gsub("\r", "").untaint end + fromhack = @sc.getgroupattr(name, 'fromhack') mldir = "ml/"+name prefix = (@opt['mailprefix'] || "") dash = prefix > '' ? "-" : "" @@ -2654,9 +2718,13 @@ gsub("%n", Regexp.quote(nickname(name))). gsub("%i", Regexp.quote(name)). gsub(/%(\d*)c/, '\d+') + tagre = Regexp.new(tagpt) subj = sjtag.strip+" "+subj.gsub(Regexp.new(tagpt), "") if viamail then - body = tagify_subj(STDIN.readlines, sjtag, Regexp.new(tagpt)).join + body = tagify_subj(STDIN.readlines, sjtag, tagre, + fromhack ? to : nil).join + elsif fromhack + from = rewritefrom(@params['user'], nick, to) end header = { "Reply-to" => to, @@ -2898,7 +2966,7 @@ @O.print \ @H.elementln("form", {'action'=>@myname+"?-groupmod", 'method'=>'POST'}){ @H.elementln("table", {'border'=>'1', 'vertical-align'=>'top'}){ - grmap.collect{|g, ghash| + grmap.sort.collect{|g, ghash| memberp = @sc.ismember(user, g) @H.elementln("tr"){ @H.element("td", @sc.isadmin(user, g) ? admclass : nil){ @@ -2923,16 +2991,18 @@ @H.radio("groupadd-#{g}", "no", "OUT", !memberp) } + \ @H.element("td"){ - memlist = ghash['members'] - if memberp # move this user to the beginning of list - memlist.delete(user) - memlist.unshift(user) - end - memlist.collect{|u| - @sc.nickname(u) + \ - ((u == user) ? ("("+@H.text("mail4-#{g}", memberp, 30, 80)+")") : "") - }.join(", ") - } + \ + @H.element("div", {'class'=>'memlist5'}){ + memlist = ghash['members'] + if memberp # move this user to the beginning of list + memlist.delete(user) + memlist.unshift(user) + end + memlist.collect{|u| + @sc.nickname(u) + \ + ((u == user) ? ("("+@H.text("mail4-#{g}", memberp, 30, 80)+")") : "") + }.join(", ") + } + } + \ @H.element("td"){ @H.a(@myname+"?-listdraft+#{g}", msg('sendall')) } @@ -3077,7 +3147,8 @@ @H.text("gname", '') + "\n" } end + \ - @H.elementln("table", {'border'=>'1'}){ + @H.elementln("div", {'class'=>'memlist'}){ + @H.elementln("table", {'border'=>'1'}){ @H.elementln("tr"){ @H.element("th"){msg('join')} + \ @H.element("th"){msg('administrator')} + \ @@ -3134,7 +3205,10 @@ } } }.join + } } + "
\n" + \ + @H.checkbox("fromhack", "yes", msg('fromhack'), + @sc.getgroupattr(group, 'fromhack')) + "
\n" + \ @H.submit_reset("GO") } # form @O.print @H.p(@H.element("span", warnclass){"(*)"}+ @@ -3329,6 +3403,18 @@ end end end # groups + # Change parameter(s) + # To be more generic... + fhsetp = (@params['fromhack'] && /^yes/i =~ @params['fromhack']) + cusetp = (@sc.getgroupattr(group, 'fromhack')!=nil) + if cusetp ^ fhsetp + @sc.putgroupattr(group, 'fromhack', @params['fromhack']) + @O.print @H.elementln("p") { + putLog(sprintf("%s[fromhack] -> %s", + group, @params['fromhack'].inspect)) + } + somethingdone = true + end unless somethingdone # @O.print @H.p(msg('nothingtodo')) end @@ -3353,7 +3439,7 @@ end @sc.creategroup(newgroup, newgname, [user]) && putLog("New group '#{newgroup}'(#{newgname}) created\n") - admgroup(newgroup) + admgroupsub() end #