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 ma...@apache.org on 2019/11/12 21:37:22 UTC

[james-project] branch master updated (379a835 -> 2044d4b)

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

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


    from 379a835  [Refactoring] Migrate tests in JUnit 4 to JUnit 5 in backends-elasticsearch module
     new b137370  [Refactoring] use StandardCharsets in more places
     new 909a919  [Refactoring] move the call to CharsetUtil.getAvailableCharsetNames() inside badCharset method
     new 2abab15  [Refactoring] remove unused method getAvailableCharsets
     new 3033780  [Refactoring] initiliazed available charset names with a stream pipeline
     new 12e1c58  [Refactoring] move available charset names into StatusResponse
     new 853b846  [Refactoring] CharsetUtils now only handle utf7, change it accordingly
     new f8f5d40  [Refactoring] move createMockMail2Recipients util function to the only class using it
     new 3c123e4  [Refactoring] inline createMockMail2Recipients and replace it with MailImpl.builder
     new eb7430c  [Refactoring] move createMimeMessage to SetMimeHeaderHandlerTest
     new eee987a  [Refactoring] inline mimemessage construction
     new e6f9d69  [Refactoring] refactor tests to actually test what's expected
     new 055e487  [Refactoring] migrate tests to junit5
     new 3c5467f  [Refactoring] suppress redundant condition
     new 598b3c4  [Refactoring] avoid building many times the same buffer
     new 2044d4b  [Refactoring] it doesn't make sense to make an abstract class mandatory when there's an interface

The 15 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .gitignore                                         |   1 +
 .../mailbox/store/streaming/FullByteContent.java   |   5 +-
 .../protocols/api/AbstractProtocolTransport.java   |   8 +-
 .../apache/james/imap/api/display/CharsetUtil.java | 100 ---------------------
 .../james/imap/api/display/ModifiedUtf7.java       |  55 ++++++------
 .../imap/api/message/response/StatusResponse.java  |  20 ++++-
 .../james/imap/decode/ImapRequestLineReader.java   |   6 +-
 .../imap/decode/parser/SearchCommandParser.java    |   3 +-
 .../james/imap/encode/ImapResponseComposer.java    |   4 +-
 .../imap/encode/base/ImapResponseComposerImpl.java |   4 +-
 .../apache/james/imap/processor/LSubProcessor.java |   6 +-
 .../apache/james/imap/processor/ListProcessor.java |   8 +-
 .../parser/FetchCommandParserPartialFetchTest.java |   7 +-
 .../SearchCommandParserAndParenthesesTest.java     |   7 +-
 .../parser/SearchCommandParserCharsetTest.java     |  22 ++---
 .../decode/parser/SearchCommandParserNotTest.java  |   5 +-
 .../decode/parser/SearchCommandParserOrTest.java   |   3 +-
 .../SearchCommandParserQuotedCharsetTest.java      |  58 ++++++------
 ...earchCommandParserSearchKeySequenceSetTest.java |   3 +-
 .../parser/SearchCommandParserSearchKeyTest.java   |   5 +-
 .../parser/SearchCommandParserTopLevelAndTest.java |   7 +-
 .../imap/decode/parser/StoreCommandParserTest.java |   3 +-
 .../james/protocols/pop3/utils/MockMailbox.java    |  20 ++---
 .../server/core/InternetHeadersInputStream.java    |  30 +++----
 .../apache/james/server/core/MimeMessageTest.java  |   3 +-
 .../apache/james/lifecycle/api/LifecycleUtil.java  |   6 +-
 .../mailrepository/lib/AbstractMailRepository.java |   3 +-
 .../imapserver/netty/ImapHeartbeatHandler.java     |   9 +-
 .../james/smtpserver/SetMimeHeaderHandlerTest.java |  93 ++++++++++---------
 .../java/org/apache/james/smtpserver/Util.java     |  54 -----------
 30 files changed, 201 insertions(+), 357 deletions(-)
 delete mode 100644 protocols/imap/src/main/java/org/apache/james/imap/api/display/CharsetUtil.java
 copy mpt/core/src/main/java/org/apache/james/mpt/helper/ByteBufferInputStream.java => protocols/imap/src/main/java/org/apache/james/imap/api/display/ModifiedUtf7.java (56%)
 delete mode 100644 server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/Util.java


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


[james-project] 02/15: [Refactoring] move the call to CharsetUtil.getAvailableCharsetNames() inside badCharset method

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 909a919479ae0d25459ce986ca1f6c4a67de5fb9
Author: Matthieu Baechler <ma...@apache.org>
AuthorDate: Thu Nov 7 21:58:04 2019 +0100

    [Refactoring] move the call to CharsetUtil.getAvailableCharsetNames() inside badCharset method
---
 .../org/apache/james/imap/api/message/response/StatusResponse.java | 7 +++----
 .../org/apache/james/imap/decode/parser/SearchCommandParser.java   | 3 +--
 .../james/imap/decode/parser/SearchCommandParserCharsetTest.java   | 3 +--
 .../imap/decode/parser/SearchCommandParserQuotedCharsetTest.java   | 3 +--
 4 files changed, 6 insertions(+), 10 deletions(-)

diff --git a/protocols/imap/src/main/java/org/apache/james/imap/api/message/response/StatusResponse.java b/protocols/imap/src/main/java/org/apache/james/imap/api/message/response/StatusResponse.java
index 9f74cb7..148ef69 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/api/message/response/StatusResponse.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/api/message/response/StatusResponse.java
@@ -26,6 +26,7 @@ import java.util.Collections;
 import javax.mail.Flags;
 
 import org.apache.james.imap.api.ImapCommand;
+import org.apache.james.imap.api.display.CharsetUtil;
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.api.message.IdRange;
 import org.apache.james.imap.api.message.MessageFlags;
@@ -211,12 +212,10 @@ public interface StatusResponse extends ImapResponseMessage {
         /**
          * Creates a RFC2060 <code>BADCHARSET</code> response code.
          * 
-         * @param charsetNames
-         *            <code>Collection<String></code> containing charset names
          * @return <code>ResponseCode</code>, not null
          */
-        public static ResponseCode badCharset(Collection<String> charsetNames) {
-            return new ResponseCode("BADCHARSET", charsetNames);
+        public static ResponseCode badCharset() {
+            return new ResponseCode("BADCHARSET", CharsetUtil.getAvailableCharsetNames());
         }
 
         /**
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/SearchCommandParser.java b/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/SearchCommandParser.java
index 22dc639..546f671 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/SearchCommandParser.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/SearchCommandParser.java
@@ -28,7 +28,6 @@ import java.util.List;
 import org.apache.james.imap.api.ImapCommand;
 import org.apache.james.imap.api.ImapConstants;
 import org.apache.james.imap.api.ImapMessage;
-import org.apache.james.imap.api.display.CharsetUtil;
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.api.message.IdRange;
 import org.apache.james.imap.api.message.UidRange;
@@ -904,7 +903,7 @@ public class SearchCommandParser extends AbstractUidCommandParser {
 
     private ImapMessage unsupportedCharset(String tag, ImapCommand command) {
         final StatusResponseFactory factory = getStatusResponseFactory();
-        final ResponseCode badCharset = StatusResponse.ResponseCode.badCharset(CharsetUtil.getAvailableCharsetNames());
+        final ResponseCode badCharset = StatusResponse.ResponseCode.badCharset();
         return factory.taggedNo(tag, command, HumanReadableText.BAD_CHARSET, badCharset);
     }
 
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserCharsetTest.java b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserCharsetTest.java
index 80b772e..7255c28 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserCharsetTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserCharsetTest.java
@@ -34,7 +34,6 @@ import java.nio.charset.StandardCharsets;
 
 import org.apache.james.imap.api.ImapCommand;
 import org.apache.james.imap.api.ImapMessage;
-import org.apache.james.imap.api.display.CharsetUtil;
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.api.message.request.SearchKey;
 import org.apache.james.imap.api.message.response.StatusResponse;
@@ -96,7 +95,7 @@ public class SearchCommandParserCharsetTest {
             eq(TAG),
             same(command),
             eq(HumanReadableText.BAD_CHARSET),
-            eq(StatusResponse.ResponseCode.badCharset(CharsetUtil.getAvailableCharsetNames())));
+            eq(StatusResponse.ResponseCode.badCharset()));
 
         verifyNoMoreInteractions(mockStatusResponseFactory);
     }
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserQuotedCharsetTest.java b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserQuotedCharsetTest.java
index 2533f77..a819196 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserQuotedCharsetTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserQuotedCharsetTest.java
@@ -35,7 +35,6 @@ import java.nio.charset.StandardCharsets;
 
 import org.apache.james.imap.api.ImapCommand;
 import org.apache.james.imap.api.ImapMessage;
-import org.apache.james.imap.api.display.CharsetUtil;
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.api.message.request.SearchKey;
 import org.apache.james.imap.api.message.response.StatusResponse;
@@ -181,7 +180,7 @@ public class SearchCommandParserQuotedCharsetTest {
             eq(TAG),
             same(command),
             eq(HumanReadableText.BAD_CHARSET),
-            eq(StatusResponse.ResponseCode.badCharset(CharsetUtil.getAvailableCharsetNames())));
+            eq(StatusResponse.ResponseCode.badCharset()));
         verifyNoMoreInteractions(mockStatusResponseFactory);
     }
 


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


[james-project] 15/15: [Refactoring] it doesn't make sense to make an abstract class mandatory when there's an interface

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 2044d4b6a2e89c6276621cd8e38a29abc4457488
Author: Matthieu Baechler <ma...@apache.org>
AuthorDate: Fri Nov 8 18:20:08 2019 +0100

    [Refactoring] it doesn't make sense to make an abstract class mandatory when there's an interface
---
 .../org/apache/james/mailrepository/lib/AbstractMailRepository.java    | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/server/data/data-library/src/main/java/org/apache/james/mailrepository/lib/AbstractMailRepository.java b/server/data/data-library/src/main/java/org/apache/james/mailrepository/lib/AbstractMailRepository.java
index 7aae23e..ecf7d46 100644
--- a/server/data/data-library/src/main/java/org/apache/james/mailrepository/lib/AbstractMailRepository.java
+++ b/server/data/data-library/src/main/java/org/apache/james/mailrepository/lib/AbstractMailRepository.java
@@ -40,8 +40,7 @@ import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterators;
 
 /**
- * This class represent an AbstractMailRepository. All MailRepositories should
- * extend this class.
+ * This class represents an AbstractMailRepository that may help implementing MailRepository interface
  */
 public abstract class AbstractMailRepository implements MailRepository, Configurable, Initializable {
     private static final Logger LOGGER = LoggerFactory.getLogger(AbstractMailRepository.class);


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


[james-project] 07/15: [Refactoring] move createMockMail2Recipients util function to the only class using it

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit f8f5d408934bfe1bad3647bc34104f7707a51588
Author: Matthieu Baechler <ma...@apache.org>
AuthorDate: Thu Nov 7 22:33:50 2019 +0100

    [Refactoring] move createMockMail2Recipients util function to the only class using it
---
 .../james/smtpserver/SetMimeHeaderHandlerTest.java       | 16 ++++++++++++++--
 .../src/test/java/org/apache/james/smtpserver/Util.java  | 12 ------------
 2 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SetMimeHeaderHandlerTest.java b/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SetMimeHeaderHandlerTest.java
index e79e909..f9f6055 100644
--- a/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SetMimeHeaderHandlerTest.java
+++ b/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SetMimeHeaderHandlerTest.java
@@ -20,12 +20,15 @@ package org.apache.james.smtpserver;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
+import java.util.concurrent.ThreadLocalRandom;
+
 import javax.mail.MessagingException;
 import javax.mail.internet.MimeMessage;
 
 import org.apache.james.protocols.smtp.SMTPSession;
 import org.apache.james.protocols.smtp.utils.BaseFakeSMTPSession;
 import org.apache.mailet.Mail;
+import org.apache.mailet.base.test.FakeMail;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -74,7 +77,7 @@ public class SetMimeHeaderHandlerTest {
         setHeaderValue(HEADER_VALUE);
 
         setupMockedMimeMessage();
-        mockedMail = Util.createMockMail2Recipients(mockedMimeMessage);
+        mockedMail = createMockMail2Recipients(mockedMimeMessage);
 
         SetMimeHeaderHandler header = new SetMimeHeaderHandler();
 
@@ -92,7 +95,7 @@ public class SetMimeHeaderHandlerTest {
         setHeaderValue(headerValue);
 
         setupMockedMimeMessage();
-        mockedMail = Util.createMockMail2Recipients(mockedMimeMessage);
+        mockedMail = createMockMail2Recipients(mockedMimeMessage);
 
         SetMimeHeaderHandler header = new SetMimeHeaderHandler();
 
@@ -102,4 +105,13 @@ public class SetMimeHeaderHandlerTest {
 
         assertThat(mockedMail.getMessage().getHeader(HEADER_NAME)[0]).isEqualTo(HEADER_VALUE);
     }
+
+    private static Mail createMockMail2Recipients(MimeMessage m) throws MessagingException {
+        return FakeMail.builder()
+            .name("ID=" + ThreadLocalRandom.current().nextLong())
+            .mimeMessage(m)
+            .recipients("test@james.apache.org", "test2@james.apache.org")
+            .build();
+    }
+
 }
diff --git a/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/Util.java b/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/Util.java
index 91c6f93..5413c8b 100644
--- a/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/Util.java
+++ b/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/Util.java
@@ -18,28 +18,16 @@
  ****************************************************************/
 package org.apache.james.smtpserver;
 
-import java.util.concurrent.ThreadLocalRandom;
-
 import javax.mail.MessagingException;
 import javax.mail.internet.MimeMessage;
 
 import org.apache.james.core.builder.MimeMessageBuilder;
-import org.apache.mailet.Mail;
-import org.apache.mailet.base.test.FakeMail;
 
 /**
  * some utilities for James unit testing
  */
 public class Util {
 
-    public static Mail createMockMail2Recipients(MimeMessage m) throws MessagingException {
-        return FakeMail.builder()
-            .name("ID=" + ThreadLocalRandom.current().nextLong())
-            .mimeMessage(m)
-            .recipients("test@james.apache.org", "test2@james.apache.org")
-            .build();
-    }
-
     public static MimeMessage createMimeMessage(String headerName, String headerValue) throws MessagingException {
         String sender = "test@james.apache.org";
         String rcpt = "test2@james.apache.org";


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


[james-project] 09/15: [Refactoring] move createMimeMessage to SetMimeHeaderHandlerTest

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit eb7430c9efd244161d79d042370d44ff5aa3eb3e
Author: Matthieu Baechler <ma...@apache.org>
AuthorDate: Thu Nov 7 22:40:14 2019 +0100

    [Refactoring] move createMimeMessage to SetMimeHeaderHandlerTest
---
 .../james/smtpserver/SetMimeHeaderHandlerTest.java | 15 +++++++-
 .../java/org/apache/james/smtpserver/Util.java     | 42 ----------------------
 2 files changed, 14 insertions(+), 43 deletions(-)

diff --git a/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SetMimeHeaderHandlerTest.java b/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SetMimeHeaderHandlerTest.java
index 2315524..3681970 100644
--- a/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SetMimeHeaderHandlerTest.java
+++ b/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SetMimeHeaderHandlerTest.java
@@ -25,6 +25,7 @@ import java.util.concurrent.ThreadLocalRandom;
 import javax.mail.MessagingException;
 import javax.mail.internet.MimeMessage;
 
+import org.apache.james.core.builder.MimeMessageBuilder;
 import org.apache.james.protocols.smtp.SMTPSession;
 import org.apache.james.protocols.smtp.utils.BaseFakeSMTPSession;
 import org.apache.james.server.core.MailImpl;
@@ -57,7 +58,7 @@ public class SetMimeHeaderHandlerTest {
     }
 
     private void setupMockedMimeMessage() throws MessagingException {
-        mockedMimeMessage = Util.createMimeMessage(headerName, headerValue);
+        mockedMimeMessage = createMimeMessage(headerName, headerValue);
     }
 
     private void setupMockedSMTPSession() {
@@ -114,4 +115,16 @@ public class SetMimeHeaderHandlerTest {
         assertThat(mail.getMessage().getHeader(HEADER_NAME)[0]).isEqualTo(HEADER_VALUE);
     }
 
+    private static MimeMessage createMimeMessage(String headerName, String headerValue) throws MessagingException {
+        String sender = "test@james.apache.org";
+        String rcpt = "test2@james.apache.org";
+        return MimeMessageBuilder.mimeMessageBuilder()
+            .addHeader(headerName, headerValue)
+            .setSubject("testmail")
+            .setText("testtext")
+            .addToRecipient(rcpt)
+            .addFrom(sender)
+            .build();
+    }
+
 }
diff --git a/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/Util.java b/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/Util.java
deleted file mode 100644
index 5413c8b..0000000
--- a/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/Util.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-package org.apache.james.smtpserver;
-
-import javax.mail.MessagingException;
-import javax.mail.internet.MimeMessage;
-
-import org.apache.james.core.builder.MimeMessageBuilder;
-
-/**
- * some utilities for James unit testing
- */
-public class Util {
-
-    public static MimeMessage createMimeMessage(String headerName, String headerValue) throws MessagingException {
-        String sender = "test@james.apache.org";
-        String rcpt = "test2@james.apache.org";
-        return MimeMessageBuilder.mimeMessageBuilder()
-            .addHeader(headerName, headerValue)
-            .setSubject("testmail")
-            .setText("testtext")
-            .addToRecipient(rcpt)
-            .addFrom(sender)
-            .build();
-    }
-}


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


[james-project] 04/15: [Refactoring] initiliazed available charset names with a stream pipeline

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 3033780d8741145bd5b35498ffb8cc7cbdc41a1e
Author: Matthieu Baechler <ma...@apache.org>
AuthorDate: Thu Nov 7 22:07:26 2019 +0100

    [Refactoring] initiliazed available charset names with a stream pipeline
---
 .../apache/james/imap/api/display/CharsetUtil.java | 32 ++++++++--------------
 1 file changed, 12 insertions(+), 20 deletions(-)

diff --git a/protocols/imap/src/main/java/org/apache/james/imap/api/display/CharsetUtil.java b/protocols/imap/src/main/java/org/apache/james/imap/api/display/CharsetUtil.java
index c001c6f..8f47d62 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/api/display/CharsetUtil.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/api/display/CharsetUtil.java
@@ -20,11 +20,11 @@ package org.apache.james.imap.api.display;
 
 import java.nio.ByteBuffer;
 import java.nio.charset.Charset;
-import java.util.Collections;
-import java.util.HashSet;
 import java.util.Set;
+import java.util.stream.Stream;
 
 import com.beetstra.jutf7.CharsetProvider;
+import com.github.steveash.guavate.Guavate;
 
 /**
  * Utility class which can be used to get a list of supported {@link Charset}'s 
@@ -33,31 +33,23 @@ import com.beetstra.jutf7.CharsetProvider;
  */
 public class CharsetUtil {
 
-    private static final Set<String> charsetNames;
+    private static final Set<String> CHARSET_NAMES =
+        Charset.availableCharsets()
+            .values()
+            .stream()
+            .flatMap(charset -> Stream.concat(
+                Stream.of(charset.name()),
+                charset.aliases().stream()))
+            .collect(Guavate.toImmutableSet());
+
     private static final String X_MODIFIED_UTF_7 = "X-MODIFIED-UTF-7";
     private static final Charset X_MODIFIED_UTF_7_CHARSET = new CharsetProvider().charsetForName(X_MODIFIED_UTF_7);
 
-
-    // build the sets which holds the charsets and names
-    static {
-        Set<String> cNames = new HashSet<>();
-
-        for (Charset charset : Charset.availableCharsets().values()) {
-            final Set<String> aliases = charset.aliases();
-            cNames.add(charset.name());
-            cNames.addAll(aliases);
-        }
-
-        charsetNames = Collections.unmodifiableSet(cNames);
-    }
-
     /**
      * Return an unmodifiable {@link Set} which holds the names (and aliases) of all supported Charsets
-     *
-     * @return supportedCharsetNames
      */
     public static final Set<String> getAvailableCharsetNames() {
-        return charsetNames;
+        return CHARSET_NAMES;
     }
 
     /**


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


[james-project] 12/15: [Refactoring] migrate tests to junit5

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 055e487b8f7616b01878ae899a2f394e8bf415dd
Author: Matthieu Baechler <ma...@apache.org>
AuthorDate: Thu Nov 7 22:53:25 2019 +0100

    [Refactoring] migrate tests to junit5
---
 .../james/smtpserver/SetMimeHeaderHandlerTest.java | 26 +++++++++-------------
 1 file changed, 11 insertions(+), 15 deletions(-)

diff --git a/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SetMimeHeaderHandlerTest.java b/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SetMimeHeaderHandlerTest.java
index ba47a3d..7e018b3 100644
--- a/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SetMimeHeaderHandlerTest.java
+++ b/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SetMimeHeaderHandlerTest.java
@@ -29,23 +29,19 @@ import org.apache.james.core.builder.MimeMessageBuilder;
 import org.apache.james.protocols.smtp.SMTPSession;
 import org.apache.james.protocols.smtp.utils.BaseFakeSMTPSession;
 import org.apache.james.server.core.MailImpl;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
-public class SetMimeHeaderHandlerTest {
+class SetMimeHeaderHandlerTest {
 
     private static final String HEADER_NAME = "JUNIT";
     private static final String HEADER_VALUE = "test-value";
 
-    private SMTPSession mockedSMTPSession;
+    private SMTPSession fakeSMTPSession;
 
-    @Before
-    public void setUp() throws Exception {
-        setupMockedSMTPSession();
-    }
-
-    private void setupMockedSMTPSession() {
-        mockedSMTPSession = new BaseFakeSMTPSession() {
+    @BeforeEach
+    void setUp() {
+        fakeSMTPSession = new BaseFakeSMTPSession() {
 
             @Override
             public int getRcptCount() {
@@ -55,7 +51,7 @@ public class SetMimeHeaderHandlerTest {
     }
 
     @Test
-    public void setMimeHeaderHandlerShouldAddSpecifiedHeader() throws MessagingException {
+    void setMimeHeaderHandlerShouldAddSpecifiedHeader() throws MessagingException {
         MimeMessage mimeMessage = MimeMessageBuilder.mimeMessageBuilder()
             .setSubject("testmail")
             .setText("testtext")
@@ -73,13 +69,13 @@ public class SetMimeHeaderHandlerTest {
         header.setHeaderName(HEADER_NAME);
         header.setHeaderValue(HEADER_VALUE);
 
-        header.onMessage(mockedSMTPSession, mail);
+        header.onMessage(fakeSMTPSession, mail);
 
         assertThat(mail.getMessage().getHeader(HEADER_NAME)).containsOnly(HEADER_VALUE);
     }
 
     @Test
-    public void setMimeHeaderHandlerShouldReplaceSpecifiedHeader() throws MessagingException {
+    void setMimeHeaderHandlerShouldReplaceSpecifiedHeader() throws MessagingException {
 
         MimeMessage mimeMessage = MimeMessageBuilder.mimeMessageBuilder()
             .addHeader(HEADER_NAME, "defaultHeaderValue")
@@ -98,7 +94,7 @@ public class SetMimeHeaderHandlerTest {
         header.setHeaderName(HEADER_NAME);
         header.setHeaderValue(HEADER_VALUE);
 
-        header.onMessage(mockedSMTPSession, mail);
+        header.onMessage(fakeSMTPSession, mail);
 
         assertThat(mail.getMessage().getHeader(HEADER_NAME)).containsOnly(HEADER_VALUE);
     }


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


[james-project] 13/15: [Refactoring] suppress redundant condition

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 3c5467fccfd66943df579fa1f478c22ade1c83db
Author: Matthieu Baechler <ma...@apache.org>
AuthorDate: Fri Nov 8 18:10:53 2019 +0100

    [Refactoring] suppress redundant condition
---
 .../src/main/java/org/apache/james/lifecycle/api/LifecycleUtil.java | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/server/container/lifecycle-api/src/main/java/org/apache/james/lifecycle/api/LifecycleUtil.java b/server/container/lifecycle-api/src/main/java/org/apache/james/lifecycle/api/LifecycleUtil.java
index c9fe860..1cb7241 100644
--- a/server/container/lifecycle-api/src/main/java/org/apache/james/lifecycle/api/LifecycleUtil.java
+++ b/server/container/lifecycle-api/src/main/java/org/apache/james/lifecycle/api/LifecycleUtil.java
@@ -22,12 +22,10 @@ package org.apache.james.lifecycle.api;
 public class LifecycleUtil {
 
     /**
-     * Dispose the given object if its an instanceof {@link Disposable}
-     * 
-     * @param obj
+     * Dispose the given object if it's an instanceof {@link Disposable}
      */
     public static void dispose(Object obj) {
-        if (obj instanceof Disposable && obj != null) {
+        if (obj instanceof Disposable) {
             ((Disposable) obj).dispose();
         }
     }


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


[james-project] 03/15: [Refactoring] remove unused method getAvailableCharsets

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 2abab15a43b6555fd0314aefc86a07d5acbb6c5d
Author: Matthieu Baechler <ma...@apache.org>
AuthorDate: Thu Nov 7 22:01:44 2019 +0100

    [Refactoring] remove unused method getAvailableCharsets
---
 .../org/apache/james/imap/api/display/CharsetUtil.java | 18 ++----------------
 1 file changed, 2 insertions(+), 16 deletions(-)

diff --git a/protocols/imap/src/main/java/org/apache/james/imap/api/display/CharsetUtil.java b/protocols/imap/src/main/java/org/apache/james/imap/api/display/CharsetUtil.java
index b8ec77c..c001c6f 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/api/display/CharsetUtil.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/api/display/CharsetUtil.java
@@ -34,7 +34,6 @@ import com.beetstra.jutf7.CharsetProvider;
 public class CharsetUtil {
 
     private static final Set<String> charsetNames;
-    private static final Set<Charset> charsets;
     private static final String X_MODIFIED_UTF_7 = "X-MODIFIED-UTF-7";
     private static final Charset X_MODIFIED_UTF_7_CHARSET = new CharsetProvider().charsetForName(X_MODIFIED_UTF_7);
 
@@ -42,37 +41,24 @@ public class CharsetUtil {
     // build the sets which holds the charsets and names
     static {
         Set<String> cNames = new HashSet<>();
-        Set<Charset> sets = new HashSet<>();
 
         for (Charset charset : Charset.availableCharsets().values()) {
             final Set<String> aliases = charset.aliases();
             cNames.add(charset.name());
             cNames.addAll(aliases);
-            sets.add(charset);
-
         }
+
         charsetNames = Collections.unmodifiableSet(cNames);
-        charsets = Collections.unmodifiableSet(sets);
     }
 
     /**
      * Return an unmodifiable {@link Set} which holds the names (and aliases) of all supported Charsets
-     * 
+     *
      * @return supportedCharsetNames
      */
     public static final Set<String> getAvailableCharsetNames() {
         return charsetNames;
     }
-    
-    /**
-     * Return an unmodifiable {@link Set} which holds all supported Charsets
-     * 
-     * @return supportedCharsets
-     */
-    public static final Set<Charset> getAvailableCharsets() {
-        return charsets;
-    }
-    
 
     /**
      * Decode the given UTF7 encoded <code>String</code>


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


[james-project] 10/15: [Refactoring] inline mimemessage construction

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit eee987abfb49775469e5514f82617524f6064c16
Author: Matthieu Baechler <ma...@apache.org>
AuthorDate: Thu Nov 7 22:47:17 2019 +0100

    [Refactoring] inline mimemessage construction
---
 .../james/smtpserver/SetMimeHeaderHandlerTest.java | 52 +++++++---------------
 1 file changed, 17 insertions(+), 35 deletions(-)

diff --git a/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SetMimeHeaderHandlerTest.java b/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SetMimeHeaderHandlerTest.java
index 3681970..73b5c7c 100644
--- a/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SetMimeHeaderHandlerTest.java
+++ b/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SetMimeHeaderHandlerTest.java
@@ -39,28 +39,14 @@ public class SetMimeHeaderHandlerTest {
     private static final String HEADER_VALUE = "test-value";
 
     private SMTPSession mockedSMTPSession;
-    private MimeMessage mockedMimeMessage;
+    private MimeMessage mimeMessage;
     private Mail mail;
-    private String headerName = "defaultHeaderName";
-    private String headerValue = "defaultHeaderValue";
 
     @Before
     public void setUp() throws Exception {
         setupMockedSMTPSession();
     }
 
-    private void setHeaderName(String headerName) {
-        this.headerName = headerName;
-    }
-
-    private void setHeaderValue(String headerValue) {
-        this.headerValue = headerValue;
-    }
-
-    private void setupMockedMimeMessage() throws MessagingException {
-        mockedMimeMessage = createMimeMessage(headerName, headerValue);
-    }
-
     private void setupMockedSMTPSession() {
         mockedSMTPSession = new BaseFakeSMTPSession() {
 
@@ -74,13 +60,17 @@ public class SetMimeHeaderHandlerTest {
     // test if the Header was add
     @Test
     public void testHeaderIsPresent() throws MessagingException {
-        setHeaderName(HEADER_NAME);
-        setHeaderValue(HEADER_VALUE);
+        mimeMessage = MimeMessageBuilder.mimeMessageBuilder()
+            .addHeader(HEADER_NAME, HEADER_VALUE)
+            .setSubject("testmail")
+            .setText("testtext")
+            .addToRecipient("test2@james.apache.org")
+            .addFrom("test@james.apache.org")
+            .build();
 
-        setupMockedMimeMessage();
         mail = MailImpl.builder()
             .name("ID=" + ThreadLocalRandom.current().nextLong())
-            .mimeMessage(mockedMimeMessage)
+            .mimeMessage(mimeMessage)
             .addRecipients("test@james.apache.org", "test2@james.apache.org")
             .build();
 
@@ -96,13 +86,17 @@ public class SetMimeHeaderHandlerTest {
     // test if the Header was replaced
     @Test
     public void testHeaderIsReplaced() throws MessagingException {
-        setHeaderName(HEADER_NAME);
-        setHeaderValue(headerValue);
 
-        setupMockedMimeMessage();
+        mimeMessage = MimeMessageBuilder.mimeMessageBuilder()
+            .addHeader(HEADER_NAME, "defaultHeaderValue")
+            .setSubject("testmail")
+            .setText("testtext")
+            .addToRecipient("test2@james.apache.org")
+            .addFrom("test@james.apache.org")
+            .build();
         mail = MailImpl.builder()
             .name("ID=" + ThreadLocalRandom.current().nextLong())
-            .mimeMessage(mockedMimeMessage)
+            .mimeMessage(mimeMessage)
             .addRecipients("test@james.apache.org", "test2@james.apache.org")
             .build();
 
@@ -115,16 +109,4 @@ public class SetMimeHeaderHandlerTest {
         assertThat(mail.getMessage().getHeader(HEADER_NAME)[0]).isEqualTo(HEADER_VALUE);
     }
 
-    private static MimeMessage createMimeMessage(String headerName, String headerValue) throws MessagingException {
-        String sender = "test@james.apache.org";
-        String rcpt = "test2@james.apache.org";
-        return MimeMessageBuilder.mimeMessageBuilder()
-            .addHeader(headerName, headerValue)
-            .setSubject("testmail")
-            .setText("testtext")
-            .addToRecipient(rcpt)
-            .addFrom(sender)
-            .build();
-    }
-
 }


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


[james-project] 14/15: [Refactoring] avoid building many times the same buffer

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 598b3c4bd5f1bb03b56d7d930ba379344acd0815
Author: Matthieu Baechler <ma...@apache.org>
AuthorDate: Fri Nov 8 18:17:32 2019 +0100

    [Refactoring] avoid building many times the same buffer
---
 .../org/apache/james/imapserver/netty/ImapHeartbeatHandler.java    | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapHeartbeatHandler.java b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapHeartbeatHandler.java
index 29e085e..4d05da2 100644
--- a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapHeartbeatHandler.java
+++ b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapHeartbeatHandler.java
@@ -20,6 +20,7 @@ package org.apache.james.imapserver.netty;
 
 import java.nio.charset.StandardCharsets;
 
+import org.jboss.netty.buffer.ChannelBuffer;
 import org.jboss.netty.buffer.ChannelBuffers;
 import org.jboss.netty.channel.ChannelHandlerContext;
 import org.jboss.netty.handler.timeout.IdleState;
@@ -28,10 +29,14 @@ import org.jboss.netty.handler.timeout.IdleStateEvent;
 
 public class ImapHeartbeatHandler extends IdleStateAwareChannelHandler {
 
+    private static final ChannelBuffer HEARTBEAT_BUFFER = ChannelBuffers
+        .unmodifiableBuffer(
+            ChannelBuffers.wrappedBuffer("* OK Hang in there..\r\n".getBytes(StandardCharsets.US_ASCII)));
+
     @Override
     public void channelIdle(ChannelHandlerContext ctx, IdleStateEvent e) throws Exception {
         if (e.getState().equals(IdleState.WRITER_IDLE)) {
-            e.getChannel().write(ChannelBuffers.wrappedBuffer("* OK Hang in there..\r\n".getBytes(StandardCharsets.US_ASCII)));
+            e.getChannel().write(HEARTBEAT_BUFFER);
         }
         super.channelIdle(ctx, e);
     }


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


[james-project] 01/15: [Refactoring] use StandardCharsets in more places

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit b137370dce2d36aab3067c341b7398c9ae8b5f2a
Author: Matthieu Baechler <ma...@apache.org>
AuthorDate: Thu Nov 7 21:54:46 2019 +0100

    [Refactoring] use StandardCharsets in more places
---
 .gitignore                                         |  1 +
 .../mailbox/store/streaming/FullByteContent.java   |  5 +-
 .../protocols/api/AbstractProtocolTransport.java   |  8 +---
 .../parser/FetchCommandParserPartialFetchTest.java |  7 +--
 .../SearchCommandParserAndParenthesesTest.java     |  7 +--
 .../parser/SearchCommandParserCharsetTest.java     | 19 ++++----
 .../decode/parser/SearchCommandParserNotTest.java  |  5 +-
 .../decode/parser/SearchCommandParserOrTest.java   |  3 +-
 .../SearchCommandParserQuotedCharsetTest.java      | 55 ++++++++++------------
 ...earchCommandParserSearchKeySequenceSetTest.java |  3 +-
 .../parser/SearchCommandParserSearchKeyTest.java   |  5 +-
 .../parser/SearchCommandParserTopLevelAndTest.java |  7 ++-
 .../imap/decode/parser/StoreCommandParserTest.java |  3 +-
 .../james/protocols/pop3/utils/MockMailbox.java    | 20 ++++----
 .../server/core/InternetHeadersInputStream.java    | 30 +++++-------
 .../apache/james/server/core/MimeMessageTest.java  |  3 +-
 .../imapserver/netty/ImapHeartbeatHandler.java     |  4 +-
 17 files changed, 90 insertions(+), 95 deletions(-)

diff --git a/.gitignore b/.gitignore
index eefcea2..67357ab 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,3 +5,4 @@ dockerfiles/run/**/*.jar
 dockerfiles/run/**/keystore
 .m2
 test-run.log
+build
\ No newline at end of file
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/streaming/FullByteContent.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/streaming/FullByteContent.java
index 758db90..8864182 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/streaming/FullByteContent.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/streaming/FullByteContent.java
@@ -23,6 +23,7 @@ import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.SequenceInputStream;
+import java.nio.charset.StandardCharsets;
 import java.util.List;
 
 import org.apache.james.mailbox.exception.MailboxException;
@@ -64,10 +65,10 @@ public class FullByteContent implements Content {
         ByteArrayOutputStream out = new ByteArrayOutputStream();
         for (Header header : headers) {
             if (header != null) {
-                out.write((header.getName() + ": " + header.getValue() + "\r\n").getBytes("US-ASCII"));
+                out.write((header.getName() + ": " + header.getValue() + "\r\n").getBytes(StandardCharsets.US_ASCII));
             }
         }
-        out.write("\r\n".getBytes("US-ASCII"));
+        out.write("\r\n".getBytes(StandardCharsets.US_ASCII));
         out.flush();
         return new SequenceInputStream(new ByteArrayInputStream(out.toByteArray()), new ByteArrayInputStream(body));
     }
diff --git a/protocols/api/src/main/java/org/apache/james/protocols/api/AbstractProtocolTransport.java b/protocols/api/src/main/java/org/apache/james/protocols/api/AbstractProtocolTransport.java
index d3f814b..3aab58b 100644
--- a/protocols/api/src/main/java/org/apache/james/protocols/api/AbstractProtocolTransport.java
+++ b/protocols/api/src/main/java/org/apache/james/protocols/api/AbstractProtocolTransport.java
@@ -20,7 +20,7 @@
 package org.apache.james.protocols.api;
 
 import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
 import java.util.List;
 
 
@@ -75,11 +75,7 @@ public abstract class AbstractProtocolTransport implements ProtocolTransport {
                 builder.append(CRLF);
             }
         }
-        try {
-            return builder.toString().getBytes("US-ASCII");
-        } catch (UnsupportedEncodingException e) {
-            throw new RuntimeException("No US-ASCII ?");
-        }
+        return builder.toString().getBytes(StandardCharsets.US_ASCII);
     }
 
     /**
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/FetchCommandParserPartialFetchTest.java b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/FetchCommandParserPartialFetchTest.java
index ebc079d..cc8a589 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/FetchCommandParserPartialFetchTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/FetchCommandParserPartialFetchTest.java
@@ -24,6 +24,7 @@ import static org.mockito.Mockito.mock;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.nio.charset.StandardCharsets;
 
 import org.apache.james.imap.api.ImapCommand;
 import org.apache.james.imap.api.message.BodyFetchElement;
@@ -68,10 +69,10 @@ public class FetchCommandParserPartialFetchTest  {
     }
 
     @Test
-    public void testShouldNotParseZeroLength() throws Exception {
+    public void testShouldNotParseZeroLength() {
         ImapRequestLineReader reader = new ImapRequestStreamLineReader(
                 new ByteArrayInputStream("1 (BODY[]<20.0>)\r\n"
-                        .getBytes("US-ASCII")), new ByteArrayOutputStream());
+                        .getBytes(StandardCharsets.US_ASCII)), new ByteArrayOutputStream());
 
         assertThatThrownBy(() -> parser.decode(command, reader, "A01", false, session))
             .isInstanceOf(DecodingException.class);
@@ -80,7 +81,7 @@ public class FetchCommandParserPartialFetchTest  {
     private void check(String input, IdRange[] idSet,
             boolean useUids, FetchData data, String tag) throws Exception {
         ImapRequestLineReader reader = new ImapRequestStreamLineReader(
-                new ByteArrayInputStream(input.getBytes("US-ASCII")),
+                new ByteArrayInputStream(input.getBytes(StandardCharsets.US_ASCII)),
                 new ByteArrayOutputStream());
 
         parser.decode(command, reader, tag, useUids, session);
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserAndParenthesesTest.java b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserAndParenthesesTest.java
index 0e81a16..95c1d78 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserAndParenthesesTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserAndParenthesesTest.java
@@ -24,6 +24,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -182,11 +183,11 @@ public class SearchCommandParserAndParenthesesTest {
         check(and(top, false));
     }
 
-    private void check(Input in) throws UnsupportedEncodingException,
-            DecodingException {
+    private void check(Input in) throws
+        DecodingException {
         String input = in.input + "\r\n";
         ImapRequestLineReader reader = new ImapRequestStreamLineReader(
-                new ByteArrayInputStream(input.getBytes("US-ASCII")),
+                new ByteArrayInputStream(input.getBytes(StandardCharsets.US_ASCII)),
                 new ByteArrayOutputStream());
 
         final SearchKey result = parser.decode(null, reader);
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserCharsetTest.java b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserCharsetTest.java
index c866b23..80b772e 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserCharsetTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserCharsetTest.java
@@ -30,6 +30,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
 
 import org.apache.james.imap.api.ImapCommand;
 import org.apache.james.imap.api.ImapMessage;
@@ -87,7 +88,7 @@ public class SearchCommandParserCharsetTest {
     @Test
     public void testBadCharset() throws Exception {
         ImapRequestLineReader reader = new ImapRequestStreamLineReader(
-                new ByteArrayInputStream("CHARSET BOGUS ".getBytes("US-ASCII")),
+                new ByteArrayInputStream("CHARSET BOGUS ".getBytes(StandardCharsets.US_ASCII)),
                 new ByteArrayOutputStream());
         parser.decode(command, reader, TAG, false, session);
 
@@ -103,50 +104,50 @@ public class SearchCommandParserCharsetTest {
     @Test
     public void testBCCShouldConvertCharset() throws Exception {
         SearchKey key = SearchKey.buildBcc(NON_ASCII_SEARCH_TERM);
-        checkUTF8Valid("BCC".getBytes("US-ASCII"), key);
+        checkUTF8Valid("BCC".getBytes(StandardCharsets.US_ASCII), key);
     }
 
     @Test
     public void testBODYShouldConvertCharset() throws Exception {
         SearchKey key = SearchKey.buildBody(NON_ASCII_SEARCH_TERM);
-        checkUTF8Valid("BODY".getBytes("US-ASCII"), key);
+        checkUTF8Valid("BODY".getBytes(StandardCharsets.US_ASCII), key);
     }
 
     @Test
     public void testCCShouldConvertCharset() throws Exception {
         SearchKey key = SearchKey.buildCc(NON_ASCII_SEARCH_TERM);
-        checkUTF8Valid("CC".getBytes("US-ASCII"), key);
+        checkUTF8Valid("CC".getBytes(StandardCharsets.US_ASCII), key);
     }
 
     @Test
     public void testFROMShouldConvertCharset() throws Exception {
         SearchKey key = SearchKey.buildFrom(NON_ASCII_SEARCH_TERM);
-        checkUTF8Valid("FROM".getBytes("US-ASCII"), key);
+        checkUTF8Valid("FROM".getBytes(StandardCharsets.US_ASCII), key);
     }
 
     @Test
     public void testHEADERShouldConvertCharset() throws Exception {
         SearchKey key = SearchKey
                 .buildHeader("whatever", NON_ASCII_SEARCH_TERM);
-        checkUTF8Valid("HEADER whatever".getBytes("US-ASCII"), key);
+        checkUTF8Valid("HEADER whatever".getBytes(StandardCharsets.US_ASCII), key);
     }
 
     @Test
     public void testSUBJECTShouldConvertCharset() throws Exception {
         SearchKey key = SearchKey.buildSubject(NON_ASCII_SEARCH_TERM);
-        checkUTF8Valid("SUBJECT".getBytes("US-ASCII"), key);
+        checkUTF8Valid("SUBJECT".getBytes(StandardCharsets.US_ASCII), key);
     }
 
     @Test
     public void testTEXTShouldConvertCharset() throws Exception {
         SearchKey key = SearchKey.buildText(NON_ASCII_SEARCH_TERM);
-        checkUTF8Valid("TEXT".getBytes("US-ASCII"), key);
+        checkUTF8Valid("TEXT".getBytes(StandardCharsets.US_ASCII), key);
     }
 
     @Test
     public void testTOShouldConvertCharset() throws Exception {
         SearchKey key = SearchKey.buildTo(NON_ASCII_SEARCH_TERM);
-        checkUTF8Valid("TO".getBytes("US-ASCII"), key);
+        checkUTF8Valid("TO".getBytes(StandardCharsets.US_ASCII), key);
     }
 
     @Test
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserNotTest.java b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserNotTest.java
index 86ec857..9b51acf 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserNotTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserNotTest.java
@@ -23,6 +23,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.nio.charset.StandardCharsets;
 import java.util.Arrays;
 import java.util.List;
 
@@ -113,7 +114,7 @@ public class SearchCommandParserNotTest {
     @Test 
     public void testUserFlagsParsing() throws Exception { 
         ImapRequestLineReader reader = new ImapRequestStreamLineReader(
-                new ByteArrayInputStream("NOT (KEYWORD bar KEYWORD foo)".getBytes("US-ASCII")), 
+                new ByteArrayInputStream("NOT (KEYWORD bar KEYWORD foo)".getBytes(StandardCharsets.US_ASCII)),
                 new ByteArrayOutputStream()); 
         SearchKey key = parser.searchKey(null, reader, null, false); 
         List<SearchKey> keys = key.getKeys().get(0).getKeys(); 
@@ -124,7 +125,7 @@ public class SearchCommandParserNotTest {
 
     private void checkValid(String input, SearchKey key) throws Exception {
         ImapRequestLineReader reader = new ImapRequestStreamLineReader(
-                new ByteArrayInputStream(input.getBytes("US-ASCII")),
+                new ByteArrayInputStream(input.getBytes(StandardCharsets.US_ASCII)),
                 new ByteArrayOutputStream());
 
         assertThat(parser.searchKey(null, reader, null, false)).isEqualTo(key);
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserOrTest.java b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserOrTest.java
index b5bb13f..eae0525 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserOrTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserOrTest.java
@@ -23,6 +23,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.nio.charset.StandardCharsets;
 import java.util.Arrays;
 
 import org.apache.james.imap.api.ImapCommand;
@@ -172,7 +173,7 @@ public class SearchCommandParserOrTest {
         String input = "OR " + one.input + " " + two.input + "\r\n";
         SearchKey key = SearchKey.buildOr(one.key, two.key);
         ImapRequestLineReader reader = new ImapRequestStreamLineReader(
-                new ByteArrayInputStream(input.getBytes("US-ASCII")),
+                new ByteArrayInputStream(input.getBytes(StandardCharsets.US_ASCII)),
                 new ByteArrayOutputStream());
 
         assertThat(parser.searchKey(null, reader, null, false)).isEqualTo(key);
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserQuotedCharsetTest.java b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserQuotedCharsetTest.java
index 1fe6191..2533f77 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserQuotedCharsetTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserQuotedCharsetTest.java
@@ -31,6 +31,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
 
 import org.apache.james.imap.api.ImapCommand;
 import org.apache.james.imap.api.ImapMessage;
@@ -48,10 +49,6 @@ import org.junit.Test;
 
 public class SearchCommandParserQuotedCharsetTest {
 
-    private static final Charset UTF8 = Charset.forName("UTF-8");
-
-    private static final Charset ASCII = Charset.forName("US-ASCII");
-
     private static final String TAG = "A1";
 
     private static final String ASCII_SEARCH_TERM = "A Search Term";
@@ -104,25 +101,25 @@ public class SearchCommandParserQuotedCharsetTest {
             + NON_ASCII_SEARCH_TERM;
 
     private static final byte[] BYTES_LENGTHY_NON_ASCII_SEARCH_TERM = NioUtils
-            .toBytes(LENGTHY_NON_ASCII_SEARCH_TERM, UTF8);
+            .toBytes(LENGTHY_NON_ASCII_SEARCH_TERM, StandardCharsets.UTF_8);
 
     private static final byte[] BYTES_NON_ASCII_SEARCH_TERM = NioUtils.toBytes(
-            NON_ASCII_SEARCH_TERM, UTF8);
+            NON_ASCII_SEARCH_TERM, StandardCharsets.UTF_8);
 
     private static final byte[] BYTES_QUOTED_UTF8_LENGTHY_NON_ASCII_SEARCH_TERM = add(
-            add(NioUtils.toBytes(" \"", ASCII),
+            add(NioUtils.toBytes(" \"", StandardCharsets.US_ASCII),
                     BYTES_LENGTHY_NON_ASCII_SEARCH_TERM), NioUtils.toBytes(
-                    "\"", ASCII));
+                    "\"", StandardCharsets.US_ASCII));
 
     private static final byte[] BYTES_QUOTED_UTF8_NON_ASCII_SEARCH_TERM = add(
-            add(NioUtils.toBytes(" \"", ASCII), BYTES_NON_ASCII_SEARCH_TERM),
-            NioUtils.toBytes("\"", ASCII));
+            add(NioUtils.toBytes(" \"", StandardCharsets.US_ASCII), BYTES_NON_ASCII_SEARCH_TERM),
+            NioUtils.toBytes("\"", StandardCharsets.US_ASCII));
 
     private static final byte[] BYTES_UTF8_NON_ASCII_SEARCH_TERM = add(NioUtils
-            .toBytes(" {16}\r\n", ASCII), BYTES_NON_ASCII_SEARCH_TERM);
+            .toBytes(" {16}\r\n", StandardCharsets.US_ASCII), BYTES_NON_ASCII_SEARCH_TERM);
 
     private static final byte[] CHARSET = NioUtils.toBytes("CHARSET UTF-8 ",
-            ASCII);
+        StandardCharsets.US_ASCII);
 
     private static byte[] add(byte[] one, byte[] two) {
         byte[] results = new byte[one.length + two.length];
@@ -154,7 +151,7 @@ public class SearchCommandParserQuotedCharsetTest {
         SearchKey key = SearchKey.buildBcc(LENGTHY_NON_ASCII_SEARCH_TERM);
         ImapRequestLineReader reader = new ImapRequestStreamLineReader(
                 new ByteArrayInputStream(add(add(CHARSET, "BCC"
-                        .getBytes("US-ASCII")),
+                        .getBytes(StandardCharsets.US_ASCII)),
                         BYTES_QUOTED_UTF8_LENGTHY_NON_ASCII_SEARCH_TERM)),
                 new ByteArrayOutputStream());
         final SearchKey searchKey = parser.searchKey(null, reader, null, true);
@@ -166,7 +163,7 @@ public class SearchCommandParserQuotedCharsetTest {
         SearchKey key = SearchKey.buildBcc(NON_ASCII_SEARCH_TERM);
         ImapRequestLineReader reader = new ImapRequestStreamLineReader(
                 new ByteArrayInputStream(add(add(CHARSET, "BCC"
-                        .getBytes("US-ASCII")),
+                        .getBytes(StandardCharsets.US_ASCII)),
                         BYTES_QUOTED_UTF8_NON_ASCII_SEARCH_TERM)),
                 new ByteArrayOutputStream());
         final SearchKey searchKey = parser.searchKey(null, reader, null, true);
@@ -176,7 +173,7 @@ public class SearchCommandParserQuotedCharsetTest {
     @Test
     public void testBadCharset() throws Exception {
         ImapRequestLineReader reader = new ImapRequestStreamLineReader(
-                new ByteArrayInputStream("CHARSET BOGUS ".getBytes("US-ASCII")),
+                new ByteArrayInputStream("CHARSET BOGUS ".getBytes(StandardCharsets.US_ASCII)),
                 new ByteArrayOutputStream());
         parser.decode(command, reader, TAG, false, session);
 
@@ -189,12 +186,11 @@ public class SearchCommandParserQuotedCharsetTest {
     }
 
     @Test
-    public void testShouldThrowProtocolExceptionWhenBytesAreNotEncodedByCharset()
-            throws Exception {
+    public void testShouldThrowProtocolExceptionWhenBytesAreNotEncodedByCharset() {
         try {
             ImapRequestLineReader reader = new ImapRequestStreamLineReader(
                     new ByteArrayInputStream(add("CHARSET US-ASCII BCC "
-                            .getBytes("US-ASCII"), BYTES_NON_ASCII_SEARCH_TERM)),
+                            .getBytes(StandardCharsets.US_ASCII), BYTES_NON_ASCII_SEARCH_TERM)),
                     new ByteArrayOutputStream());
             parser.decode(command, reader, TAG, false, session);
             fail("A protocol exception should be thrown when charset is incompatible with input");
@@ -206,64 +202,64 @@ public class SearchCommandParserQuotedCharsetTest {
     @Test
     public void testBCCShouldConvertCharset() throws Exception {
         SearchKey key = SearchKey.buildBcc(NON_ASCII_SEARCH_TERM);
-        checkUTF8Valid("BCC".getBytes("US-ASCII"), key);
+        checkUTF8Valid("BCC".getBytes(StandardCharsets.US_ASCII), key);
     }
 
     @Test
     public void testBODYShouldConvertCharset() throws Exception {
         SearchKey key = SearchKey.buildBody(NON_ASCII_SEARCH_TERM);
-        checkUTF8Valid("BODY".getBytes("US-ASCII"), key);
+        checkUTF8Valid("BODY".getBytes(StandardCharsets.US_ASCII), key);
     }
 
     @Test
     public void testCCShouldConvertCharset() throws Exception {
         SearchKey key = SearchKey.buildCc(NON_ASCII_SEARCH_TERM);
-        checkUTF8Valid("CC".getBytes("US-ASCII"), key);
+        checkUTF8Valid("CC".getBytes(StandardCharsets.US_ASCII), key);
     }
 
     @Test
     public void testFROMShouldConvertCharset() throws Exception {
         SearchKey key = SearchKey.buildFrom(NON_ASCII_SEARCH_TERM);
-        checkUTF8Valid("FROM".getBytes("US-ASCII"), key);
+        checkUTF8Valid("FROM".getBytes(StandardCharsets.US_ASCII), key);
     }
 
     @Test
     public void testHEADERShouldConvertCharset() throws Exception {
         SearchKey key = SearchKey
                 .buildHeader("whatever", NON_ASCII_SEARCH_TERM);
-        checkUTF8Valid("HEADER whatever".getBytes("US-ASCII"), key);
+        checkUTF8Valid("HEADER whatever".getBytes(StandardCharsets.US_ASCII), key);
     }
 
     @Test
     public void testSUBJECTShouldConvertCharset() throws Exception {
         SearchKey key = SearchKey.buildSubject(NON_ASCII_SEARCH_TERM);
-        checkUTF8Valid("SUBJECT".getBytes("US-ASCII"), key);
+        checkUTF8Valid("SUBJECT".getBytes(StandardCharsets.US_ASCII), key);
     }
 
     @Test
     public void testTEXTShouldConvertCharset() throws Exception {
         SearchKey key = SearchKey.buildText(NON_ASCII_SEARCH_TERM);
-        checkUTF8Valid("TEXT".getBytes("US-ASCII"), key);
+        checkUTF8Valid("TEXT".getBytes(StandardCharsets.US_ASCII), key);
     }
 
     @Test
     public void testTOShouldConvertCharset() throws Exception {
         SearchKey key = SearchKey.buildTo(NON_ASCII_SEARCH_TERM);
-        checkUTF8Valid("TO".getBytes("US-ASCII"), key);
+        checkUTF8Valid("TO".getBytes(StandardCharsets.US_ASCII), key);
     }
 
     @Test
     public void testASCIICharset() throws Exception {
         SearchKey key = SearchKey.buildBcc(ASCII_SEARCH_TERM);
         checkValid("CHARSET US-ASCII BCC \"" + ASCII_SEARCH_TERM + "\"", key,
-                true, "US-ASCII");
+                true, StandardCharsets.US_ASCII);
     }
 
     @Test
     public void testSimpleUTF8Charset() throws Exception {
         SearchKey key = SearchKey.buildBcc(ASCII_SEARCH_TERM);
         checkValid("CHARSET UTF-8 BCC \"" + ASCII_SEARCH_TERM + "\"", key,
-                true, "US-ASCII");
+                true, StandardCharsets.US_ASCII);
     }
 
     private void checkUTF8Valid(byte[] term, SearchKey key)
@@ -276,8 +272,7 @@ public class SearchCommandParserQuotedCharsetTest {
         assertThat(searchKey).isEqualTo(key);
     }
 
-    private void checkValid(String input, SearchKey key, boolean isFirst,
-            String charset) throws Exception {
+    private void checkValid(String input, SearchKey key, boolean isFirst, Charset charset) throws Exception {
         ImapRequestLineReader reader = new ImapRequestStreamLineReader(
                 new ByteArrayInputStream(input.getBytes(charset)),
                 new ByteArrayOutputStream());
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserSearchKeySequenceSetTest.java b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserSearchKeySequenceSetTest.java
index fa6eebb..1287082 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserSearchKeySequenceSetTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserSearchKeySequenceSetTest.java
@@ -23,6 +23,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.nio.charset.StandardCharsets;
 import java.util.Arrays;
 
 import org.apache.james.imap.api.ImapCommand;
@@ -130,7 +131,7 @@ public class SearchCommandParserSearchKeySequenceSetTest {
     private void checkValid(String input, SearchKey key) throws Exception {
         input = input + "\r\n";
         ImapRequestLineReader reader = new ImapRequestStreamLineReader(
-                new ByteArrayInputStream(input.getBytes("US-ASCII")),
+                new ByteArrayInputStream(input.getBytes(StandardCharsets.US_ASCII)),
                 new ByteArrayOutputStream());
 
         final SearchKey searchKey = parser.searchKey(null, reader, null, false);
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserSearchKeyTest.java b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserSearchKeyTest.java
index 774914c..2534ab0 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserSearchKeyTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserSearchKeyTest.java
@@ -24,6 +24,7 @@ import static org.assertj.core.api.Fail.fail;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.nio.charset.StandardCharsets;
 
 import org.apache.james.imap.api.ImapCommand;
 import org.apache.james.imap.api.ImapMessage;
@@ -374,7 +375,7 @@ public class SearchCommandParserSearchKeyTest {
    
     private void checkValid(String input, SearchKey key) throws Exception {
         ImapRequestLineReader reader = new ImapRequestStreamLineReader(
-                new ByteArrayInputStream(input.getBytes("US-ASCII")),
+                new ByteArrayInputStream(input.getBytes(StandardCharsets.US_ASCII)),
                 new ByteArrayOutputStream());
 
         assertThat(parser.searchKey(null, reader, null, false)).isEqualTo(key);
@@ -727,7 +728,7 @@ public class SearchCommandParserSearchKeyTest {
     private void checkInvalid(String input, SearchKey key)
             throws Exception {
         ImapRequestLineReader reader = new ImapRequestStreamLineReader(
-                new ByteArrayInputStream(input.getBytes("US-ASCII")),
+                new ByteArrayInputStream(input.getBytes(StandardCharsets.US_ASCII)),
                 new ByteArrayOutputStream());
 
         try {
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserTopLevelAndTest.java b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserTopLevelAndTest.java
index 4417f38..4e779cf 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserTopLevelAndTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserTopLevelAndTest.java
@@ -23,7 +23,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
-import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -183,13 +183,12 @@ public class SearchCommandParserTopLevelAndTest {
         }
     }
 
-    private void check(List<SearchKey> keys, StringBuffer buffer)
-            throws UnsupportedEncodingException, DecodingException {
+    private void check(List<SearchKey> keys, StringBuffer buffer) throws DecodingException {
         buffer.append("\r\n");
         String input = buffer.toString();
         SearchKey key = SearchKey.buildAnd(keys);
         ImapRequestLineReader reader = new ImapRequestStreamLineReader(
-                new ByteArrayInputStream(input.getBytes("US-ASCII")),
+                new ByteArrayInputStream(input.getBytes(StandardCharsets.US_ASCII)),
                 new ByteArrayOutputStream());
 
         assertThat(parser.decode(null, reader)).describedAs(input).isEqualTo(key);
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/StoreCommandParserTest.java b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/StoreCommandParserTest.java
index 865a2bc..5e07a19 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/StoreCommandParserTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/StoreCommandParserTest.java
@@ -23,6 +23,7 @@ import static org.mockito.Mockito.mock;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.nio.charset.StandardCharsets;
 
 import javax.mail.Flags;
 
@@ -75,7 +76,7 @@ public class StoreCommandParserTest {
             final Boolean sign, Flags flags, boolean useUids, String tag)
             throws Exception {
         ImapRequestLineReader reader = new ImapRequestStreamLineReader(
-                new ByteArrayInputStream(input.getBytes("US-ASCII")),
+                new ByteArrayInputStream(input.getBytes(StandardCharsets.US_ASCII)),
                 new ByteArrayOutputStream());
 
         parser.decode(command, reader, tag, useUids, session);
diff --git a/protocols/pop3/src/test/java/org/apache/james/protocols/pop3/utils/MockMailbox.java b/protocols/pop3/src/test/java/org/apache/james/protocols/pop3/utils/MockMailbox.java
index bc6a846..e0f014b 100644
--- a/protocols/pop3/src/test/java/org/apache/james/protocols/pop3/utils/MockMailbox.java
+++ b/protocols/pop3/src/test/java/org/apache/james/protocols/pop3/utils/MockMailbox.java
@@ -19,9 +19,9 @@
 package org.apache.james.protocols.pop3.utils;
 
 import java.io.ByteArrayInputStream;
-import java.io.IOException;
 import java.io.InputStream;
 import java.io.SequenceInputStream;
+import java.nio.charset.StandardCharsets;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -51,25 +51,25 @@ public class MockMailbox extends ImapMailbox {
     }
 
     @Override
-    public InputStream getMessageBody(long uid) throws IOException {
+    public InputStream getMessageBody(long uid) {
         Message m = messages.get(uid);
         if (m == null) {
             return null;
         }
-        return new ByteArrayInputStream(m.body.getBytes("US-ASCII"));
+        return new ByteArrayInputStream(m.body.getBytes(StandardCharsets.US_ASCII));
     }
 
     @Override
-    public InputStream getMessageHeaders(long uid) throws IOException {
+    public InputStream getMessageHeaders(long uid) {
         Message m = messages.get(uid);
         if (m == null) {
             return null;
         }
-        return new ByteArrayInputStream((m.headers + "\r\n").getBytes("US-ASCII"));
+        return new ByteArrayInputStream((m.headers + "\r\n").getBytes(StandardCharsets.US_ASCII));
     }
 
     @Override
-    public InputStream getMessage(long uid) throws IOException {
+    public InputStream getMessage(long uid) {
         InputStream body = getMessageBody(uid);
         InputStream headers = getMessageHeaders(uid);
         if (body == null || headers == null) {
@@ -79,7 +79,7 @@ public class MockMailbox extends ImapMailbox {
     }
 
     @Override
-    public List<MessageMetaData> getMessages() throws IOException {
+    public List<MessageMetaData> getMessages() {
         return messages.values()
             .stream()
             .map(m -> m.meta)
@@ -87,19 +87,19 @@ public class MockMailbox extends ImapMailbox {
     }
 
     @Override
-    public void remove(long... uids) throws IOException {
+    public void remove(long... uids) {
         for (long uid: uids) {
             messages.remove(uid);
         }
     }
 
     @Override
-    public String getIdentifier() throws IOException {
+    public String getIdentifier() {
         return identifier;
     }
 
     @Override
-    public void close() throws IOException {
+    public void close() {
         // nothing
     }
     
diff --git a/server/container/core/src/main/java/org/apache/james/server/core/InternetHeadersInputStream.java b/server/container/core/src/main/java/org/apache/james/server/core/InternetHeadersInputStream.java
index f6911f8..c73f890 100644
--- a/server/container/core/src/main/java/org/apache/james/server/core/InternetHeadersInputStream.java
+++ b/server/container/core/src/main/java/org/apache/james/server/core/InternetHeadersInputStream.java
@@ -19,9 +19,8 @@
 
 package org.apache.james.server.core;
 
-import java.io.IOException;
 import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
 import java.util.Enumeration;
 
 import javax.mail.internet.InternetHeaders;
@@ -48,7 +47,7 @@ public class InternetHeadersInputStream extends InputStream {
     }
 
     @Override
-    public int read() throws IOException {
+    public int read() {
         if (currLine == null || pos == currLine.length) {
             if (!readNextLine()) {
                 return -1;
@@ -61,31 +60,24 @@ public class InternetHeadersInputStream extends InputStream {
      * Load the next header line if possible
      * 
      * @return true if there was an headerline which could be read
-     * 
-     * @throws IOException
      */
-    private boolean readNextLine() throws IOException {
+    private boolean readNextLine() {
         if (headerLines.hasMoreElements()) {
-            try {
-                pos = 0;
-                String line = (headerLines.nextElement() + LINE_SEPERATOR);
-                // Add seperator to show that headers are complete
-                if (!headerLines.hasMoreElements()) {
-                    line += LINE_SEPERATOR;
-                }
-                currLine = line.getBytes("US-ASCII");
-                return true;
-            } catch (UnsupportedEncodingException e) {
-                // should never happen
-                throw new IOException("US-ASCII encoding not supported by this platform ?!");
+            pos = 0;
+            String line = (headerLines.nextElement() + LINE_SEPERATOR);
+            // Add seperator to show that headers are complete
+            if (!headerLines.hasMoreElements()) {
+                line += LINE_SEPERATOR;
             }
+            currLine = line.getBytes(StandardCharsets.US_ASCII);
+            return true;
         } else {
             return false;
         }
     }
 
     @Override
-    public void close() throws IOException {
+    public void close() {
         currLine = null;
     }
 
diff --git a/server/container/core/src/test/java/org/apache/james/server/core/MimeMessageTest.java b/server/container/core/src/test/java/org/apache/james/server/core/MimeMessageTest.java
index eab98ac..3e02407 100644
--- a/server/container/core/src/test/java/org/apache/james/server/core/MimeMessageTest.java
+++ b/server/container/core/src/test/java/org/apache/james/server/core/MimeMessageTest.java
@@ -24,6 +24,7 @@ import static org.assertj.core.api.Fail.fail;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.nio.charset.StandardCharsets;
 import java.util.Arrays;
 import java.util.Enumeration;
 import java.util.Properties;
@@ -401,7 +402,7 @@ public class MimeMessageTest {
     public void testGeronimoIndexOutOfBounds() throws Exception {
         String message = "                  \r\n" + "Subject: test\r\n" + "\r\n" + "Body\r\n";
 
-        byte[] messageBytes = message.getBytes("US-ASCII");
+        byte[] messageBytes = message.getBytes(StandardCharsets.US_ASCII);
         new MimeMessage(null, new ByteArrayInputStream(messageBytes));
     }
 }
diff --git a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapHeartbeatHandler.java b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapHeartbeatHandler.java
index ae44ab7..29e085e 100644
--- a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapHeartbeatHandler.java
+++ b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapHeartbeatHandler.java
@@ -18,6 +18,8 @@
  ****************************************************************/
 package org.apache.james.imapserver.netty;
 
+import java.nio.charset.StandardCharsets;
+
 import org.jboss.netty.buffer.ChannelBuffers;
 import org.jboss.netty.channel.ChannelHandlerContext;
 import org.jboss.netty.handler.timeout.IdleState;
@@ -29,7 +31,7 @@ public class ImapHeartbeatHandler extends IdleStateAwareChannelHandler {
     @Override
     public void channelIdle(ChannelHandlerContext ctx, IdleStateEvent e) throws Exception {
         if (e.getState().equals(IdleState.WRITER_IDLE)) {
-            e.getChannel().write(ChannelBuffers.wrappedBuffer("* OK Hang in there..\r\n".getBytes("US-ASCII")));
+            e.getChannel().write(ChannelBuffers.wrappedBuffer("* OK Hang in there..\r\n".getBytes(StandardCharsets.US_ASCII)));
         }
         super.channelIdle(ctx, e);
     }


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


[james-project] 05/15: [Refactoring] move available charset names into StatusResponse

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 12e1c580bb47a2d7fdef33aef2b99671d4bd8f33
Author: Matthieu Baechler <ma...@apache.org>
AuthorDate: Thu Nov 7 22:10:29 2019 +0100

    [Refactoring] move available charset names into StatusResponse
---
 .../apache/james/imap/api/display/CharsetUtil.java    | 19 -------------------
 .../imap/api/message/response/StatusResponse.java     | 17 +++++++++++++++--
 2 files changed, 15 insertions(+), 21 deletions(-)

diff --git a/protocols/imap/src/main/java/org/apache/james/imap/api/display/CharsetUtil.java b/protocols/imap/src/main/java/org/apache/james/imap/api/display/CharsetUtil.java
index 8f47d62..915716c 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/api/display/CharsetUtil.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/api/display/CharsetUtil.java
@@ -20,11 +20,8 @@ package org.apache.james.imap.api.display;
 
 import java.nio.ByteBuffer;
 import java.nio.charset.Charset;
-import java.util.Set;
-import java.util.stream.Stream;
 
 import com.beetstra.jutf7.CharsetProvider;
-import com.github.steveash.guavate.Guavate;
 
 /**
  * Utility class which can be used to get a list of supported {@link Charset}'s 
@@ -33,26 +30,10 @@ import com.github.steveash.guavate.Guavate;
  */
 public class CharsetUtil {
 
-    private static final Set<String> CHARSET_NAMES =
-        Charset.availableCharsets()
-            .values()
-            .stream()
-            .flatMap(charset -> Stream.concat(
-                Stream.of(charset.name()),
-                charset.aliases().stream()))
-            .collect(Guavate.toImmutableSet());
-
     private static final String X_MODIFIED_UTF_7 = "X-MODIFIED-UTF-7";
     private static final Charset X_MODIFIED_UTF_7_CHARSET = new CharsetProvider().charsetForName(X_MODIFIED_UTF_7);
 
     /**
-     * Return an unmodifiable {@link Set} which holds the names (and aliases) of all supported Charsets
-     */
-    public static final Set<String> getAvailableCharsetNames() {
-        return CHARSET_NAMES;
-    }
-
-    /**
      * Decode the given UTF7 encoded <code>String</code>
      *
      * @return decoded
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/api/message/response/StatusResponse.java b/protocols/imap/src/main/java/org/apache/james/imap/api/message/response/StatusResponse.java
index 148ef69..15f9931 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/api/message/response/StatusResponse.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/api/message/response/StatusResponse.java
@@ -19,20 +19,24 @@
 
 package org.apache.james.imap.api.message.response;
 
+import java.nio.charset.Charset;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Set;
+import java.util.stream.Stream;
 
 import javax.mail.Flags;
 
 import org.apache.james.imap.api.ImapCommand;
-import org.apache.james.imap.api.display.CharsetUtil;
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.api.message.IdRange;
 import org.apache.james.imap.api.message.MessageFlags;
 import org.apache.james.imap.api.message.UidRange;
 import org.apache.james.mailbox.MessageUid;
 
+import com.github.steveash.guavate.Guavate;
+
 /**
  * <p>
  * Represents an <code>RFC2060</code> status response. The five specified status
@@ -44,6 +48,15 @@ import org.apache.james.mailbox.MessageUid;
  */
 public interface StatusResponse extends ImapResponseMessage {
 
+    Set<String> AVAILABLE_CHARSET_NAMES =
+        Charset.availableCharsets()
+            .values()
+            .stream()
+            .flatMap(charset -> Stream.concat(
+                Stream.of(charset.name()),
+                charset.aliases().stream()))
+            .collect(Guavate.toImmutableSet());
+
     /**
      * Gets the server response type of this status message.
      * 
@@ -215,7 +228,7 @@ public interface StatusResponse extends ImapResponseMessage {
          * @return <code>ResponseCode</code>, not null
          */
         public static ResponseCode badCharset() {
-            return new ResponseCode("BADCHARSET", CharsetUtil.getAvailableCharsetNames());
+            return new ResponseCode("BADCHARSET", AVAILABLE_CHARSET_NAMES);
         }
 
         /**


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


[james-project] 08/15: [Refactoring] inline createMockMail2Recipients and replace it with MailImpl.builder

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 3c123e4a727a27d1f4f4af20bd3532ca8537c9df
Author: Matthieu Baechler <ma...@apache.org>
AuthorDate: Thu Nov 7 22:38:54 2019 +0100

    [Refactoring] inline createMockMail2Recipients and replace it with MailImpl.builder
---
 .../james/smtpserver/SetMimeHeaderHandlerTest.java | 32 +++++++++++-----------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SetMimeHeaderHandlerTest.java b/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SetMimeHeaderHandlerTest.java
index f9f6055..2315524 100644
--- a/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SetMimeHeaderHandlerTest.java
+++ b/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SetMimeHeaderHandlerTest.java
@@ -27,8 +27,8 @@ import javax.mail.internet.MimeMessage;
 
 import org.apache.james.protocols.smtp.SMTPSession;
 import org.apache.james.protocols.smtp.utils.BaseFakeSMTPSession;
+import org.apache.james.server.core.MailImpl;
 import org.apache.mailet.Mail;
-import org.apache.mailet.base.test.FakeMail;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -39,7 +39,7 @@ public class SetMimeHeaderHandlerTest {
 
     private SMTPSession mockedSMTPSession;
     private MimeMessage mockedMimeMessage;
-    private Mail mockedMail;
+    private Mail mail;
     private String headerName = "defaultHeaderName";
     private String headerValue = "defaultHeaderValue";
 
@@ -77,15 +77,19 @@ public class SetMimeHeaderHandlerTest {
         setHeaderValue(HEADER_VALUE);
 
         setupMockedMimeMessage();
-        mockedMail = createMockMail2Recipients(mockedMimeMessage);
+        mail = MailImpl.builder()
+            .name("ID=" + ThreadLocalRandom.current().nextLong())
+            .mimeMessage(mockedMimeMessage)
+            .addRecipients("test@james.apache.org", "test2@james.apache.org")
+            .build();
 
         SetMimeHeaderHandler header = new SetMimeHeaderHandler();
 
         header.setHeaderName(HEADER_NAME);
         header.setHeaderValue(HEADER_VALUE);
-        header.onMessage(mockedSMTPSession, mockedMail);
+        header.onMessage(mockedSMTPSession, mail);
 
-        assertThat(mockedMail.getMessage().getHeader(HEADER_NAME)[0]).isEqualTo(HEADER_VALUE);
+        assertThat(mail.getMessage().getHeader(HEADER_NAME)[0]).isEqualTo(HEADER_VALUE);
     }
 
     // test if the Header was replaced
@@ -95,23 +99,19 @@ public class SetMimeHeaderHandlerTest {
         setHeaderValue(headerValue);
 
         setupMockedMimeMessage();
-        mockedMail = createMockMail2Recipients(mockedMimeMessage);
+        mail = MailImpl.builder()
+            .name("ID=" + ThreadLocalRandom.current().nextLong())
+            .mimeMessage(mockedMimeMessage)
+            .addRecipients("test@james.apache.org", "test2@james.apache.org")
+            .build();
 
         SetMimeHeaderHandler header = new SetMimeHeaderHandler();
 
         header.setHeaderName(HEADER_NAME);
         header.setHeaderValue(HEADER_VALUE);
-        header.onMessage(mockedSMTPSession, mockedMail);
+        header.onMessage(mockedSMTPSession, mail);
 
-        assertThat(mockedMail.getMessage().getHeader(HEADER_NAME)[0]).isEqualTo(HEADER_VALUE);
-    }
-
-    private static Mail createMockMail2Recipients(MimeMessage m) throws MessagingException {
-        return FakeMail.builder()
-            .name("ID=" + ThreadLocalRandom.current().nextLong())
-            .mimeMessage(m)
-            .recipients("test@james.apache.org", "test2@james.apache.org")
-            .build();
+        assertThat(mail.getMessage().getHeader(HEADER_NAME)[0]).isEqualTo(HEADER_VALUE);
     }
 
 }


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


[james-project] 11/15: [Refactoring] refactor tests to actually test what's expected

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit e6f9d69d3e71b72cac922e5a9b68727c9e16edc3
Author: Matthieu Baechler <ma...@apache.org>
AuthorDate: Thu Nov 7 22:52:00 2019 +0100

    [Refactoring] refactor tests to actually test what's expected
---
 .../james/smtpserver/SetMimeHeaderHandlerTest.java | 26 +++++++++-------------
 1 file changed, 10 insertions(+), 16 deletions(-)

diff --git a/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SetMimeHeaderHandlerTest.java b/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SetMimeHeaderHandlerTest.java
index 73b5c7c..ba47a3d 100644
--- a/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SetMimeHeaderHandlerTest.java
+++ b/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SetMimeHeaderHandlerTest.java
@@ -29,7 +29,6 @@ import org.apache.james.core.builder.MimeMessageBuilder;
 import org.apache.james.protocols.smtp.SMTPSession;
 import org.apache.james.protocols.smtp.utils.BaseFakeSMTPSession;
 import org.apache.james.server.core.MailImpl;
-import org.apache.mailet.Mail;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -39,8 +38,6 @@ public class SetMimeHeaderHandlerTest {
     private static final String HEADER_VALUE = "test-value";
 
     private SMTPSession mockedSMTPSession;
-    private MimeMessage mimeMessage;
-    private Mail mail;
 
     @Before
     public void setUp() throws Exception {
@@ -57,56 +54,53 @@ public class SetMimeHeaderHandlerTest {
         };
     }
 
-    // test if the Header was add
     @Test
-    public void testHeaderIsPresent() throws MessagingException {
-        mimeMessage = MimeMessageBuilder.mimeMessageBuilder()
-            .addHeader(HEADER_NAME, HEADER_VALUE)
+    public void setMimeHeaderHandlerShouldAddSpecifiedHeader() throws MessagingException {
+        MimeMessage mimeMessage = MimeMessageBuilder.mimeMessageBuilder()
             .setSubject("testmail")
             .setText("testtext")
             .addToRecipient("test2@james.apache.org")
             .addFrom("test@james.apache.org")
             .build();
 
-        mail = MailImpl.builder()
+        MailImpl mail = MailImpl.builder()
             .name("ID=" + ThreadLocalRandom.current().nextLong())
             .mimeMessage(mimeMessage)
             .addRecipients("test@james.apache.org", "test2@james.apache.org")
             .build();
 
         SetMimeHeaderHandler header = new SetMimeHeaderHandler();
-
         header.setHeaderName(HEADER_NAME);
         header.setHeaderValue(HEADER_VALUE);
+
         header.onMessage(mockedSMTPSession, mail);
 
-        assertThat(mail.getMessage().getHeader(HEADER_NAME)[0]).isEqualTo(HEADER_VALUE);
+        assertThat(mail.getMessage().getHeader(HEADER_NAME)).containsOnly(HEADER_VALUE);
     }
 
-    // test if the Header was replaced
     @Test
-    public void testHeaderIsReplaced() throws MessagingException {
+    public void setMimeHeaderHandlerShouldReplaceSpecifiedHeader() throws MessagingException {
 
-        mimeMessage = MimeMessageBuilder.mimeMessageBuilder()
+        MimeMessage mimeMessage = MimeMessageBuilder.mimeMessageBuilder()
             .addHeader(HEADER_NAME, "defaultHeaderValue")
             .setSubject("testmail")
             .setText("testtext")
             .addToRecipient("test2@james.apache.org")
             .addFrom("test@james.apache.org")
             .build();
-        mail = MailImpl.builder()
+        MailImpl mail = MailImpl.builder()
             .name("ID=" + ThreadLocalRandom.current().nextLong())
             .mimeMessage(mimeMessage)
             .addRecipients("test@james.apache.org", "test2@james.apache.org")
             .build();
 
         SetMimeHeaderHandler header = new SetMimeHeaderHandler();
-
         header.setHeaderName(HEADER_NAME);
         header.setHeaderValue(HEADER_VALUE);
+
         header.onMessage(mockedSMTPSession, mail);
 
-        assertThat(mail.getMessage().getHeader(HEADER_NAME)[0]).isEqualTo(HEADER_VALUE);
+        assertThat(mail.getMessage().getHeader(HEADER_NAME)).containsOnly(HEADER_VALUE);
     }
 
 }


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


[james-project] 06/15: [Refactoring] CharsetUtils now only handle utf7, change it accordingly

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 853b846e1687306ccf95c99f4b89e307d28543a9
Author: Matthieu Baechler <ma...@apache.org>
AuthorDate: Thu Nov 7 22:15:18 2019 +0100

    [Refactoring] CharsetUtils now only handle utf7, change it accordingly
---
 .../{CharsetUtil.java => ModifiedUtf7.java}        | 31 +++++++++-------------
 .../james/imap/decode/ImapRequestLineReader.java   |  6 ++---
 .../james/imap/encode/ImapResponseComposer.java    |  4 +--
 .../imap/encode/base/ImapResponseComposerImpl.java |  4 +--
 .../apache/james/imap/processor/LSubProcessor.java |  6 ++---
 .../apache/james/imap/processor/ListProcessor.java |  8 +++---
 6 files changed, 27 insertions(+), 32 deletions(-)

diff --git a/protocols/imap/src/main/java/org/apache/james/imap/api/display/CharsetUtil.java b/protocols/imap/src/main/java/org/apache/james/imap/api/display/ModifiedUtf7.java
similarity index 71%
rename from protocols/imap/src/main/java/org/apache/james/imap/api/display/CharsetUtil.java
rename to protocols/imap/src/main/java/org/apache/james/imap/api/display/ModifiedUtf7.java
index 915716c..f132e87 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/api/display/CharsetUtil.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/api/display/ModifiedUtf7.java
@@ -24,36 +24,31 @@ import java.nio.charset.Charset;
 import com.beetstra.jutf7.CharsetProvider;
 
 /**
- * Utility class which can be used to get a list of supported {@link Charset}'s 
- * 
- * Beside this it has some methods included which helps to encode/decode modified UTF7
+ * This class has some methods included which helps to encode/decode modified UTF7
  */
-public class CharsetUtil {
+public class ModifiedUtf7 {
 
-    private static final String X_MODIFIED_UTF_7 = "X-MODIFIED-UTF-7";
-    private static final Charset X_MODIFIED_UTF_7_CHARSET = new CharsetProvider().charsetForName(X_MODIFIED_UTF_7);
+    private static final Charset X_MODIFIED_UTF_7_CHARSET = new CharsetProvider().charsetForName("X-MODIFIED-UTF-7");
 
     /**
      * Decode the given UTF7 encoded <code>String</code>
-     *
-     * @return decoded
+     * 
+     * @param input utf7-encoded value
+     * @return decoded value
      */
-    public static String decodeModifiedUTF7(String string) {
-        return X_MODIFIED_UTF_7_CHARSET.decode(ByteBuffer.wrap(string.getBytes())).toString();
-
+    public static String decodeModifiedUTF7(String input) {
+        return X_MODIFIED_UTF_7_CHARSET.decode(ByteBuffer.wrap(input.getBytes())).toString();
     }
-    
 
     /**
      * Encode the given <code>String</code> to modified UTF7. 
      * See RFC3501 for more details
-     *
-     * @return encoded
+     * 
+     * @param input
+     * @return utf7-encoded value
      */
-    
-    public static String encodeModifiedUTF7(String string) {
-        ByteBuffer encode = X_MODIFIED_UTF_7_CHARSET.encode(string);
+    public static String encodeModifiedUTF7(String input) {
+        ByteBuffer encode = X_MODIFIED_UTF_7_CHARSET.encode(input);
         return new String(encode.array(), 0, encode.remaining());
-
     }
 }
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java b/protocols/imap/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java
index 233d450..0981fa0 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java
@@ -35,8 +35,8 @@ import java.util.List;
 import javax.mail.Flags;
 
 import org.apache.james.imap.api.ImapConstants;
-import org.apache.james.imap.api.display.CharsetUtil;
 import org.apache.james.imap.api.display.HumanReadableText;
+import org.apache.james.imap.api.display.ModifiedUtf7;
 import org.apache.james.imap.api.message.IdRange;
 import org.apache.james.imap.api.message.UidRange;
 import org.apache.james.imap.api.message.request.DayMonthYear;
@@ -240,7 +240,7 @@ public abstract class ImapRequestLineReader {
 
     /**
      * 
-     * Reads the mailbox name via {@link #mailboxUTF7()} but also decode it via {@link CharsetUtil#decodeModifiedUTF7(String)}
+     * Reads the mailbox name via {@link #mailboxUTF7()} but also decode it via {@link ModifiedUtf7#decodeModifiedUTF7(String)}
      * 
      * If you really want to get the modified UTF7 version you should use {@link #mailboxUTF7()}
      * 
@@ -248,7 +248,7 @@ public abstract class ImapRequestLineReader {
      * 
      */
     public String mailbox() throws DecodingException {
-       return CharsetUtil.decodeModifiedUTF7(mailboxUTF7());
+       return ModifiedUtf7.decodeModifiedUTF7(mailboxUTF7());
     }
 
     /**
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/encode/ImapResponseComposer.java b/protocols/imap/src/main/java/org/apache/james/imap/encode/ImapResponseComposer.java
index 6df18b2..3018d2b 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/encode/ImapResponseComposer.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/encode/ImapResponseComposer.java
@@ -24,7 +24,7 @@ import java.io.IOException;
 import javax.mail.Flags;
 
 import org.apache.james.imap.api.ImapCommand;
-import org.apache.james.imap.api.display.CharsetUtil;
+import org.apache.james.imap.api.display.ModifiedUtf7;
 import org.apache.james.imap.api.message.IdRange;
 import org.apache.james.imap.api.message.UidRange;
 import org.apache.james.imap.message.response.Literal;
@@ -112,7 +112,7 @@ public interface ImapResponseComposer {
 
     /**
      * First encodes the given {@code mailboxName} using
-     * {@link CharsetUtil#encodeModifiedUTF7(String)} and then quotes the result
+     * {@link ModifiedUtf7#encodeModifiedUTF7(String)} and then quotes the result
      * with {@link #quote(String)}.
      * 
      * @param mailboxName
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/encode/base/ImapResponseComposerImpl.java b/protocols/imap/src/main/java/org/apache/james/imap/encode/base/ImapResponseComposerImpl.java
index ce7e575..b3a1e5d 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/encode/base/ImapResponseComposerImpl.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/encode/base/ImapResponseComposerImpl.java
@@ -26,7 +26,7 @@ import javax.mail.Flags;
 
 import org.apache.james.imap.api.ImapCommand;
 import org.apache.james.imap.api.ImapConstants;
-import org.apache.james.imap.api.display.CharsetUtil;
+import org.apache.james.imap.api.display.ModifiedUtf7;
 import org.apache.james.imap.api.message.IdRange;
 import org.apache.james.imap.api.message.UidRange;
 import org.apache.james.imap.encode.ImapResponseComposer;
@@ -237,7 +237,7 @@ public class ImapResponseComposerImpl implements ImapConstants, ImapResponseComp
     
     @Override
     public ImapResponseComposer mailbox(String mailboxName) throws IOException {
-        quote(CharsetUtil.encodeModifiedUTF7(mailboxName));
+        quote(ModifiedUtf7.encodeModifiedUTF7(mailboxName));
         return this;
     }
 
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/LSubProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/LSubProcessor.java
index 3befe65..a7a6115 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/LSubProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/LSubProcessor.java
@@ -25,8 +25,8 @@ import java.util.Collection;
 
 import org.apache.james.imap.api.ImapCommand;
 import org.apache.james.imap.api.ImapSessionUtils;
-import org.apache.james.imap.api.display.CharsetUtil;
 import org.apache.james.imap.api.display.HumanReadableText;
+import org.apache.james.imap.api.display.ModifiedUtf7;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapProcessor;
 import org.apache.james.imap.api.process.ImapSession;
@@ -71,11 +71,11 @@ public class LSubProcessor extends AbstractSubscriptionProcessor<LsubRequest> {
         MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
         Collection<String> mailboxes = getSubscriptionManager().subscriptions(mailboxSession);
 
-        String decodedMailName = CharsetUtil.decodeModifiedUTF7(referenceName);
+        String decodedMailName = ModifiedUtf7.decodeModifiedUTF7(referenceName);
 
         MailboxNameExpression expression = new PrefixedRegex(
             decodedMailName,
-            CharsetUtil.decodeModifiedUTF7(mailboxName),
+            ModifiedUtf7.decodeModifiedUTF7(mailboxName),
             mailboxSession.getPathDelimiter());
         Collection<String> mailboxResponses = new ArrayList<>();
 
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/ListProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/ListProcessor.java
index f1972bd..7170415 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/ListProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/ListProcessor.java
@@ -26,8 +26,8 @@ import java.util.List;
 import org.apache.james.imap.api.ImapCommand;
 import org.apache.james.imap.api.ImapMessage;
 import org.apache.james.imap.api.ImapSessionUtils;
-import org.apache.james.imap.api.display.CharsetUtil;
 import org.apache.james.imap.api.display.HumanReadableText;
+import org.apache.james.imap.api.display.ModifiedUtf7;
 import org.apache.james.imap.api.message.response.ImapResponseMessage;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapProcessor;
@@ -104,7 +104,7 @@ public class ListProcessor extends AbstractMailboxProcessor<ListRequest> {
                     } else {
                         referenceRoot = referenceName.substring(0, firstDelimiter);
                     }
-                    referenceRoot = CharsetUtil.decodeModifiedUTF7(referenceRoot);
+                    referenceRoot = ModifiedUtf7.decodeModifiedUTF7(referenceRoot);
                 } else {
                     // A relative reference name, return "" to indicate it is
                     // non-rooted
@@ -127,7 +127,7 @@ public class ListProcessor extends AbstractMailboxProcessor<ListRequest> {
                 // Is the interpreted (combined) pattern relative?
                 isRelative = ((finalReferencename + mailboxName).charAt(0) != MailboxConstants.NAMESPACE_PREFIX_CHAR);
 
-                finalReferencename = CharsetUtil.decodeModifiedUTF7(finalReferencename);
+                finalReferencename = ModifiedUtf7.decodeModifiedUTF7(finalReferencename);
 
                 MailboxPath basePath = null;
                 if (isRelative) {
@@ -141,7 +141,7 @@ public class ListProcessor extends AbstractMailboxProcessor<ListRequest> {
                             .userAndNamespaceFrom(basePath)
                             .expression(new PrefixedRegex(
                                 basePath.getName(),
-                                CharsetUtil.decodeModifiedUTF7(mailboxName),
+                                ModifiedUtf7.decodeModifiedUTF7(mailboxName),
                                 mailboxSession.getPathDelimiter()))
                             .build(), mailboxSession);
             }


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