Mercurial > hgrepos > hgweb.cgi > after5
comparison after5.rb @ 92:52a3c4444a4c draft
Set from:comment to email if post from alien
author | HIROSE Yuuji <yuuji@gentei.org> |
---|---|
date | Thu, 20 Feb 2014 12:50:25 +0900 |
parents | 9ed5d139232f |
children | 8ea193772cbd |
comparison
equal
deleted
inserted
replaced
91:9ed5d139232f | 92:52a3c4444a4c |
---|---|
1 #!/usr/local/bin/ruby19 | 1 #!/usr/local/bin/ruby20 |
2 # -*- coding: euc-jp -*- | 2 # -*- coding: euc-jp -*- |
3 # | 3 # |
4 # Associative Scheduling Table - after5 | 4 # Associative Scheduling Table - after5 |
5 # (C)2003, 2004, 2006, 2008, 2012, 2013 by HIROSE Yuuji [yuuji<at>gentei.org] | 5 # (C)2003, 2004, 2006, 2008, 2012, 2013 by HIROSE Yuuji [yuuji<at>gentei.org] |
6 # $Id: after5.rb,v 1.20 2012/12/03 15:54:20 yuuji Exp $ | 6 # $Id: after5.rb,v 1.20 2012/12/03 15:54:20 yuuji Exp $ |
7 # Last modified Mon Dec 23 12:33:10 2013 on firestorm | 7 # Last modified Thu Feb 20 12:49:36 2014 on firestorm |
8 # See http://www.gentei.org/~yuuji/software/after5/ | 8 # See http://www.gentei.org/~yuuji/software/after5/ |
9 # このスクリプトはEUCで保存してください。 | 9 # このスクリプトはEUCで保存してください。 |
10 $hgid = <<_HGID_.split[1..-2].join(" ") | 10 $hgid = <<_HGID_.split[1..-2].join(" ") |
11 $HGid$ | 11 $HGid$ |
12 _HGID_ | 12 _HGID_ |
2799 sj = sj.sub(/^(re: *)+/i, "Re: ").gsub("\n", "") | 2799 sj = sj.sub(/^(re: *)+/i, "Re: ").gsub("\n", "") |
2800 hold = ["Subject: "+NKF.nkf('-jM', tag+" "+sj).strip+"\n"] | 2800 hold = ["Subject: "+NKF.nkf('-jM', tag+" "+sj).strip+"\n"] |
2801 elsif /^from/i =~ hold[0] && fromhack.is_a?(String) | 2801 elsif /^from/i =~ hold[0] && fromhack.is_a?(String) |
2802 from = hold.join.toeuc.sub(/From: */i, "").strip | 2802 from = hold.join.toeuc.sub(/From: */i, "").strip |
2803 email, comment = parseaddress(from) | 2803 email, comment = parseaddress(from) |
2804 if (!comment || comment=="") && comment = @sc.ismembersemail(email) | 2804 if (!comment || comment=="") |
2805 # Reverse conversion of uname<->email | 2805 if comment = @sc.ismembersemail(email) |
2806 comment = @sc.nickname(comment) || "whoareyou" | 2806 # Reverse conversion of uname<->email |
2807 comment = @sc.nickname(comment) || "whoareyou" | |
2808 else | |
2809 comment = email # email from alien | |
2810 end | |
2807 end | 2811 end |
2808 hold = ["From: "+rewritefrom(email, comment, fromhack)+"\n"] | 2812 hold = ["From: "+rewritefrom(email, comment, fromhack)+"\n"] |
2809 elsif /^received:/i =~ line | 2813 elsif /^received:/i =~ line |
2810 # Put original received headers aside to reduce hop count | 2814 # Put original received headers aside to reduce hop count |
2811 line = "X-pre"+line | 2815 line = "X-pre"+line |
2820 hold << line | 2824 hold << line |
2821 end | 2825 end |
2822 end | 2826 end |
2823 ret + hold + body | 2827 ret + hold + body |
2824 end | 2828 end |
2829 def recompose_multipart(string) | |
2830 /(\r?)\n\r?\n/ =~ string or return string | |
2831 $1 > "" ? eol = "\r\n" : eol = "\n" | |
2832 head, body = $`, $' | |
2833 r = Hash.new | |
2834 if %r,^Content-type:\s*text/plain,i =~ head | |
2835 # open("/tmp/a", "a"){|a| a.printf("str=<<<%s>>>\n\n", string)} | |
2836 r["name"] = ":TEXT" | |
2837 r["value"] = body.sub(Regexp.new(".*?"+eol+eol, Regexp::MULTILINE), "") | |
2838 return [head, r] | |
2839 elsif %r,^Content-type:\s*(multipart/(.*));\s*boundary=([\'\"])?(.*)\3,mi =~ | |
2840 head | |
2841 ct, boundary = $1, $4 | |
2842 [head] + body.split(eol+"--"+boundary).collect {|pc| | |
2843 recompose_multipart(pc) | |
2844 } | |
2845 elsif %r,^Content-type:\s*(.*);\s*name=([\'\"])?(\S*)\2,mi =~ head | |
2846 r["name"] = $3 | |
2847 %r,filename=([\'\"])?(\S+)\1,mi =~ head | |
2848 r["filename"] = $2 | |
2849 content = body.sub(Regexp.new(".*?"+eol+eol, Regexp::MULTILINE), "") | |
2850 r['value'] = content | |
2851 return [head, r] | |
2852 end | |
2853 end | |
2825 def extract_attachment(attachment) | 2854 def extract_attachment(attachment) |
2826 # Must return [text, href] strings to attached files | 2855 # Must return [text, href] strings to attached files |
2856 # Argument ATTACHMENT is a array of attached files. | |
2857 # Each element is an Hash of a form of: | |
2858 # {'filename'=>name, 'value'=>content, 'content-type'=>contentType} | |
2827 href = ""; text = "" | 2859 href = ""; text = "" |
2828 dir = @attachmentdir + Time.now.strftime("/%Y%m") | 2860 dir = @attachmentdir + Time.now.strftime("/%Y%m") |
2829 if %r,(https?://[^/]+), =~ @opt['url'] | 2861 if %r,(https?://[^/]+), =~ @opt['url'] |
2830 server = $1 | 2862 server = $1 |
2831 else | 2863 else |
4260 gr = safecopy(grepgroup(ARGV[0])) | 4292 gr = safecopy(grepgroup(ARGV[0])) |
4261 @job = 'delgroupsub "'+gr+'"' | 4293 @job = 'delgroupsub "'+gr+'"' |
4262 when /-(setpasswd|deluser|adduser)$/ | 4294 when /-(setpasswd|deluser|adduser)$/ |
4263 ARGV.shift | 4295 ARGV.shift |
4264 @job = $1+ " '#{ARGV[0]}'" # + exit | 4296 @job = $1+ " '#{ARGV[0]}'" # + exit |
4297 when "-mp" | |
4298 ARGV.shift | |
4299 r = recompose_multipart(ARGF.readlines.join) | |
4300 open("/tmp/a", "w"){|a| | |
4301 | |
4302 a.printf("R:(((%s)))\n", r) | |
4303 } | |
4304 | |
4305 exit 0 | |
4265 when "" | 4306 when "" |
4266 end | 4307 end |
4267 ARGV.shift | 4308 ARGV.shift |
4268 end | 4309 end |
4269 | 4310 |