You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by bt...@apache.org on 2022/05/09 02:25:05 UTC

[james-project] 07/07: [REFACTORING] Use CHarMatcher in FetchCommandParser

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 8e83d948d26996425db7d736683aaccf7c68f2a1
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri May 6 11:38:07 2022 +0700

    [REFACTORING] Use CHarMatcher in FetchCommandParser
---
 .../apache/james/imap/decode/parser/FetchCommandParser.java | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/FetchCommandParser.java b/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/FetchCommandParser.java
index b878f6f1d1..17ec87e8de 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/FetchCommandParser.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/FetchCommandParser.java
@@ -46,12 +46,16 @@ import org.apache.james.imap.decode.ImapRequestLineReader;
 import org.apache.james.imap.decode.ImapRequestLineReader.StringMatcherCharacterValidator;
 import org.apache.james.imap.message.request.FetchRequest;
 
+import com.google.common.base.CharMatcher;
+
 /**
  * Parse FETCH commands
  */
 public class FetchCommandParser extends AbstractUidCommandParser {
     private static final String CHANGEDSINCE = "CHANGEDSINCE";
     private static final String VANISHED = "VANISHED";
+    private static final CharMatcher CLOSING_BRACKET = CharMatcher.is(']');
+    private static final CharMatcher NEXT_ELEMENT_END = CharMatcher.anyOf(" [)\r\n");
 
     public FetchCommandParser(StatusResponseFactory statusResponseFactory) {
         super(ImapConstants.FETCH_COMMAND, statusResponseFactory);
@@ -115,8 +119,7 @@ public class FetchCommandParser extends AbstractUidCommandParser {
     }
 
     private void addNextElement(ImapRequestLineReader reader, FetchData.Builder fetch) throws DecodingException {
-        // String name = element.toString();
-        String name = readWord(reader, " [)\r\n");
+        String name = readWord(reader, NEXT_ELEMENT_END);
         char next = reader.nextChar();
         // Simple elements with no '[]' parameters.
         if (next != '[') {
@@ -124,7 +127,7 @@ public class FetchCommandParser extends AbstractUidCommandParser {
         } else {
             reader.consumeChar('[');
 
-            String parameter = readWord(reader, "]");
+            String parameter = readWord(reader, CLOSING_BRACKET);
 
             reader.consumeChar(']');
 
@@ -209,10 +212,10 @@ public class FetchCommandParser extends AbstractUidCommandParser {
         return new BodyFetchElement(responseName, sectionType, path, names, firstOctet, numberOfOctets);
     }
 
-    private String readWord(ImapRequestLineReader request, String terminator) throws DecodingException {
+    private String readWord(ImapRequestLineReader request, CharMatcher terminator) throws DecodingException {
         StringBuilder builder = new StringBuilder();
         char next = request.nextChar();
-        while (terminator.indexOf(next) == -1) {
+        while (!terminator.matches(next)) {
             builder.append(next);
             request.consume();
             next = request.nextChar();


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org