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 <[email protected]>
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: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to