public MailboxWrapper(Mailbox root, boolean post) { this.root = root; this.post = post; }
public boolean postok() { return post; }
public void post(Message m) throws IOException { current.accept(m); }
-
- public Group group(String s) {
+ public Group group(String s) {
ptr = 0;
Group g = getgroup(s);
if (g==null) return null;
}
private Group getgroup(String s) {
Mailbox box = root;
+ Log.error("", "getgroup " + s);
+ Log.error("", "mailbox " + root);
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()));
if (command.equals("AUTHINFO")) {
// FIXME technically the RFC says we need to use this info to generate a SEnder: header...
String uop = st.nextToken().toUpperCase();
- if (uop.equals("USER")) user = st.nextToken();
- else if (uop.equals("PASS")) pass = st.nextToken();
- // FIXME error here
+ if (uop.equals("USER")) {
+ user = st.nextToken();
+ println("381 More authentication required");
+ continue;
+ } else if (uop.equals("PASS")) {
+ pass = st.nextToken();
+ account = login.login(user, pass);
+ if (account == null) { println("502 Invalid"); continue; }
+ Mailbox box = account.getMailbox(NNTP.class);
+ this.api = new MailboxWrapper(box, true);
+ println("281 Good to go");
+ continue;
+ }
+ throw new Bad("wtf are you talking about?");
}
if (this.api == null) {
if (user == null) { println("480 Authentication required"); continue; }
if (pass == null) { println("381 Password required"); continue; }
- account = login.login(user, pass);
- if (account == null) { println("502 Invalid"); continue; }
- Mailbox box = account.getMailbox(NNTP.class);
- this.api = new MailboxWrapper(box, true);
- println("281 Good to go");
- continue;
}
if (command.equals("ARTICLE")) { article(st.hasMoreTokens() ? st.nextToken() : null, true, true);
} else if (command.equals("HEAD")) { article(st.hasMoreTokens() ? st.nextToken() : null, true, false);
}
} else if (command.equals("POST")) {
- // add NNTP-Posting-Host header
// FIXME
- // required headers: Newsgroups, Subject, Message-ID, Path, From, Date. No wildcars in newsgroups list
+ // add NNTP-Posting-Host header
// Path header: prepend <myname>, (any punctuation separates the list)
// Expires header: the date when expiration happens (??) should we ignore this?
// Control header: body is the command. Inteprert posts to all.all.ctl as control messages, use Subject line if no Cntrol line
}
String body = buf.toString();
try {
- api.post(Message.newMessage(new Fountain.StringFountain(body)));
- println("240 article posted ok");
+ Message m = Message.newMessage(new Fountain.StringFountain(body));
+ if (m.headers.get("newsgroups")==null)
+ println("441 posted messages must have a Newsgroups header per RFC 977");
+ else if (m.headers.get("newsgroups").indexOf('*')!=-1)
+ println("441 Newsgroups header in posted messages may not contain wildcards (*) per RFC 977");
+ else if (m.headers.get("subject")==null)
+ println("441 posted messages must have a Subject header per RFC 977");
+ // else if (m.headers.get("path")==null)
+ //println("441 posted messages must have a Path header per RFC 977");
+ else if (m.headers.get("from")==null)
+ println("441 posted messages must have a From header per RFC 977");
+ else if (m.headers.get("date")==null)
+ println("441 posted messages must have a Date header per RFC 977");
+ else {
+ api.post(m);
+ println("240 article posted ok");
+ }
} catch (Exception e) {
- e.printStackTrace();
- println("441 posting failed: " + e);
+ e.printStackTrace();
+ println("441 posting failed: " + e);
}
}