1.1 --- a/src/org/sonews/daemon/command/XPatCommand.java Sun Aug 29 17:28:58 2010 +0200
1.2 +++ b/src/org/sonews/daemon/command/XPatCommand.java Sun Sep 11 15:05:04 2011 +0200
1.3 @@ -78,93 +78,79 @@
1.4 public class XPatCommand implements Command
1.5 {
1.6
1.7 - @Override
1.8 - public String[] getSupportedCommandStrings()
1.9 - {
1.10 - return new String[]{"XPAT"};
1.11 - }
1.12 -
1.13 - @Override
1.14 - public boolean hasFinished()
1.15 - {
1.16 - return true;
1.17 - }
1.18 + @Override
1.19 + public String[] getSupportedCommandStrings()
1.20 + {
1.21 + return new String[] {"XPAT"};
1.22 + }
1.23
1.24 - @Override
1.25 - public String impliedCapability()
1.26 - {
1.27 - return null;
1.28 - }
1.29 + @Override
1.30 + public boolean hasFinished()
1.31 + {
1.32 + return true;
1.33 + }
1.34
1.35 - @Override
1.36 - public boolean isStateful()
1.37 - {
1.38 - return false;
1.39 - }
1.40 + @Override
1.41 + public String impliedCapability()
1.42 + {
1.43 + return null;
1.44 + }
1.45
1.46 - @Override
1.47 - public void processLine(NNTPConnection conn, final String line, byte[] raw)
1.48 - throws IOException, StorageBackendException
1.49 - {
1.50 - if(conn.getCurrentChannel() == null)
1.51 - {
1.52 - conn.println("430 no group selected");
1.53 - return;
1.54 - }
1.55 + @Override
1.56 + public boolean isStateful()
1.57 + {
1.58 + return false;
1.59 + }
1.60
1.61 - String[] command = line.split("\\p{Space}+");
1.62 + @Override
1.63 + public void processLine(NNTPConnection conn, final String line, byte[] raw)
1.64 + throws IOException, StorageBackendException
1.65 + {
1.66 + if (conn.getCurrentChannel() == null) {
1.67 + conn.println("430 no group selected");
1.68 + return;
1.69 + }
1.70
1.71 - // There may be multiple patterns and Thunderbird produces
1.72 - // additional spaces between range and pattern
1.73 - if(command.length >= 4)
1.74 - {
1.75 - String header = command[1].toLowerCase(Locale.US);
1.76 - String range = command[2];
1.77 - String pattern = command[3];
1.78 + String[] command = line.split("\\p{Space}+");
1.79
1.80 - long start = -1;
1.81 - long end = -1;
1.82 - if(range.contains("-"))
1.83 - {
1.84 - String[] rsplit = range.split("-", 2);
1.85 - start = Long.parseLong(rsplit[0]);
1.86 - if(rsplit[1].length() > 0)
1.87 - {
1.88 - end = Long.parseLong(rsplit[1]);
1.89 - }
1.90 - }
1.91 - else // TODO: Handle Message-IDs
1.92 - {
1.93 - start = Long.parseLong(range);
1.94 - }
1.95 + // There may be multiple patterns and Thunderbird produces
1.96 + // additional spaces between range and pattern
1.97 + if (command.length >= 4) {
1.98 + String header = command[1].toLowerCase(Locale.US);
1.99 + String range = command[2];
1.100 + String pattern = command[3];
1.101
1.102 - try
1.103 - {
1.104 - List<Pair<Long, String>> heads = StorageManager.current().
1.105 - getArticleHeaders(conn.getCurrentChannel(), start, end, header, pattern);
1.106 -
1.107 - conn.println("221 header follows");
1.108 - for(Pair<Long, String> head : heads)
1.109 - {
1.110 - conn.println(head.getA() + " " + head.getB());
1.111 - }
1.112 - conn.println(".");
1.113 - }
1.114 - catch(PatternSyntaxException ex)
1.115 - {
1.116 - ex.printStackTrace();
1.117 - conn.println("500 invalid pattern syntax");
1.118 - }
1.119 - catch(StorageBackendException ex)
1.120 - {
1.121 - ex.printStackTrace();
1.122 - conn.println("500 internal server error");
1.123 - }
1.124 - }
1.125 - else
1.126 - {
1.127 - conn.println("430 invalid command usage");
1.128 - }
1.129 - }
1.130 + long start = -1;
1.131 + long end = -1;
1.132 + if (range.contains("-")) {
1.133 + String[] rsplit = range.split("-", 2);
1.134 + start = Long.parseLong(rsplit[0]);
1.135 + if (rsplit[1].length() > 0) {
1.136 + end = Long.parseLong(rsplit[1]);
1.137 + }
1.138 + } else // TODO: Handle Message-IDs
1.139 + {
1.140 + start = Long.parseLong(range);
1.141 + }
1.142
1.143 + try {
1.144 + List<Pair<Long, String>> heads = StorageManager.current().
1.145 + getArticleHeaders(conn.getCurrentChannel(), start, end, header, pattern);
1.146 +
1.147 + conn.println("221 header follows");
1.148 + for (Pair<Long, String> head : heads) {
1.149 + conn.println(head.getA() + " " + head.getB());
1.150 + }
1.151 + conn.println(".");
1.152 + } catch (PatternSyntaxException ex) {
1.153 + ex.printStackTrace();
1.154 + conn.println("500 invalid pattern syntax");
1.155 + } catch (StorageBackendException ex) {
1.156 + ex.printStackTrace();
1.157 + conn.println("500 internal server error");
1.158 + }
1.159 + } else {
1.160 + conn.println("430 invalid command usage");
1.161 + }
1.162 + }
1.163 }