You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2019/11/14 02:09:29 UTC
[james-project] 12/32: [Refactoring] StatusCommandParser:
uncorrelate word splitting from item parsing
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 4bbc17082706262249025d81fe4b536a7f16114c
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Wed Nov 13 11:55:17 2019 +0700
[Refactoring] StatusCommandParser: uncorrelate word splitting from item parsing
---
.../imap/decode/parser/StatusCommandParser.java | 23 +++++++++++++++++-----
1 file changed, 18 insertions(+), 5 deletions(-)
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/StatusCommandParser.java b/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/StatusCommandParser.java
index c319e98..88bebe0 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/StatusCommandParser.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/StatusCommandParser.java
@@ -33,6 +33,10 @@ import org.apache.james.imap.decode.ImapRequestLineReader.CharacterValidator;
import org.apache.james.imap.decode.base.AbstractImapCommandParser;
import org.apache.james.imap.message.request.StatusRequest;
+import com.github.fge.lambdas.Throwing;
+import com.github.steveash.guavate.Guavate;
+import com.google.common.collect.ImmutableList;
+
/**
* Parse STATUS commands
*/
@@ -42,7 +46,17 @@ public class StatusCommandParser extends AbstractImapCommandParser {
}
private StatusDataItems statusDataItems(ImapRequestLineReader request) throws DecodingException {
- EnumSet<StatusDataItems.StatusItem> items = EnumSet.noneOf(StatusDataItems.StatusItem.class);
+ ImmutableList<String> words = splitWords(request);
+
+ EnumSet<StatusDataItems.StatusItem> items = EnumSet.copyOf(words.stream()
+ .map(Throwing.function(this::parseStatus).sneakyThrow())
+ .collect(Guavate.toImmutableList()));
+
+ return new StatusDataItems(items);
+ }
+
+ private ImmutableList<String> splitWords(ImapRequestLineReader request) throws DecodingException {
+ ImmutableList.Builder<String> words = ImmutableList.builder();
request.nextWordChar();
request.consumeChar('(');
@@ -50,15 +64,14 @@ public class StatusCommandParser extends AbstractImapCommandParser {
String nextWord = request.consumeWord(validator);
while (!nextWord.endsWith(")")) {
- items.add(parseStatus(nextWord));
+ words.add(nextWord);
nextWord = request.consumeWord(validator);
}
// Got the closing ")", may be attached to a word.
if (nextWord.length() > 1) {
- items.add(parseStatus(nextWord.substring(0, nextWord.length() - 1)));
+ words.add(nextWord.substring(0, nextWord.length() - 1));
}
-
- return new StatusDataItems(items);
+ return words.build();
}
private StatusDataItems.StatusItem parseStatus(String nextWord) throws DecodingException {
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org