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; }
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; }
}
}
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()));
}
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;
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;
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(".");
} 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);
}