したらばTOP ■掲示板に戻る■ 全部 1-100 最新50 | メール | |

管理人の独り言(プログラミング関連)

3613ACUVE★:2011/07/25(月) 23:00:24
# encoding: UTF-8

require 'socket'
require 'kconv'
require 'net/http'

def log(*str)
str.each{|s|
print s.to_s.tosjis
}
end

class String
def startwith(str)
self.slice(0, str.length) === str
end
end

gs = TCPServer.open(25)
addr = gs.addr
addr.shift
printf("server is on %s\n", addr.join(':'))

while true
Thread.start(gs.accept) do |s|
log s, " is accepted.\n"
s.write "220 OK\r\n"
line = s.gets
if line.startwith('EHLO')
s.write "502 ERR\r\n"
line = s.gets
end

if !line.startwith('HELO')
s.write "500 ERR\r\n"
s.close
return
end
s.write "250 OK\r\n"

while !(line = s.gets).startwith('DATA')
s.write "250 OK\r\n"
log line
end
s.write "354 ENTER\r\n"
log line

body = []
while !((line = s.gets) === ".\r\n")
log line
body.push line
end
s.write "250 OK\r\n"

if !(line = s.gets).startwith('QUIT')
s.write "500 ERR\r\n"
s.close
return
end
s.write "221 CLOSE\r\n"

log s, " is done.\n"
s.close

if body.length != 0
key = nil
bodystr = ''

body.each do |line|
if line.startwith 'To:'
key = line[/\d{10,}/]
break
end
end

lambda do
state = 0
body.each do |line|
if state == 0 && line == "\r\n"
state = 1
elsif state == 1
bodystr << line.chomp << "\n"
end
end
end.call



Net::HTTP.post_form(
URI.parse('http://jbbs.livedoor.jp/bbs/write.cgi/computer/38153/1307542890/'),
{
'DIR' => 'computer',
'BBS' => '38153',
'KEY' => key,
'TIME' => Time.now.to_i.to_s,
'NAME' => '',
'MAIL' => '',
'MESSAGE' => bodystr.toeuc
}
) if key != nil && !bodystr.empty?
end
end
end


新着レスの表示


名前: E-mail(省略可)

※書き込む際の注意事項はこちら

※画像アップローダーはこちら

(画像を表示できるのは「画像リンクのサムネイル表示」がオンの掲示板に限ります)

掲示板管理者へ連絡 無料レンタル掲示板