1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package examples.nntp; |
18 |
|
|
19 |
|
import java.io.IOException; |
20 |
|
import java.io.PrintWriter; |
21 |
|
import java.net.SocketException; |
22 |
|
|
23 |
|
import org.apache.commons.net.nntp.Article; |
24 |
|
import org.apache.commons.net.nntp.NNTPClient; |
25 |
|
import org.apache.commons.net.nntp.NewsgroupInfo; |
26 |
|
import org.apache.commons.net.nntp.Threader; |
27 |
|
|
28 |
|
import examples.PrintCommandListener; |
29 |
|
|
30 |
|
public class MessageThreading { |
31 |
0 |
public MessageThreading() { |
32 |
0 |
} |
33 |
|
|
34 |
|
public static void main(String[] args) throws SocketException, IOException { |
35 |
|
|
36 |
0 |
if (args.length != 3) |
37 |
0 |
usage(); |
38 |
|
|
39 |
0 |
String hostname = args[0]; |
40 |
0 |
String user = args[1]; |
41 |
0 |
String password = args[2]; |
42 |
|
|
43 |
0 |
NNTPClient client = new NNTPClient(); |
44 |
0 |
client.addProtocolCommandListener(new PrintCommandListener(class="keyword">new PrintWriter(System.out))); |
45 |
0 |
client.connect(hostname); |
46 |
|
|
47 |
0 |
if(!client.authenticate(user, password)) { |
48 |
0 |
System.out.println("Authentication failed for user " + user + "!"); |
49 |
0 |
System.exit(1); |
50 |
|
} |
51 |
|
|
52 |
0 |
NewsgroupInfo group = new NewsgroupInfo(); |
53 |
0 |
client.selectNewsgroup("comp.lang.lisp", group); |
54 |
|
|
55 |
0 |
int lowArticleNumber = group.getFirstArticle(); |
56 |
0 |
int highArticleNumber = lowArticleNumber + 100; |
57 |
|
|
58 |
0 |
System.out.println("Retrieving articles between [" + lowArticleNumber + "] and [" + highArticleNumber + "]"); |
59 |
0 |
Article[] articles = NNTPUtils.getArticleInfo(client, lowArticleNumber, highArticleNumber); |
60 |
|
|
61 |
0 |
System.out.println("Building message thread tree..."); |
62 |
0 |
Threader threader = new Threader(); |
63 |
0 |
Article root = (Article)threader.thread(articles); |
64 |
|
|
65 |
0 |
Article.printThread(root, 0); |
66 |
|
|
67 |
0 |
} |
68 |
|
|
69 |
|
|
70 |
|
public static void usage() { |
71 |
0 |
System.out.println("Usage: MessageThreading <hostname> <user> <password>"); |
72 |
0 |
System.exit(0); |
73 |
0 |
} |
74 |
|
} |