summary refs log tree commit diff
path: root/contrib/mblow
blob: 7ad163cc006a34aeb752af9d3e791825d8260218 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/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