From: Dave Thomas Date: 2001-12-09T11:04:36+09:00 Subject: [ruby-talk:27986] Re: Dictionary.com speeder upper -- Win2k problem "Ralph Mason" writes: > Any thoughts Mr Thomas? Here's the code that sends from the ml to the newsgroup: # Take a mail message and post it as a news article require "nntp" include NNTP require "log" require "params" log = Logger.new("mail2news") # Read in the message, splitting it into a heading and # a body. Only allow certain headers through in the heading HEADERS = %w{From Subject References In-Reply-To Message-Id Content-Type Content-Transfer-Encoding Date X-ML-Name X-Mail-Count } allowed_headers = Regexp.new(%{^(#{HEADERS.join("|")}):}, Regexp::IGNORECASE) # Read in the header. Only allow certain ones. Add a newsgroups line # and a X-rubymirror line head = "Newsgroups: #{Params::NEWSGROUP}\n" subject = "unknown" valid_header = false msg_id = "unknown" while line = gets exit if line =~ /^#{Params::LOOP_FLAG}/o # shouldn't happen break if line =~ /^\s*$/ # allow continuation lines only after valid headers if line =~ /^\s/ head << line if valid_header next end msg_id = $1 if line =~ /Message-Id:\s+(.*)/i valid_header = (line =~ allowed_headers) next unless valid_header if line =~ /^Subject:\s*(.*)/i subject = $1 # The following strips off the special ruby-talk number # from the front of mailing list messages before forwarding # them on to the news server. line.sub!(/\[ruby-talk:(\d+)\]\s*/, '') subject = "[#$1] #{line}" end head << line end head << "X-ruby-talk: #{msg_id}\n" head << "#{Params::LOOP_FLAG}\n" body = "" while line = gets body << line end log.log("Forwarding #{subject}") msg = head + "\n" + body msg.gsub!(/\r?\n/, "\r\n") nntp = NNTPIO.new(Params::NEWS_SERVER) raise "Failed to connect" unless nntp.connect nntp.post(msg)