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 rc...@apache.org on 2020/02/13 02:29:20 UTC

[james-project] 09/21: [Refactoring] Improve Append command parser readability

This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit ace778f57448ca34458e00382fbf0ecc3b7192d3
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri Dec 13 07:40:49 2019 +0100

    [Refactoring] Improve Append command parser readability
---
 .../imap/decode/parser/AppendCommandParser.java    | 24 ++++++++--------------
 1 file changed, 8 insertions(+), 16 deletions(-)

diff --git a/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/AppendCommandParser.java b/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/AppendCommandParser.java
index a64259c..239fa80 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/AppendCommandParser.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/AppendCommandParser.java
@@ -44,42 +44,34 @@ public class AppendCommandParser extends AbstractImapCommandParser {
 
     /**
      * If the next character in the request is a '(', tries to read a
-     * "flag_list" argument from the request. If not, returns a MessageFlags
+     * "flag_list" argument from the request. If not, returns a Flags
      * with no flags set.
      */
-    public Flags optionalAppendFlags(ImapRequestLineReader request) throws DecodingException {
+    private Flags parseFlags(ImapRequestLineReader request) throws DecodingException {
         char next = request.nextWordChar();
         if (next == '(') {
             return request.flagList();
-        } else {
-            return null;
         }
+        return new Flags();
     }
 
     /**
      * If the next character in the request is a '"', tries to read a DateTime
-     * argument. If not, returns null.
+     * argument. If not, returns now.
      */
-    public LocalDateTime optionalDateTime(ImapRequestLineReader request) throws DecodingException {
+    private LocalDateTime parseDateTime(ImapRequestLineReader request) throws DecodingException {
         char next = request.nextWordChar();
         if (next == '"') {
             return request.dateTime();
-        } else {
-            return null;
         }
+        return LocalDateTime.now();
     }
 
     @Override
     protected ImapMessage decode(ImapRequestLineReader request, Tag tag, ImapSession session) throws DecodingException {
         String mailboxName = request.mailbox();
-        Flags flags = optionalAppendFlags(request);
-        if (flags == null) {
-            flags = new Flags();
-        }
-        LocalDateTime datetime = optionalDateTime(request);
-        if (datetime == null) {
-            datetime = LocalDateTime.now();
-        }
+        Flags flags = parseFlags(request);
+        LocalDateTime datetime = parseDateTime(request);
         request.nextWordChar();
 
         return new AppendRequest(mailboxName, flags, Date.from(datetime.atZone(ZoneId.systemDefault()).toInstant()), request.consumeLiteral(true), tag);


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