X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fibex%2Fmail%2Fprotocol%2FNNTP.java;h=6d441e77a5aa4c4d2af2c20c96ee1d80ed9c49fb;hb=5ba029eb8467b22e33db3dcabd9f29380a8cd9a3;hp=f1291b67d6a05428779adfd217d57436803cc995;hpb=fab67c8262b062c00d179a5f057d4e489e7c4366;p=org.ibex.mail.git diff --git a/src/org/ibex/mail/protocol/NNTP.java b/src/org/ibex/mail/protocol/NNTP.java index f1291b6..6d441e7 100644 --- a/src/org/ibex/mail/protocol/NNTP.java +++ b/src/org/ibex/mail/protocol/NNTP.java @@ -60,7 +60,13 @@ public class NNTP { private Mailbox current; private int ptr = 0; public MailboxWrapper(Mailbox root) { this.root = root; } - public Group group(String s) { ptr = 0; setgroup(s); return getgroup(s); } + public Group group(String s) { + ptr = 0; + Group g = getgroup(s); + if (g==null) return null; + setgroup(s); + return g; + } public boolean ihave(String messageid) { /* FEATURE */ return false; } public boolean post(Message m) { /* FEATURE */ return false; } @@ -74,7 +80,6 @@ public class NNTP { if (!it.next()) return null; try { Message m = body ? it.cur() : Message.newMessage(new Fountain.StringFountain(it.head() + "\r\n")); - //Message m = it.cur(); // FIXME return new Article(it.num(), m); } catch (Exception e) { return null; } } @@ -94,14 +99,16 @@ public class NNTP { } private void setgroup(String s) { - current = root; + Mailbox ncurrent = root; for(StringTokenizer st = new StringTokenizer(s, "."); - st.hasMoreTokens(); - current = current.slash(st.nextToken(), false)); + ncurrent != null && st.hasMoreTokens(); + ncurrent = ncurrent.slash(st.nextToken(), false)); + if (ncurrent!=null) current=ncurrent; } private Group getgroup(String s) { Mailbox box = root; - for(StringTokenizer st = new StringTokenizer(s, "."); st.hasMoreTokens(); box = box.slash(st.nextToken(), false)); + for(StringTokenizer st = new StringTokenizer(s, "."); box!=null && st.hasMoreTokens(); box = box.slash(st.nextToken(), false)); + if (box==null) return null; return new Group(s, true, 1, box.count(Query.all()), box.count(Query.all())); } @@ -109,7 +116,7 @@ public class NNTP { public String[] newnews(String[] groups, Date d, String[] distributions) { /* FIXME */ return null; } } - public static class Listener implements Worker { + public static class Listener { private Server api = null; private Login login; private Connection conn; @@ -133,7 +140,7 @@ public class NNTP { if (head) println(a.message.headers.getString()); if (head && body) println(); if (body) { - Stream stream = a.message.getBody(); + Stream stream = a.message.getBody().getStream(); while(true) { s = stream.readln(); if (s == null) break; @@ -201,7 +208,7 @@ public class NNTP { try { Message m = it.cur(); println(it.num()+"\t"+m.subject+"\t"+m.from+"\t"+m.date+"\t"+m.messageid+"\t"+ - m.headers.get("references") + "\t" + m.size() + "\t" + m.lines()); + m.headers.get("references") + "\t" + m.getLength() + "\t" + m.getNumLines()); } catch (Exception e) { Log.error(this, e); } } println("."); @@ -210,19 +217,21 @@ public class NNTP { } else if (command.equals("QUIT")) { println("205 Bye."); conn.close(); return; } else if (command.equals("GROUP")) { Group g = api.group(st.nextToken().toLowerCase()); - println("211 " + g.count + " " + g.first + " " + g.last + " " + g.name); + if (g==null) println("411 no such group"); + else println("211 " + g.count + " " + g.first + " " + g.last + " " + g.name); } else if (command.equals("NEWGROUPS") || command.equals("NEWNEWS")) { // FIXME: * and ! unsupported // NEWNEWS is often not supported String groups = command.equals("NEWNEWS") ? st.nextToken() : null; String datetime = st.nextToken() + " " + st.nextToken(); String gmt = st.nextToken(); - String distributions = gmt.equals("GMT") ? (st.hasMoreTokens() ? st.nextToken() : null) : gmt; + String distributions = gmt.equals("GMT") ? (st.hasMoreTokens() ? st.nextToken() : "") : gmt; while(st.hasMoreTokens()) distributions += " " + st.nextToken(); + // FIXME deal with GMT Date d = new Date(); try { - d = new SimpleDateFormat("yyMMDD HHMMSS").parse(gmt); + d = new SimpleDateFormat("yyMMDD HHMMSS").parse(datetime); } catch (ParseException pe) { Log.warn(this, pe); }