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 ad...@apache.org on 2017/01/26 12:53:01 UTC

[07/13] james-project git commit: JAMES-1869: mailbox functions should limit the size of a mailbox name

JAMES-1869: mailbox functions should limit the size of a mailbox name


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/e9436237
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/e9436237
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/e9436237

Branch: refs/heads/master
Commit: e94362374f28c90bf582e78637ab96840ba49de5
Parents: ab03b63
Author: Quynh Nguyen <qn...@linagora.com>
Authored: Mon Dec 26 16:14:10 2016 +0700
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Thu Jan 26 12:58:22 2017 +0100

----------------------------------------------------------------------
 .../mailbox/exception/MailboxNameException.java |  35 +
 .../exception/TooLongMailboxNameException.java  |  35 +
 .../james/mailbox/model/MailboxConstants.java   |   1 -
 .../mailbox/store/StoreMailboxManager.java      |  11 +
 .../james/mpt/helper/ByteBufferInputStream.java |   2 +-
 .../mpt/imapmailbox/suite/SelectedInbox.java    |   5 +
 .../james/imap/scripts/CreateWithLongName.test  | 802 +++++++++++++++++++
 .../imap/api/display/HumanReadableText.java     |   2 +
 .../james/imap/processor/CreateProcessor.java   |   6 +
 .../james/imap/processor/DeleteProcessor.java   |   6 +
 .../james/imap/processor/RenameProcessor.java   |   6 +
 .../integration/SetMailboxesMethodTest.java     |  67 ++
 .../jmap/exceptions/MailboxNameException.java   |  27 -
 .../methods/SetMailboxesCreationProcessor.java  |  16 +-
 .../SetMailboxesDestructionProcessor.java       |  13 +-
 .../methods/SetMailboxesUpdateProcessor.java    |   8 +-
 16 files changed, 1004 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/e9436237/mailbox/api/src/main/java/org/apache/james/mailbox/exception/MailboxNameException.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/exception/MailboxNameException.java b/mailbox/api/src/main/java/org/apache/james/mailbox/exception/MailboxNameException.java
new file mode 100644
index 0000000..666d069
--- /dev/null
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/exception/MailboxNameException.java
@@ -0,0 +1,35 @@
+/****************************************************************
+ * 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.mailbox.exception;
+
+public class MailboxNameException extends MailboxException {
+    public MailboxNameException() {
+        super();
+    }
+
+    public MailboxNameException(String message) {
+        super(message);
+    }
+
+    public MailboxNameException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/e9436237/mailbox/api/src/main/java/org/apache/james/mailbox/exception/TooLongMailboxNameException.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/exception/TooLongMailboxNameException.java b/mailbox/api/src/main/java/org/apache/james/mailbox/exception/TooLongMailboxNameException.java
new file mode 100644
index 0000000..1055a07
--- /dev/null
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/exception/TooLongMailboxNameException.java
@@ -0,0 +1,35 @@
+/****************************************************************
+ * 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.mailbox.exception;
+
+public class TooLongMailboxNameException extends MailboxNameException {
+    public TooLongMailboxNameException() {
+        super();
+    }
+
+    public TooLongMailboxNameException(String message) {
+        super(message);
+    }
+
+    public TooLongMailboxNameException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/e9436237/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxConstants.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxConstants.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxConstants.java
index e146168..9e61e2a 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxConstants.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxConstants.java
@@ -45,5 +45,4 @@ public interface MailboxConstants {
 
     /** The maximum number of annotations on a mailbox */
     int DEFAULT_LIMIT_ANNOTATIONS_ON_MAILBOX = 10;
-
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/e9436237/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
index b4d83b4..67bb7ef 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
@@ -46,7 +46,9 @@ import org.apache.james.mailbox.exception.AnnotationException;
 import org.apache.james.mailbox.exception.BadCredentialsException;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.exception.MailboxExistsException;
+import org.apache.james.mailbox.exception.MailboxNameException;
 import org.apache.james.mailbox.exception.MailboxNotFoundException;
+import org.apache.james.mailbox.exception.TooLongMailboxNameException;
 import org.apache.james.mailbox.model.MailboxACL;
 import org.apache.james.mailbox.model.MailboxAnnotation;
 import org.apache.james.mailbox.model.MailboxAnnotationKey;
@@ -504,6 +506,7 @@ public class StoreMailboxManager implements MailboxManager {
         if (length == 0) {
             mailboxSession.getLog().warn("Ignoring mailbox with empty name");
         } else {
+            validateMailboxName(mailboxPath.getName());
             if (mailboxPath.getName().charAt(length - 1) == getDelimiter())
                 mailboxPath.setName(mailboxPath.getName().substring(0, length - 1));
             if (mailboxExists(mailboxPath, mailboxSession))
@@ -541,6 +544,7 @@ public class StoreMailboxManager implements MailboxManager {
     @Override
     public void deleteMailbox(final MailboxPath mailboxPath, final MailboxSession session) throws MailboxException {
         session.getLog().info("deleteMailbox " + mailboxPath);
+        validateMailboxName(mailboxPath.getName());
         final MailboxMapper mapper = mailboxSessionMapperFactory.getMailboxMapper(session);
 
         Mailbox mailbox = mapper.execute(new Mapper.Transaction<Mailbox>() {
@@ -569,6 +573,7 @@ public class StoreMailboxManager implements MailboxManager {
         final Logger log = session.getLog();
         if (log.isDebugEnabled())
             log.debug("renameMailbox " + from + " to " + to);
+        validateMailboxName(to.getName());
         if (mailboxExists(to, session)) {
             throw new MailboxExistsException(to.toString());
         }
@@ -909,4 +914,10 @@ public class StoreMailboxManager implements MailboxManager {
         Mailbox mailbox = mapper.findMailboxByPath(mailboxPath);
         return mapper.hasChildren(mailbox, session.getPathDelimiter());
     }
+
+    private void validateMailboxName(String mailboxName) throws MailboxNameException {
+        if (mailboxName.length() >= MailboxConstants.DEFAULT_LIMIT_MAILBOX_NAME_LENGTH) {
+            throw new TooLongMailboxNameException("too long mailbox name");
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/e9436237/mpt/core/src/main/java/org/apache/james/mpt/helper/ByteBufferInputStream.java
----------------------------------------------------------------------
diff --git a/mpt/core/src/main/java/org/apache/james/mpt/helper/ByteBufferInputStream.java b/mpt/core/src/main/java/org/apache/james/mpt/helper/ByteBufferInputStream.java
index 9223205..7848c46 100644
--- a/mpt/core/src/main/java/org/apache/james/mpt/helper/ByteBufferInputStream.java
+++ b/mpt/core/src/main/java/org/apache/james/mpt/helper/ByteBufferInputStream.java
@@ -28,7 +28,7 @@ import java.nio.charset.CharsetEncoder;
 
 
 public class ByteBufferInputStream extends InputStream {
-    private final ByteBuffer buffer = ByteBuffer.allocate(16384);
+    private final ByteBuffer buffer = ByteBuffer.allocate(160384);
 
     private final CharsetEncoder encoder = Charset.forName("ASCII").newEncoder();
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/e9436237/mpt/impl/imap-mailbox/core/src/main/java/org/apache/james/mpt/imapmailbox/suite/SelectedInbox.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/core/src/main/java/org/apache/james/mpt/imapmailbox/suite/SelectedInbox.java b/mpt/impl/imap-mailbox/core/src/main/java/org/apache/james/mpt/imapmailbox/suite/SelectedInbox.java
index c76d4be..82c822e 100644
--- a/mpt/impl/imap-mailbox/core/src/main/java/org/apache/james/mpt/imapmailbox/suite/SelectedInbox.java
+++ b/mpt/impl/imap-mailbox/core/src/main/java/org/apache/james/mpt/imapmailbox/suite/SelectedInbox.java
@@ -62,6 +62,11 @@ public class SelectedInbox extends BaseSelectedInbox {
     }
 
     @Test
+    public void testWithLongMailboxNameUS() throws Exception {
+        scriptTest("CreateWithLongName", Locale.US);
+    }
+
+    @Test
     public void testExamineEmptyUS() throws Exception {
         scriptTest("ExamineEmpty", Locale.US);
     }


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