mirror of
https://github.com/leahneukirchen/mblaze
synced 2024-11-11 13:10:32 +00:00
38 lines
585 B
Ruby
Executable File
38 lines
585 B
Ruby
Executable File
#!/usr/bin/ruby
|
|
# mblow - post an article via NNTP
|
|
|
|
require 'socket'
|
|
require 'optparse'
|
|
|
|
params = ARGV.getopts("s:")
|
|
|
|
port = 119
|
|
if params["s"] =~ /(.*):(.*)/
|
|
params["s"] = $1
|
|
port = Integer($2)
|
|
end
|
|
|
|
SERVER = params["s"] || ENV["NNTPSERVER"] || "news"
|
|
|
|
nntp = TCPSocket.new SERVER, port
|
|
|
|
msg = nntp.gets
|
|
abort msg unless msg =~ /^200 /
|
|
|
|
nntp.write "POST\r\n"
|
|
msg = nntp.gets
|
|
|
|
abort msg unless msg =~ /^340 /
|
|
|
|
while line = gets
|
|
line.chomp!
|
|
line.sub!(/\A\./, '..')
|
|
nntp.write(line + "\r\n")
|
|
end
|
|
|
|
nntp.write(".\r\n")
|
|
msg = nntp.gets
|
|
|
|
abort msg unless msg =~ /^240 /
|
|
puts msg
|