1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.geronimo.javamail.transport.nntp;
21
22 import java.io.BufferedReader;
23 import java.io.IOException;
24 import java.util.ArrayList;
25 import java.util.List;
26
27 import javax.mail.MessagingException;
28
29
30
31
32
33
34 public class NNTPReply {
35
36 public static final int CAPABILITY_LIST = 101;
37
38 public static final int POSTING_ALLOWED = 200;
39
40 public static final int NO_POSTING_ALLOWED = 201;
41
42 public static final int EXTENSIONS_SUPPORTED = 202;
43
44 public static final int SERVICE_DISCONTINUED = 400;
45
46 public static final int COMMAND_NOT_RECOGNIZED = 500;
47
48 public static final int COMMAND_SYNTAX_ERROR = 501;
49
50 public static final int PERMISSION_DENIED = 502;
51
52 public static final int PROGRAM_FAULT = 503;
53
54
55 public static final int ARTICLE_FOLLOWS = 220;
56
57 public static final int HEAD_FOLLOWS = 221;
58
59 public static final int BODY_FOLLOWS = 222;
60
61 public static final int REQUEST_TEXT_SEPARATELY = 223;
62
63 public static final int OVERVIEW_FOLLOWS = 224;
64
65 public static final int NEW_ARTICLES_FOLLOWS = 230;
66
67 public static final int NEW_GROUPS_FOLLOWS = 231;
68
69 public static final int ARTICLE_TRANSFERRED = 235;
70
71 public static final int NO_NEWSGROUP_SELECTED = 412;
72
73 public static final int NO_ARTICLE_SELECTED = 420;
74
75 public static final int NO_ARTICLE_NUMBER = 423;
76
77 public static final int NO_ARTICLE_FOUND = 430;
78
79
80 public static final int GROUP_SELECTED = 211;
81
82 public static final int NO_SUCH_NEWSGROUP = 411;
83
84
85 public static final int POSTED_OK = 240;
86
87 public static final int SEND_ARTICLE = 340;
88
89 public static final int POSTING_NOT_ALLOWED = 440;
90
91 public static final int POSTING_FAILED = 441;
92
93
94 public static final int CLOSING_CONNECTION = 205;
95
96
97 public static final int AUTHINFO_ACCEPTED = 250;
98
99 public static final int AUTHINFO_ACCEPTED_FINAL = 251;
100
101 public static final int AUTHINFO_CONTINUE = 350;
102
103 public static final int AUTHINFO_CHALLENGE = 350;
104
105 public static final int AUTHINFO_SIMPLE_REJECTED = 402;
106
107 public static final int AUTHENTICATION_ACCEPTED = 281;
108
109 public static final int MORE_AUTHENTICATION_REQUIRED = 381;
110
111 public static final int AUTHINFO_REQUIRED = 480;
112
113 public static final int AUTHINFO_SIMPLE_REQUIRED = 450;
114
115 public static final int AUTHENTICATION_REJECTED = 482;
116
117
118 public static final int LIST_FOLLOWS = 215;
119
120
121 private final String reply;
122
123
124 private final int code;
125
126
127 private final String message;
128
129
130 private ArrayList data;
131
132 NNTPReply(String s) throws MessagingException {
133
134 reply = s;
135
136
137
138
139
140
141 if (s == null || s.length() < 3) {
142 code = -1;
143 message = s;
144 return;
145 }
146
147 try {
148 code = Integer.parseInt(s.substring(0, 3));
149
150
151
152
153 if (s.length() > 4) {
154 message = s.substring(4);
155 } else {
156 message = "";
157 }
158 } catch (NumberFormatException e) {
159 throw new MessagingException("error in parsing reply code", e);
160 }
161 }
162
163
164
165
166
167
168
169
170
171 public void retrieveData(BufferedReader in) throws MessagingException {
172 try {
173 data = new ArrayList();
174
175 String line = in.readLine();
176
177
178 while (line != null && !line.equals(".")) {
179
180
181
182 if (line.startsWith(".")) {
183 line = line.substring(1);
184 }
185
186
187 data.add(line);
188 line = in.readLine();
189 }
190 } catch (IOException e) {
191 throw new MessagingException("Error reading message reply", e);
192 }
193 }
194
195
196
197
198
199
200 public List getData() {
201 return data;
202 }
203
204
205
206
207
208
209 public int getCode() {
210 return this.code;
211 }
212
213
214
215
216
217
218 public String getMessage() {
219 return this.message;
220 }
221
222
223
224
225
226
227 public String getReply() {
228 return reply;
229 }
230
231
232
233
234 boolean isError() {
235
236 return code >= 400;
237 }
238
239 public String toString() {
240 return "CODE = " + getCode() + " : MSG = " + getMessage();
241 }
242 }