NNTP: better error handling
authoradam <adam@megacz.com>
Fri, 7 Jan 2005 18:19:40 +0000 (18:19 +0000)
committeradam <adam@megacz.com>
Fri, 7 Jan 2005 18:19:40 +0000 (18:19 +0000)
darcs-hash:20050107181940-5007d-1042280d6f18f9d8f39af1daf1dee12d66d04217.gz

src/org/ibex/mail/protocol/NNTP.java

index 6c2d29e..235b236 100644 (file)
@@ -169,9 +169,11 @@ public class NNTP {
                     int end   = Integer.parseInt(range.substring(range.indexOf('-') + 1));
                     Mailbox.Iterator it = api.current.iterator(Query.messagenum(start, end));
                     while(it.next()) {
-                        Message m = it.cur();
-                        println(it.num()+"\t"+m.subject+"\t"+m.from+"\t"+m.date+"\t"+m.messageid+"\t"+
-                                m.headers.gets("references") + "\t" + m.size() + "\t" + m.lines);
+                        try {
+                            Message m = Message.newMessage(new Stream(it.head() + "\r\n"));
+                            println(it.num()+"\t"+m.subject+"\t"+m.from+"\t"+m.date+"\t"+m.messageid+"\t"+
+                                    m.headers.gets("references") + "\t" + m.size() + "\t" + m.lines);
+                        } catch (Exception e) { Log.error(this, e); }
                     }
                     println(".");
                 } else if (command.equals("LAST"))      { Article a = api.last(); println("223 "+a.num+" "+a.messageid+" ok");
@@ -230,6 +232,7 @@ public class NNTP {
                         //}
 
                 } else if (command.equals("LIST"))      { 
+                    if (st.hasMoreTokens()) throw new Bad("LIST " + st.nextToken() + " not supported");
                     Group[] g = api.list();
                     println("215 list of groups follows");
                     for(int i=0; i<g.length; i++)
@@ -245,6 +248,8 @@ public class NNTP {
                         // FIXME read article here
                         println("235 Got it");
                     }
+                } else {
+                    throw new Bad("wtf are you talking about?");
                 }
             } catch (No n)  { println(n.code + " " + n.getMessage());
             } catch (Bad b) { println(b.code + " " + b.getMessage()); Log.warn(this, b); }