Changeset 7803 for platform/tdiary/util
- Timestamp:
- 03/11/08 20:14:32 (9 months ago)
- Location:
- platform/tdiary/util/posttdiary
- Files:
-
- 2 modified
-
posttdiary-ex.rb (modified) (6 diffs)
-
posttdiary.rb (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
platform/tdiary/util/posttdiary/posttdiary-ex.rb
r4633 r7803 1 1 #!/usr/bin/env ruby 2 $KCODE= ' e'2 $KCODE= 'u' 3 3 # 4 # posttdiary-ex: update tDiary via e-mail. $Revision: 1. 9$4 # posttdiary-ex: update tDiary via e-mail. $Revision: 1.6.2.4 $ 5 5 # 6 6 # Copyright (C) 2002, All right reserved by TADA Tadashi <sho@spc.gr.jp> 7 7 # You can redistribute it and/or modify it under GPL2. 8 8 # 9 # 2007. 11.22: v.1.66: Modified by K.Sakurai (http://ks.nwr.jp)9 # 2007.9.22: v.1.66: Modified by K.Sakurai (http://ks.nwr.jp) 10 10 # Acknowledgements: 11 11 # * Based on posttdiary.rb v1.2 by TADA. … … 327 327 s.each do |t| 328 328 t.gsub!( /.*Value:/, '' ) 329 v = NKF::nkf( '-m0 - Xed', t ).gsub!( /^\s+/, '' ).chomp! if $&329 v = NKF::nkf( '-m0 -wXd', t ).gsub!( /^\s+/, '' ).chomp! if $& 330 330 end 331 331 end … … 407 407 end 408 408 if sub_head =~ %r[^Content-Transfer-Encoding:\s*base64]i then 409 addtext += NKF::nkf( '- eXd -mB', sub_body )409 addtext += NKF::nkf( '-wXd -mB', sub_body ) 410 410 elsif 411 411 addtext += sub_body … … 638 638 if /^[ \t]/ =~ headlines[n] then 639 639 s = headlines[n].sub( /^[ \t]/, '' ) 640 subject += NKF::nkf( '- eXd', s )640 subject += NKF::nkf( '-wXd', s ) 641 641 else 642 642 break … … 645 645 if /^Subject:(.*)$/ =~ headlines[n] then 646 646 s = $1.sub( /^\s+/, '' ) 647 subject = NKF::nkf( '- eXd', s )647 subject = NKF::nkf( '-wXd', s ) 648 648 nextline = true 649 649 end … … 902 902 Net::HTTP.version_1_2 903 903 904 mail = NKF::nkf( '-m0 - Xed', ARGF.read )904 mail = NKF::nkf( '-m0 -wXd', ARGF.read ) 905 905 raise "posttdiary-ex: no mail text." if not mail or mail.length == 0 906 906 -
platform/tdiary/util/posttdiary/posttdiary.rb
r7629 r7803 1 1 #!/usr/bin/env ruby 2 $KCODE= ' e'2 $KCODE= 'u' 3 3 # 4 # posttdiary: update tDiary via e-mail. $Revision: 1.5 $4 # posttdiary: update tDiary via e-mail. $Revision: 1.5.2.1 $ 5 5 # 6 6 # Copyright (C) 2002, All right reserved by TADA Tadashi <sho@spc.gr.jp> … … 9 9 10 10 def usage 11 <<-TEXT.gsub( /^\t{2}/, '' )11 text = <<-TEXT 12 12 #{File::basename __FILE__}: update tDiary via e-mail. 13 13 usage: ruby #{File::basename __FILE__} [options] <url> [user] [passwd] … … 27 27 --use-subject, -s: use mail subject to subtitle. 28 28 and insert image between subtitle and body. 29 TEXT 29 TEXT 30 text.gsub( /\t/, '' ) 30 31 end 31 32 … … 33 34 image_path = [] 34 35 Dir.foreach( path ) do |file| 35 if file =~ /(\d{8,})_(\d+)\./ and $1 == date then 36 image_path[$2.to_i] = file 36 if file =~ /(\d{8,})_(\d+)\.(.*)/ then 37 if $1 == date then 38 image_path[$2.to_i] = file 39 end 37 40 end 38 41 end … … 90 93 end 91 94 raise usage if (image_dir and not image_url) or (not image_dir and image_url) 92 image_dir.sub!( %r[/*$], '/' ) if image_dir 93 image_url.sub!( %r[/*$], '/' ) if image_url 95 if image_dir then 96 image_dir += '/' unless %r[/$] =~ image_dir 97 end 98 if image_url then 99 image_url += '/' unless %r[/$] =~ image_url 100 end 94 101 url = ARGV.shift 95 if %r|http://([^:/] +)(?::(\d+))?(/.*)| =~ url then102 if %r|http://([^:/]*):?(\d*)(/.*)| =~ url then 96 103 host = $1 97 port = ($2 || 80).to_i 98 cgi = $3 104 port = $2.to_i 105 cgi = $3 106 raise 'bad url.' if not host or not cgi 107 port = 80 if port == 0 99 108 else 100 109 raise 'bad url.' 101 110 end 102 111 103 112 user = ARGV.shift 104 113 pass = ARGV.shift … … 108 117 image_name = nil 109 118 110 mail = NKF::nkf( '-m0 - Xed', ARGF.read )119 mail = NKF::nkf( '-m0 -wXd', ARGF.read ) 111 120 raise "#{File::basename __FILE__}: no mail text." if not mail or mail.length == 0 112 113 head, body = mail.split( / (?:\r?\n){2}/, 2 )121 122 head, body = mail.split( /\r*\n\r*\n/, 2 ) 114 123 115 124 if head =~ /Content-Type:\s*Multipart\/Mixed.*boundary=\"(.*?)\"/im then … … 117 126 raise "no --image-path and --image-url options" 118 127 end 119 128 120 129 bound = "--" + $1 121 130 body_sub = body.split( Regexp.compile( Regexp.escape( bound ) ) ) 122 131 body_sub.each do |b| 123 sub_head, sub_body = b.split( / (?:\r?\n){2}/, 2 )124 125 next unless sub_head =~ /Content-Type :/i132 sub_head, sub_body = b.split( /\r*\n\r*\n/, 2 ) 133 134 next unless sub_head =~ /Content-Type/ 126 135 127 136 if sub_head =~ %r[^Content-Type:\s*text/plain]i then 128 137 @body = sub_body 129 elsif sub_head =~ %r[ 130 ^Content-Type:\s* 131 (?:image/ | application/octet-stream).+ 132 name=".+(\.[^.]+?)" (?# 1: extension) 133 ]imx 134 image_ext = $1.downcase 138 elsif sub_head =~ %r[^Content-Type:\s*(image/|application/octet-stream).*name=".*(\..*?)"]im 139 image_ext = $2.downcase 135 140 now = Time::now 136 141 list = image_list( now.strftime( "%Y%m%d" ), image_dir ) … … 146 151 if /\.bmp$/i =~ image_name then 147 152 bmp_to_png( image_dir + image_name ) 148 image_name.sub!( /\.bmp$/ i, '.png' )153 image_name.sub!( /\.bmp$/, '.png' ) 149 154 end 150 @image_name ||= []155 @image_name = [] unless @image_name 151 156 @image_name << image_name 152 157 end 153 158 end 154 elsif head =~ /^Content-Type:\s*text\/plain/i 159 elsif head =~ /^Content-Type:\s*text\/plain/i 155 160 @body = body 156 161 else 157 raise "can not read this mail"162 raise "can not read this mail" 158 163 end 159 164 … … 161 166 img_src = "" 162 167 @image_name.each do |i| 163 serial = i.sub( /^\d+_(\d+)\..*$/ n, '\1' )168 serial = i.sub( /^\d+_(\d+)\..*$/, '\1' ) 164 169 img_src += image_format.gsub( /\$0/, serial ).gsub( /\$1/, image_url + i ) 165 170 end 166 171 if use_subject then 167 @body = "#{img_src}\n#{@body }".sub( /(?:\r?\n|\r)+\z/, "\n" )172 @body = "#{img_src}\n#{@body.sub( /\n+\z/, '' )}" 168 173 else 169 @body = "#{@body }".sub( /(?:\r?\n|\r)+\z/, "\n" ) << img_src174 @body = "#{@body.sub( /\n+\z/, '' )}\n#{img_src}" 170 175 end 171 176 end … … 173 178 addr = nil 174 179 if /^To:(.*)$/ =~ head then 175 addr = case to = $1.strip 176 when /.*?\s*<(.+)>/, /(.+?)\s*\(.*\)/ 177 $1 180 to = $1.strip 181 if /.*?\s*<(.*)>/ =~ to then 182 addr = $1 183 elsif /(.*?)\s*\(.*\)/ =~ to 184 addr = $1 178 185 else 179 to180 end 181 end 182 186 addr = to 187 end 188 end 189 183 190 if /([^-]+)-(.*)@/ =~ addr then 184 user ||= $1185 pass ||= $2186 end 187 191 user = $1 unless user 192 pass = $2 unless pass 193 end 194 188 195 raise "no user." unless user 189 196 raise "no passwd." unless pass 190 197 191 198 subject = '' 192 199 nextline = false 193 headlines = head.split( / (?:\r?\n|\r)+/ )200 headlines = head.split( /[\r\n]+/ ) 194 201 for n in 0 .. headlines.size-1 195 202 if nextline then 196 203 if /^[ \t]/ =~ headlines[n] then 197 204 s = headlines[n].sub( /^[ \t]/, '' ) 198 subject += NKF::nkf( '- eXd', s )205 subject += NKF::nkf( '-wXd', s ) 199 206 else 200 207 break 201 208 end 202 209 end 203 if /^Subject:\s*(.+)$/i =~ headlines[n] then 204 subject = NKF::nkf( '-eXd', $1 ) 210 if /^Subject:(.*)$/ =~ headlines[n] then 211 s = $1.sub( /^\s+/, '' ) 212 subject = NKF::nkf( '-wXd', s ) 205 213 nextline = true 206 214 end … … 222 230 Net::HTTP.start( host, port ) do |http| 223 231 auth = ["#{user}:#{pass}"].pack( 'm' ).strip 224 res, = http.get( cgi, {232 res, = http.get( cgi, 225 233 'Authorization' => "Basic #{auth}", 226 'Referer' => url })234 'Referer' => url ) 227 235 if %r|<input type="hidden" name="csrf_protection_key" value="([^"]+)">| =~ res.body then 228 236 data << "&csrf_protection_key=#{CGI::escape( CGI::unescapeHTML( $1 ) )}" 229 237 end 230 res, = http.post( cgi, data, {238 res, = http.post( cgi, data, 231 239 'Authorization' => "Basic #{auth}", 232 'Referer' => url })240 'Referer' => url ) 233 241 end 234 242 235 243 rescue 236 244 $stderr.puts $! 237 $stderr.puts $@.join( "\n" )238 245 File::delete( image_dir + image_name ) if image_dir and image_name and FileTest::exist?( image_dir + image_name ) 239 246 exit 1
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)