1 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 public MessageThreading() { 32 } 33 34 public static void main(String [] args) throws SocketException , IOException { 35 36 if (args.length != 3) 37 usage(); 38 39 String hostname = args[0]; 40 String user = args[1]; 41 String password = args[2]; 42 43 NNTPClient client = new NNTPClient(); 44 client.addProtocolCommandListener(new PrintCommandListener(new PrintWriter (System.out))); 45 client.connect(hostname); 46 47 if(!client.authenticate(user, password)) { 48 System.out.println("Authentication failed for user " + user + "!"); 49 System.exit(1); 50 } 51 52 NewsgroupInfo group = new NewsgroupInfo(); 53 client.selectNewsgroup("comp.lang.lisp", group); 54 55 int lowArticleNumber = group.getFirstArticle(); 56 int highArticleNumber = lowArticleNumber + 100; 57 58 System.out.println("Retrieving articles between [" + lowArticleNumber + "] and [" + highArticleNumber + "]"); 59 Article[] articles = NNTPUtils.getArticleInfo(client, lowArticleNumber, highArticleNumber); 60 61 System.out.println("Building message thread tree..."); 62 Threader threader = new Threader(); 63 Article root = (Article)threader.thread(articles); 64 65 Article.printThread(root, 0); 66 67 } 68 69 70 public static void usage() { 71 System.out.println("Usage: MessageThreading <hostname> <user> <password>"); 72 System.exit(0); 73 } 74 } 75 | Popular Tags |