thoughtafter-nntp 1.0.0.2 → 1.0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Authors.txt +18 -0
- data/History.txt +42 -0
- data/License.txt +32 -0
- data/Manifest.txt +24 -0
- data/README.txt +9 -0
- data/Rakefile +4 -0
- data/config/hoe.rb +71 -0
- data/config/requirements.rb +17 -0
- data/lib/nntp.rb +883 -0
- data/lib/nntp/version.rb +34 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +74 -0
- data/setup.rb +1585 -0
- data/tasks/deployment.rake +34 -0
- data/tasks/environment.rake +7 -0
- data/tasks/website.rake +17 -0
- data/test/test_helper.rb +2 -0
- data/test/test_nntp.rb +11 -0
- data/website/index.html +254 -0
- data/website/index.txt +163 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +138 -0
- data/website/template.rhtml +48 -0
- metadata +26 -2
@@ -0,0 +1,34 @@
|
|
1
|
+
desc 'Release the website and new gem version'
|
2
|
+
task :deploy => [:check_version, :website, :release] do
|
3
|
+
puts "Remember to create SVN tag:"
|
4
|
+
puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
|
5
|
+
"svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
|
6
|
+
puts "Suggested comment:"
|
7
|
+
puts "Tagging release #{CHANGES}"
|
8
|
+
end
|
9
|
+
|
10
|
+
desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
|
11
|
+
task :local_deploy => [:website_generate, :install_gem]
|
12
|
+
|
13
|
+
task :check_version do
|
14
|
+
unless ENV['VERSION']
|
15
|
+
puts 'Must pass a VERSION=x.y.z release version'
|
16
|
+
exit
|
17
|
+
end
|
18
|
+
unless ENV['VERSION'] == VERS
|
19
|
+
puts "Please update your version.rb to match the release version, currently #{VERS}"
|
20
|
+
exit
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
desc 'Install the package as a gem, without generating documentation(ri/rdoc)'
|
25
|
+
task :install_gem_no_doc => [:clean, :package] do
|
26
|
+
sh "#{'sudo ' unless Hoe::WINDOZE }gem install pkg/*.gem --no-rdoc --no-ri"
|
27
|
+
end
|
28
|
+
|
29
|
+
namespace :manifest do
|
30
|
+
desc 'Recreate Manifest.txt to include ALL files'
|
31
|
+
task :refresh do
|
32
|
+
`rake check_manifest | patch -p0 > Manifest.txt`
|
33
|
+
end
|
34
|
+
end
|
data/tasks/website.rake
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
desc 'Generate website files'
|
2
|
+
task :website_generate => :ruby_env do
|
3
|
+
(Dir['website/**/*.txt'] - Dir['website/version*.txt']).each do |txt|
|
4
|
+
sh %{ #{RUBY_APP} script/txt2html #{txt} > #{txt.gsub(/txt$/,'html')} }
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
desc 'Upload website files to rubyforge'
|
9
|
+
task :website_upload do
|
10
|
+
host = "#{rubyforge_username}@rubyforge.org"
|
11
|
+
remote_dir = "/var/www/gforge-projects/#{PATH}/"
|
12
|
+
local_dir = 'website'
|
13
|
+
sh %{rsync -rlgoDCv #{local_dir}/ #{host}:#{remote_dir}}
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'Generate and upload website files'
|
17
|
+
task :website => [:website_generate, :website_upload, :publish_docs]
|
data/test/test_helper.rb
ADDED
data/test/test_nntp.rb
ADDED
data/website/index.html
ADDED
@@ -0,0 +1,254 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
+
<head>
|
5
|
+
<link rel="stylesheet" href="stylesheets/screen.css" type="text/css" media="screen" />
|
6
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
7
|
+
<title>
|
8
|
+
Net::NNTP Client Library
|
9
|
+
</title>
|
10
|
+
<script src="javascripts/rounded_corners_lite.inc.js" type="text/javascript"></script>
|
11
|
+
<style>
|
12
|
+
|
13
|
+
</style>
|
14
|
+
<script type="text/javascript">
|
15
|
+
window.onload = function() {
|
16
|
+
settings = {
|
17
|
+
tl: { radius: 10 },
|
18
|
+
tr: { radius: 10 },
|
19
|
+
bl: { radius: 10 },
|
20
|
+
br: { radius: 10 },
|
21
|
+
antiAlias: true,
|
22
|
+
autoPad: true,
|
23
|
+
validTags: ["div"]
|
24
|
+
}
|
25
|
+
var versionBox = new curvyCorners(settings, document.getElementById("version"));
|
26
|
+
versionBox.applyCornersToAll();
|
27
|
+
}
|
28
|
+
</script>
|
29
|
+
</head>
|
30
|
+
<body>
|
31
|
+
<div id="main">
|
32
|
+
|
33
|
+
<h1>Net::NNTP Client Library</h1>
|
34
|
+
<div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/nntp"; return false'>
|
35
|
+
<p>Get Version</p>
|
36
|
+
<a href="http://rubyforge.org/projects/nntp" class="numbers">1.0.0</a>
|
37
|
+
</div>
|
38
|
+
<h1>→ ‘nntp’</h1>
|
39
|
+
|
40
|
+
|
41
|
+
<h2>What</h2>
|
42
|
+
|
43
|
+
|
44
|
+
<p>This gem allows you to to retrieve and post Usenet news articles via <span class="caps">NNTP</span>, the Network News Transfer Protocol. For details of <span class="caps">NNTP</span> itself, see <a href="http://www.ietf.org/rfc/rfc977.txt"><span class="caps">RFC977</span></a>.</p>
|
45
|
+
|
46
|
+
|
47
|
+
<p>This library does <span class="caps">NOT</span> provide functions to compose Usenet news articles. You must create and format them yourself per Standard for Interchange of Usenet Messages. See <a href="http://www.ietf.org/rfc/rfc850.txt"><span class="caps">RFC850</span></a>, <a href="http://www.ietf.org/rfc/rfc2047.txt"><span class="caps">RFC2047</span></a>.</p>
|
48
|
+
|
49
|
+
|
50
|
+
<h2>Installing</h2>
|
51
|
+
|
52
|
+
|
53
|
+
<p><pre class='syntax'><span class="ident">sudo</span> <span class="ident">gem</span> <span class="ident">install</span> <span class="ident">nntp</span></pre></p>
|
54
|
+
|
55
|
+
|
56
|
+
<p>Alternatively, you may download the gem from the <a href="http://rubyforge.org/projects/nntp">project info page</a> and install manually.</p>
|
57
|
+
|
58
|
+
|
59
|
+
<h2>The basics</h2>
|
60
|
+
|
61
|
+
|
62
|
+
<h3>Posting Messages</h3>
|
63
|
+
|
64
|
+
|
65
|
+
<p>You must open a connection to a <span class="caps">NNTP</span> server before posting messages. The first argument is the address of your <span class="caps">NNTP</span> server, and the second argument is the port number. Using <span class="caps">NNTP</span>.start with a block is the simplest way to do this because the <span class="caps">NNTP</span> connection closes automatically after the block executes.</p>
|
66
|
+
|
67
|
+
|
68
|
+
<p><pre class='syntax'>
|
69
|
+
<span class="ident">require</span> <span class="punct">'</span><span class="string">rubygems</span><span class="punct">'</span>
|
70
|
+
<span class="ident">require</span> <span class="punct">'</span><span class="string">nntp</span><span class="punct">'</span>
|
71
|
+
<span class="constant">Net</span><span class="punct">::</span><span class="constant">NNTP</span><span class="punct">.</span><span class="ident">start</span><span class="punct">('</span><span class="string">your.nntp.server</span><span class="punct">',</span> <span class="number">119</span><span class="punct">)</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">nntp</span><span class="punct">|</span>
|
72
|
+
<span class="comment"># Use the NNTP object nntp only in this block.</span>
|
73
|
+
<span class="keyword">end</span>
|
74
|
+
</pre></p>
|
75
|
+
|
76
|
+
|
77
|
+
<p>Replace ‘your.nntp.server’ with your <span class="caps">NNTP</span> server. Normally your systems administrator or internet service provider supplies a server for you.</p>
|
78
|
+
|
79
|
+
|
80
|
+
<p>Then you can post messages.</p>
|
81
|
+
|
82
|
+
|
83
|
+
<p><pre class='syntax'>
|
84
|
+
<span class="ident">require</span> <span class="punct">'</span><span class="string">date</span><span class="punct">'</span>
|
85
|
+
<span class="ident">date</span> <span class="punct">=</span> <span class="constant">DateTime</span><span class="punct">.</span><span class="ident">now</span><span class="punct">().</span><span class="ident">strftime</span><span class="punct">(</span><span class="ident">fmt</span><span class="punct">='</span><span class="string">%a, %d %b %Y %T %z</span><span class="punct">')</span>
|
86
|
+
|
87
|
+
<span class="ident">msgstr</span> <span class="punct">=</span> <span class="punct"><<</span><span class="constant">END_OF_MESSAGE</span><span class="string">
|
88
|
+
From: Your Name <your@mail.address>
|
89
|
+
Newsgroups: news.group.one, news.group.two ...
|
90
|
+
Subject: test message
|
91
|
+
Date: <span class="expr">#{date}</span>
|
92
|
+
|
93
|
+
This is a test message.
|
94
|
+
END_OF_MESSAGE
|
95
|
+
|
96
|
+
require 'rubygems'
|
97
|
+
require 'nntp'
|
98
|
+
Net::NNTP.start('your.nntp.server', 119) do |nntp|
|
99
|
+
nntp.post msgstr
|
100
|
+
end<span class="normal">
|
101
|
+
</span></span></pre></p>
|
102
|
+
|
103
|
+
|
104
|
+
<p><span class="caps">NOTE</span>: The <span class="caps">NNTP</span> message headers such as <code>Date:</code>, <code>Message-ID:</code>, and <code>Path:</code>, if ommited, may automatically be added by your Usenet news server; however, it is best not to rely on this behavior.</p>
|
105
|
+
|
106
|
+
|
107
|
+
<h3>Reading Messages</h3>
|
108
|
+
|
109
|
+
|
110
|
+
<p>This snippet will display all subject lines within a particular news group.</p>
|
111
|
+
|
112
|
+
|
113
|
+
<p><pre class='syntax'>
|
114
|
+
<span class="ident">require</span> <span class="punct">'</span><span class="string">rubygems</span><span class="punct">'</span>
|
115
|
+
<span class="ident">require</span> <span class="punct">'</span><span class="string">nntp</span><span class="punct">'</span>
|
116
|
+
|
117
|
+
<span class="ident">newsgroup</span> <span class="punct">=</span> <span class="punct">'</span><span class="string">comp.lang.ruby</span><span class="punct">'</span>
|
118
|
+
|
119
|
+
<span class="constant">Net</span><span class="punct">::</span><span class="constant">NNTP</span><span class="punct">.</span><span class="ident">start</span><span class="punct">('</span><span class="string">your.nntp.server</span><span class="punct">',</span> <span class="number">119</span><span class="punct">)</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">nntp</span><span class="punct">|</span>
|
120
|
+
<span class="ident">message_ids</span> <span class="punct">=</span> <span class="ident">nntp</span><span class="punct">.</span><span class="ident">listgroup</span><span class="punct">(</span><span class="ident">newsgroup</span><span class="punct">)</span>
|
121
|
+
<span class="ident">message_ids</span><span class="punct">[</span><span class="number">1</span><span class="punct">].</span><span class="ident">each</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">id</span><span class="punct">|</span>
|
122
|
+
<span class="ident">nntp</span><span class="punct">.</span><span class="ident">head</span><span class="punct">(</span><span class="ident">id</span><span class="punct">).</span><span class="ident">each</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">header</span><span class="punct">|</span>
|
123
|
+
<span class="ident">header</span><span class="punct">.</span><span class="ident">each</span> <span class="punct">{</span> <span class="punct">|</span><span class="ident">line</span><span class="punct">|</span> <span class="ident">puts</span><span class="punct">(</span><span class="ident">line</span><span class="punct">)</span> <span class="keyword">if</span> <span class="ident">line</span><span class="punct">.</span><span class="ident">index</span><span class="punct">('</span><span class="string">Subject:</span><span class="punct">')</span> <span class="punct">}</span>
|
124
|
+
<span class="keyword">end</span>
|
125
|
+
<span class="keyword">end</span>
|
126
|
+
<span class="keyword">end</span>
|
127
|
+
</pre></p>
|
128
|
+
|
129
|
+
|
130
|
+
<h3>Closing the Session</h3>
|
131
|
+
|
132
|
+
|
133
|
+
<p>You <span class="caps">MUST</span> close the <span class="caps">NNTP</span> session after posting messages by calling the Net::NNTP#finish method:</p>
|
134
|
+
|
135
|
+
|
136
|
+
<p><pre class='syntax'>
|
137
|
+
<span class="comment"># using NNTP#finish</span>
|
138
|
+
<span class="ident">nntp</span> <span class="punct">=</span> <span class="constant">Net</span><span class="punct">::</span><span class="constant">NNTP</span><span class="punct">.</span><span class="ident">start</span><span class="punct">('</span><span class="string">your.nntp.server</span><span class="punct">',</span> <span class="number">119</span><span class="punct">)</span>
|
139
|
+
<span class="ident">nntp</span><span class="punct">.</span><span class="ident">post</span> <span class="ident">msgstr</span>
|
140
|
+
<span class="ident">nntp</span><span class="punct">.</span><span class="ident">finish</span>
|
141
|
+
</pre></p>
|
142
|
+
|
143
|
+
|
144
|
+
<p>You can also use the block form of <span class="caps">NNTP</span>.start/NNTP#start. This closes the <span class="caps">NNTP</span> session automatically:</p>
|
145
|
+
|
146
|
+
|
147
|
+
<p><pre class='syntax'>
|
148
|
+
<span class="comment"># using block form of NNTP.start</span>
|
149
|
+
<span class="constant">Net</span><span class="punct">::</span><span class="constant">NNTP</span><span class="punct">.</span><span class="ident">start</span><span class="punct">('</span><span class="string">your.nntp.server</span><span class="punct">',</span> <span class="number">119</span><span class="punct">)</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">nntp</span><span class="punct">|</span>
|
150
|
+
<span class="ident">nntp</span><span class="punct">.</span><span class="ident">post</span> <span class="ident">msgstr</span>
|
151
|
+
<span class="keyword">end</span>
|
152
|
+
</pre></p>
|
153
|
+
|
154
|
+
|
155
|
+
<p>We strongly recommend the latter scheme since it is simpler and more robust.</p>
|
156
|
+
|
157
|
+
|
158
|
+
<h3><span class="caps">NNTP</span> Authentication</h3>
|
159
|
+
|
160
|
+
|
161
|
+
<p>The Net::NNTP class may support various authentication schemes depending on your news server‘s reponse to <span class="caps">CAPABILITIES</span> command. To use <span class="caps">NNTP</span> authentication, pass extra arguments to <span class="caps">NNTP</span>.start/NNTP#start.</p>
|
162
|
+
|
163
|
+
|
164
|
+
<p>See <a href="http://www.ietf.org/internet-drafts/draft-ietf-nntpext-authinfo-07.txt"><span class="caps">NNTP</span> Extension for Authentication</a>.</p>
|
165
|
+
|
166
|
+
|
167
|
+
<p><pre class='syntax'>
|
168
|
+
<span class="constant">Net</span><span class="punct">::</span><span class="constant">NNTP</span><span class="punct">.</span><span class="ident">start</span><span class="punct">('</span><span class="string">your.nntp.server</span><span class="punct">',</span> <span class="number">119</span><span class="punct">,</span>
|
169
|
+
<span class="punct">'</span><span class="string">YourAccountName</span><span class="punct">',</span> <span class="punct">'</span><span class="string">YourPassword</span><span class="punct">',</span> <span class="symbol">:method</span><span class="punct">)</span>
|
170
|
+
</pre></p>
|
171
|
+
|
172
|
+
|
173
|
+
<p>Where <code>:method</code> can be one of ‘gassapi’, ‘digest_md5’, ‘cram_md5’, ‘starttls’, ‘external’, ‘plain’, ‘generic’, ‘simple’ or ‘original’.</p>
|
174
|
+
|
175
|
+
|
176
|
+
<p>In the case of method <code>:generic</code>, arguments should be passed to a format string as follows:</p>
|
177
|
+
|
178
|
+
|
179
|
+
<p><pre class='syntax'>
|
180
|
+
<span class="constant">Net</span><span class="punct">::</span><span class="constant">NNTP</span><span class="punct">.</span><span class="ident">start</span><span class="punct">('</span><span class="string">your.nntp.server</span><span class="punct">',</span> <span class="number">119</span><span class="punct">,</span>
|
181
|
+
<span class="punct">"</span><span class="string">format</span><span class="punct">",</span> <span class="punct">*</span><span class="ident">arguments</span><span class="punct">,</span> <span class="symbol">:generic</span><span class="punct">)</span>
|
182
|
+
</pre></p>
|
183
|
+
|
184
|
+
|
185
|
+
<p><span class="caps">NOTE</span>: With the exception of <code>:generic</code>, the authentication mechanism will fallback to a less secure scheme if your Usenet server does not support the method you selected.</p>
|
186
|
+
|
187
|
+
|
188
|
+
<h2>How to Submit Patches</h2>
|
189
|
+
|
190
|
+
|
191
|
+
<ul>
|
192
|
+
<li>Read the <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/">8 steps for fixing other people’s code</a>.</li>
|
193
|
+
<li>The trunk repository is <code>svn://rubyforge.org/var/svn/nntp/trunk</code> for anonymous access.</li>
|
194
|
+
<li>You can upload your patch to the “Patches” section of the <a href="http://rubyforge.org/projects/nntp">project info page</a>.</li>
|
195
|
+
</ul>
|
196
|
+
|
197
|
+
|
198
|
+
<h2>License</h2>
|
199
|
+
|
200
|
+
|
201
|
+
<p>This code is free to use under the terms of version 2.1 of the <span class="caps">GNU</span> Lesser General Public License.</p>
|
202
|
+
|
203
|
+
|
204
|
+
<h2>Donate</h2>
|
205
|
+
|
206
|
+
|
207
|
+
Any contribution of yours, however small it may be, will highly be appreciated and used for further development of this and other F/LOSS (Free/Libre Open Source Software) Projects.
|
208
|
+
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
|
209
|
+
<input type="hidden" name="cmd" value="_xclick" />
|
210
|
+
<input type="hidden" name="business" value="bsd@rubyforge.org" />
|
211
|
+
<input type="image" src="https://www.paypal.com/en_US/i/logo/PayPal_mark_37x23.gif" style="border:0" name="submit" alt="[ Make payments with PayPal -it's fast, free and secure! ]" title="Please do donate to keep this project alive!" />
|
212
|
+
</form>
|
213
|
+
|
214
|
+
<h2>Documentation</h2>
|
215
|
+
|
216
|
+
|
217
|
+
<p>In addition to this page, you can also view the automatically generated RDocs in the “DocManager: Project Documentation”
|
218
|
+
section of the <a href="http://rubyforge.org/projects/nntp">project info page</a>. If you elect to install the RI documentation
|
219
|
+
when you install the gem, you can afterwards issue the following command for the <span class="caps">API</span> reference:</p>
|
220
|
+
|
221
|
+
|
222
|
+
<code>
|
223
|
+
ri Net::NNTP
|
224
|
+
</code>
|
225
|
+
|
226
|
+
<h2>Similar Gems</h2>
|
227
|
+
|
228
|
+
|
229
|
+
<p>Anton Bangratz’s <a href="http://rubyforge.org/projects/ruby-net-nntp/">ruby-net-nntp</a></p>
|
230
|
+
|
231
|
+
|
232
|
+
<h2>Credits</h2>
|
233
|
+
|
234
|
+
|
235
|
+
<ul>
|
236
|
+
<li><a href="http://rubyforge.org/">RubyForge</a> – hosting and project management</li>
|
237
|
+
<li><a href="http://newgem.rubyforge.org/">newgem</a> – new gem generator</li>
|
238
|
+
</ul>
|
239
|
+
|
240
|
+
|
241
|
+
<h2>Where to get help</h2>
|
242
|
+
|
243
|
+
|
244
|
+
<p>If you need assistance with this gem, visit the <a href="http://rubyforge.org/projects/nntp">project info page</a> to file a bug, make a support request, or suggest a new feature.</p>
|
245
|
+
<p class="coda">
|
246
|
+
Albert Vernon, 2nd January 2008<br>
|
247
|
+
Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
|
248
|
+
</p>
|
249
|
+
</div>
|
250
|
+
|
251
|
+
<!-- insert site tracking codes here, like Google Urchin -->
|
252
|
+
|
253
|
+
</body>
|
254
|
+
</html>
|
data/website/index.txt
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
h1. Net::NNTP Client Library
|
2
|
+
|
3
|
+
h1. → 'nntp'
|
4
|
+
|
5
|
+
|
6
|
+
h2. What
|
7
|
+
|
8
|
+
This gem allows you to to retrieve and post Usenet news articles via NNTP, the Network News Transfer Protocol. For details of NNTP itself, see "RFC977":http://www.ietf.org/rfc/rfc977.txt.
|
9
|
+
|
10
|
+
This library does NOT provide functions to compose Usenet news articles. You must create and format them yourself per Standard for Interchange of Usenet Messages. See "RFC850":http://www.ietf.org/rfc/rfc850.txt, "RFC2047":http://www.ietf.org/rfc/rfc2047.txt.
|
11
|
+
|
12
|
+
h2. Installing
|
13
|
+
|
14
|
+
<pre syntax="ruby">sudo gem install nntp</pre>
|
15
|
+
|
16
|
+
Alternatively, you may download the gem from the "project info page":http://rubyforge.org/projects/nntp and install manually.
|
17
|
+
|
18
|
+
h2. The basics
|
19
|
+
|
20
|
+
h3. Posting Messages
|
21
|
+
|
22
|
+
You must open a connection to a NNTP server before posting messages. The first argument is the address of your NNTP server, and the second argument is the port number. Using NNTP.start with a block is the simplest way to do this because the NNTP connection closes automatically after the block executes.
|
23
|
+
|
24
|
+
<pre syntax="ruby">
|
25
|
+
require 'rubygems'
|
26
|
+
require 'nntp'
|
27
|
+
Net::NNTP.start('your.nntp.server', 119) do |nntp|
|
28
|
+
# Use the NNTP object nntp only in this block.
|
29
|
+
end
|
30
|
+
</pre>
|
31
|
+
|
32
|
+
Replace ‘your.nntp.server’ with your NNTP server. Normally your systems administrator or internet service provider supplies a server for you.
|
33
|
+
|
34
|
+
Then you can post messages.
|
35
|
+
|
36
|
+
<pre syntax="ruby">
|
37
|
+
require 'date'
|
38
|
+
date = DateTime.now().strftime(fmt='%a, %d %b %Y %T %z')
|
39
|
+
|
40
|
+
msgstr = <<END_OF_MESSAGE
|
41
|
+
From: Your Name <your@mail.address>
|
42
|
+
Newsgroups: news.group.one, news.group.two ...
|
43
|
+
Subject: test message
|
44
|
+
Date: #{date}
|
45
|
+
|
46
|
+
This is a test message.
|
47
|
+
END_OF_MESSAGE
|
48
|
+
|
49
|
+
require 'rubygems'
|
50
|
+
require 'nntp'
|
51
|
+
Net::NNTP.start('your.nntp.server', 119) do |nntp|
|
52
|
+
nntp.post msgstr
|
53
|
+
end
|
54
|
+
</pre>
|
55
|
+
|
56
|
+
NOTE: The NNTP message headers such as @Date:@, @Message-ID:@, and @Path:@, if ommited, may automatically be added by your Usenet news server; however, it is best not to rely on this behavior.
|
57
|
+
|
58
|
+
h3. Reading Messages
|
59
|
+
|
60
|
+
This snippet will display all subject lines within a particular news group.
|
61
|
+
|
62
|
+
<pre syntax="ruby">
|
63
|
+
require 'rubygems'
|
64
|
+
require 'nntp'
|
65
|
+
|
66
|
+
newsgroup = 'comp.lang.ruby'
|
67
|
+
|
68
|
+
Net::NNTP.start('your.nntp.server', 119) do |nntp|
|
69
|
+
message_ids = nntp.listgroup(newsgroup)
|
70
|
+
message_ids[1].each do |id|
|
71
|
+
nntp.head(id).each do |header|
|
72
|
+
header.each { |line| puts(line) if line.index('Subject:') }
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
</pre>
|
77
|
+
|
78
|
+
h3. Closing the Session
|
79
|
+
|
80
|
+
You MUST close the NNTP session after posting messages by calling the Net::NNTP#finish method:
|
81
|
+
|
82
|
+
<pre syntax="ruby">
|
83
|
+
# using NNTP#finish
|
84
|
+
nntp = Net::NNTP.start('your.nntp.server', 119)
|
85
|
+
nntp.post msgstr
|
86
|
+
nntp.finish
|
87
|
+
</pre>
|
88
|
+
|
89
|
+
You can also use the block form of NNTP.start/NNTP#start. This closes the NNTP session automatically:
|
90
|
+
|
91
|
+
<pre syntax="ruby">
|
92
|
+
# using block form of NNTP.start
|
93
|
+
Net::NNTP.start('your.nntp.server', 119) do |nntp|
|
94
|
+
nntp.post msgstr
|
95
|
+
end
|
96
|
+
</pre>
|
97
|
+
|
98
|
+
We strongly recommend the latter scheme since it is simpler and more robust.
|
99
|
+
|
100
|
+
h3. NNTP Authentication
|
101
|
+
|
102
|
+
The Net::NNTP class may support various authentication schemes depending on your news server‘s reponse to CAPABILITIES command. To use NNTP authentication, pass extra arguments to NNTP.start/NNTP#start.
|
103
|
+
|
104
|
+
See "NNTP Extension for Authentication":http://www.ietf.org/internet-drafts/draft-ietf-nntpext-authinfo-07.txt.
|
105
|
+
|
106
|
+
<pre syntax="ruby">
|
107
|
+
Net::NNTP.start('your.nntp.server', 119,
|
108
|
+
'YourAccountName', 'YourPassword', :method)
|
109
|
+
</pre>
|
110
|
+
|
111
|
+
Where @:method@ can be one of ‘gassapi’, ‘digest_md5’, ‘cram_md5’, ‘starttls’, ‘external’, ‘plain’, ‘generic’, ‘simple’ or ‘original’.
|
112
|
+
|
113
|
+
In the case of method @:generic@, arguments should be passed to a format string as follows:
|
114
|
+
|
115
|
+
<pre syntax="ruby">
|
116
|
+
Net::NNTP.start('your.nntp.server', 119,
|
117
|
+
"format", *arguments, :generic)
|
118
|
+
</pre>
|
119
|
+
|
120
|
+
NOTE: With the exception of @:generic@, the authentication mechanism will fallback to a less secure scheme if your Usenet server does not support the method you selected.
|
121
|
+
|
122
|
+
|
123
|
+
h2. How to Submit Patches
|
124
|
+
|
125
|
+
* Read the "8 steps for fixing other people's code":http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/.
|
126
|
+
* The trunk repository is <code>svn://rubyforge.org/var/svn/nntp/trunk</code> for anonymous access.
|
127
|
+
* You can upload your patch to the "Patches" section of the "project info page":http://rubyforge.org/projects/nntp.
|
128
|
+
|
129
|
+
h2. License
|
130
|
+
|
131
|
+
This code is free to use under the terms of version 2.1 of the GNU Lesser General Public License.
|
132
|
+
|
133
|
+
h2. Donate
|
134
|
+
|
135
|
+
Any contribution of yours, however small it may be, will highly be appreciated and used for further development of this and other F/LOSS (Free/Libre Open Source Software) Projects.
|
136
|
+
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
|
137
|
+
<input type="hidden" name="cmd" value="_xclick" />
|
138
|
+
<input type="hidden" name="business" value="bsd@rubyforge.org" />
|
139
|
+
<input type="image" src="https://www.paypal.com/en_US/i/logo/PayPal_mark_37x23.gif" style="border:0" name="submit" alt="[ Make payments with PayPal -it's fast, free and secure! ]" title="Please do donate to keep this project alive!" />
|
140
|
+
</form>
|
141
|
+
|
142
|
+
h2. Documentation
|
143
|
+
|
144
|
+
In addition to this page, you can also view the automatically generated RDocs in the "DocManager: Project Documentation"
|
145
|
+
section of the "project info page":http://rubyforge.org/projects/nntp. If you elect to install the RI documentation
|
146
|
+
when you install the gem, you can afterwards issue the following command for the API reference:
|
147
|
+
|
148
|
+
<code>
|
149
|
+
ri Net::NNTP
|
150
|
+
</code>
|
151
|
+
|
152
|
+
h2. Similar Gems
|
153
|
+
|
154
|
+
Anton Bangratz's "ruby-net-nntp":http://rubyforge.org/projects/ruby-net-nntp/
|
155
|
+
|
156
|
+
h2. Credits
|
157
|
+
|
158
|
+
* "RubyForge":http://rubyforge.org/ – hosting and project management
|
159
|
+
* "newgem":http://newgem.rubyforge.org/ - new gem generator
|
160
|
+
|
161
|
+
h2. Where to get help
|
162
|
+
|
163
|
+
If you need assistance with this gem, visit the "project info page":http://rubyforge.org/projects/nntp to file a bug, make a support request, or suggest a new feature.
|