Article(javax.mail.Message) now has a safe method to read the byte body from the given message object (fixes #16).
3 * see AUTHORS for the list of contributors
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 package org.sonews.daemon.command;
21 import java.io.IOException;
22 import java.util.List;
23 import java.util.regex.Matcher;
24 import java.util.regex.Pattern;
25 import java.util.regex.PatternSyntaxException;
26 import org.sonews.daemon.NNTPConnection;
27 import org.sonews.storage.Channel;
28 import org.sonews.storage.StorageBackendException;
29 import org.sonews.util.Log;
32 * Class handling the LIST command.
33 * @author Christian Lins
34 * @author Dennis Schwerdel
37 public class ListCommand implements Command
41 public String[] getSupportedCommandStrings()
43 return new String[]{"LIST"};
47 public boolean hasFinished()
53 public String impliedCapability()
59 public boolean isStateful()
65 public void processLine(NNTPConnection conn, final String line, byte[] raw)
66 throws IOException, StorageBackendException
68 final String[] command = line.split(" ");
70 if(command.length >= 2)
72 if(command[1].equalsIgnoreCase("OVERVIEW.FMT"))
74 conn.println("215 information follows");
75 conn.println("Subject:\nFrom:\nDate:\nMessage-ID:\nReferences:\nBytes:\nLines:\nXref");
78 else if(command[1].equalsIgnoreCase("NEWSGROUPS"))
80 conn.println("215 information follows");
81 final List<Channel> list = Channel.getAll();
82 for (Channel g : list)
84 conn.println(g.getName() + "\t" + "-");
88 else if(command[1].equalsIgnoreCase("SUBSCRIPTIONS"))
90 conn.println("215 information follows");
93 else if(command[1].equalsIgnoreCase("EXTENSIONS"))
95 conn.println("202 Supported NNTP extensions.");
96 conn.println("LISTGROUP");
97 conn.println("XDAEMON");
101 else if(command[1].equalsIgnoreCase("ACTIVE"))
103 String pattern = command.length == 2
104 ? null : command[2].replace("*", "\\w*");
105 printGroupInfo(conn, pattern);
109 conn.println("500 unknown argument to LIST command");
114 printGroupInfo(conn, null);
118 private void printGroupInfo(NNTPConnection conn, String pattern)
119 throws IOException, StorageBackendException
121 final List<Channel> groups = Channel.getAll();
124 conn.println("215 list of newsgroups follows");
125 for(Channel g : groups)
129 Matcher matcher = pattern == null ?
130 null : Pattern.compile(pattern).matcher(g.getName());
132 (matcher == null || matcher.find()))
134 String writeable = g.isWriteable() ? " y" : " n";
135 // Indeed first the higher article number then the lower
136 conn.println(g.getName() + " " + g.getLastArticleNumber() + " "
137 + g.getFirstArticleNumber() + writeable);
140 catch(PatternSyntaxException ex)
142 Log.get().info(ex.toString());
149 conn.println("500 server backend malfunction");