ruby-net-nntp 0.2.0 → 0.2.1
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/lib/net/nntp/article.rb +16 -4
- data/lib/net/nntp/version.rb +1 -1
- data/test/unit/test_nntp_article.rb +9 -1
- metadata +4 -4
data/lib/net/nntp/article.rb
CHANGED
@@ -11,6 +11,7 @@ end
|
|
11
11
|
|
12
12
|
module Net
|
13
13
|
class NNTP
|
14
|
+
# Article parsing class
|
14
15
|
class Article
|
15
16
|
attr_accessor :group, :headers, :body
|
16
17
|
attr_reader :overview_format
|
@@ -132,10 +133,21 @@ module Net
|
|
132
133
|
#
|
133
134
|
# Parses a line of the format "Header: Value" and sets the @headers accordingly.
|
134
135
|
# (Example: "Message-ID: <abc@def.gh>" will become @headers.message_id with the
|
135
|
-
# value '<abc@def.gh>'.
|
136
|
+
# value '<abc@def.gh>'. Scans multiline headers (if header does start with a
|
137
|
+
# whitespace, it is part of the last header.
|
136
138
|
def set_header(line)
|
137
|
-
|
138
|
-
|
139
|
+
value = nil
|
140
|
+
if line =~ /^\s/ # line starts with a whitespace
|
141
|
+
oldval = @headers.send(@last_header)
|
142
|
+
value = []
|
143
|
+
value << oldval.strip
|
144
|
+
value << line.strip
|
145
|
+
key = @last_header
|
146
|
+
else
|
147
|
+
name, value = line.scan(/^(.*?): (.*)$/).flatten
|
148
|
+
key = name.strip.gsub(/[^\w]/, '_').downcase
|
149
|
+
end
|
150
|
+
@last_header = key
|
139
151
|
@headers.add_pair(key, value)
|
140
152
|
@headers
|
141
153
|
end
|
@@ -157,7 +169,7 @@ module Net
|
|
157
169
|
lines.each do |line|
|
158
170
|
count += 1
|
159
171
|
next if count == 1
|
160
|
-
break if line =~
|
172
|
+
break if line =~ /^\.$/
|
161
173
|
do_header = (do_header && line !~ /^$/)
|
162
174
|
next if line =~ /^$/
|
163
175
|
if do_header
|
data/lib/net/nntp/version.rb
CHANGED
@@ -55,6 +55,12 @@ class TestNNTPArticle < Test::Unit::TestCase
|
|
55
55
|
assert_equal 'Test', @article.headers.subject
|
56
56
|
@article.set_header('Message-ID: <this.post@is.invalid>')
|
57
57
|
assert_equal '<this.post@is.invalid>', @article.headers.message_id
|
58
|
+
@article.set_header('References: <this.is.a.reference.test@invalid>')
|
59
|
+
@article.set_header(' <this.is.another.reference.test@invalid>')
|
60
|
+
assert_kind_of Array, @article.headers.references
|
61
|
+
assert_equal 2, @article.headers.references.size
|
62
|
+
assert_equal '<this.is.a.reference.test@invalid>', @article.headers.references[0]
|
63
|
+
assert_equal '<this.is.another.reference.test@invalid>', @article.headers.references[1]
|
58
64
|
end
|
59
65
|
|
60
66
|
def test_parse
|
@@ -66,14 +72,16 @@ class TestNNTPArticle < Test::Unit::TestCase
|
|
66
72
|
"",
|
67
73
|
"test please ignore",
|
68
74
|
"test ",
|
75
|
+
"\t",
|
69
76
|
"."])
|
70
77
|
assert_equal '17 Aug 2004 14:00:00 GMT', article.headers.date
|
71
78
|
assert_equal '"abc" abc@ide.invalid', article.headers.from
|
72
79
|
assert_equal '<this.post@is.invalid>', article.headers.message_id
|
73
80
|
assert_equal 'ignore test', article.headers.subject
|
74
|
-
assert_equal
|
81
|
+
assert_equal 3, article.body.size
|
75
82
|
assert_equal 'test please ignore', article.body[0]
|
76
83
|
assert_equal 'test ', article.body[1]
|
84
|
+
assert_equal "\t", article.body[2]
|
77
85
|
article = Net::NNTP::Article.parse(["221 1 article retrieved - head follows", "Date: 17 Aug 2004 14:00:00 GMT", "From: \"abc\" abc@ide.invalid",
|
78
86
|
"Message-ID: <this.post@is.invalid>", "Subject: ignore test", "."])
|
79
87
|
assert_equal '17 Aug 2004 14:00:00 GMT', article.headers.date
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
|
|
3
3
|
specification_version: 1
|
4
4
|
name: ruby-net-nntp
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.2.
|
7
|
-
date: 2007-
|
6
|
+
version: 0.2.1
|
7
|
+
date: 2007-11-19 00:00:00 +01:00
|
8
8
|
summary: Net::XXX style NNTP Library for easy access.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -40,8 +40,8 @@ files:
|
|
40
40
|
- test/mock
|
41
41
|
- test/mock/mock_socket.rb
|
42
42
|
- test/unit
|
43
|
-
- test/unit/test_nntp_article.rb
|
44
43
|
- test/unit/test_nntp_group.rb
|
44
|
+
- test/unit/test_nntp_article.rb
|
45
45
|
- README
|
46
46
|
- CHANGELOG
|
47
47
|
- MIT-LICENSE
|
@@ -51,8 +51,8 @@ test_files:
|
|
51
51
|
- test/mock
|
52
52
|
- test/mock/mock_socket.rb
|
53
53
|
- test/unit
|
54
|
-
- test/unit/test_nntp_article.rb
|
55
54
|
- test/unit/test_nntp_group.rb
|
55
|
+
- test/unit/test_nntp_article.rb
|
56
56
|
rdoc_options:
|
57
57
|
- -S
|
58
58
|
- -N
|