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 bt...@apache.org on 2016/03/04 13:37:58 UTC
[01/20] james-project git commit: IMAP-370 Missing license
Repository: james-project
Updated Branches:
refs/heads/master 0af4d200f -> 8b970f59d
IMAP-370 Missing license
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/8a292171
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/8a292171
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/8a292171
Branch: refs/heads/master
Commit: 8a292171f63472ac362a8a3f980f62a01a56baa7
Parents: 0af4d20
Author: Benoit Tellier <bt...@linagora.com>
Authored: Wed Feb 24 16:57:45 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Fri Mar 4 19:32:17 2016 +0700
----------------------------------------------------------------------
.../james/imap/message/request/MoveRequest.java | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/8a292171/protocols/imap/src/main/java/org/apache/james/imap/message/request/MoveRequest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/message/request/MoveRequest.java b/protocols/imap/src/main/java/org/apache/james/imap/message/request/MoveRequest.java
index 3f5370f..9015ea0 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/message/request/MoveRequest.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/message/request/MoveRequest.java
@@ -1,3 +1,22 @@
+/****************************************************************
+ * 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.imap.message.request;
import org.apache.james.imap.api.ImapCommand;
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[03/20] james-project git commit: IMAP-370 Factorize code between
copies and moves
Posted by bt...@apache.org.
IMAP-370 Factorize code between copies and moves
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/b06992f1
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/b06992f1
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/b06992f1
Branch: refs/heads/master
Commit: b06992f18a09ca351d64880e37cc9ef7f13433d0
Parents: ea9d77d
Author: Benoit Tellier <bt...@linagora.com>
Authored: Wed Feb 24 12:09:53 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Fri Mar 4 19:33:23 2016 +0700
----------------------------------------------------------------------
.../james/mailbox/store/MessageBatcher.java | 57 ++++++++++++++++
.../mailbox/store/StoreMailboxManager.java | 57 +++++++---------
.../mailbox/store/StoreMessageManager.java | 39 ++++-------
.../james/mailbox/store/MessageBatcherTest.java | 71 ++++++++++++++++++++
4 files changed, 168 insertions(+), 56 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/b06992f1/mailbox/store/src/main/java/org/apache/james/mailbox/store/MessageBatcher.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/MessageBatcher.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/MessageBatcher.java
new file mode 100644
index 0000000..0631f02
--- /dev/null
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/MessageBatcher.java
@@ -0,0 +1,57 @@
+/****************************************************************
+ * 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.store;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.MessageRange;
+import org.apache.james.mailbox.store.mail.model.MailboxId;
+import org.msgpack.core.Preconditions;
+
+public class MessageBatcher {
+
+ public static final int NO_BATCH_SIZE = 0;
+
+ public interface BatchedOperation {
+ List<MessageRange> execute(MessageRange messageRange) throws MailboxException;
+ }
+
+ private final int moveBatchSize;
+
+ public MessageBatcher(int moveBatchSize) {
+ Preconditions.checkArgument(moveBatchSize >= NO_BATCH_SIZE);
+ this.moveBatchSize = moveBatchSize;
+ }
+
+ public List<MessageRange> batchMessages(MessageRange set, BatchedOperation batchedOperation) throws MailboxException {
+ if (moveBatchSize > 0) {
+ List<MessageRange> movedRanges = new ArrayList<MessageRange>();
+ for (MessageRange messageRange : set.split(moveBatchSize)) {
+ movedRanges.addAll(batchedOperation.execute(messageRange));
+ }
+ return movedRanges;
+ } else {
+ return batchedOperation.execute(set);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/b06992f1/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 7a2fda2..9262a87 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
@@ -21,7 +21,6 @@ package org.apache.james.mailbox.store;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Random;
@@ -99,9 +98,9 @@ public class StoreMailboxManager<Id extends MailboxId> implements MailboxManager
private final static Random RANDOM = new Random();
- private int copyBatchSize = 0;
+ private MessageBatcher copyBatcher;
- private int moveBatchSize = 0;
+ private MessageBatcher moveBatcher;
private final MailboxPathLocker locker;
@@ -148,11 +147,11 @@ public class StoreMailboxManager<Id extends MailboxId> implements MailboxManager
}
public void setCopyBatchSize(int copyBatchSize) {
- this.copyBatchSize = copyBatchSize;
+ this.copyBatcher = new MessageBatcher(copyBatchSize);
}
public void setMoveBatchSize(int moveBatchSize) {
- this.moveBatchSize = moveBatchSize;
+ this.moveBatcher = new MessageBatcher(moveBatchSize);
}
public void setFetchBatchSize(int fetchBatchSize) {
@@ -189,6 +188,12 @@ public class StoreMailboxManager<Id extends MailboxId> implements MailboxManager
if (quotaUpdater != null && quotaUpdater instanceof MailboxListener) {
this.addGlobalListener((MailboxListener) quotaUpdater, null);
}
+ if (copyBatcher == null) {
+ copyBatcher = new MessageBatcher(MessageBatcher.NO_BATCH_SIZE);
+ }
+ if (moveBatcher == null) {
+ moveBatcher = new MessageBatcher(MessageBatcher.NO_BATCH_SIZE);
+ }
}
/**
@@ -505,38 +510,28 @@ public class StoreMailboxManager<Id extends MailboxId> implements MailboxManager
@Override
@SuppressWarnings("unchecked")
- public List<MessageRange> copyMessages(MessageRange set, MailboxPath from, MailboxPath to, MailboxSession session) throws MailboxException {
- StoreMessageManager<Id> toMailbox = (StoreMessageManager<Id>) getMailbox(to, session);
- StoreMessageManager<Id> fromMailbox = (StoreMessageManager<Id>) getMailbox(from, session);
-
- if (copyBatchSize > 0) {
- List<MessageRange> copiedRanges = new ArrayList<MessageRange>();
- Iterator<MessageRange> ranges = set.split(copyBatchSize).iterator();
- while (ranges.hasNext()) {
- copiedRanges.addAll(fromMailbox.copyTo(ranges.next(), toMailbox, session));
+ public List<MessageRange> copyMessages(MessageRange set, MailboxPath from, MailboxPath to, final MailboxSession session) throws MailboxException {
+ final StoreMessageManager<Id> toMailbox = (StoreMessageManager<Id>) getMailbox(to, session);
+ final StoreMessageManager<Id> fromMailbox = (StoreMessageManager<Id>) getMailbox(from, session);
+
+ return copyBatcher.batchMessages(set, new MessageBatcher.BatchedOperation() {
+ public List<MessageRange> execute(MessageRange messageRange) throws MailboxException {
+ return fromMailbox.copyTo(messageRange, toMailbox, session);
}
- return copiedRanges;
- } else {
- return fromMailbox.copyTo(set, toMailbox, session);
- }
+ });
}
@Override
@SuppressWarnings("unchecked")
- public List<MessageRange> moveMessages(MessageRange set, MailboxPath from, MailboxPath to, MailboxSession session) throws MailboxException {
- StoreMessageManager<Id> toMailbox = (StoreMessageManager<Id>) getMailbox(to, session);
- StoreMessageManager<Id> fromMailbox = (StoreMessageManager<Id>) getMailbox(from, session);
-
- if (moveBatchSize > 0) {
- List<MessageRange> movedRanges = new ArrayList<MessageRange>();
- Iterator<MessageRange> ranges = set.split(moveBatchSize).iterator();
- while (ranges.hasNext()) {
- movedRanges.addAll(fromMailbox.moveTo(ranges.next(), toMailbox, session));
+ public List<MessageRange> moveMessages(MessageRange set, MailboxPath from, MailboxPath to, final MailboxSession session) throws MailboxException {
+ final StoreMessageManager<Id> toMailbox = (StoreMessageManager<Id>) getMailbox(to, session);
+ final StoreMessageManager<Id> fromMailbox = (StoreMessageManager<Id>) getMailbox(from, session);
+
+ return moveBatcher.batchMessages(set, new MessageBatcher.BatchedOperation() {
+ public List<MessageRange> execute(MessageRange messageRange) throws MailboxException {
+ return fromMailbox.moveTo(messageRange, toMailbox, session);
}
- return movedRanges;
- } else {
- return fromMailbox.moveTo(set, toMailbox, session);
- }
+ });
}
@Override
http://git-wip-us.apache.org/repos/asf/james-project/blob/b06992f1/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
index 9005d89..f0098c3 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
@@ -51,6 +51,7 @@ import org.apache.james.mailbox.exception.ReadOnlyException;
import org.apache.james.mailbox.exception.UnsupportedRightException;
import org.apache.james.mailbox.model.MailboxACL;
import org.apache.james.mailbox.model.MailboxACL.MailboxACLRights;
+import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.model.MessageMetaData;
import org.apache.james.mailbox.model.MessageRange;
import org.apache.james.mailbox.model.MessageResult.FetchGroup;
@@ -735,41 +736,29 @@ public class StoreMessageManager<Id extends MailboxId> implements org.apache.jam
}
- /**
- * @see org.apache.james.mailbox.store.AbstractStoreMessageManager#copy(org.apache.james.mailbox.model.MessageRange,
- * org.apache.james.mailbox.store.AbstractStoreMessageManager,
- * org.apache.james.mailbox.MailboxSession)
- */
private SortedMap<Long, MessageMetaData> copy(MessageRange set, StoreMessageManager<Id> to, MailboxSession session) throws MailboxException {
+ Iterator<MailboxMessage<Id>> originalRows = retrieveOriginalRows(set, session);
+ return collectMetadata(to.copy(originalRows, session));
+ }
+
+ private SortedMap<Long, MessageMetaData> move(MessageRange set, StoreMessageManager<Id> to, MailboxSession session) throws MailboxException {
+ Iterator<MailboxMessage<Id>> originalRows = retrieveOriginalRows(set, session);
+ return collectMetadata(to.move(originalRows, session));
+ }
+
+ private Iterator<MailboxMessage<Id>> retrieveOriginalRows(MessageRange set, MailboxSession session) throws MailboxException {
MessageMapper<Id> messageMapper = mapperFactory.getMessageMapper(session);
+ return messageMapper.findInMailbox(mailbox, set, FetchType.Full, -1);
+ }
+ private SortedMap<Long, MessageMetaData> collectMetadata(Iterator<MessageMetaData> ids) {
final SortedMap<Long, MessageMetaData> copiedMessages = new TreeMap<Long, MessageMetaData>();
- Iterator<MailboxMessage<Id>> originalRows = messageMapper.findInMailbox(mailbox, set, FetchType.Full, -1);
- Iterator<MessageMetaData> ids = to.copy(originalRows, session);
while (ids.hasNext()) {
MessageMetaData data = ids.next();
copiedMessages.put(data.getUid(), data);
}
-
return copiedMessages;
}
-
- private SortedMap<Long, MessageMetaData> move(MessageRange set,
- final StoreMessageManager<Id> to, MailboxSession session) throws MailboxException {
- MessageMapper<Id> messageMapper = mapperFactory.getMessageMapper(session);
-
- final SortedMap<Long, MessageMetaData> movedMessages = new TreeMap<Long, MessageMetaData>();
- Iterator<MailboxMessage<Id>> originalRows = messageMapper.findInMailbox(mailbox, set, FetchType.Full, -1);
- Iterator<MessageMetaData> ids = to.move(originalRows, session);
- while (ids.hasNext()) {
- MessageMetaData data = ids.next();
- movedMessages.put(data.getUid(), data);
- }
-
- return movedMessages;
- }
-
-
/**
* Return the count of unseen messages
*
http://git-wip-us.apache.org/repos/asf/james-project/blob/b06992f1/mailbox/store/src/test/java/org/apache/james/mailbox/store/MessageBatcherTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/MessageBatcherTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/MessageBatcherTest.java
new file mode 100644
index 0000000..7de44ee
--- /dev/null
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/MessageBatcherTest.java
@@ -0,0 +1,71 @@
+/****************************************************************
+ * 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.store;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.List;
+
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.MessageRange;
+import org.junit.Test;
+
+import com.google.common.collect.Lists;
+
+public class MessageBatcherTest {
+
+ private MessageBatcher.BatchedOperation incrementBatcher = new MessageBatcher.BatchedOperation() {
+ @Override
+ public List<MessageRange> execute(MessageRange messageRange) throws MailboxException {
+ return Lists.<MessageRange>newArrayList(MessageRange.range(messageRange.getUidFrom() + 1, messageRange.getUidTo() + 1));
+ }
+ };
+
+ @Test
+ public void batchMessagesShouldWorkOnSingleRangeMode() throws Exception {
+ MessageBatcher messageBatcher = new MessageBatcher(0);
+
+ assertThat(messageBatcher.batchMessages(MessageRange.range(1, 10), incrementBatcher)).containsOnly(MessageRange.range(2, 11));
+ }
+
+ @Test
+ public void batchMessagesShouldWorkWithNonZeroBatchedSize() throws Exception {
+ MessageBatcher messageBatcher = new MessageBatcher(5);
+
+ assertThat(messageBatcher.batchMessages(MessageRange.range(1, 10), incrementBatcher)).containsOnly(MessageRange.range(2, 6), MessageRange.range(7, 11));
+ }
+
+ @Test(expected = MailboxException.class)
+ public void batchMessagesShouldPropagateExceptions() throws Exception {
+ MessageBatcher messageBatcher = new MessageBatcher(0);
+
+ messageBatcher.batchMessages(MessageRange.range(1, 10), new MessageBatcher.BatchedOperation() {
+ public List<MessageRange> execute(MessageRange messageRange) throws MailboxException {
+ throw new MailboxException();
+ }
+ });
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void messageBatcherShouldThrowOnNegativeBatchSize() throws Exception {
+ MessageBatcher messageBatcher = new MessageBatcher(-1);
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[07/20] james-project git commit: MAILBOX-265 Cassandra Message
Mapper should take Body fetch Type into account
Posted by bt...@apache.org.
MAILBOX-265 Cassandra Message Mapper should take Body fetch Type into account
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/fb4a3ec3
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/fb4a3ec3
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/fb4a3ec3
Branch: refs/heads/master
Commit: fb4a3ec303693d95403118ac9b284d1f61a5b561
Parents: 16cbae9
Author: Benoit Tellier <bt...@linagora.com>
Authored: Thu Mar 3 13:47:47 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Fri Mar 4 19:35:24 2016 +0700
----------------------------------------------------------------------
.../mailbox/cassandra/mail/CassandraMessageMapper.java | 11 +++++++++--
.../cassandra/modules/CassandraMessageModule.java | 4 ++--
.../mailbox/cassandra/table/CassandraMessageTable.java | 1 +
3 files changed, 12 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/fb4a3ec3/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
index a401b90..7f9bbc4 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
@@ -28,6 +28,7 @@ import static com.datastax.driver.core.querybuilder.QueryBuilder.lte;
import static com.datastax.driver.core.querybuilder.QueryBuilder.select;
import static com.datastax.driver.core.querybuilder.QueryBuilder.set;
import static com.datastax.driver.core.querybuilder.QueryBuilder.update;
+import static org.apache.james.mailbox.cassandra.table.CassandraMessageTable.BODY;
import static org.apache.james.mailbox.cassandra.table.CassandraMessageTable.BODY_CONTENT;
import static org.apache.james.mailbox.cassandra.table.CassandraMessageTable.BODY_OCTECTS;
import static org.apache.james.mailbox.cassandra.table.CassandraMessageTable.BODY_START_OCTET;
@@ -277,7 +278,7 @@ public class CassandraMessageMapper implements MessageMapper<CassandraId> {
SimpleMailboxMessage<CassandraId> message =
new SimpleMailboxMessage<>(
row.getDate(INTERNAL_DATE),
- row.getInt(FULL_CONTENT_OCTETS),
+ row.getLong(FULL_CONTENT_OCTETS),
row.getInt(BODY_START_OCTET),
buildContent(row, fetchType),
getFlags(row),
@@ -469,6 +470,7 @@ public class CassandraMessageMapper implements MessageMapper<CassandraId> {
private String[] retrieveFields(FetchType fetchType) {
switch (fetchType) {
case Body:
+ return BODY;
case Full:
return FIELDS;
case Headers:
@@ -483,10 +485,11 @@ public class CassandraMessageMapper implements MessageMapper<CassandraId> {
private SharedByteArrayInputStream buildContent(Row row, FetchType fetchType) {
switch (fetchType) {
case Full:
- case Body:
return new SharedByteArrayInputStream(getFullContent(row));
case Headers:
return new SharedByteArrayInputStream(getFieldContent(HEADER_CONTENT, row));
+ case Body:
+ return new SharedByteArrayInputStream(getBodyContent(row));
case Metadata:
return new SharedByteArrayInputStream(new byte[]{});
default:
@@ -498,6 +501,10 @@ public class CassandraMessageMapper implements MessageMapper<CassandraId> {
return Bytes.concat(getFieldContent(HEADER_CONTENT, row), getFieldContent(BODY_CONTENT, row));
}
+ private byte[] getBodyContent(Row row) {
+ return Bytes.concat(new byte[row.getInt(BODY_START_OCTET)], getFieldContent(BODY_CONTENT, row));
+ }
+
private byte[] getFieldContent(String field, Row row) {
byte[] headerContent = new byte[row.getBytes(field).remaining()];
row.getBytes(field).get(headerContent);
http://git-wip-us.apache.org/repos/asf/james-project/blob/fb4a3ec3/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/modules/CassandraMessageModule.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/modules/CassandraMessageModule.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/modules/CassandraMessageModule.java
index febfba0..d401782 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/modules/CassandraMessageModule.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/modules/CassandraMessageModule.java
@@ -54,10 +54,10 @@ public class CassandraMessageModule implements CassandraModule {
.addClusteringColumn(CassandraMessageTable.IMAP_UID, bigint())
.addColumn(CassandraMessageTable.INTERNAL_DATE, timestamp())
.addColumn(CassandraMessageTable.BODY_START_OCTET, cint())
- .addColumn(CassandraMessageTable.BODY_OCTECTS, cint())
+ .addColumn(CassandraMessageTable.BODY_OCTECTS, bigint())
.addColumn(CassandraMessageTable.TEXTUAL_LINE_COUNT, bigint())
.addColumn(CassandraMessageTable.MOD_SEQ, bigint())
- .addColumn(CassandraMessageTable.FULL_CONTENT_OCTETS, cint())
+ .addColumn(CassandraMessageTable.FULL_CONTENT_OCTETS, bigint())
.addColumn(CassandraMessageTable.BODY_CONTENT, blob())
.addColumn(CassandraMessageTable.HEADER_CONTENT, blob())
.addColumn(CassandraMessageTable.Flag.ANSWERED, cboolean())
http://git-wip-us.apache.org/repos/asf/james-project/blob/fb4a3ec3/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/table/CassandraMessageTable.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/table/CassandraMessageTable.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/table/CassandraMessageTable.java
index aaf3692..446ca50 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/table/CassandraMessageTable.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/table/CassandraMessageTable.java
@@ -41,6 +41,7 @@ public interface CassandraMessageTable {
String[] FIELDS = { MAILBOX_ID, IMAP_UID, INTERNAL_DATE, MOD_SEQ, BODY_START_OCTET, FULL_CONTENT_OCTETS, BODY_OCTECTS, Flag.ANSWERED, Flag.DELETED, Flag.DRAFT, Flag.FLAGGED, Flag.RECENT, Flag.SEEN, Flag.USER, Flag.USER_FLAGS, BODY_CONTENT, HEADER_CONTENT, TEXTUAL_LINE_COUNT, PROPERTIES };
String[] METADATA = { MAILBOX_ID, IMAP_UID, INTERNAL_DATE, MOD_SEQ, BODY_START_OCTET, FULL_CONTENT_OCTETS, BODY_OCTECTS, Flag.ANSWERED, Flag.DELETED, Flag.DRAFT, Flag.FLAGGED, Flag.RECENT, Flag.SEEN, Flag.USER, Flag.USER_FLAGS, TEXTUAL_LINE_COUNT, PROPERTIES };
String[] HEADERS = { MAILBOX_ID, IMAP_UID, INTERNAL_DATE, MOD_SEQ, BODY_START_OCTET, FULL_CONTENT_OCTETS, BODY_OCTECTS, Flag.ANSWERED, Flag.DELETED, Flag.DRAFT, Flag.FLAGGED, Flag.RECENT, Flag.SEEN, Flag.USER, Flag.USER_FLAGS, HEADER_CONTENT, TEXTUAL_LINE_COUNT, PROPERTIES };
+ String[] BODY = { MAILBOX_ID, IMAP_UID, INTERNAL_DATE, MOD_SEQ, BODY_START_OCTET, FULL_CONTENT_OCTETS, BODY_OCTECTS, Flag.ANSWERED, Flag.DELETED, Flag.DRAFT, Flag.FLAGGED, Flag.RECENT, Flag.SEEN, Flag.USER, Flag.USER_FLAGS, BODY_CONTENT, TEXTUAL_LINE_COUNT, PROPERTIES };
interface Flag {
String ANSWERED = "flagAnswered";
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[16/20] james-project git commit: MAILBOX-265 Cassandra Message
Mapper should take Headers and Metadata fetch Type into account
Posted by bt...@apache.org.
MAILBOX-265 Cassandra Message Mapper should take Headers and Metadata fetch Type into account
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/7a86fe1a
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/7a86fe1a
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/7a86fe1a
Branch: refs/heads/master
Commit: 7a86fe1a7250fa05c658cf817190c2eff7e83c1f
Parents: 6a90560
Author: Benoit Tellier <bt...@linagora.com>
Authored: Thu Mar 3 11:52:26 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Fri Mar 4 19:35:24 2016 +0700
----------------------------------------------------------------------
.../cassandra/mail/CassandraMessageMapper.java | 103 +++++++++++++------
.../cassandra/table/CassandraMessageTable.java | 3 +
2 files changed, 72 insertions(+), 34 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/7a86fe1a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
index e001839..a401b90 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
@@ -33,10 +33,12 @@ import static org.apache.james.mailbox.cassandra.table.CassandraMessageTable.BOD
import static org.apache.james.mailbox.cassandra.table.CassandraMessageTable.BODY_START_OCTET;
import static org.apache.james.mailbox.cassandra.table.CassandraMessageTable.FIELDS;
import static org.apache.james.mailbox.cassandra.table.CassandraMessageTable.FULL_CONTENT_OCTETS;
+import static org.apache.james.mailbox.cassandra.table.CassandraMessageTable.HEADERS;
import static org.apache.james.mailbox.cassandra.table.CassandraMessageTable.HEADER_CONTENT;
import static org.apache.james.mailbox.cassandra.table.CassandraMessageTable.IMAP_UID;
import static org.apache.james.mailbox.cassandra.table.CassandraMessageTable.INTERNAL_DATE;
import static org.apache.james.mailbox.cassandra.table.CassandraMessageTable.MAILBOX_ID;
+import static org.apache.james.mailbox.cassandra.table.CassandraMessageTable.METADATA;
import static org.apache.james.mailbox.cassandra.table.CassandraMessageTable.MOD_SEQ;
import static org.apache.james.mailbox.cassandra.table.CassandraMessageTable.PROPERTIES;
import static org.apache.james.mailbox.cassandra.table.CassandraMessageTable.TABLE_NAME;
@@ -164,15 +166,15 @@ public class CassandraMessageMapper implements MessageMapper<CassandraId> {
@Override
public Iterator<MailboxMessage<CassandraId>> findInMailbox(Mailbox<CassandraId> mailbox, MessageRange set, FetchType ftype, int max) throws MailboxException {
- return CassandraUtils.convertToStream(session.execute(buildQuery(mailbox, set)))
- .map(this::message)
+ return CassandraUtils.convertToStream(session.execute(buildQuery(mailbox, set, ftype)))
+ .map(row -> message(row, ftype))
.sorted(Comparator.comparingLong(MailboxMessage::getUid))
.iterator();
}
@Override
public List<Long> findRecentMessageUidsInMailbox(Mailbox<CassandraId> mailbox) throws MailboxException {
- return CassandraUtils.convertToStream(session.execute(selectAll(mailbox).and((eq(RECENT, true)))))
+ return CassandraUtils.convertToStream(session.execute(selectAll(mailbox, FetchType.Metadata).and((eq(RECENT, true)))))
.map((row) -> row.getLong(IMAP_UID))
.sorted()
.collect(Collectors.toList());
@@ -180,7 +182,7 @@ public class CassandraMessageMapper implements MessageMapper<CassandraId> {
@Override
public Long findFirstUnseenMessageUid(Mailbox<CassandraId> mailbox) throws MailboxException {
- return CassandraUtils.convertToStream(session.execute(selectAll(mailbox).and((eq(SEEN, false)))))
+ return CassandraUtils.convertToStream(session.execute(selectAll(mailbox, FetchType.Metadata).and((eq(SEEN, false)))))
.map((row) -> row.getLong(IMAP_UID))
.sorted()
.findFirst()
@@ -189,8 +191,8 @@ public class CassandraMessageMapper implements MessageMapper<CassandraId> {
@Override
public Map<Long, MessageMetaData> expungeMarkedForDeletionInMailbox(Mailbox<CassandraId> mailbox, MessageRange set) throws MailboxException {
- return CassandraUtils.convertToStream(session.execute(buildQuery(mailbox, set).and(eq(DELETED, true))))
- .map(this::message)
+ return CassandraUtils.convertToStream(session.execute(buildQuery(mailbox, set, FetchType.Metadata).and(eq(DELETED, true))))
+ .map(row -> message(row, FetchType.Metadata))
.peek((message) -> delete(mailbox, message))
.collect(Collectors.toMap(MailboxMessage::getUid, SimpleMessageMetaData::new));
}
@@ -226,7 +228,7 @@ public class CassandraMessageMapper implements MessageMapper<CassandraId> {
@Override
public Iterator<UpdatedFlags> updateFlags(Mailbox<CassandraId> mailbox, FlagsUpdateCalculator flagUpdateCalculator, MessageRange set) throws MailboxException {
- return CassandraUtils.convertToStream(session.execute(buildQuery(mailbox, set)))
+ return CassandraUtils.convertToStream(session.execute(buildQuery(mailbox, set, FetchType.Metadata)))
.map((row) -> updateFlagsOnMessage(mailbox, flagUpdateCalculator, row))
.filter(Optional::isPresent)
.map(Optional::get)
@@ -271,13 +273,13 @@ public class CassandraMessageMapper implements MessageMapper<CassandraId> {
session.execute(update(CassandraMailboxCountersTable.TABLE_NAME).with(operation).where(eq(CassandraMailboxCountersTable.MAILBOX_ID, mailboxId.asUuid())));
}
- private MailboxMessage<CassandraId> message(Row row) {
+ private MailboxMessage<CassandraId> message(Row row, FetchType fetchType) {
SimpleMailboxMessage<CassandraId> message =
new SimpleMailboxMessage<>(
row.getDate(INTERNAL_DATE),
row.getInt(FULL_CONTENT_OCTETS),
row.getInt(BODY_START_OCTET),
- new SharedByteArrayInputStream(getFullContent(row)),
+ buildContent(row, fetchType),
getFlags(row),
getPropertyBuilder(row),
CassandraId.of(row.getUUID(MAILBOX_ID)));
@@ -286,14 +288,6 @@ public class CassandraMessageMapper implements MessageMapper<CassandraId> {
return message;
}
- private byte[] getFullContent(Row row) {
- byte[] headerContent = new byte[row.getBytes(HEADER_CONTENT).remaining()];
- byte[] bodyContent = new byte[row.getBytes(BODY_CONTENT).remaining()];
- row.getBytes(HEADER_CONTENT).get(headerContent);
- row.getBytes(BODY_CONTENT).get(bodyContent);
- return Bytes.concat(headerContent, bodyContent);
- }
-
private Flags getFlags(Row row) {
Flags flags = new Flags();
for (String flag : CassandraMessageTable.Flag.ALL) {
@@ -365,7 +359,7 @@ public class CassandraMessageMapper implements MessageMapper<CassandraId> {
}
private Optional<UpdatedFlags> updateFlagsOnMessage(Mailbox<CassandraId> mailbox, FlagsUpdateCalculator flagUpdateCalculator, Row row) {
- return tryMessageFlagsUpdate(flagUpdateCalculator, mailbox, message(row))
+ return tryMessageFlagsUpdate(flagUpdateCalculator, mailbox, message(row, FetchType.Metadata))
.map(Optional::of)
.orElse(handleRetries(mailbox, flagUpdateCalculator, row.getLong(IMAP_UID)));
}
@@ -401,7 +395,11 @@ public class CassandraMessageMapper implements MessageMapper<CassandraId> {
}
private Optional<UpdatedFlags> retryMessageFlagsUpdate(Mailbox<CassandraId> mailbox, long uid, FlagsUpdateCalculator flagUpdateCalculator) {
- return tryMessageFlagsUpdate(flagUpdateCalculator, mailbox, message(Optional.ofNullable(session.execute(selectMessage(mailbox, uid)).one()).orElseThrow(() -> new MessageDeletedDuringFlagsUpdateException(mailbox.getMailboxId(), uid))));
+ return tryMessageFlagsUpdate(flagUpdateCalculator,
+ mailbox,
+ message(Optional.ofNullable(session.execute(selectMessage(mailbox, uid, FetchType.Metadata)).one())
+ .orElseThrow(() -> new MessageDeletedDuringFlagsUpdateException(mailbox.getMailboxId(), uid)),
+ FetchType.Metadata));
}
private boolean conditionalSave(MailboxMessage<CassandraId> message, long oldModSeq) {
@@ -426,47 +424,84 @@ public class CassandraMessageMapper implements MessageMapper<CassandraId> {
return ByteBuffer.wrap(ByteStreams.toByteArray(stream));
}
- private Where buildQuery(Mailbox<CassandraId> mailbox, MessageRange set) {
- final MessageRange.Type type = set.getType();
- switch (type) {
+ private Where buildQuery(Mailbox<CassandraId> mailbox, MessageRange set, FetchType fetchType) {
+ switch (set.getType()) {
case ALL:
- return selectAll(mailbox);
+ return selectAll(mailbox, fetchType);
case FROM:
- return selectFrom(mailbox, set.getUidFrom());
+ return selectFrom(mailbox, set.getUidFrom(), fetchType);
case RANGE:
- return selectRange(mailbox, set.getUidFrom(), set.getUidTo());
+ return selectRange(mailbox, set.getUidFrom(), set.getUidTo(), fetchType);
case ONE:
- return selectMessage(mailbox, set.getUidFrom());
+ return selectMessage(mailbox, set.getUidFrom(), fetchType);
}
throw new UnsupportedOperationException();
}
- private Where selectAll(Mailbox<CassandraId> mailbox) {
- return select(FIELDS)
+ private Where selectAll(Mailbox<CassandraId> mailbox, FetchType fetchType) {
+ return select(retrieveFields(fetchType))
.from(TABLE_NAME)
.where(eq(MAILBOX_ID, mailbox.getMailboxId().asUuid()));
}
- private Where selectFrom(Mailbox<CassandraId> mailbox, long uid) {
- return select(FIELDS)
+ private Where selectFrom(Mailbox<CassandraId> mailbox, long uid, FetchType fetchType) {
+ return select(retrieveFields(fetchType))
.from(TABLE_NAME)
.where(eq(MAILBOX_ID, mailbox.getMailboxId().asUuid()))
.and(gte(IMAP_UID, uid));
}
- private Where selectRange(Mailbox<CassandraId> mailbox, long from, long to) {
- return select(FIELDS)
+ private Where selectRange(Mailbox<CassandraId> mailbox, long from, long to, FetchType fetchType) {
+ return select(retrieveFields(fetchType))
.from(TABLE_NAME)
.where(eq(MAILBOX_ID, mailbox.getMailboxId().asUuid()))
.and(gte(IMAP_UID, from))
.and(lte(IMAP_UID, to));
}
- private Where selectMessage(Mailbox<CassandraId> mailbox, long uid) {
- return select(FIELDS)
+ private Where selectMessage(Mailbox<CassandraId> mailbox, long uid, FetchType fetchType) {
+ return select(retrieveFields(fetchType))
.from(TABLE_NAME)
.where(eq(MAILBOX_ID, mailbox.getMailboxId().asUuid()))
.and(eq(IMAP_UID, uid));
}
+ private String[] retrieveFields(FetchType fetchType) {
+ switch (fetchType) {
+ case Body:
+ case Full:
+ return FIELDS;
+ case Headers:
+ return HEADERS;
+ case Metadata:
+ return METADATA;
+ default:
+ throw new RuntimeException("Unknown FetchType " + fetchType);
+ }
+ }
+
+ private SharedByteArrayInputStream buildContent(Row row, FetchType fetchType) {
+ switch (fetchType) {
+ case Full:
+ case Body:
+ return new SharedByteArrayInputStream(getFullContent(row));
+ case Headers:
+ return new SharedByteArrayInputStream(getFieldContent(HEADER_CONTENT, row));
+ case Metadata:
+ return new SharedByteArrayInputStream(new byte[]{});
+ default:
+ throw new RuntimeException("Unknown FetchType " + fetchType);
+ }
+ }
+
+ private byte[] getFullContent(Row row) {
+ return Bytes.concat(getFieldContent(HEADER_CONTENT, row), getFieldContent(BODY_CONTENT, row));
+ }
+
+ private byte[] getFieldContent(String field, Row row) {
+ byte[] headerContent = new byte[row.getBytes(field).remaining()];
+ row.getBytes(field).get(headerContent);
+ return headerContent;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/7a86fe1a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/table/CassandraMessageTable.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/table/CassandraMessageTable.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/table/CassandraMessageTable.java
index b1829ba..aaf3692 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/table/CassandraMessageTable.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/table/CassandraMessageTable.java
@@ -37,7 +37,10 @@ public interface CassandraMessageTable {
String BODY_CONTENT = "bodyContent";
String HEADER_CONTENT = "headerContent";
String PROPERTIES = "properties";
+
String[] FIELDS = { MAILBOX_ID, IMAP_UID, INTERNAL_DATE, MOD_SEQ, BODY_START_OCTET, FULL_CONTENT_OCTETS, BODY_OCTECTS, Flag.ANSWERED, Flag.DELETED, Flag.DRAFT, Flag.FLAGGED, Flag.RECENT, Flag.SEEN, Flag.USER, Flag.USER_FLAGS, BODY_CONTENT, HEADER_CONTENT, TEXTUAL_LINE_COUNT, PROPERTIES };
+ String[] METADATA = { MAILBOX_ID, IMAP_UID, INTERNAL_DATE, MOD_SEQ, BODY_START_OCTET, FULL_CONTENT_OCTETS, BODY_OCTECTS, Flag.ANSWERED, Flag.DELETED, Flag.DRAFT, Flag.FLAGGED, Flag.RECENT, Flag.SEEN, Flag.USER, Flag.USER_FLAGS, TEXTUAL_LINE_COUNT, PROPERTIES };
+ String[] HEADERS = { MAILBOX_ID, IMAP_UID, INTERNAL_DATE, MOD_SEQ, BODY_START_OCTET, FULL_CONTENT_OCTETS, BODY_OCTECTS, Flag.ANSWERED, Flag.DELETED, Flag.DRAFT, Flag.FLAGGED, Flag.RECENT, Flag.SEEN, Flag.USER, Flag.USER_FLAGS, HEADER_CONTENT, TEXTUAL_LINE_COUNT, PROPERTIES };
interface Flag {
String ANSWERED = "flagAnswered";
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[11/20] james-project git commit: IMAP-370 Add MPT checks for MOVE
command
Posted by bt...@apache.org.
IMAP-370 Add MPT checks for MOVE command
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/7958d56f
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/7958d56f
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/7958d56f
Branch: refs/heads/master
Commit: 7958d56f2eab83795fb9367fe1019f6d05ea9e3c
Parents: 53755c7
Author: Benoit Tellier <bt...@linagora.com>
Authored: Thu Feb 25 10:26:29 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Fri Mar 4 19:35:24 2016 +0700
----------------------------------------------------------------------
.../cassandra/CassandraMailboxTest.java | 4 +-
.../james/mpt/imapmailbox/suite/Move.java | 44 +++++++++++++
.../org/apache/james/imap/scripts/Move.test | 69 ++++++++++++++++++++
3 files changed, 116 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/7958d56f/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraMailboxTest.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraMailboxTest.java b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraMailboxTest.java
index da7ce09..643c9c6 100644
--- a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraMailboxTest.java
+++ b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraMailboxTest.java
@@ -28,6 +28,7 @@ import org.apache.james.mpt.imapmailbox.suite.FetchBodySection;
import org.apache.james.mpt.imapmailbox.suite.FetchBodyStructure;
import org.apache.james.mpt.imapmailbox.suite.FetchHeaders;
import org.apache.james.mpt.imapmailbox.suite.Listing;
+import org.apache.james.mpt.imapmailbox.suite.Move;
import org.apache.james.mpt.imapmailbox.suite.NonAuthenticatedState;
import org.apache.james.mpt.imapmailbox.suite.PartialFetch;
import org.apache.james.mpt.imapmailbox.suite.QuotaTest;
@@ -65,7 +66,8 @@ import org.junit.runners.Suite;
SelectedState.class,
UidSearch.class,
UserFlagsSupport.class,
- QuotaTest.class
+ QuotaTest.class,
+ Move.class
})
@GuiceModules({ CassandraMailboxTestModule.class })
public class CassandraMailboxTest {
http://git-wip-us.apache.org/repos/asf/james-project/blob/7958d56f/mpt/impl/imap-mailbox/core/src/main/java/org/apache/james/mpt/imapmailbox/suite/Move.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/core/src/main/java/org/apache/james/mpt/imapmailbox/suite/Move.java b/mpt/impl/imap-mailbox/core/src/main/java/org/apache/james/mpt/imapmailbox/suite/Move.java
new file mode 100644
index 0000000..489b148
--- /dev/null
+++ b/mpt/impl/imap-mailbox/core/src/main/java/org/apache/james/mpt/imapmailbox/suite/Move.java
@@ -0,0 +1,44 @@
+/****************************************************************
+ * 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.mpt.imapmailbox.suite;
+
+import java.util.Locale;
+
+import javax.inject.Inject;
+
+import org.apache.james.mpt.api.HostSystem;
+import org.apache.james.mpt.imapmailbox.suite.base.BaseSelectedState;
+import org.junit.Test;
+
+public class Move extends BaseSelectedState {
+
+ @Inject
+ private static HostSystem system;
+
+ public Move() throws Exception {
+ super(system);
+ }
+
+ @Test
+ public void moveShouldWork() throws Exception {
+ scriptTest("Move", Locale.US);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/7958d56f/mpt/impl/imap-mailbox/core/src/main/resources/org/apache/james/imap/scripts/Move.test
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/core/src/main/resources/org/apache/james/imap/scripts/Move.test b/mpt/impl/imap-mailbox/core/src/main/resources/org/apache/james/imap/scripts/Move.test
new file mode 100644
index 0000000..ade2415
--- /dev/null
+++ b/mpt/impl/imap-mailbox/core/src/main/resources/org/apache/james/imap/scripts/Move.test
@@ -0,0 +1,69 @@
+################################################################
+# 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. #
+################################################################
+C: a1 CREATE moved
+S: a1 OK CREATE completed.
+
+C: a2 STATUS moved (MESSAGES)
+S: \* STATUS "moved" \(MESSAGES 0\)
+S: a2 OK STATUS completed.
+
+# mark one message as deleted before moving it (to check that flags are moved)
+C: a3 STORE 3 FLAGS (\Deleted)
+S: \* 3 FETCH \(FLAGS \(\\Deleted \\Recent\)\)
+S: a3 OK STORE completed.
+
+# Check there's 4 messages in the selected mailbox
+C: a5 STATUS selected (MESSAGES)
+S: \* STATUS "selected" \(MESSAGES 4\)
+S: a5 OK STATUS completed.
+
+# move messages 2-3
+C: a4 MOVE 2:3 moved
+S: \* 2 EXPUNGE
+S: \* 2 EXPUNGE
+S: a4 OK (\[.+\] )?MOVE completed.
+
+# Check there's 2 messages in the moved mailbox
+C: a5 STATUS moved (MESSAGES)
+S: \* STATUS "moved" \(MESSAGES 2\)
+S: a5 OK STATUS completed.
+
+# Check there's 2 messages in the selected mailbox
+C: a5 STATUS selected (MESSAGES)
+S: \* STATUS "selected" \(MESSAGES 2\)
+S: a5 OK STATUS completed.
+
+C: a7 SELECT moved
+S: \* FLAGS \(\\Answered \\Deleted \\Draft \\Flagged \\Seen\)
+S: \* 2 EXISTS
+S: \* \d+ RECENT
+S: \* OK \[UIDVALIDITY \d+\].*
+S: \* OK \[UNSEEN \d+\].*
+S: \* OK \[PERMANENTFLAGS \(\\Answered \\Deleted \\Draft \\Flagged \\\Seen( \\\*)?\)\].*
+S: \* OK \[HIGHESTMODSEQ \d+\].*
+S: \* OK \[UIDNEXT \d+\].*
+S: a7 OK \[READ-WRITE\] SELECT completed.
+
+C: a8 FETCH 1:2 (FLAGS)
+S: \* 1 FETCH \(FLAGS \(\\Recent\)\)
+S: \* 2 FETCH \(FLAGS \(\\Deleted \\Recent\)\)
+S: a8 OK FETCH completed.
+
+C: a9 DELETE moved
+S: a9 OK DELETE completed.
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[12/20] james-project git commit: IMAP-370 MOVE capability should be
exposed and MoveProcessor enabled only if implemented by the MailboxManager
Posted by bt...@apache.org.
IMAP-370 MOVE capability should be exposed and MoveProcessor enabled only if implemented by the MailboxManager
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/f37d2b42
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/f37d2b42
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/f37d2b42
Branch: refs/heads/master
Commit: f37d2b42a8121827a0092ca71a6e3b35d78004fc
Parents: 7958d56
Author: Benoit Tellier <bt...@linagora.com>
Authored: Thu Feb 25 13:30:44 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Fri Mar 4 19:35:24 2016 +0700
----------------------------------------------------------------------
.../apache/james/mailbox/MailboxManager.java | 7 +++
.../cassandra/CassandraMailboxManager.java | 9 ++++
.../mailbox/store/StoreMailboxManager.java | 7 +++
.../imap/processor/DefaultProcessorChain.java | 10 +++-
.../james/imap/processor/MoveProcessor.java | 53 ++++++++++++++------
.../james/imap/processor/MoveProcessorTest.java | 14 ++++++
.../base/MailboxEventAnalyserTest.java | 10 +++-
7 files changed, 90 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/f37d2b42/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxManager.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxManager.java b/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxManager.java
index 712291d..22cad9d 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxManager.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxManager.java
@@ -69,6 +69,13 @@ import org.slf4j.Logger;
public interface MailboxManager extends RequestAware, MailboxListenerSupport {
+ enum Capabilities {
+ Basic,
+ Move
+ }
+
+ List<Capabilities> getSupportedCapabilities();
+
/**
* Return the delimiter to use for folders
*
http://git-wip-us.apache.org/repos/asf/james-project/blob/f37d2b42/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxManager.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxManager.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxManager.java
index 2f8c736..369a928 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxManager.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxManager.java
@@ -19,6 +19,8 @@
package org.apache.james.mailbox.cassandra;
+import java.util.List;
+
import javax.inject.Inject;
import javax.inject.Singleton;
@@ -36,6 +38,8 @@ import org.apache.james.mailbox.store.mail.model.Mailbox;
import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox;
import org.apache.james.mailbox.store.search.MessageSearchIndex;
+import com.google.common.collect.Lists;
+
/**
* Cassandra implementation of {@link StoreMailboxManager}
*/
@@ -60,6 +64,11 @@ public class CassandraMailboxManager extends StoreMailboxManager<CassandraId> {
}
@Override
+ public List<Capabilities> getSupportedCapabilities() {
+ return Lists.newArrayList(Capabilities.Basic, Capabilities.Move);
+ }
+
+ @Override
protected Mailbox<CassandraId> doCreateMailbox(MailboxPath mailboxPath, MailboxSession session) throws MailboxException {
SimpleMailbox<CassandraId> cassandraMailbox = new SimpleMailbox<>(mailboxPath, randomUidValidity());
cassandraMailbox.setACL(SimpleMailboxACL.EMPTY);
http://git-wip-us.apache.org/repos/asf/james-project/blob/f37d2b42/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 9262a87..4d7f463 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
@@ -71,6 +71,8 @@ import org.apache.james.mailbox.store.transaction.Mapper;
import org.apache.james.mailbox.store.transaction.TransactionalMapper;
import org.slf4j.Logger;
+import com.google.common.collect.Lists;
+
/**
* This base class of an {@link MailboxManager} implementation provides a high-level api for writing your own
* {@link MailboxManager} implementation. If you plan to write your own {@link MailboxManager} its most times so easiest
@@ -196,6 +198,11 @@ public class StoreMailboxManager<Id extends MailboxId> implements MailboxManager
}
}
+ @Override
+ public List<Capabilities> getSupportedCapabilities() {
+ return Lists.newArrayList(Capabilities.Basic);
+ }
+
/**
* Return the {@link DelegatingMailboxListener} which is used by this {@link MailboxManager}
*
http://git-wip-us.apache.org/repos/asf/james-project/blob/f37d2b42/protocols/imap/src/main/java/org/apache/james/imap/processor/DefaultProcessorChain.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/DefaultProcessorChain.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/DefaultProcessorChain.java
index a3d655d..176f347 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/DefaultProcessorChain.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/DefaultProcessorChain.java
@@ -57,8 +57,14 @@ public class DefaultProcessorChain {
final UnsubscribeProcessor unsubscribeProcessor = new UnsubscribeProcessor(closeProcessor, mailboxManager, subscriptionManager, statusResponseFactory);
final SubscribeProcessor subscribeProcessor = new SubscribeProcessor(unsubscribeProcessor, mailboxManager, subscriptionManager, statusResponseFactory);
final CopyProcessor copyProcessor = new CopyProcessor(subscribeProcessor, mailboxManager, statusResponseFactory);
- final MoveProcessor moveProcessor = new MoveProcessor(copyProcessor, mailboxManager, statusResponseFactory);
- final AuthenticateProcessor authenticateProcessor = new AuthenticateProcessor(moveProcessor, mailboxManager, statusResponseFactory);
+ AuthenticateProcessor authenticateProcessor;
+ if (mailboxManager.getSupportedCapabilities().contains(MailboxManager.Capabilities.Move)) {
+ final MoveProcessor moveProcessor = new MoveProcessor(copyProcessor, mailboxManager, statusResponseFactory);
+ authenticateProcessor = new AuthenticateProcessor(moveProcessor, mailboxManager, statusResponseFactory);
+ capabilityProcessor.addProcessor(moveProcessor);
+ } else {
+ authenticateProcessor = new AuthenticateProcessor(copyProcessor, mailboxManager, statusResponseFactory);
+ }
final ExpungeProcessor expungeProcessor = new ExpungeProcessor(authenticateProcessor, mailboxManager, statusResponseFactory);
final ExamineProcessor examineProcessor = new ExamineProcessor(expungeProcessor, mailboxManager, statusResponseFactory);
final AppendProcessor appendProcessor = new AppendProcessor(examineProcessor, mailboxManager, statusResponseFactory);
http://git-wip-us.apache.org/repos/asf/james-project/blob/f37d2b42/protocols/imap/src/main/java/org/apache/james/imap/processor/MoveProcessor.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/MoveProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/MoveProcessor.java
index ca8e612..a2a2f84 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/MoveProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/MoveProcessor.java
@@ -1,6 +1,24 @@
+/****************************************************************
+ * 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.imap.processor;
-import java.util.Collections;
import java.util.List;
import org.apache.james.imap.api.ImapConstants;
@@ -15,33 +33,36 @@ import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.model.MessageRange;
+import com.google.common.collect.ImmutableList;
+
public class MoveProcessor extends AbstractMessageRangeProcessor<MoveRequest> implements CapabilityImplementingProcessor {
- private static final List<String> CAPS = Collections.unmodifiableList(Collections.singletonList(ImapConstants.MOVE_COMMAND_NAME));
+ private final boolean moveCapabilitySupported;
- public MoveProcessor(ImapProcessor next, MailboxManager mailboxManager, StatusResponseFactory factory) {
- super(MoveRequest.class, next, mailboxManager, factory);
- }
+ public MoveProcessor(ImapProcessor next, MailboxManager mailboxManager, StatusResponseFactory factory) {
+ super(MoveRequest.class, next, mailboxManager, factory);
+ moveCapabilitySupported = mailboxManager.getSupportedCapabilities().contains(MailboxManager.Capabilities.Move);
+ }
@Override
- protected List<MessageRange> process(MailboxPath targetMailbox,
- SelectedMailbox currentMailbox,
+ protected List<MessageRange> process(MailboxPath targetMailbox, SelectedMailbox currentMailbox,
MailboxSession mailboxSession,
MailboxManager mailboxManager, MessageRange messageSet) throws MailboxException {
- return mailboxManager.moveMessages(messageSet, currentMailbox.getPath(), targetMailbox, mailboxSession);
- }
+ return mailboxManager.moveMessages(messageSet, currentMailbox.getPath(), targetMailbox, mailboxSession);
+ }
@Override
protected String getOperationName() {
return "Move";
}
- /**
- * @see org.apache.james.imap.processor.CapabilityImplementingProcessor
- * #getImplementedCapabilities(org.apache.james.imap.api.process.ImapSession)
- */
- public List<String> getImplementedCapabilities(ImapSession session) {
- return CAPS;
- }
+ @Override
+ public List<String> getImplementedCapabilities(ImapSession session) {
+ if (moveCapabilitySupported) {
+ return ImmutableList.of(ImapConstants.MOVE_COMMAND_NAME);
+ } else {
+ return ImmutableList.of();
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f37d2b42/protocols/imap/src/test/java/org/apache/james/imap/processor/MoveProcessorTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/MoveProcessorTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/MoveProcessorTest.java
index 3b9ee72..63b299e 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/MoveProcessorTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/MoveProcessorTest.java
@@ -19,6 +19,7 @@
package org.apache.james.imap.processor;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -74,7 +75,20 @@ public class MoveProcessorTest {
mockImapSession = mock(ImapSession.class);
mockMailboxSession = mock(MailboxSession.class);
+ when(mockMailboxManager.getSupportedCapabilities()).thenReturn(Lists.newArrayList(MailboxManager.Capabilities.Move, MailboxManager.Capabilities.Basic));
testee = new MoveProcessor(mockNextProcessor, mockMailboxManager, mockStatusResponseFactory);
+ verify(mockMailboxManager).getSupportedCapabilities();
+ }
+
+ @Test
+ public void getImplementedCapabilitiesShouldContainMoveWhenSupportedByMailboxManager() {
+ assertThat(testee.getImplementedCapabilities(null)).containsExactly(ImapConstants.MOVE_COMMAND_NAME);
+ }
+
+ @Test
+ public void getImplementedCapabilitiesShouldNotContainMoveWhenUnSupportedByMailboxManager() {
+ when(mockMailboxManager.getSupportedCapabilities()).thenReturn(Lists.newArrayList(MailboxManager.Capabilities.Basic));
+ assertThat(new MoveProcessor(mockNextProcessor, mockMailboxManager, mockStatusResponseFactory).getImplementedCapabilities(null)).isEmpty();
}
@Test
http://git-wip-us.apache.org/repos/asf/james-project/blob/f37d2b42/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
index e7b9547..d5286b3 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
@@ -66,6 +66,8 @@ import org.apache.james.mailbox.model.UpdatedFlags;
import org.junit.Test;
import org.slf4j.Logger;
+import com.google.common.collect.Lists;
+
public class MailboxEventAnalyserTest {
private static final long BASE_SESSION_ID = 99;
@@ -73,8 +75,12 @@ public class MailboxEventAnalyserTest {
private MailboxPath mailboxPath = new MailboxPath("namespace", "user", "name");
private final MailboxManager mockManager = new MailboxManager() {
-
-
+
+ @Override
+ public List<Capabilities> getSupportedCapabilities() {
+ return Lists.newArrayList(Capabilities.Basic);
+ }
+
public void removeListener(MailboxPath mailboxPath, MailboxListener listner, MailboxSession session) throws MailboxException {
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[20/20] james-project git commit: MAILBOX-265 Cassandra Message
Mapper should take limit into account
Posted by bt...@apache.org.
MAILBOX-265 Cassandra Message Mapper should take limit into account
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/8b970f59
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/8b970f59
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/8b970f59
Branch: refs/heads/master
Commit: 8b970f59d6103ad1852409b5e11939b7d7d4b2c6
Parents: fb4a3ec
Author: Benoit Tellier <bt...@linagora.com>
Authored: Thu Mar 3 12:05:51 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Fri Mar 4 19:35:25 2016 +0700
----------------------------------------------------------------------
.../mailbox/cassandra/mail/CassandraMessageMapper.java | 11 ++++++++++-
.../store/mail/model/AbstractMessageMapperTest.java | 3 ---
2 files changed, 10 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/8b970f59/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
index 7f9bbc4..b406391 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
@@ -69,6 +69,8 @@ import javax.mail.Flags;
import javax.mail.Flags.Flag;
import javax.mail.util.SharedByteArrayInputStream;
+import com.datastax.driver.core.Statement;
+import com.datastax.driver.core.querybuilder.Select;
import com.google.common.base.Throwables;
import org.apache.james.backends.cassandra.init.CassandraTypesProvider;
import org.apache.james.backends.cassandra.utils.CassandraConstants;
@@ -167,12 +169,19 @@ public class CassandraMessageMapper implements MessageMapper<CassandraId> {
@Override
public Iterator<MailboxMessage<CassandraId>> findInMailbox(Mailbox<CassandraId> mailbox, MessageRange set, FetchType ftype, int max) throws MailboxException {
- return CassandraUtils.convertToStream(session.execute(buildQuery(mailbox, set, ftype)))
+ return CassandraUtils.convertToStream(session.execute(buildSelectQueryWithLimit(buildQuery(mailbox, set, ftype), max)))
.map(row -> message(row, ftype))
.sorted(Comparator.comparingLong(MailboxMessage::getUid))
.iterator();
}
+ private Statement buildSelectQueryWithLimit(Select.Where selectStatement, int max) {
+ if (max <= 0) {
+ return selectStatement;
+ }
+ return selectStatement.limit(max);
+ }
+
@Override
public List<Long> findRecentMessageUidsInMailbox(Mailbox<CassandraId> mailbox) throws MailboxException {
return CassandraUtils.convertToStream(session.execute(selectAll(mailbox, FetchType.Metadata).and((eq(RECENT, true)))))
http://git-wip-us.apache.org/repos/asf/james-project/blob/8b970f59/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AbstractMessageMapperTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AbstractMessageMapperTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AbstractMessageMapperTest.java
index a8ede55..3198507 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AbstractMessageMapperTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AbstractMessageMapperTest.java
@@ -44,7 +44,6 @@ import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox;
import org.apache.james.mailbox.store.mail.model.impl.SimpleMailboxMessage;
import org.junit.After;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
public abstract class AbstractMessageMapperTest<Id extends MailboxId> {
@@ -256,8 +255,6 @@ public abstract class AbstractMessageMapperTest<Id extends MailboxId> {
assertThat(retrievedMessageIterator).isEmpty();
}
- // No limit used for the moment
- @Ignore
@Test
public void retrievingMessagesWithALimitShouldLimitTheNumberOfMessages() throws MailboxException {
int limit = 2;
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[17/20] james-project git commit: IMAP-370 MOVE capability should be
announced when MailboxManager supports Move capability
Posted by bt...@apache.org.
IMAP-370 MOVE capability should be announced when MailboxManager supports Move capability
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/33a53faa
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/33a53faa
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/33a53faa
Branch: refs/heads/master
Commit: 33a53faaa2b4f77a77f1dca6452cc325dcf1d4ac
Parents: f37d2b4
Author: Benoit Tellier <bt...@linagora.com>
Authored: Thu Feb 25 14:17:46 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Fri Mar 4 19:35:24 2016 +0700
----------------------------------------------------------------------
.../src/main/resources/org/apache/james/imap/scripts/Move.test | 5 +++++
1 file changed, 5 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/33a53faa/mpt/impl/imap-mailbox/core/src/main/resources/org/apache/james/imap/scripts/Move.test
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/core/src/main/resources/org/apache/james/imap/scripts/Move.test b/mpt/impl/imap-mailbox/core/src/main/resources/org/apache/james/imap/scripts/Move.test
index ade2415..de6067c 100644
--- a/mpt/impl/imap-mailbox/core/src/main/resources/org/apache/james/imap/scripts/Move.test
+++ b/mpt/impl/imap-mailbox/core/src/main/resources/org/apache/james/imap/scripts/Move.test
@@ -16,6 +16,11 @@
# specific language governing permissions and limitations #
# under the License. #
################################################################
+
+C: a0 CAPABILITY
+S: \* CAPABILITY .* MOVE .*
+S: a0 OK CAPABILITY completed.
+
C: a1 CREATE moved
S: a1 OK CREATE completed.
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[15/20] james-project git commit: IMAP-370 Mailbox configuration page
should link to mailbox project page and include a notice about Cassandra
back-end
Posted by bt...@apache.org.
IMAP-370 Mailbox configuration page should link to mailbox project page and include a notice about Cassandra back-end
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/c7e784f4
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/c7e784f4
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/c7e784f4
Branch: refs/heads/master
Commit: c7e784f479616bf7f8fee2ffe4e8b609a0c39f30
Parents: 2782a95
Author: Benoit Tellier <bt...@linagora.com>
Authored: Fri Feb 26 14:19:20 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Fri Mar 4 19:35:24 2016 +0700
----------------------------------------------------------------------
server/src/site/xdoc/config-mailbox.xml | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/c7e784f4/server/src/site/xdoc/config-mailbox.xml
----------------------------------------------------------------------
diff --git a/server/src/site/xdoc/config-mailbox.xml b/server/src/site/xdoc/config-mailbox.xml
index c37d7bf..bdb6307 100644
--- a/server/src/site/xdoc/config-mailbox.xml
+++ b/server/src/site/xdoc/config-mailbox.xml
@@ -35,9 +35,12 @@
<dl>
<dt><strong>provider</strong></dt>
- <dd>Supported providers are: jpa (default), jcr, maildir, memory. Be aware that maildir will only work on unix like operation systems!</dd>
+ <dd>Supported providers are: jpa (default), jcr, maildir, cassandra, memory. Be aware that maildir will only work on unix like operation systems!
+ Cassandra mailbox need to be compiled and run using java 8.</dd>
</dl>
+ <p>See <a href="http://james.apache.org/mailbox/index.html">documentation page</a> to learn more about the different back-ends and their capabilities.</p>
+
</section>
</body>
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[14/20] james-project git commit: IMAP-370 In Memory implementation
for the MOVE method
Posted by bt...@apache.org.
IMAP-370 In Memory implementation for the MOVE method
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/6a90560a
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/6a90560a
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/6a90560a
Branch: refs/heads/master
Commit: 6a90560af84d2b1d01fb8573b6ee57be6a761e2b
Parents: ca531c0
Author: Benoit Tellier <bt...@linagora.com>
Authored: Thu Mar 3 16:43:06 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Fri Mar 4 19:35:24 2016 +0700
----------------------------------------------------------------------
.../inmemory/InMemoryMailboxManager.java | 43 +++++++++++++++++++
.../inmemory/mail/InMemoryMessageMapper.java | 28 ++++++------
.../inmemory/InMemoryMailboxManagerTest.java | 8 ++--
.../inmemory/mail/InMemoryMapperProvider.java | 45 ++++++++++++++++++++
.../inmemory/mail/InMemoryMessageMoveTest.java | 30 +++++++++++++
.../manager/InMemoryIntegrationResources.java | 4 +-
.../mail/model/AbstractMessageMoveTest.java | 4 +-
.../inmemory/InMemoryMailboxTest.java | 4 +-
.../inmemory/host/InMemoryHostSystem.java | 15 +++----
9 files changed, 152 insertions(+), 29 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/6a90560a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMailboxManager.java
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMailboxManager.java b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMailboxManager.java
new file mode 100644
index 0000000..1814766
--- /dev/null
+++ b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMailboxManager.java
@@ -0,0 +1,43 @@
+/****************************************************************
+ * 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.inmemory;
+
+import java.util.List;
+
+import org.apache.james.mailbox.MailboxPathLocker;
+import org.apache.james.mailbox.acl.GroupMembershipResolver;
+import org.apache.james.mailbox.acl.MailboxACLResolver;
+import org.apache.james.mailbox.store.Authenticator;
+import org.apache.james.mailbox.store.StoreMailboxManager;
+
+import com.google.common.collect.Lists;
+
+public class InMemoryMailboxManager extends StoreMailboxManager<InMemoryId> {
+
+ public InMemoryMailboxManager(Authenticator authenticator, MailboxPathLocker locker, MailboxACLResolver aclResolver, GroupMembershipResolver groupMembershipResolver) {
+ super(new InMemoryMailboxSessionMapperFactory(), authenticator, locker, aclResolver, groupMembershipResolver);
+ }
+
+ @Override
+ public List<Capabilities> getSupportedCapabilities() {
+ return Lists.newArrayList(Capabilities.Basic, Capabilities.Move);
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/6a90560a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMessageMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMessageMapper.java b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMessageMapper.java
index b201d34..1986946 100644
--- a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMessageMapper.java
+++ b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMessageMapper.java
@@ -55,10 +55,14 @@ public class InMemoryMessageMapper extends AbstractMessageMapper<InMemoryId> {
}
private Map<Long, MailboxMessage<InMemoryId>> getMembershipByUidForMailbox(Mailbox<InMemoryId> mailbox) {
- Map<Long, MailboxMessage<InMemoryId>> membershipByUid = mailboxByUid.get(mailbox.getMailboxId());
+ return getMembershipByUidForId(mailbox.getMailboxId());
+ }
+
+ private Map<Long, MailboxMessage<InMemoryId>> getMembershipByUidForId(InMemoryId id) {
+ Map<Long, MailboxMessage<InMemoryId>> membershipByUid = mailboxByUid.get(id);
if (membershipByUid == null) {
membershipByUid = new ConcurrentHashMap<Long, MailboxMessage<InMemoryId>>(INITIAL_SIZE);
- mailboxByUid.put(mailbox.getMailboxId(), membershipByUid);
+ mailboxByUid.put(id, membershipByUid);
}
return membershipByUid;
}
@@ -91,6 +95,15 @@ public class InMemoryMessageMapper extends AbstractMessageMapper<InMemoryId> {
getMembershipByUidForMailbox(mailbox).remove(message.getUid());
}
+ @Override
+ public MessageMetaData move(Mailbox<InMemoryId> mailbox, MailboxMessage<InMemoryId> original) throws MailboxException {
+ InMemoryId originalMailboxId = original.getMailboxId();
+ long uid = original.getUid();
+ MessageMetaData messageMetaData = copy(mailbox, original);
+ getMembershipByUidForId(originalMailboxId).remove(uid);
+ return messageMetaData;
+ }
+
/**
* @see org.apache.james.mailbox.store.mail.MessageMapper#findInMailbox(org.apache.james.mailbox.store.mail.model.Mailbox,
* org.apache.james.mailbox.model.MessageRange,
@@ -191,17 +204,6 @@ public class InMemoryMessageMapper extends AbstractMessageMapper<InMemoryId> {
}
/**
- * (non-Javadoc)
- *
- * @see org.apache.james.mailbox.store.mail.MessageMapper#move(org.apache.james.mailbox.store.mail.model.Mailbox,
- * MailboxMessage)
- */
- @Override
- public MessageMetaData move(Mailbox<InMemoryId> mailbox, MailboxMessage<InMemoryId> original) throws MailboxException {
- throw new UnsupportedOperationException("Not implemented - see https://issues.apache.org/jira/browse/IMAP-370");
- }
-
- /**
* Do nothing
*/
public void endRequest() {
http://git-wip-us.apache.org/repos/asf/james-project/blob/6a90560a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMailboxManagerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMailboxManagerTest.java b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMailboxManagerTest.java
index c843f96..f960885 100644
--- a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMailboxManagerTest.java
+++ b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMailboxManagerTest.java
@@ -31,6 +31,7 @@ import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.model.MailboxMetaData;
import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.model.MailboxQuery;
+import org.apache.james.mailbox.store.JVMMailboxPathLocker;
import org.apache.james.mailbox.store.MockAuthenticator;
import org.apache.james.mailbox.store.StoreMailboxManager;
import org.junit.After;
@@ -67,7 +68,7 @@ public class InMemoryMailboxManagerTest extends AbstractMailboxManagerTest {
* @throws BadCredentialsException
*/
@After
- public void tearDown() throws BadCredentialsException, MailboxException {
+ public void tearDown() throws MailboxException {
getMailboxManager().logout(session, true);
getMailboxManager().endProcessingRequest(session);
getMailboxManager().createSystemSession("test", LoggerFactory.getLogger("Test")).close();
@@ -78,12 +79,11 @@ public class InMemoryMailboxManagerTest extends AbstractMailboxManagerTest {
*/
@Override
protected void createMailboxManager() throws MailboxException {
-
- InMemoryMailboxSessionMapperFactory factory = new InMemoryMailboxSessionMapperFactory();
+
MailboxACLResolver aclResolver = new UnionMailboxACLResolver();
GroupMembershipResolver groupMembershipResolver = new SimpleGroupMembershipResolver();
- StoreMailboxManager<InMemoryId> mailboxManager = new StoreMailboxManager<InMemoryId>(factory, new MockAuthenticator(), aclResolver, groupMembershipResolver);
+ StoreMailboxManager<InMemoryId> mailboxManager = new InMemoryMailboxManager(new MockAuthenticator(), new JVMMailboxPathLocker(), aclResolver, groupMembershipResolver);
mailboxManager.init();
setMailboxManager(mailboxManager);
http://git-wip-us.apache.org/repos/asf/james-project/blob/6a90560a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/mail/InMemoryMapperProvider.java
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/mail/InMemoryMapperProvider.java b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/mail/InMemoryMapperProvider.java
new file mode 100644
index 0000000..c0ce7fb
--- /dev/null
+++ b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/mail/InMemoryMapperProvider.java
@@ -0,0 +1,45 @@
+package org.apache.james.mailbox.inmemory.mail;
+
+import java.util.Random;
+
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.inmemory.InMemoryId;
+import org.apache.james.mailbox.inmemory.InMemoryMailboxSessionMapperFactory;
+import org.apache.james.mailbox.mock.MockMailboxSession;
+import org.apache.james.mailbox.store.mail.MailboxMapper;
+import org.apache.james.mailbox.store.mail.MessageMapper;
+import org.apache.james.mailbox.store.mail.model.MapperProvider;
+
+public class InMemoryMapperProvider implements MapperProvider<InMemoryId> {
+
+ private final Random random;
+
+ public InMemoryMapperProvider() {
+ random = new Random();
+ }
+
+ @Override
+ public MailboxMapper<InMemoryId> createMailboxMapper() throws MailboxException {
+ return new InMemoryMailboxSessionMapperFactory().createMailboxMapper(new MockMailboxSession("user"));
+ }
+
+ @Override
+ public MessageMapper<InMemoryId> createMessageMapper() throws MailboxException {
+ return new InMemoryMailboxSessionMapperFactory().createMessageMapper(new MockMailboxSession("user"));
+ }
+
+ @Override
+ public InMemoryId generateId() {
+ return InMemoryId.of(random.nextInt());
+ }
+
+ @Override
+ public void clearMapper() throws MailboxException {
+
+ }
+
+ @Override
+ public void ensureMapperPrepared() throws MailboxException {
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/6a90560a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/mail/InMemoryMessageMoveTest.java
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/mail/InMemoryMessageMoveTest.java b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/mail/InMemoryMessageMoveTest.java
new file mode 100644
index 0000000..0a1aaa3
--- /dev/null
+++ b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/mail/InMemoryMessageMoveTest.java
@@ -0,0 +1,30 @@
+/****************************************************************
+ * 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.inmemory.mail;
+
+import org.apache.james.mailbox.inmemory.InMemoryId;
+import org.apache.james.mailbox.store.mail.model.AbstractMessageMoveTest;
+
+public class InMemoryMessageMoveTest extends AbstractMessageMoveTest<InMemoryId> {
+
+ public InMemoryMessageMoveTest() {
+ super(new InMemoryMapperProvider());
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/6a90560a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryIntegrationResources.java
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryIntegrationResources.java b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryIntegrationResources.java
index be94e75..b9c6f9d 100644
--- a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryIntegrationResources.java
+++ b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryIntegrationResources.java
@@ -25,6 +25,7 @@ import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver;
import org.apache.james.mailbox.acl.UnionMailboxACLResolver;
import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.inmemory.InMemoryId;
+import org.apache.james.mailbox.inmemory.InMemoryMailboxManager;
import org.apache.james.mailbox.inmemory.InMemoryMailboxSessionMapperFactory;
import org.apache.james.mailbox.inmemory.quota.InMemoryCurrentQuotaManager;
import org.apache.james.mailbox.inmemory.quota.InMemoryPerUserMaxQuotaManager;
@@ -52,8 +53,7 @@ public class InMemoryIntegrationResources implements IntegrationResources {
MockAuthenticator mockAuthenticator = new MockAuthenticator();
mockAuthenticator.addUser(ManagerTestResources.USER, ManagerTestResources.USER_PASS);
MailboxSessionMapperFactory<InMemoryId> factory = new InMemoryMailboxSessionMapperFactory();
- final StoreMailboxManager<InMemoryId> manager = new StoreMailboxManager<InMemoryId>(
- factory,
+ final StoreMailboxManager<InMemoryId> manager = new InMemoryMailboxManager(
mockAuthenticator,
new NoMailboxPathLocker(),
new UnionMailboxACLResolver(),
http://git-wip-us.apache.org/repos/asf/james-project/blob/6a90560a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AbstractMessageMoveTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AbstractMessageMoveTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AbstractMessageMoveTest.java
index ed38feb..6a44f54 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AbstractMessageMoveTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AbstractMessageMoveTest.java
@@ -89,7 +89,9 @@ public abstract class AbstractMessageMoveTest<Id extends MailboxId> {
MessageMetaData messageMetaData = messageMapper.move(benwaWorkMailbox, message1);
- assertThat(messageMetaData.getFlags()).isEqualTo(message1.createFlags());
+ Flags expectedFlags = message1.createFlags();
+ expectedFlags.add(Flags.Flag.RECENT);
+ assertThat(messageMetaData.getFlags()).isEqualTo(expectedFlags);
assertThat(messageMetaData.getUid()).isEqualTo(messageMapper.getLastUid(benwaWorkMailbox));
assertThat(messageMetaData.getModSeq()).isEqualTo(messageMapper.getHighestModSeq(benwaWorkMailbox));
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/6a90560a/mpt/impl/imap-mailbox/inmemory/src/test/java/org/apache/james/mpt/imapmailbox/inmemory/InMemoryMailboxTest.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/inmemory/src/test/java/org/apache/james/mpt/imapmailbox/inmemory/InMemoryMailboxTest.java b/mpt/impl/imap-mailbox/inmemory/src/test/java/org/apache/james/mpt/imapmailbox/inmemory/InMemoryMailboxTest.java
index c632abe..26b475e 100644
--- a/mpt/impl/imap-mailbox/inmemory/src/test/java/org/apache/james/mpt/imapmailbox/inmemory/InMemoryMailboxTest.java
+++ b/mpt/impl/imap-mailbox/inmemory/src/test/java/org/apache/james/mpt/imapmailbox/inmemory/InMemoryMailboxTest.java
@@ -27,6 +27,7 @@ import org.apache.james.mpt.imapmailbox.suite.FetchBodySection;
import org.apache.james.mpt.imapmailbox.suite.FetchBodyStructure;
import org.apache.james.mpt.imapmailbox.suite.FetchHeaders;
import org.apache.james.mpt.imapmailbox.suite.Listing;
+import org.apache.james.mpt.imapmailbox.suite.Move;
import org.apache.james.mpt.imapmailbox.suite.NonAuthenticatedState;
import org.apache.james.mpt.imapmailbox.suite.PartialFetch;
import org.apache.james.mpt.imapmailbox.suite.QuotaTest;
@@ -62,7 +63,8 @@ import org.junit.runners.Suite;
SelectedInbox.class,
SelectedState.class,
UidSearch.class,
- QuotaTest.class
+ QuotaTest.class,
+ Move.class
})
@GuiceModules({ InMemoryMailboxTestModule.class })
public class InMemoryMailboxTest {
http://git-wip-us.apache.org/repos/asf/james-project/blob/6a90560a/mpt/impl/imap-mailbox/inmemory/src/test/java/org/apache/james/mpt/imapmailbox/inmemory/host/InMemoryHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/inmemory/src/test/java/org/apache/james/mpt/imapmailbox/inmemory/host/InMemoryHostSystem.java b/mpt/impl/imap-mailbox/inmemory/src/test/java/org/apache/james/mpt/imapmailbox/inmemory/host/InMemoryHostSystem.java
index 3fa9e82..d054fe1 100644
--- a/mpt/impl/imap-mailbox/inmemory/src/test/java/org/apache/james/mpt/imapmailbox/inmemory/host/InMemoryHostSystem.java
+++ b/mpt/impl/imap-mailbox/inmemory/src/test/java/org/apache/james/mpt/imapmailbox/inmemory/host/InMemoryHostSystem.java
@@ -29,13 +29,13 @@ import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver;
import org.apache.james.mailbox.acl.UnionMailboxACLResolver;
import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.inmemory.InMemoryId;
-import org.apache.james.mailbox.inmemory.InMemoryMailboxSessionMapperFactory;
+import org.apache.james.mailbox.inmemory.InMemoryMailboxManager;
import org.apache.james.mailbox.inmemory.quota.InMemoryCurrentQuotaManager;
import org.apache.james.mailbox.inmemory.quota.InMemoryPerUserMaxQuotaManager;
import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.quota.QuotaRootResolver;
+import org.apache.james.mailbox.store.JVMMailboxPathLocker;
import org.apache.james.mailbox.store.MockAuthenticator;
-import org.apache.james.mailbox.store.StoreMailboxManager;
import org.apache.james.mailbox.store.StoreSubscriptionManager;
import org.apache.james.mailbox.store.quota.CurrentQuotaCalculator;
import org.apache.james.mailbox.store.quota.DefaultQuotaRootResolver;
@@ -50,7 +50,7 @@ public class InMemoryHostSystem extends JamesImapHostSystem {
private static final ImapFeatures SUPPORTED_FEATURES = ImapFeatures.of(Feature.NAMESPACE_SUPPORT);
- private StoreMailboxManager<InMemoryId> mailboxManager;
+ private InMemoryMailboxManager mailboxManager;
private MockAuthenticator userManager;
public static JamesImapHostSystem build() throws Exception {
@@ -73,19 +73,18 @@ public class InMemoryHostSystem extends JamesImapHostSystem {
private void initFields() throws MailboxException {
userManager = new MockAuthenticator();
- InMemoryMailboxSessionMapperFactory factory = new InMemoryMailboxSessionMapperFactory();
MailboxACLResolver aclResolver = new UnionMailboxACLResolver();
GroupMembershipResolver groupMembershipResolver = new SimpleGroupMembershipResolver();
- mailboxManager = new StoreMailboxManager<InMemoryId>(factory, userManager, aclResolver, groupMembershipResolver);
- QuotaRootResolver quotaRootResolver = new DefaultQuotaRootResolver(factory);
+ mailboxManager = new InMemoryMailboxManager(userManager, new JVMMailboxPathLocker(), aclResolver, groupMembershipResolver);
+ QuotaRootResolver quotaRootResolver = new DefaultQuotaRootResolver(mailboxManager.getMapperFactory());
InMemoryPerUserMaxQuotaManager perUserMaxQuotaManager = new InMemoryPerUserMaxQuotaManager();
perUserMaxQuotaManager.setDefaultMaxMessage(4096);
perUserMaxQuotaManager.setDefaultMaxStorage(5L * 1024L * 1024L * 1024L);
InMemoryCurrentQuotaManager currentQuotaManager = new InMemoryCurrentQuotaManager(
- new CurrentQuotaCalculator<InMemoryId>(factory, quotaRootResolver),
+ new CurrentQuotaCalculator<InMemoryId>(mailboxManager.getMapperFactory(), quotaRootResolver),
mailboxManager);
StoreQuotaManager quotaManager = new StoreQuotaManager();
@@ -102,7 +101,7 @@ public class InMemoryHostSystem extends JamesImapHostSystem {
mailboxManager.init();
- final ImapProcessor defaultImapProcessorFactory = DefaultImapProcessorFactory.createDefaultProcessor(mailboxManager, new StoreSubscriptionManager(factory), quotaManager, quotaRootResolver);
+ final ImapProcessor defaultImapProcessorFactory = DefaultImapProcessorFactory.createDefaultProcessor(mailboxManager, new StoreSubscriptionManager(mailboxManager.getMapperFactory()), quotaManager, quotaRootResolver);
configure(new DefaultImapDecoderFactory().buildImapDecoder(),
new DefaultImapEncoderFactory().buildImapEncoder(),
defaultImapProcessorFactory);
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[08/20] james-project git commit: MAILBOX-265 FetchType FULL should
be used when computing and reading Mime structure
Posted by bt...@apache.org.
MAILBOX-265 FetchType FULL should be used when computing and reading Mime structure
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/16cbae9f
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/16cbae9f
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/16cbae9f
Branch: refs/heads/master
Commit: 16cbae9fea243f68ba3ce94b16e5b58cdeaf7aaf
Parents: 7a86fe1
Author: Benoit Tellier <bt...@linagora.com>
Authored: Thu Mar 3 14:50:31 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Fri Mar 4 19:35:24 2016 +0700
----------------------------------------------------------------------
.../java/org/apache/james/mailbox/model/FetchGroupImpl.java | 6 ++----
.../apache/james/mailbox/store/StoreMessageResultIterator.java | 5 ++++-
.../mailbox/store/StoreMailboxMessageResultIteratorTest.java | 3 ++-
.../org/apache/james/mailbox/copier/MailboxCopierImpl.java | 3 ++-
.../org/apache/james/pop3server/mailbox/MailboxAdapter.java | 3 ++-
5 files changed, 12 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/16cbae9f/mailbox/api/src/main/java/org/apache/james/mailbox/model/FetchGroupImpl.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/FetchGroupImpl.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/FetchGroupImpl.java
index b7faba7..38d4bd1 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/FetchGroupImpl.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/FetchGroupImpl.java
@@ -42,16 +42,14 @@ public class FetchGroupImpl implements MessageResult.FetchGroup {
private Set<PartContentDescriptor> partContentDescriptors;
public FetchGroupImpl() {
- super();
+ this(0, new HashSet<PartContentDescriptor>());
}
public FetchGroupImpl(int content) {
- super();
- this.content = content;
+ this(content, new HashSet<PartContentDescriptor>());
}
public FetchGroupImpl(int content, Set<PartContentDescriptor> partContentDescriptors) {
- super();
this.content = content;
this.partContentDescriptors = partContentDescriptors;
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/16cbae9f/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageResultIterator.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageResultIterator.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageResultIterator.java
index 4e2b635..6741352 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageResultIterator.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageResultIterator.java
@@ -82,7 +82,10 @@ public class StoreMessageResultIterator<Id extends MailboxId> implements Message
headers = true;
content -= FetchGroup.HEADERS;
}
- if ((content & FetchGroup.BODY_CONTENT) > 0) {
+ if (group.getPartContentDescriptors().size() > 0) {
+ full = true;
+ }
+ if ((content & FetchGroup.BODY_CONTENT ) > 0 ) {
body = true;
content -= FetchGroup.BODY_CONTENT;
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/16cbae9f/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMailboxMessageResultIteratorTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMailboxMessageResultIteratorTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMailboxMessageResultIteratorTest.java
index de9e35d..b60e238 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMailboxMessageResultIteratorTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMailboxMessageResultIteratorTest.java
@@ -22,6 +22,7 @@ package org.apache.james.mailbox.store;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -50,7 +51,7 @@ public class StoreMailboxMessageResultIteratorTest {
private final class TestFetchGroup implements FetchGroup {
@Override
public Set<PartContentDescriptor> getPartContentDescriptors() {
- return null;
+ return new HashSet<PartContentDescriptor>();
}
@Override
http://git-wip-us.apache.org/repos/asf/james-project/blob/16cbae9f/mailbox/tool/src/main/java/org/apache/james/mailbox/copier/MailboxCopierImpl.java
----------------------------------------------------------------------
diff --git a/mailbox/tool/src/main/java/org/apache/james/mailbox/copier/MailboxCopierImpl.java b/mailbox/tool/src/main/java/org/apache/james/mailbox/copier/MailboxCopierImpl.java
index a52761d..9cab809 100644
--- a/mailbox/tool/src/main/java/org/apache/james/mailbox/copier/MailboxCopierImpl.java
+++ b/mailbox/tool/src/main/java/org/apache/james/mailbox/copier/MailboxCopierImpl.java
@@ -20,6 +20,7 @@ package org.apache.james.mailbox.copier;
import java.io.IOException;
import java.util.Calendar;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
@@ -54,7 +55,7 @@ public class MailboxCopierImpl implements MailboxCopier {
@Override
public Set<PartContentDescriptor> getPartContentDescriptors() {
- return null;
+ return new HashSet<PartContentDescriptor>();
}
};
http://git-wip-us.apache.org/repos/asf/james-project/blob/16cbae9f/server/protocols/protocols-pop3/src/main/java/org/apache/james/pop3server/mailbox/MailboxAdapter.java
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-pop3/src/main/java/org/apache/james/pop3server/mailbox/MailboxAdapter.java b/server/protocols/protocols-pop3/src/main/java/org/apache/james/pop3server/mailbox/MailboxAdapter.java
index 248e202..f018009 100644
--- a/server/protocols/protocols-pop3/src/main/java/org/apache/james/pop3server/mailbox/MailboxAdapter.java
+++ b/server/protocols/protocols-pop3/src/main/java/org/apache/james/pop3server/mailbox/MailboxAdapter.java
@@ -22,6 +22,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
@@ -43,7 +44,7 @@ public class MailboxAdapter implements Mailbox {
private static abstract class POP3FetchGroup implements FetchGroup {
@Override
public Set<PartContentDescriptor> getPartContentDescriptors() {
- return null;
+ return new HashSet<PartContentDescriptor>();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[18/20] james-project git commit: IMAP-370 Document capabilities on
mailboxes + add cassandra page
Posted by bt...@apache.org.
IMAP-370 Document capabilities on mailboxes + add cassandra page
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/2782a955
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/2782a955
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/2782a955
Branch: refs/heads/master
Commit: 2782a9551dd8e8c0a0523b447542af33348832e6
Parents: 6ffe855
Author: Benoit Tellier <bt...@linagora.com>
Authored: Fri Feb 26 14:09:52 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Fri Mar 4 19:35:24 2016 +0700
----------------------------------------------------------------------
mailbox/src/site/site.xml | 2 +-
mailbox/src/site/xdoc/index.xml | 8 +++++
mailbox/src/site/xdoc/mailbox-api.xml | 10 +++++-
mailbox/src/site/xdoc/mailbox-cassandra.xml | 40 ++++++++++++++++++++++++
mailbox/src/site/xdoc/mailbox-guice.xml | 33 -------------------
mailbox/src/site/xdoc/mailbox-hbase.xml | 11 ++++---
mailbox/src/site/xdoc/mailbox-jcr.xml | 1 +
mailbox/src/site/xdoc/mailbox-jpa.xml | 3 +-
mailbox/src/site/xdoc/mailbox-maildir.xml | 3 +-
mailbox/src/site/xdoc/mailbox-memory.xml | 1 +
mailbox/src/site/xdoc/mailbox-spring.xml | 2 +-
mailbox/src/site/xdoc/mailbox-store.xml | 6 ++--
12 files changed, 74 insertions(+), 46 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/2782a955/mailbox/src/site/site.xml
----------------------------------------------------------------------
diff --git a/mailbox/src/site/site.xml b/mailbox/src/site/site.xml
index 0ab1cd4..ca68afe 100644
--- a/mailbox/src/site/site.xml
+++ b/mailbox/src/site/site.xml
@@ -45,6 +45,7 @@
</menu>
<menu name="Implementations">
<item name="Mailbox Memory" href="/mailbox-memory.html" />
+ <item name="Mailbox Cassandra" href="/mailbox-cassandra.html" />
<item name="Mailbox Maildir" href="/mailbox-maildir.html" />
<item name="Mailbox JPA" href="/mailbox-jpa.html" />
<item name="Mailbox JCR" href="/mailbox-jcr.html" />
@@ -52,7 +53,6 @@
</menu>
<menu name="Wiring">
<item name="Spring" href="/mailbox-spring.html" />
- <item name="Guice" href="/mailbox-guice.html" />
</menu>
<menu name="References">
http://git-wip-us.apache.org/repos/asf/james-project/blob/2782a955/mailbox/src/site/xdoc/index.xml
----------------------------------------------------------------------
diff --git a/mailbox/src/site/xdoc/index.xml b/mailbox/src/site/xdoc/index.xml
index 3abe9bc..f91c206 100644
--- a/mailbox/src/site/xdoc/index.xml
+++ b/mailbox/src/site/xdoc/index.xml
@@ -46,6 +46,14 @@
<p>You can <a href="http://james.apache.org/download.cgi">download</a> current 0.4 release.
The <a href="apidocs/">API</a> as the schemas for the different implementations are susceptible to evolve.
</p>
+ <ul>Here are the different implementations of the mailbox we propose :
+ <li><a href="mailbox-memory.html">Memory</a> for testing purposes</li>
+ <li><a href="mailbox-cassandra.html">Cassandra</a></li>
+ <li><a href="mailbox-maildir.html">Maildir</a></li>
+ <li><a href="mailbox-jpa.html">JPA</a> </li>
+ <li><a href="mailbox-jcr.html">JCR</a> </li>
+ <li><a href="mailbox-hbase.html">HBase</a>)</li>
+ </ul>
</section>
<section name="Apache James Mailbox in Server">
http://git-wip-us.apache.org/repos/asf/james-project/blob/2782a955/mailbox/src/site/xdoc/mailbox-api.xml
----------------------------------------------------------------------
diff --git a/mailbox/src/site/xdoc/mailbox-api.xml b/mailbox/src/site/xdoc/mailbox-api.xml
index f80f326..a0084ce 100644
--- a/mailbox/src/site/xdoc/mailbox-api.xml
+++ b/mailbox/src/site/xdoc/mailbox-api.xml
@@ -49,7 +49,15 @@
<subsection name="Mailbox Manager">
<p>The Mailbox Manager is responsible for session creation, operations on mailbox (create, delete, search)
- and to return a Message Manager. It also allows to copy and list messages.</p>
+ and to return a Message Manager. It also allows to copy and list messages.
+ </p>
+
+ <ul>
+ Mailbox manager capabilities represents which operations a mailbox manager is able to support. For now the list is :
+ <li>Basic: supports all basic operations</li>
+ <li>Move: implements the move capability</li>
+ </ul>
+
<!--
Image is no more in line with trunk
<p><img src="images/uml/org-apache-james-mailbox-api-mailboxmanager.png"/></p>
http://git-wip-us.apache.org/repos/asf/james-project/blob/2782a955/mailbox/src/site/xdoc/mailbox-cassandra.xml
----------------------------------------------------------------------
diff --git a/mailbox/src/site/xdoc/mailbox-cassandra.xml b/mailbox/src/site/xdoc/mailbox-cassandra.xml
new file mode 100644
index 0000000..66a1913
--- /dev/null
+++ b/mailbox/src/site/xdoc/mailbox-cassandra.xml
@@ -0,0 +1,40 @@
+<?xml version="1.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.
+-->
+<document>
+
+ <properties>
+ <title>Mailbox Cassandra</title>
+ </properties>
+
+ <body>
+
+ <section name="Mailbox Cassandra">
+ <p>This module provides a mailbox implementation for persisting mailboxes (messages, and subscriptions) in a Cassandra cluster.</p>
+ <p>It supports the Basic and Move capabilities.</p>
+ </section>
+
+ <section name="Overview">
+ <p>The Cassandra implementation comes with a CassandraMailboxManager and a CassandraMessageManager for persisting users mailboxes.</p>
+ <p>This implementation also have a CurrentQuotaManager and a MaxQuotaManager, for storing users quotas in a Cassandra cluster.</p>
+ </section>
+
+ </body>
+
+</document>
http://git-wip-us.apache.org/repos/asf/james-project/blob/2782a955/mailbox/src/site/xdoc/mailbox-guice.xml
----------------------------------------------------------------------
diff --git a/mailbox/src/site/xdoc/mailbox-guice.xml b/mailbox/src/site/xdoc/mailbox-guice.xml
deleted file mode 100644
index 6abdf12..0000000
--- a/mailbox/src/site/xdoc/mailbox-guice.xml
+++ /dev/null
@@ -1,33 +0,0 @@
-<?xml version="1.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.
--->
-<document>
-
- <properties>
- <title>Mailbox Guice</title>
- </properties>
-
-<body>
-
- <section name="Mailbox Guice Responsability">
- </section>
-
-</body>
-
-</document>
http://git-wip-us.apache.org/repos/asf/james-project/blob/2782a955/mailbox/src/site/xdoc/mailbox-hbase.xml
----------------------------------------------------------------------
diff --git a/mailbox/src/site/xdoc/mailbox-hbase.xml b/mailbox/src/site/xdoc/mailbox-hbase.xml
index 17e8271..84681ea 100644
--- a/mailbox/src/site/xdoc/mailbox-hbase.xml
+++ b/mailbox/src/site/xdoc/mailbox-hbase.xml
@@ -26,7 +26,8 @@
<body>
<section name="Mailbox HBase Responsibility">
- This module provides a mailbox implementation for peristing mailboxes (messages, and subscriptions) in a HBase cluster.
+ <p>This module provides a mailbox implementation for persisting mailboxes (messages, and subscriptions) in a HBase cluster.</p>
+ <p>It only supports the Basic capability.</p>
</section>
<section name="Overview">
@@ -68,8 +69,8 @@
</ul>
</subsection>
<subsection name="Misc">
- <p>Message bodyes (more importantly big attachements) sent to many users are stored many times. There is no space sharing yet.</p>
- <p>Message data and mssage meta-data (flags and properties) are stored in different column families
+ <p>Message bodies (more importantly big attachements) sent to many users are stored many times. There is no space sharing yet.</p>
+ <p>Message data and message meta-data (flags and properties) are stored in different column families
so the column family optimization options can apply. Keep in mind that message data does not change, while meta-data does change.
</p>
</subsection>
@@ -83,7 +84,7 @@
</section>
<section name="Mailbox HBase Classes">
- <p>This is a onverview of the most important classes in the implementation. </p>
+ <p>This is a overview of the most important classes in the implementation. </p>
<subsection name="HBaseMailboxManager">
<p>
<strong>HBaseMailboxManager</strong> extends the
@@ -105,7 +106,7 @@
<p>Message bodies can have varying sizes. Some have attachements of up to 25Mb, some even greater.
There are practical limits to the size of a HBase column (see
<a href="http://hbase.apache.org/book.html#supported.datatypes">http://hbase.apache.org/book.html#supported.datatypes</a>).
- To adress this issue, the implementation splits the message into smaller chunks and saves each chunk into a separate column.
+ To address this issue, the implementation splits the message into smaller chunks and saves each chunk into a separate column.
The columns have increasing integer names starting with 1 and there can be at most Long.MAX_VALUE chunks.
</p>
<p>
http://git-wip-us.apache.org/repos/asf/james-project/blob/2782a955/mailbox/src/site/xdoc/mailbox-jcr.xml
----------------------------------------------------------------------
diff --git a/mailbox/src/site/xdoc/mailbox-jcr.xml b/mailbox/src/site/xdoc/mailbox-jcr.xml
index e2e4f12..3b5691a 100644
--- a/mailbox/src/site/xdoc/mailbox-jcr.xml
+++ b/mailbox/src/site/xdoc/mailbox-jcr.xml
@@ -30,6 +30,7 @@
<p>The default JCR provider used is
<a hfre="http://jackrabbit.apache.org/">Apache Jackrabbit</a>.
</p>
+ <p>It only supports the Basic capability.</p>
</section>
<!--
<section name="Installation">
http://git-wip-us.apache.org/repos/asf/james-project/blob/2782a955/mailbox/src/site/xdoc/mailbox-jpa.xml
----------------------------------------------------------------------
diff --git a/mailbox/src/site/xdoc/mailbox-jpa.xml b/mailbox/src/site/xdoc/mailbox-jpa.xml
index 3b8f1f5..7f3dcf9 100644
--- a/mailbox/src/site/xdoc/mailbox-jpa.xml
+++ b/mailbox/src/site/xdoc/mailbox-jpa.xml
@@ -35,10 +35,11 @@
but you can roll your own by extending JPAMailboxManager and JPAMessageManager in the same way
as OpenJPAMailboxManager and OpenJPAMessageManager do.
</p>
+ <p>It only supports the Basic capability.</p>
</section>
<section name="Overview">
- <p>The JPA implementation uses Java Persistenca API Annotations to map Java objects to data base tables.
+ <p>The JPA implementation uses Java Persistence API Annotations to map Java objects to data base tables.
The current implementation also supports features such as storing messages in an encrypted database and provide
on the fly encryption/decryption.
</p>
http://git-wip-us.apache.org/repos/asf/james-project/blob/2782a955/mailbox/src/site/xdoc/mailbox-maildir.xml
----------------------------------------------------------------------
diff --git a/mailbox/src/site/xdoc/mailbox-maildir.xml b/mailbox/src/site/xdoc/mailbox-maildir.xml
index fd1ac47..9ce6932 100644
--- a/mailbox/src/site/xdoc/mailbox-maildir.xml
+++ b/mailbox/src/site/xdoc/mailbox-maildir.xml
@@ -26,7 +26,8 @@
<body>
<section name="Mailbox Maildir Responsibility">
- <p>This implementation stores messages using the popular <a href="http://en.wikipedia.org/wiki/Maildir">Maildir</a> format.</p>
+ <p>This implementation stores messages using the popular <a href="http://en.wikipedia.org/wiki/Maildir">Maildir</a> format.</p>
+ <p>It only supports the Basic capability. This implementation do not support namespaces.</p>
</section>
<!--
<section name="Mailbox Maildir Classes">
http://git-wip-us.apache.org/repos/asf/james-project/blob/2782a955/mailbox/src/site/xdoc/mailbox-memory.xml
----------------------------------------------------------------------
diff --git a/mailbox/src/site/xdoc/mailbox-memory.xml b/mailbox/src/site/xdoc/mailbox-memory.xml
index ce55ec0..9ae4d06 100644
--- a/mailbox/src/site/xdoc/mailbox-memory.xml
+++ b/mailbox/src/site/xdoc/mailbox-memory.xml
@@ -27,6 +27,7 @@
<section name="Mailbox Memory Responsibility">
<p>Provides an in-memory mail store.</p>
+ <p>It only supports the Basic capability.</p>
</section>
<!--
<section name="Mailbox Memory Classes">
http://git-wip-us.apache.org/repos/asf/james-project/blob/2782a955/mailbox/src/site/xdoc/mailbox-spring.xml
----------------------------------------------------------------------
diff --git a/mailbox/src/site/xdoc/mailbox-spring.xml b/mailbox/src/site/xdoc/mailbox-spring.xml
index f6a2a3b..5d18494 100644
--- a/mailbox/src/site/xdoc/mailbox-spring.xml
+++ b/mailbox/src/site/xdoc/mailbox-spring.xml
@@ -25,7 +25,7 @@
<body>
- <section name="Mailbox Spring Responsability">
+ <section name="Mailbox Spring Responsibility">
<p>The Mailbox Spring module is designed to test the loading of mailbox implementations. </p>
</section>
http://git-wip-us.apache.org/repos/asf/james-project/blob/2782a955/mailbox/src/site/xdoc/mailbox-store.xml
----------------------------------------------------------------------
diff --git a/mailbox/src/site/xdoc/mailbox-store.xml b/mailbox/src/site/xdoc/mailbox-store.xml
index 3c84016..c8d882f 100644
--- a/mailbox/src/site/xdoc/mailbox-store.xml
+++ b/mailbox/src/site/xdoc/mailbox-store.xml
@@ -44,7 +44,7 @@ Image is no more in line with trunk
<subsection name="Store Mailbox Manager">
<p>All public and protected methods that can be used by a Mailbox Manager implementations.</p>
- <p>You need to instanciate the StoreMailboxManager with a mailboxSessionMapperFactory,
+ <p>You need to instantiate the StoreMailboxManager with a mailboxSessionMapperFactory,
an authenticator, a uidProvider and a mailboxPathlocker.</p>
<!--
Image is no more in line with trunk
@@ -54,7 +54,7 @@ Image is no more in line with trunk
<subsection name="Store Message Manager">
<p>All public and protected methods that can be used by a Message Manager implementations.</p>
- <p>You need to instanciate the StoreMessageManager with a messageSessionMapperFactory,
+ <p>You need to instantiate the StoreMessageManager with a messageSessionMapperFactory,
a uidProvider, a mailboxEventDispatcher and a mailbox.</p>
<!--
Image is no more in line with trunk
@@ -64,7 +64,7 @@ Image is no more in line with trunk
<subsection name="Store Subscription Manager">
<p>All public and protected methods that can be used by a Subscription Manager implementations.</p>
- <p>You need to instanciate the StoreSubscriptionManager with a subscriptionSessionMapperFactory.</p>
+ <p>You need to instantiate the StoreSubscriptionManager with a subscriptionSessionMapperFactory.</p>
<!--
Image is no more in line with trunk
<p><img src="images/uml/org-apache-james-mailbox-store-subscriptionmanager.png"/></p>
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[04/20] james-project git commit: IMAP-370 Solve inheritance bugg on
request handling
Posted by bt...@apache.org.
IMAP-370 Solve inheritance bugg on request handling
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/792a87a0
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/792a87a0
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/792a87a0
Branch: refs/heads/master
Commit: 792a87a04872842060cd9054a86bb6de8987ca19
Parents: b06992f
Author: Benoit Tellier <bt...@linagora.com>
Authored: Wed Feb 24 13:31:53 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Fri Mar 4 19:35:19 2016 +0700
----------------------------------------------------------------------
.../AbstractMessageRangeCommandParser.java | 45 ++++++++
.../imap/decode/parser/CopyCommandParser.java | 26 +----
.../imap/decode/parser/MoveCommandParser.java | 5 +-
.../request/AbstractMessageRangeRequest.java | 49 ++++++++
.../james/imap/message/request/CopyRequest.java | 35 +-----
.../james/imap/message/request/MoveRequest.java | 5 +-
.../AbstractMessageRangeProcessor.java | 114 +++++++++++++++++++
.../james/imap/processor/CopyProcessor.java | 93 ++-------------
.../imap/processor/DefaultProcessorChain.java | 5 +-
.../james/imap/processor/MoveProcessor.java | 23 ++--
10 files changed, 245 insertions(+), 155 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/792a87a0/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/AbstractMessageRangeCommandParser.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/AbstractMessageRangeCommandParser.java b/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/AbstractMessageRangeCommandParser.java
new file mode 100644
index 0000000..0a2f81b
--- /dev/null
+++ b/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/AbstractMessageRangeCommandParser.java
@@ -0,0 +1,45 @@
+/****************************************************************
+ * 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.imap.decode.parser;
+
+import org.apache.james.imap.api.ImapCommand;
+import org.apache.james.imap.api.ImapMessage;
+import org.apache.james.imap.api.message.IdRange;
+import org.apache.james.imap.api.process.ImapSession;
+import org.apache.james.imap.decode.ImapRequestLineReader;
+import org.apache.james.imap.message.request.AbstractMessageRangeRequest;
+import org.apache.james.protocols.imap.DecodingException;
+
+public abstract class AbstractMessageRangeCommandParser extends AbstractUidCommandParser {
+
+ public AbstractMessageRangeCommandParser(ImapCommand command) {
+ super(command);
+ }
+
+ protected ImapMessage decode(ImapCommand command, ImapRequestLineReader request, String tag, boolean useUids, ImapSession session) throws DecodingException {
+ IdRange[] idSet = request.parseIdRange(session);
+ String mailboxName = request.mailbox();
+ request.eol();
+ return createRequest(command, tag, useUids, idSet, mailboxName);
+ }
+
+ abstract protected AbstractMessageRangeRequest createRequest(ImapCommand command, String tag, boolean useUids, IdRange[] idSet, String mailboxName);
+
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/792a87a0/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/CopyCommandParser.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/CopyCommandParser.java b/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/CopyCommandParser.java
index 4abc0b4..0487839 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/CopyCommandParser.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/CopyCommandParser.java
@@ -30,31 +30,15 @@ import org.apache.james.protocols.imap.DecodingException;
/**
* Parse COPY commands
*/
-public class CopyCommandParser extends AbstractUidCommandParser {
+public class CopyCommandParser extends AbstractMessageRangeCommandParser {
public CopyCommandParser() {
- this(ImapCommand.selectedStateCommand(ImapConstants.COPY_COMMAND_NAME));
+ super(ImapCommand.selectedStateCommand(ImapConstants.COPY_COMMAND_NAME));
}
- protected CopyCommandParser(ImapCommand command) {
- super(command);
+ @Override
+ protected CopyRequest createRequest(ImapCommand command, String tag, boolean useUids, IdRange[] idSet, String mailboxName) {
+ return new CopyRequest(command, idSet, mailboxName, useUids, tag);
}
- /**
- * @see
- * org.apache.james.imap.decode.parser.AbstractUidCommandParser#decode(org.apache.james.imap.api.ImapCommand,
- * org.apache.james.imap.decode.ImapRequestLineReader, java.lang.String,
- * boolean, org.apache.james.imap.api.process.ImapSession)
- */
- protected ImapMessage decode(ImapCommand command, ImapRequestLineReader request, String tag, boolean useUids, ImapSession session) throws DecodingException {
- IdRange[] idSet = request.parseIdRange(session);
- String mailboxName = request.mailbox();
- request.eol();
- return createRequest(command, tag, useUids, idSet, mailboxName);
- }
-
- protected CopyRequest createRequest(ImapCommand command, String tag,
- boolean useUids, IdRange[] idSet, String mailboxName) {
- return new CopyRequest(command, idSet, mailboxName, useUids, tag);
-}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/792a87a0/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/MoveCommandParser.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/MoveCommandParser.java b/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/MoveCommandParser.java
index 63b984f..a30dfdc 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/MoveCommandParser.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/MoveCommandParser.java
@@ -8,12 +8,13 @@ import org.apache.james.imap.message.request.MoveRequest;
/**
* Parse MOVE commands
*/
-public class MoveCommandParser extends CopyCommandParser {
+public class MoveCommandParser extends AbstractMessageRangeCommandParser {
public MoveCommandParser() {
super(ImapCommand.selectedStateCommand(ImapConstants.MOVE_COMMAND_NAME));
}
-
+
+ @Override
protected MoveRequest createRequest(ImapCommand command, String tag,
boolean useUids, IdRange[] idSet, String mailboxName) {
return new MoveRequest(command, idSet, mailboxName, useUids, tag);
http://git-wip-us.apache.org/repos/asf/james-project/blob/792a87a0/protocols/imap/src/main/java/org/apache/james/imap/message/request/AbstractMessageRangeRequest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/message/request/AbstractMessageRangeRequest.java b/protocols/imap/src/main/java/org/apache/james/imap/message/request/AbstractMessageRangeRequest.java
new file mode 100644
index 0000000..f9672a0
--- /dev/null
+++ b/protocols/imap/src/main/java/org/apache/james/imap/message/request/AbstractMessageRangeRequest.java
@@ -0,0 +1,49 @@
+/****************************************************************
+ * 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.imap.message.request;
+
+import org.apache.james.imap.api.ImapCommand;
+import org.apache.james.imap.api.message.IdRange;
+
+public abstract class AbstractMessageRangeRequest extends AbstractImapRequest {
+
+ private final IdRange[] idSet;
+ private final String mailboxName;
+ private final boolean useUids;
+
+ public AbstractMessageRangeRequest(ImapCommand command, IdRange[] idSet, String mailboxName, boolean useUids, String tag) {
+ super(tag, command);
+ this.idSet = idSet;
+ this.mailboxName = mailboxName;
+ this.useUids = useUids;
+ }
+
+ public final IdRange[] getIdSet() {
+ return idSet;
+ }
+
+ public final String getMailboxName() {
+ return mailboxName;
+ }
+
+ public final boolean isUseUids() {
+ return useUids;
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/792a87a0/protocols/imap/src/main/java/org/apache/james/imap/message/request/CopyRequest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/message/request/CopyRequest.java b/protocols/imap/src/main/java/org/apache/james/imap/message/request/CopyRequest.java
index 77f9077..8408a24 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/message/request/CopyRequest.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/message/request/CopyRequest.java
@@ -25,40 +25,9 @@ import org.apache.james.imap.api.message.request.ImapRequest;
/**
* {@link ImapRequest} which request the copy of messages
*/
-public class CopyRequest extends AbstractImapRequest {
-
- private final IdRange[] idSet;
-
- private final String mailboxName;
-
- private final boolean useUids;
+public class CopyRequest extends AbstractMessageRangeRequest {
public CopyRequest(ImapCommand command, IdRange[] idSet, String mailboxName, boolean useUids, String tag) {
- super(tag, command);
- this.idSet = idSet;
- this.mailboxName = mailboxName;
- this.useUids = useUids;
- }
-
- /**
- * Return an Array of {@link IdRange} to copy
- *
- * @return range
- */
- public final IdRange[] getIdSet() {
- return idSet;
- }
-
- /**
- * Return the name of the mailbox
- *
- * @return mailbox
- */
- public final String getMailboxName() {
- return mailboxName;
- }
-
- public final boolean isUseUids() {
- return useUids;
+ super(command, idSet, mailboxName, useUids, tag);
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/792a87a0/protocols/imap/src/main/java/org/apache/james/imap/message/request/MoveRequest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/message/request/MoveRequest.java b/protocols/imap/src/main/java/org/apache/james/imap/message/request/MoveRequest.java
index 9015ea0..270a7ca 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/message/request/MoveRequest.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/message/request/MoveRequest.java
@@ -26,10 +26,9 @@ import org.apache.james.imap.api.message.request.ImapRequest;
/**
* {@link ImapRequest} which request the move of messages
*/
-public class MoveRequest extends CopyRequest {
+public class MoveRequest extends AbstractMessageRangeRequest {
- public MoveRequest(ImapCommand command, IdRange[] idSet,
- String mailboxName, boolean useUids, String tag) {
+ public MoveRequest(ImapCommand command, IdRange[] idSet, String mailboxName, boolean useUids, String tag) {
super(command, idSet, mailboxName, useUids, tag);
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/792a87a0/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractMessageRangeProcessor.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractMessageRangeProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractMessageRangeProcessor.java
new file mode 100644
index 0000000..a900afa
--- /dev/null
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractMessageRangeProcessor.java
@@ -0,0 +1,114 @@
+/****************************************************************
+ * 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.imap.processor;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.james.imap.api.ImapCommand;
+import org.apache.james.imap.api.ImapSessionUtils;
+import org.apache.james.imap.api.display.HumanReadableText;
+import org.apache.james.imap.api.message.IdRange;
+import org.apache.james.imap.api.message.response.StatusResponse;
+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;
+import org.apache.james.imap.api.process.SelectedMailbox;
+import org.apache.james.imap.message.request.AbstractMessageRangeRequest;
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.MessageManager;
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.exception.MessageRangeException;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.MessageRange;
+
+public abstract class AbstractMessageRangeProcessor<M extends AbstractMessageRangeRequest> extends AbstractMailboxProcessor<M> {
+
+ public AbstractMessageRangeProcessor(Class<M> acceptableClass, ImapProcessor next, MailboxManager mailboxManager, StatusResponseFactory factory) {
+ super(acceptableClass, next, mailboxManager, factory);
+ }
+
+ abstract protected List<MessageRange> process(final MailboxPath targetMailbox,
+ final SelectedMailbox currentMailbox,
+ final MailboxSession mailboxSession,
+ final MailboxManager mailboxManager,
+ MessageRange messageSet) throws MailboxException;
+
+ abstract protected String getOperationName();
+
+ @Override
+ protected void doProcess(M request, ImapSession session, String tag, ImapCommand command, Responder responder) {
+ final MailboxPath targetMailbox = buildFullPath(session, request.getMailboxName());
+ final IdRange[] idSet = request.getIdSet();
+ final boolean useUids = request.isUseUids();
+ final SelectedMailbox currentMailbox = session.getSelected();
+ try {
+ final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
+ final MailboxManager mailboxManager = getMailboxManager();
+ final boolean mailboxExists = mailboxManager.mailboxExists(targetMailbox, mailboxSession);
+
+ if (!mailboxExists) {
+ no(command, tag, responder, HumanReadableText.FAILURE_NO_SUCH_MAILBOX, StatusResponse.ResponseCode.tryCreate());
+ } else {
+
+ final MessageManager mailbox = mailboxManager.getMailbox(targetMailbox, mailboxSession);
+
+ List<IdRange> resultRanges = new ArrayList<IdRange>();
+ for (IdRange range : idSet) {
+ MessageRange messageSet = messageRange(currentMailbox, range, useUids);
+ if (messageSet != null) {
+ List<MessageRange> processedUids = process(
+ targetMailbox, currentMailbox, mailboxSession,
+ mailboxManager, messageSet);
+ for (MessageRange mr : processedUids) {
+ // Set recent flag on copied message as this SHOULD be
+ // done.
+ // See RFC 3501 6.4.7. COPY Command
+ // See IMAP-287
+ //
+ // Disable this as this is now done directly in the scope of the copy operation.
+ // See MAILBOX-85
+ //mailbox.setFlags(new Flags(Flags.Flag.RECENT), true, false, mr, mailboxSession);
+ resultRanges.add(new IdRange(mr.getUidFrom(), mr.getUidTo()));
+ }
+ }
+ }
+ IdRange[] resultUids = IdRange.mergeRanges(resultRanges).toArray(new IdRange[0]);
+
+ // get folder UIDVALIDITY
+ Long uidValidity = mailbox.getMetaData(false, mailboxSession, MessageManager.MetaData.FetchGroup.NO_UNSEEN).getUidValidity();
+
+ unsolicitedResponses(session, responder, useUids);
+ okComplete(command, tag, StatusResponse.ResponseCode.copyUid(uidValidity, idSet, resultUids), responder);
+ }
+ } catch (MessageRangeException e) {
+ if (session.getLog().isDebugEnabled()) {
+ session.getLog().debug(getOperationName() + " failed from mailbox " + currentMailbox.getPath() + " to " + targetMailbox + " for invalid sequence-set " + idSet.toString(), e);
+ }
+ taggedBad(command, tag, responder, HumanReadableText.INVALID_MESSAGESET);
+ } catch (MailboxException e) {
+ if (session.getLog().isInfoEnabled()) {
+ session.getLog().info(getOperationName() + " failed from mailbox " + currentMailbox.getPath() + " to " + targetMailbox + " for sequence-set " + idSet.toString(), e);
+ }
+ no(command, tag, responder, HumanReadableText.GENERIC_FAILURE_DURING_PROCESSING);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/792a87a0/protocols/imap/src/main/java/org/apache/james/imap/processor/CopyProcessor.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/CopyProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/CopyProcessor.java
index 2e71d42..f55a356 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/CopyProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/CopyProcessor.java
@@ -19,107 +19,34 @@
package org.apache.james.imap.processor;
-import java.util.ArrayList;
import java.util.List;
-import org.apache.james.imap.api.ImapCommand;
-import org.apache.james.imap.api.ImapSessionUtils;
-import org.apache.james.imap.api.display.HumanReadableText;
-import org.apache.james.imap.api.message.IdRange;
-import org.apache.james.imap.api.message.response.StatusResponse.ResponseCode;
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;
import org.apache.james.imap.api.process.SelectedMailbox;
import org.apache.james.imap.message.request.CopyRequest;
import org.apache.james.mailbox.MailboxManager;
import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.MessageManager;
-import org.apache.james.mailbox.MessageManager.MetaData.FetchGroup;
import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.exception.MessageRangeException;
import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.model.MessageRange;
-public class CopyProcessor extends AbstractMailboxProcessor<CopyRequest> {
+public class CopyProcessor extends AbstractMessageRangeProcessor<CopyRequest> {
public CopyProcessor(ImapProcessor next, MailboxManager mailboxManager, StatusResponseFactory factory) {
- this(CopyRequest.class, next, mailboxManager, factory);
- }
-
- protected CopyProcessor(Class<? extends CopyRequest> acceptableClass, ImapProcessor next, MailboxManager mailboxManager, StatusResponseFactory factory) {
super(CopyRequest.class, next, mailboxManager, factory);
}
- /**
- * @see
- * org.apache.james.imap.processor.AbstractMailboxProcessor#doProcess(org.apache.james.imap.api.message.request.ImapRequest,
- * org.apache.james.imap.api.process.ImapSession, java.lang.String,
- * org.apache.james.imap.api.ImapCommand,
- * org.apache.james.imap.api.process.ImapProcessor.Responder)
- */
- protected void doProcess(CopyRequest request, ImapSession session, String tag, ImapCommand command, Responder responder) {
- final MailboxPath targetMailbox = buildFullPath(session, request.getMailboxName());
- final IdRange[] idSet = request.getIdSet();
- final boolean useUids = request.isUseUids();
- final SelectedMailbox currentMailbox = session.getSelected();
- try {
- final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
- final MailboxManager mailboxManager = getMailboxManager();
- final boolean mailboxExists = mailboxManager.mailboxExists(targetMailbox, mailboxSession);
-
- if (!mailboxExists) {
- no(command, tag, responder, HumanReadableText.FAILURE_NO_SUCH_MAILBOX, ResponseCode.tryCreate());
- } else {
-
- final MessageManager mailbox = mailboxManager.getMailbox(targetMailbox, mailboxSession);
-
- List<IdRange> resultRanges = new ArrayList<IdRange>();
- for (IdRange range : idSet) {
- MessageRange messageSet = messageRange(currentMailbox, range, useUids);
- if (messageSet != null) {
- List<MessageRange> processedUids = process(
- targetMailbox, currentMailbox, mailboxSession,
- mailboxManager, messageSet);
- for (MessageRange mr : processedUids) {
- // Set recent flag on copied message as this SHOULD be
- // done.
- // See RFC 3501 6.4.7. COPY Command
- // See IMAP-287
- //
- // Disable this as this is now done directly in the scope of the copy operation.
- // See MAILBOX-85
- //mailbox.setFlags(new Flags(Flags.Flag.RECENT), true, false, mr, mailboxSession);
- resultRanges.add(new IdRange(mr.getUidFrom(), mr.getUidTo()));
- }
- }
- }
- IdRange[] resultUids = IdRange.mergeRanges(resultRanges).toArray(new IdRange[0]);
-
- // get folder UIDVALIDITY
- Long uidValidity = mailbox.getMetaData(false, mailboxSession, FetchGroup.NO_UNSEEN).getUidValidity();
-
- unsolicitedResponses(session, responder, useUids);
- okComplete(command, tag, ResponseCode.copyUid(uidValidity, idSet, resultUids), responder);
- }
- } catch (MessageRangeException e) {
- if (session.getLog().isDebugEnabled()) {
- session.getLog().debug("Copy failed from mailbox " + currentMailbox.getPath() + " to " + targetMailbox + " for invalid sequence-set " + idSet.toString(), e);
- }
- taggedBad(command, tag, responder, HumanReadableText.INVALID_MESSAGESET);
- } catch (MailboxException e) {
- if (session.getLog().isInfoEnabled()) {
- session.getLog().info("Copy failed from mailbox " + currentMailbox.getPath() + " to " + targetMailbox + " for sequence-set " + idSet.toString(), e);
- }
- no(command, tag, responder, HumanReadableText.GENERIC_FAILURE_DURING_PROCESSING);
- }
+ @Override
+ protected String getOperationName() {
+ return "Copy";
}
- protected List<MessageRange> process(MailboxPath targetMailbox,
- final SelectedMailbox currentMailbox,
- final MailboxSession mailboxSession,
- final MailboxManager mailboxManager, MessageRange messageSet)
- throws MailboxException {
+ @Override
+ protected List<MessageRange> process(MailboxPath targetMailbox,
+ SelectedMailbox currentMailbox,
+ MailboxSession mailboxSession,
+ MailboxManager mailboxManager, MessageRange messageSet) throws MailboxException {
return mailboxManager.copyMessages(messageSet, currentMailbox.getPath(), targetMailbox, mailboxSession);
-}
+ }
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/792a87a0/protocols/imap/src/main/java/org/apache/james/imap/processor/DefaultProcessorChain.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/DefaultProcessorChain.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/DefaultProcessorChain.java
index b47afcf..a3d655d 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/DefaultProcessorChain.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/DefaultProcessorChain.java
@@ -57,9 +57,8 @@ public class DefaultProcessorChain {
final UnsubscribeProcessor unsubscribeProcessor = new UnsubscribeProcessor(closeProcessor, mailboxManager, subscriptionManager, statusResponseFactory);
final SubscribeProcessor subscribeProcessor = new SubscribeProcessor(unsubscribeProcessor, mailboxManager, subscriptionManager, statusResponseFactory);
final CopyProcessor copyProcessor = new CopyProcessor(subscribeProcessor, mailboxManager, statusResponseFactory);
- // TODO Active the MoveProcess when IMAP-370 is solved
-// final MoveProcessor moveProcessor = new MoveProcessor(copyProcessor, mailboxManager, statusResponseFactory);
- final AuthenticateProcessor authenticateProcessor = new AuthenticateProcessor(copyProcessor, mailboxManager, statusResponseFactory);
+ final MoveProcessor moveProcessor = new MoveProcessor(copyProcessor, mailboxManager, statusResponseFactory);
+ final AuthenticateProcessor authenticateProcessor = new AuthenticateProcessor(moveProcessor, mailboxManager, statusResponseFactory);
final ExpungeProcessor expungeProcessor = new ExpungeProcessor(authenticateProcessor, mailboxManager, statusResponseFactory);
final ExamineProcessor examineProcessor = new ExamineProcessor(expungeProcessor, mailboxManager, statusResponseFactory);
final AppendProcessor appendProcessor = new AppendProcessor(examineProcessor, mailboxManager, statusResponseFactory);
http://git-wip-us.apache.org/repos/asf/james-project/blob/792a87a0/protocols/imap/src/main/java/org/apache/james/imap/processor/MoveProcessor.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/MoveProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/MoveProcessor.java
index 2666cc2..ca8e612 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/MoveProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/MoveProcessor.java
@@ -1,6 +1,5 @@
package org.apache.james.imap.processor;
-import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@@ -16,23 +15,27 @@ import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.model.MessageRange;
-public class MoveProcessor extends CopyProcessor implements CapabilityImplementingProcessor {
+public class MoveProcessor extends AbstractMessageRangeProcessor<MoveRequest> implements CapabilityImplementingProcessor {
- private static final List<String> CAPS = Collections.unmodifiableList(Arrays.asList(ImapConstants.MOVE_COMMAND_NAME));
+ private static final List<String> CAPS = Collections.unmodifiableList(Collections.singletonList(ImapConstants.MOVE_COMMAND_NAME));
- public MoveProcessor(ImapProcessor next, MailboxManager mailboxManager,
- StatusResponseFactory factory) {
+ public MoveProcessor(ImapProcessor next, MailboxManager mailboxManager, StatusResponseFactory factory) {
super(MoveRequest.class, next, mailboxManager, factory);
}
- protected List<MessageRange> process(MailboxPath targetMailbox,
- final SelectedMailbox currentMailbox,
- final MailboxSession mailboxSession,
- final MailboxManager mailboxManager, MessageRange messageSet)
- throws MailboxException {
+ @Override
+ protected List<MessageRange> process(MailboxPath targetMailbox,
+ SelectedMailbox currentMailbox,
+ MailboxSession mailboxSession,
+ MailboxManager mailboxManager, MessageRange messageSet) throws MailboxException {
return mailboxManager.moveMessages(messageSet, currentMailbox.getPath(), targetMailbox, mailboxSession);
}
+ @Override
+ protected String getOperationName() {
+ return "Move";
+ }
+
/**
* @see org.apache.james.imap.processor.CapabilityImplementingProcessor
* #getImplementedCapabilities(org.apache.james.imap.api.process.ImapSession)
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[02/20] james-project git commit: IMAP-370 Cassandra should implement
move command
Posted by bt...@apache.org.
IMAP-370 Cassandra should implement move command
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/ea9d77de
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/ea9d77de
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/ea9d77de
Branch: refs/heads/master
Commit: ea9d77dee363f4b197ff42eece6a731f64d63b17
Parents: 8a29217
Author: Benoit Tellier <bt...@linagora.com>
Authored: Tue Feb 23 16:11:15 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Fri Mar 4 19:32:49 2016 +0700
----------------------------------------------------------------------
.../cassandra/mail/CassandraMessageMapper.java | 48 +++---
.../mail/CassandraMessageMoveTest.java | 30 ++++
.../mail/model/AbstractMessageMoveTest.java | 145 +++++++++++++++++++
3 files changed, 202 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/ea9d77de/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
index 1ec2348..c46447d 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
@@ -151,14 +151,18 @@ public class CassandraMessageMapper implements MessageMapper<CassandraId> {
@Override
public void delete(Mailbox<CassandraId> mailbox, MailboxMessage<CassandraId> message) {
+ deleteUsingMailboxId(mailbox.getMailboxId(), message);
+ }
+
+ private void deleteUsingMailboxId(CassandraId mailboxId, MailboxMessage<CassandraId> message) {
session.execute(
QueryBuilder.delete()
.from(TABLE_NAME)
- .where(eq(MAILBOX_ID, mailbox.getMailboxId().asUuid()))
+ .where(eq(MAILBOX_ID, mailboxId.asUuid()))
.and(eq(IMAP_UID, message.getUid())));
- decrementCount(mailbox);
+ decrementCount(mailboxId);
if (!message.isSeen()) {
- decrementUnseen(mailbox);
+ decrementUnseen(mailboxId);
}
}
@@ -196,8 +200,10 @@ public class CassandraMessageMapper implements MessageMapper<CassandraId> {
}
@Override
- public MessageMetaData move(Mailbox<CassandraId> mailbox, MailboxMessage<CassandraId> original) throws MailboxException {
- throw new UnsupportedOperationException("Not implemented - see https://issues.apache.org/jira/browse/IMAP-370");
+ public MessageMetaData move(Mailbox<CassandraId> destinationMailbox, MailboxMessage<CassandraId> original) throws MailboxException {
+ MessageMetaData messageMetaData = copy(destinationMailbox, original);
+ deleteUsingMailboxId(original.getMailboxId(), original);
+ return messageMetaData;
}
@Override
@@ -216,9 +222,9 @@ public class CassandraMessageMapper implements MessageMapper<CassandraId> {
message.setModSeq(modSeqProvider.nextModSeq(mailboxSession, mailbox));
MessageMetaData messageMetaData = save(mailbox, message);
if (!message.isSeen()) {
- incrementUnseen(mailbox);
+ incrementUnseen(mailbox.getMailboxId());
}
- incrementCount(mailbox);
+ incrementCount(mailbox.getMailboxId());
return messageMetaData;
}
@@ -243,9 +249,9 @@ public class CassandraMessageMapper implements MessageMapper<CassandraId> {
original.setUid(uidProvider.nextUid(mailboxSession, mailbox));
original.setModSeq(modSeqProvider.nextModSeq(mailboxSession, mailbox));
- incrementCount(mailbox);
+ incrementCount(mailbox.getMailboxId());
if(!original.isSeen()) {
- incrementUnseen(mailbox);
+ incrementUnseen(mailbox.getMailboxId());
}
original.setFlags(new FlagsBuilder().add(original.createFlags()).add(Flag.RECENT).build());
return save(mailbox, original);
@@ -256,24 +262,24 @@ public class CassandraMessageMapper implements MessageMapper<CassandraId> {
return uidProvider.lastUid(mailboxSession, mailbox);
}
- private void decrementCount(Mailbox<CassandraId> mailbox) {
- updateMailbox(mailbox, decr(CassandraMailboxCountersTable.COUNT));
+ private void decrementCount(CassandraId mailboxId) {
+ updateMailbox(mailboxId, decr(CassandraMailboxCountersTable.COUNT));
}
- private void incrementCount(Mailbox<CassandraId> mailbox) {
- updateMailbox(mailbox, incr(CassandraMailboxCountersTable.COUNT));
+ private void incrementCount(CassandraId mailboxId) {
+ updateMailbox(mailboxId, incr(CassandraMailboxCountersTable.COUNT));
}
- private void decrementUnseen(Mailbox<CassandraId> mailbox) {
- updateMailbox(mailbox, decr(CassandraMailboxCountersTable.UNSEEN));
+ private void decrementUnseen(CassandraId mailboxId) {
+ updateMailbox(mailboxId, decr(CassandraMailboxCountersTable.UNSEEN));
}
- private void incrementUnseen(Mailbox<CassandraId> mailbox) {
- updateMailbox(mailbox, incr(CassandraMailboxCountersTable.UNSEEN));
+ private void incrementUnseen(CassandraId mailboxId) {
+ updateMailbox(mailboxId, incr(CassandraMailboxCountersTable.UNSEEN));
}
- private void updateMailbox(Mailbox<CassandraId> mailbox, Assignment operation) {
- session.execute(update(CassandraMailboxCountersTable.TABLE_NAME).with(operation).where(eq(CassandraMailboxCountersTable.MAILBOX_ID, mailbox.getMailboxId().asUuid())));
+ private void updateMailbox(CassandraId mailboxId, Assignment operation) {
+ session.execute(update(CassandraMailboxCountersTable.TABLE_NAME).with(operation).where(eq(CassandraMailboxCountersTable.MAILBOX_ID, mailboxId.asUuid())));
}
private MailboxMessage<CassandraId> message(Row row) {
@@ -366,10 +372,10 @@ public class CassandraMessageMapper implements MessageMapper<CassandraId> {
private void manageUnseenMessageCounts(Mailbox<CassandraId> mailbox, Flags oldFlags, Flags newFlags) {
if (oldFlags.contains(Flag.SEEN) && !newFlags.contains(Flag.SEEN)) {
- incrementUnseen(mailbox);
+ incrementUnseen(mailbox.getMailboxId());
}
if (!oldFlags.contains(Flag.SEEN) && newFlags.contains(Flag.SEEN)) {
- decrementUnseen(mailbox);
+ decrementUnseen(mailbox.getMailboxId());
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/ea9d77de/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMoveTest.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMoveTest.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMoveTest.java
new file mode 100644
index 0000000..51bc8c3
--- /dev/null
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMoveTest.java
@@ -0,0 +1,30 @@
+/****************************************************************
+ * 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.cassandra.mail;
+
+import org.apache.james.mailbox.cassandra.CassandraId;
+import org.apache.james.mailbox.store.mail.model.AbstractMessageMoveTest;
+
+public class CassandraMessageMoveTest extends AbstractMessageMoveTest<CassandraId> {
+
+ public CassandraMessageMoveTest() {
+ super(new CassandraMapperProvider());
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/ea9d77de/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AbstractMessageMoveTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AbstractMessageMoveTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AbstractMessageMoveTest.java
new file mode 100644
index 0000000..ed38feb
--- /dev/null
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AbstractMessageMoveTest.java
@@ -0,0 +1,145 @@
+/****************************************************************
+ * 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.store.mail.model;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.Date;
+
+import javax.mail.Flags;
+import javax.mail.util.SharedByteArrayInputStream;
+
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.MessageMetaData;
+import org.apache.james.mailbox.model.MessageRange;
+import org.apache.james.mailbox.store.mail.MessageMapper;
+import org.apache.james.mailbox.store.mail.MessageMapper.FetchType;
+import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
+import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox;
+import org.apache.james.mailbox.store.mail.model.impl.SimpleMailboxMessage;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public abstract class AbstractMessageMoveTest<Id extends MailboxId> {
+
+ private final static char DELIMITER = ':';
+ private static final int LIMIT = 10;
+ private static final int BODY_START = 16;
+ public static final int UID_VALIDITY = 42;
+
+ private MapperProvider<Id> mapperProvider;
+ private MessageMapper<Id> messageMapper;
+
+ private SimpleMailbox<Id> benwaInboxMailbox;
+ private SimpleMailbox<Id> benwaWorkMailbox;
+
+ private SimpleMailboxMessage<Id> message1;
+
+ public AbstractMessageMoveTest(MapperProvider<Id> mapperProvider) {
+ this.mapperProvider = mapperProvider;
+ }
+
+ @Before
+ public void setUp() throws MailboxException {
+ mapperProvider.ensureMapperPrepared();
+ messageMapper = mapperProvider.createMessageMapper();
+ benwaInboxMailbox = createMailbox(new MailboxPath("#private", "benwa", "INBOX"));
+ benwaWorkMailbox = createMailbox( new MailboxPath("#private", "benwa", "INBOX"+DELIMITER+"work"));
+ message1 = createMessage(benwaInboxMailbox, "Subject: Test1 \n\nBody1\n.\n", BODY_START, new PropertyBuilder());
+ }
+
+ @After
+ public void tearDown() throws MailboxException {
+ mapperProvider.clearMapper();
+ }
+
+ @Test
+ public void movingAMessageShouldWork() throws Exception {
+ messageMapper.add(benwaInboxMailbox, message1);
+ message1.setModSeq(messageMapper.getHighestModSeq(benwaInboxMailbox));
+
+ messageMapper.move(benwaWorkMailbox, message1);
+
+ assertThat(retrieveMessageFromStorage(benwaWorkMailbox, message1)).isEqualTo(message1);
+ }
+
+ @Test
+ public void movingAMessageShouldReturnCorrectMetadata() throws Exception {
+ messageMapper.add(benwaInboxMailbox, message1);
+ message1.setModSeq(messageMapper.getHighestModSeq(benwaInboxMailbox));
+
+ MessageMetaData messageMetaData = messageMapper.move(benwaWorkMailbox, message1);
+
+ assertThat(messageMetaData.getFlags()).isEqualTo(message1.createFlags());
+ assertThat(messageMetaData.getUid()).isEqualTo(messageMapper.getLastUid(benwaWorkMailbox));
+ assertThat(messageMetaData.getModSeq()).isEqualTo(messageMapper.getHighestModSeq(benwaWorkMailbox));
+ }
+
+ @Test
+ public void movingAMessageShouldNotViolateMessageCount() throws Exception {
+ messageMapper.add(benwaInboxMailbox, message1);
+ message1.setModSeq(messageMapper.getHighestModSeq(benwaInboxMailbox));
+
+ messageMapper.move(benwaWorkMailbox, message1);
+
+ assertThat(messageMapper.countMessagesInMailbox(benwaInboxMailbox)).isEqualTo(0);
+ assertThat(messageMapper.countMessagesInMailbox(benwaWorkMailbox)).isEqualTo(1);
+ }
+
+ @Test
+ public void movingAMessageShouldNotViolateUnseenMessageCount() throws Exception {
+ messageMapper.add(benwaInboxMailbox, message1);
+ message1.setModSeq(messageMapper.getHighestModSeq(benwaInboxMailbox));
+
+ messageMapper.move(benwaWorkMailbox, message1);
+
+ assertThat(messageMapper.countUnseenMessagesInMailbox(benwaInboxMailbox)).isEqualTo(0);
+ assertThat(messageMapper.countUnseenMessagesInMailbox(benwaWorkMailbox)).isEqualTo(1);
+ }
+
+ @Test
+ public void movingASeenMessageShouldNotIncrementUnseenMessageCount() throws Exception {
+ message1.setFlags(new Flags(Flags.Flag.SEEN));
+ messageMapper.add(benwaInboxMailbox, message1);
+ message1.setModSeq(messageMapper.getHighestModSeq(benwaInboxMailbox));
+
+ messageMapper.move(benwaWorkMailbox, message1);
+
+ assertThat(messageMapper.countUnseenMessagesInMailbox(benwaInboxMailbox)).isEqualTo(0);
+ assertThat(messageMapper.countUnseenMessagesInMailbox(benwaWorkMailbox)).isEqualTo(0);
+ }
+
+ private SimpleMailbox<Id> createMailbox(MailboxPath mailboxPath) {
+ SimpleMailbox<Id> mailbox = new SimpleMailbox<Id>(mailboxPath, UID_VALIDITY);
+ Id id = mapperProvider.generateId();
+ mailbox.setMailboxId(id);
+ return mailbox;
+ }
+
+ private MailboxMessage<Id> retrieveMessageFromStorage(Mailbox<Id> mailbox, MailboxMessage<Id> message) throws MailboxException {
+ return messageMapper.findInMailbox(mailbox, MessageRange.one(message.getUid()), FetchType.Metadata, LIMIT).next();
+ }
+
+ private SimpleMailboxMessage<Id> createMessage(Mailbox<Id> mailbox, String content, int bodyStart, PropertyBuilder propertyBuilder) {
+ return new SimpleMailboxMessage<Id>(new Date(), content.length(), bodyStart, new SharedByteArrayInputStream(content.getBytes()), new Flags(), propertyBuilder, mailbox.getMailboxId());
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[09/20] james-project git commit: IMAP-370 Provide tests for
CopyCommandParser and MoveCommandParser
Posted by bt...@apache.org.
IMAP-370 Provide tests for CopyCommandParser and MoveCommandParser
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/53755c7b
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/53755c7b
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/53755c7b
Branch: refs/heads/master
Commit: 53755c7b785c03ccaf6b92af73e321f9722e1d46
Parents: 45edd6c
Author: Benoit Tellier <bt...@linagora.com>
Authored: Wed Feb 24 16:55:05 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Fri Mar 4 19:35:24 2016 +0700
----------------------------------------------------------------------
protocols/imap/pom.xml | 6 +++
.../request/AbstractMessageRangeRequest.java | 28 +++++++++++
.../imap/decode/parser/CopyParserTest.java | 49 ++++++++++++++++++++
.../imap/decode/parser/MoveParserTest.java | 49 ++++++++++++++++++++
4 files changed, 132 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/53755c7b/protocols/imap/pom.xml
----------------------------------------------------------------------
diff --git a/protocols/imap/pom.xml b/protocols/imap/pom.xml
index 49c074f..305985d 100644
--- a/protocols/imap/pom.xml
+++ b/protocols/imap/pom.xml
@@ -86,6 +86,12 @@
<artifactId>guava</artifactId>
</dependency>
<dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <version>${assertj-1.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.jmock</groupId>
<artifactId>jmock</artifactId>
<scope>test</scope>
http://git-wip-us.apache.org/repos/asf/james-project/blob/53755c7b/protocols/imap/src/main/java/org/apache/james/imap/message/request/AbstractMessageRangeRequest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/message/request/AbstractMessageRangeRequest.java b/protocols/imap/src/main/java/org/apache/james/imap/message/request/AbstractMessageRangeRequest.java
index f9672a0..a6c56c1 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/message/request/AbstractMessageRangeRequest.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/message/request/AbstractMessageRangeRequest.java
@@ -19,9 +19,15 @@
package org.apache.james.imap.message.request;
+import java.util.Arrays;
+import java.util.List;
+
import org.apache.james.imap.api.ImapCommand;
import org.apache.james.imap.api.message.IdRange;
+import com.google.common.base.Objects;
+import com.google.common.hash.HashCode;
+
public abstract class AbstractMessageRangeRequest extends AbstractImapRequest {
private final IdRange[] idSet;
@@ -46,4 +52,26 @@ public abstract class AbstractMessageRangeRequest extends AbstractImapRequest {
public final boolean isUseUids() {
return useUids;
}
+
+ @Override
+ public boolean equals(Object o) {
+ if (o == null || getClass() != o.getClass()) return false;
+
+ AbstractMessageRangeRequest that = (AbstractMessageRangeRequest) o;
+
+ return equals(this.idSet, that.idSet)
+ && Objects.equal(this.mailboxName, that.mailboxName)
+ && Objects.equal(this.useUids, that.useUids);
+ }
+
+ private boolean equals(IdRange[] idSet1, IdRange[] idSet2) {
+ List<IdRange> idRanges1 = Arrays.asList(idSet1);
+ List<IdRange> idRanges2 = Arrays.asList(idSet2);
+ return Objects.equal(idRanges1, idRanges2);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(idSet, mailboxName, useUids);
+ }
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/53755c7b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/CopyParserTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/CopyParserTest.java b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/CopyParserTest.java
new file mode 100644
index 0000000..05a5bfc
--- /dev/null
+++ b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/CopyParserTest.java
@@ -0,0 +1,49 @@
+/****************************************************************
+ * 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.imap.decode.parser;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+import org.apache.james.imap.api.ImapCommand;
+import org.apache.james.imap.api.message.IdRange;
+import org.apache.james.imap.decode.ImapRequestStreamLineReader;
+import org.apache.james.imap.message.request.CopyRequest;
+import org.apache.james.protocols.imap.DecodingException;
+import org.junit.Test;
+
+public class CopyParserTest {
+
+ @Test
+ public void testQuotaParsing() throws DecodingException {
+ CopyCommandParser parser = new CopyCommandParser();
+ ImapCommand command = ImapCommand.anyStateCommand("Command");
+ String commandString = " 42:69 foo \n";
+
+ InputStream inputStream = new ByteArrayInputStream(commandString.getBytes());
+ ImapRequestStreamLineReader lineReader = new ImapRequestStreamLineReader(inputStream, null);
+ CopyRequest request = (CopyRequest) parser.decode(command, lineReader, "A003", null);
+ CopyRequest expected = new CopyRequest(command, new IdRange[] {new IdRange(42, 69)}, "foo", false, "A003");
+
+ assertThat(request).isEqualTo(expected);
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/53755c7b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/MoveParserTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/MoveParserTest.java b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/MoveParserTest.java
new file mode 100644
index 0000000..c17b379
--- /dev/null
+++ b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/MoveParserTest.java
@@ -0,0 +1,49 @@
+/****************************************************************
+ * 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.imap.decode.parser;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+import org.apache.james.imap.api.ImapCommand;
+import org.apache.james.imap.api.message.IdRange;
+import org.apache.james.imap.decode.ImapRequestStreamLineReader;
+import org.apache.james.imap.message.request.MoveRequest;
+import org.apache.james.protocols.imap.DecodingException;
+import org.junit.Test;
+
+public class MoveParserTest {
+
+ @Test
+ public void testQuotaParsing() throws DecodingException {
+ MoveCommandParser parser = new MoveCommandParser();
+ ImapCommand command = ImapCommand.anyStateCommand("Command");
+ String commandString = " 42:69 foo \n";
+
+ InputStream inputStream = new ByteArrayInputStream(commandString.getBytes());
+ ImapRequestStreamLineReader lineReader = new ImapRequestStreamLineReader(inputStream, null);
+ MoveRequest request = (MoveRequest) parser.decode(command, lineReader, "A003", null);
+ MoveRequest expected = new MoveRequest(command, new IdRange[] {new IdRange(42, 69)}, "foo", false, "A003");
+
+ assertThat(request).isEqualTo(expected);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[13/20] james-project git commit: IMAP-370 Kill un efficient and
unnecessary prepared query from query string
Posted by bt...@apache.org.
IMAP-370 Kill un efficient and unnecessary prepared query from query string
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/ca531c0d
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/ca531c0d
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/ca531c0d
Branch: refs/heads/master
Commit: ca531c0d9dbbae1facfd1b5abf1727575c152243
Parents: bb92cd4
Author: Benoit Tellier <bt...@linagora.com>
Authored: Thu Mar 3 10:25:03 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Fri Mar 4 19:35:24 2016 +0700
----------------------------------------------------------------------
.../cassandra/mail/CassandraMessageMapper.java | 16 ++++------------
1 file changed, 4 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/ca531c0d/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
index 12137c5..e001839 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
@@ -19,7 +19,6 @@
package org.apache.james.mailbox.cassandra.mail;
-import static com.datastax.driver.core.querybuilder.QueryBuilder.bindMarker;
import static com.datastax.driver.core.querybuilder.QueryBuilder.decr;
import static com.datastax.driver.core.querybuilder.QueryBuilder.eq;
import static com.datastax.driver.core.querybuilder.QueryBuilder.gte;
@@ -94,14 +93,11 @@ import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
import org.apache.james.mailbox.store.mail.model.impl.SimpleMailboxMessage;
import org.apache.james.mailbox.store.mail.model.impl.SimpleProperty;
-import com.datastax.driver.core.BoundStatement;
-import com.datastax.driver.core.PreparedStatement;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Row;
import com.datastax.driver.core.Session;
import com.datastax.driver.core.UDTValue;
import com.datastax.driver.core.querybuilder.Assignment;
-import com.datastax.driver.core.querybuilder.Insert;
import com.datastax.driver.core.querybuilder.QueryBuilder;
import com.datastax.driver.core.querybuilder.Select.Where;
import com.google.common.io.ByteStreams;
@@ -322,7 +318,7 @@ public class CassandraMessageMapper implements MessageMapper<CassandraId> {
private MessageMetaData save(Mailbox<CassandraId> mailbox, MailboxMessage<CassandraId> message) throws MailboxException {
try {
- Insert query = insertInto(TABLE_NAME)
+ session.execute(insertInto(TABLE_NAME)
.value(MAILBOX_ID, mailbox.getMailboxId().asUuid())
.value(IMAP_UID, message.getUid())
.value(MOD_SEQ, message.getModSeq())
@@ -338,8 +334,8 @@ public class CassandraMessageMapper implements MessageMapper<CassandraId> {
.value(SEEN, message.isSeen())
.value(USER, message.createFlags().contains(Flag.USER))
.value(USER_FLAGS, userFlagsSet(message))
- .value(BODY_CONTENT, bindMarker())
- .value(HEADER_CONTENT, bindMarker())
+ .value(BODY_CONTENT, toByteBuffer(message.getBodyContent()))
+ .value(HEADER_CONTENT, toByteBuffer(message.getHeaderContent()))
.value(PROPERTIES, message.getProperties().stream()
.map(x -> typesProvider.getDefinedUserType(PROPERTIES)
.newValue()
@@ -347,12 +343,8 @@ public class CassandraMessageMapper implements MessageMapper<CassandraId> {
.setString(Properties.NAME, x.getLocalName())
.setString(Properties.VALUE, x.getValue()))
.collect(Collectors.toList()))
- .value(TEXTUAL_LINE_COUNT, message.getTextualLineCount());
- PreparedStatement preparedStatement = session.prepare(query.toString());
+ .value(TEXTUAL_LINE_COUNT, message.getTextualLineCount()));
-
- BoundStatement boundStatement = preparedStatement.bind(toByteBuffer(message.getBodyContent()), toByteBuffer(message.getHeaderContent()));
- session.execute(boundStatement);
return new SimpleMessageMetaData(message);
} catch (IOException e) {
throw new MailboxException("Error saving mail", e);
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[10/20] james-project git commit: IMAP-370 Factorize COPY operations
with APPEND operations on Cassandra backend
Posted by bt...@apache.org.
IMAP-370 Factorize COPY operations with APPEND operations on Cassandra backend
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/bb92cd4b
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/bb92cd4b
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/bb92cd4b
Branch: refs/heads/master
Commit: bb92cd4b2367555d61c00ab2305ad29e3f8011b7
Parents: c7e784f
Author: Benoit Tellier <bt...@linagora.com>
Authored: Thu Mar 3 10:10:28 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Fri Mar 4 19:35:24 2016 +0700
----------------------------------------------------------------------
.../mailbox/cassandra/mail/CassandraMessageMapper.java | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/bb92cd4b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
index c46447d..12137c5 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
@@ -246,15 +246,8 @@ public class CassandraMessageMapper implements MessageMapper<CassandraId> {
@Override
public MessageMetaData copy(Mailbox<CassandraId> mailbox, MailboxMessage<CassandraId> original) throws MailboxException {
-
- original.setUid(uidProvider.nextUid(mailboxSession, mailbox));
- original.setModSeq(modSeqProvider.nextModSeq(mailboxSession, mailbox));
- incrementCount(mailbox.getMailboxId());
- if(!original.isSeen()) {
- incrementUnseen(mailbox.getMailboxId());
- }
original.setFlags(new FlagsBuilder().add(original.createFlags()).add(Flag.RECENT).build());
- return save(mailbox, original);
+ return add(mailbox, original);
}
@Override
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[05/20] james-project git commit: IMAP-370 Provide tests for
CopyProcessor and MoveProcessor
Posted by bt...@apache.org.
IMAP-370 Provide tests for CopyProcessor and MoveProcessor
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/45edd6c0
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/45edd6c0
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/45edd6c0
Branch: refs/heads/master
Commit: 45edd6c04f8d00fa4ea55d7d0c9400f6810f1140
Parents: 762af8e
Author: Benoit Tellier <bt...@linagora.com>
Authored: Wed Feb 24 16:28:04 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Fri Mar 4 19:35:23 2016 +0700
----------------------------------------------------------------------
protocols/imap/pom.xml | 5 +
.../james/imap/processor/CopyProcessorTest.java | 232 +++++++++++++++++++
.../james/imap/processor/MoveProcessorTest.java | 231 ++++++++++++++++++
3 files changed, 468 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/45edd6c0/protocols/imap/pom.xml
----------------------------------------------------------------------
diff --git a/protocols/imap/pom.xml b/protocols/imap/pom.xml
index 20e8586..49c074f 100644
--- a/protocols/imap/pom.xml
+++ b/protocols/imap/pom.xml
@@ -96,6 +96,11 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.apache.james</groupId>
<artifactId>apache-james-mailbox-store</artifactId>
<scope>test</scope>
http://git-wip-us.apache.org/repos/asf/james-project/blob/45edd6c0/protocols/imap/src/test/java/org/apache/james/imap/processor/CopyProcessorTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/CopyProcessorTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/CopyProcessorTest.java
new file mode 100644
index 0000000..bacef9d
--- /dev/null
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/CopyProcessorTest.java
@@ -0,0 +1,232 @@
+/****************************************************************
+ * 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.imap.processor;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.when;
+
+import org.apache.james.imap.api.ImapCommand;
+import org.apache.james.imap.api.ImapConstants;
+import org.apache.james.imap.api.ImapSessionState;
+import org.apache.james.imap.api.ImapSessionUtils;
+import org.apache.james.imap.api.display.HumanReadableText;
+import org.apache.james.imap.api.message.IdRange;
+import org.apache.james.imap.api.message.response.StatusResponse;
+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;
+import org.apache.james.imap.api.process.SelectedMailbox;
+import org.apache.james.imap.message.request.CopyRequest;
+import org.apache.james.imap.message.request.MoveRequest;
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.MessageManager;
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.MessageRange;
+import org.apache.james.mailbox.store.MailboxMetaData;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.Lists;
+
+public class CopyProcessorTest {
+
+ public static final String TAG = "TAG";
+ private static final Logger LOGGER = LoggerFactory.getLogger(CopyProcessorTest.class);
+
+ private CopyProcessor testee;
+ private ImapProcessor mockNextProcessor;
+ private MailboxManager mockMailboxManager;
+ private StatusResponseFactory mockStatusResponseFactory;
+ private ImapProcessor.Responder mockResponder;
+ private ImapSession mockImapSession;
+ private MailboxSession mockMailboxSession;
+
+ @Before
+ public void setUp() {
+ mockNextProcessor = mock(ImapProcessor.class);
+ mockMailboxManager = mock(MailboxManager.class);
+ mockStatusResponseFactory = mock(StatusResponseFactory.class);
+ mockResponder = mock(ImapProcessor.Responder.class);
+ mockImapSession = mock(ImapSession.class);
+ mockMailboxSession = mock(MailboxSession.class);
+
+ testee = new CopyProcessor(mockNextProcessor, mockMailboxManager, mockStatusResponseFactory);
+ }
+
+ @Test
+ public void processShouldWork() throws Exception {
+ CopyRequest copyRequest = new CopyRequest(ImapCommand.anyStateCommand("Name"), new IdRange[] {new IdRange(4, 6)}, ImapConstants.INBOX_NAME, true, TAG);
+
+ MailboxSession.User user = mock(MailboxSession.User.class);
+ when(user.getUserName()).thenReturn("username");
+ when(mockMailboxSession.getPersonalSpace()).thenReturn("");
+ when(mockMailboxSession.getUser()).thenReturn(user);
+ when(mockMailboxSession.getSessionId()).thenReturn(42L);
+ when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED);
+ when(mockImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mockMailboxSession);
+ MailboxPath inbox = MailboxPath.inbox(mockMailboxSession);
+ MailboxPath selected = new MailboxPath(inbox, "selected");
+ SelectedMailbox selectedMailbox = mock(SelectedMailbox.class);
+ when(selectedMailbox.getLastUid()).thenReturn(8L);
+ when(selectedMailbox.existsCount()).thenReturn(8L);
+ when(selectedMailbox.getPath()).thenReturn(selected);
+ when(mockImapSession.getSelected()).thenReturn(selectedMailbox);
+ when(mockMailboxManager.mailboxExists(inbox, mockMailboxSession)).thenReturn(true);
+ MessageManager targetMessageManager = mock(MessageManager.class);
+ when(mockMailboxManager.getMailbox(inbox, mockMailboxSession)).thenReturn(targetMessageManager);
+ when(targetMessageManager.getMetaData(false, mockMailboxSession, MessageManager.MetaData.FetchGroup.NO_UNSEEN)).thenReturn(new MailboxMetaData(null, null, 58L, 18L, 8L, 8L, 8L, 8L, true, true, null));
+ StatusResponse okResponse = mock(StatusResponse.class);
+ when(mockStatusResponseFactory.taggedOk(any(String.class), any(ImapCommand.class), any(HumanReadableText.class), any(StatusResponse.ResponseCode.class))).thenReturn(okResponse);
+ when(mockMailboxManager.moveMessages(MessageRange.range(4, 6), selected, inbox, mockMailboxSession)).thenReturn(Lists.<MessageRange>newArrayList(MessageRange.range(4, 6)));
+
+ testee.process(copyRequest, mockResponder, mockImapSession);
+
+ verify(mockMailboxManager).startProcessingRequest(mockMailboxSession);
+ verify(mockMailboxManager).endProcessingRequest(mockMailboxSession);
+ verify(mockMailboxManager).mailboxExists(inbox, mockMailboxSession);
+ verify(mockMailboxManager).getMailbox(inbox, mockMailboxSession);
+ verify(mockMailboxManager).copyMessages(MessageRange.range(4, 6), selected, inbox, mockMailboxSession);
+ verify(targetMessageManager).getMetaData(false, mockMailboxSession, MessageManager.MetaData.FetchGroup.NO_UNSEEN);
+ verify(mockResponder).respond(okResponse);
+ verifyNoMoreInteractions(mockMailboxManager, targetMessageManager, mockResponder, mockNextProcessor);
+ }
+
+
+ @Test
+ public void processShouldWorkWithMultipleRanges() throws Exception {
+ CopyRequest copyRequest = new CopyRequest(ImapCommand.anyStateCommand("Name"), new IdRange[] {new IdRange(5, 6), new IdRange(1, 3)}, ImapConstants.INBOX_NAME, true, TAG);
+
+ MailboxSession.User user = mock(MailboxSession.User.class);
+ when(user.getUserName()).thenReturn("username");
+ when(mockMailboxSession.getPersonalSpace()).thenReturn("");
+ when(mockMailboxSession.getUser()).thenReturn(user);
+ when(mockMailboxSession.getSessionId()).thenReturn(42L);
+ when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED);
+ when(mockImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mockMailboxSession);
+ MailboxPath inbox = MailboxPath.inbox(mockMailboxSession);
+ MailboxPath selected = new MailboxPath(inbox, "selected");
+ SelectedMailbox selectedMailbox = mock(SelectedMailbox.class);
+ when(selectedMailbox.getLastUid()).thenReturn(8L);
+ when(selectedMailbox.existsCount()).thenReturn(8L);
+ when(selectedMailbox.getPath()).thenReturn(selected);
+ when(mockImapSession.getSelected()).thenReturn(selectedMailbox);
+ when(mockMailboxManager.mailboxExists(inbox, mockMailboxSession)).thenReturn(true);
+ MessageManager targetMessageManager = mock(MessageManager.class);
+ when(mockMailboxManager.getMailbox(inbox, mockMailboxSession)).thenReturn(targetMessageManager);
+ when(targetMessageManager.getMetaData(false, mockMailboxSession, MessageManager.MetaData.FetchGroup.NO_UNSEEN)).thenReturn(new MailboxMetaData(null, null, 58L, 18L, 8L, 8L, 8L, 8L, true, true, null));
+ StatusResponse okResponse = mock(StatusResponse.class);
+ when(mockStatusResponseFactory.taggedOk(any(String.class), any(ImapCommand.class), any(HumanReadableText.class), any(StatusResponse.ResponseCode.class))).thenReturn(okResponse);
+
+ testee.process(copyRequest, mockResponder, mockImapSession);
+
+ verify(mockMailboxManager).startProcessingRequest(mockMailboxSession);
+ verify(mockMailboxManager).endProcessingRequest(mockMailboxSession);
+ verify(mockMailboxManager).mailboxExists(inbox, mockMailboxSession);
+ verify(mockMailboxManager).getMailbox(inbox, mockMailboxSession);
+ verify(mockMailboxManager).copyMessages(MessageRange.range(5, 6), selected, inbox, mockMailboxSession);
+ verify(mockMailboxManager).copyMessages(MessageRange.range(1, 3), selected, inbox, mockMailboxSession);
+ verify(targetMessageManager).getMetaData(false, mockMailboxSession, MessageManager.MetaData.FetchGroup.NO_UNSEEN);
+ verify(mockResponder).respond(okResponse);
+ verifyNoMoreInteractions(mockMailboxManager, targetMessageManager, mockResponder, mockNextProcessor);
+ }
+
+ @Test
+ public void processShouldRespondNoOnUnExistingTargetMailbox() throws Exception {
+ CopyRequest copyRequest = new CopyRequest(ImapCommand.anyStateCommand("Name"), new IdRange[] {new IdRange(4, 6)}, ImapConstants.INBOX_NAME, true, TAG);
+
+ MailboxSession.User user = mock(MailboxSession.User.class);
+ when(user.getUserName()).thenReturn("username");
+ when(mockMailboxSession.getPersonalSpace()).thenReturn("");
+ when(mockMailboxSession.getUser()).thenReturn(user);
+ when(mockMailboxSession.getSessionId()).thenReturn(42L);
+ when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED);
+ when(mockImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mockMailboxSession);
+ MailboxPath inbox = MailboxPath.inbox(mockMailboxSession);
+ MailboxPath selected = new MailboxPath(inbox, "selected");
+ SelectedMailbox selectedMailbox = mock(SelectedMailbox.class);
+ when(selectedMailbox.getLastUid()).thenReturn(8L);
+ when(selectedMailbox.existsCount()).thenReturn(8L);
+ when(selectedMailbox.getPath()).thenReturn(selected);
+ when(mockImapSession.getSelected()).thenReturn(selectedMailbox);
+ when(mockMailboxManager.mailboxExists(inbox, mockMailboxSession)).thenReturn(false);
+
+ StatusResponse noResponse = mock(StatusResponse.class);
+ when(mockStatusResponseFactory.taggedNo(any(String.class), any(ImapCommand.class), any(HumanReadableText.class), any(StatusResponse.ResponseCode.class))).thenReturn(noResponse);
+
+ testee.process(copyRequest, mockResponder, mockImapSession);
+
+ verify(mockMailboxManager).startProcessingRequest(mockMailboxSession);
+ verify(mockMailboxManager).endProcessingRequest(mockMailboxSession);
+ verify(mockMailboxManager).mailboxExists(inbox, mockMailboxSession);
+ verify(mockResponder).respond(noResponse);
+ verifyNoMoreInteractions(mockMailboxManager, mockResponder, mockNextProcessor);
+ }
+
+ @Test
+ public void processShouldRespondNoOnMailboxException() throws Exception {
+ CopyRequest copyRequest = new CopyRequest(ImapCommand.anyStateCommand("Name"), new IdRange[] {new IdRange(4, 6)}, ImapConstants.INBOX_NAME, true, TAG);
+
+ MailboxSession.User user = mock(MailboxSession.User.class);
+ when(user.getUserName()).thenReturn("username");
+ when(mockMailboxSession.getPersonalSpace()).thenReturn("");
+ when(mockMailboxSession.getUser()).thenReturn(user);
+ when(mockImapSession.getLog()).thenReturn(LOGGER);
+ when(mockMailboxSession.getSessionId()).thenReturn(42L);
+ when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED);
+ when(mockImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mockMailboxSession);
+ MailboxPath inbox = MailboxPath.inbox(mockMailboxSession);
+ MailboxPath selected = new MailboxPath(inbox, "selected");
+ SelectedMailbox selectedMailbox = mock(SelectedMailbox.class);
+ when(selectedMailbox.getLastUid()).thenReturn(8L);
+ when(selectedMailbox.existsCount()).thenReturn(8L);
+ when(selectedMailbox.getPath()).thenReturn(selected);
+ when(mockImapSession.getSelected()).thenReturn(selectedMailbox);
+ when(mockMailboxManager.mailboxExists(inbox, mockMailboxSession)).thenThrow(new MailboxException());
+
+ StatusResponse noResponse = mock(StatusResponse.class);
+ when(mockStatusResponseFactory.taggedNo(any(String.class), any(ImapCommand.class), any(HumanReadableText.class))).thenReturn(noResponse);
+
+ testee.process(copyRequest, mockResponder, mockImapSession);
+
+ verify(mockMailboxManager).startProcessingRequest(mockMailboxSession);
+ verify(mockMailboxManager).endProcessingRequest(mockMailboxSession);
+ verify(mockMailboxManager).mailboxExists(inbox, mockMailboxSession);
+ verify(mockResponder).respond(noResponse);
+ verifyNoMoreInteractions(mockMailboxManager, mockResponder, mockNextProcessor);
+ }
+
+ @Test
+ public void processShouldNotHandleMoveRequests() throws Exception {
+ MoveRequest moveRequest = new MoveRequest(ImapCommand.anyStateCommand("Name"), new IdRange[] {new IdRange(4, 6)}, ImapConstants.INBOX_NAME, true, TAG);
+
+ testee.process(moveRequest, mockResponder, mockImapSession);
+
+ verify(mockNextProcessor).process(moveRequest, mockResponder, mockImapSession);
+ verifyNoMoreInteractions(mockMailboxManager, mockResponder, mockNextProcessor);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/45edd6c0/protocols/imap/src/test/java/org/apache/james/imap/processor/MoveProcessorTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/MoveProcessorTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/MoveProcessorTest.java
new file mode 100644
index 0000000..3b9ee72
--- /dev/null
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/MoveProcessorTest.java
@@ -0,0 +1,231 @@
+/****************************************************************
+ * 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.imap.processor;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.when;
+
+import org.apache.james.imap.api.ImapCommand;
+import org.apache.james.imap.api.ImapConstants;
+import org.apache.james.imap.api.ImapSessionState;
+import org.apache.james.imap.api.ImapSessionUtils;
+import org.apache.james.imap.api.display.HumanReadableText;
+import org.apache.james.imap.api.message.IdRange;
+import org.apache.james.imap.api.message.response.StatusResponse;
+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;
+import org.apache.james.imap.api.process.SelectedMailbox;
+import org.apache.james.imap.message.request.CopyRequest;
+import org.apache.james.imap.message.request.MoveRequest;
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.MessageManager;
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.MessageRange;
+import org.apache.james.mailbox.store.MailboxMetaData;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.Lists;
+
+public class MoveProcessorTest {
+
+ public static final String TAG = "TAG";
+ private static final Logger LOGGER = LoggerFactory.getLogger(MoveProcessorTest.class);
+
+ private MoveProcessor testee;
+ private ImapProcessor mockNextProcessor;
+ private MailboxManager mockMailboxManager;
+ private StatusResponseFactory mockStatusResponseFactory;
+ private ImapProcessor.Responder mockResponder;
+ private ImapSession mockImapSession;
+ private MailboxSession mockMailboxSession;
+
+ @Before
+ public void setUp() {
+ mockNextProcessor = mock(ImapProcessor.class);
+ mockMailboxManager = mock(MailboxManager.class);
+ mockStatusResponseFactory = mock(StatusResponseFactory.class);
+ mockResponder = mock(ImapProcessor.Responder.class);
+ mockImapSession = mock(ImapSession.class);
+ mockMailboxSession = mock(MailboxSession.class);
+
+ testee = new MoveProcessor(mockNextProcessor, mockMailboxManager, mockStatusResponseFactory);
+ }
+
+ @Test
+ public void processShouldWork() throws Exception {
+ MoveRequest moveRequest = new MoveRequest(ImapCommand.anyStateCommand("Name"), new IdRange[] {new IdRange(4, 6)}, ImapConstants.INBOX_NAME, true, TAG);
+
+ MailboxSession.User user = mock(MailboxSession.User.class);
+ when(user.getUserName()).thenReturn("username");
+ when(mockMailboxSession.getPersonalSpace()).thenReturn("");
+ when(mockMailboxSession.getUser()).thenReturn(user);
+ when(mockMailboxSession.getSessionId()).thenReturn(42L);
+ when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED);
+ when(mockImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mockMailboxSession);
+ MailboxPath inbox = MailboxPath.inbox(mockMailboxSession);
+ MailboxPath selected = new MailboxPath(inbox, "selected");
+ SelectedMailbox selectedMailbox = mock(SelectedMailbox.class);
+ when(selectedMailbox.getLastUid()).thenReturn(8L);
+ when(selectedMailbox.existsCount()).thenReturn(8L);
+ when(selectedMailbox.getPath()).thenReturn(selected);
+ when(mockImapSession.getSelected()).thenReturn(selectedMailbox);
+ when(mockMailboxManager.mailboxExists(inbox, mockMailboxSession)).thenReturn(true);
+ MessageManager targetMessageManager = mock(MessageManager.class);
+ when(mockMailboxManager.getMailbox(inbox, mockMailboxSession)).thenReturn(targetMessageManager);
+ when(targetMessageManager.getMetaData(false, mockMailboxSession, MessageManager.MetaData.FetchGroup.NO_UNSEEN)).thenReturn(new MailboxMetaData(null, null, 58L, 18L, 8L, 8L, 8L, 8L, true, true, null));
+ StatusResponse okResponse = mock(StatusResponse.class);
+ when(mockStatusResponseFactory.taggedOk(any(String.class), any(ImapCommand.class), any(HumanReadableText.class), any(StatusResponse.ResponseCode.class))).thenReturn(okResponse);
+ when(mockMailboxManager.moveMessages(MessageRange.range(4, 6), selected, inbox, mockMailboxSession)).thenReturn(Lists.<MessageRange>newArrayList(MessageRange.range(4, 6)));
+
+ testee.process(moveRequest, mockResponder, mockImapSession);
+
+ verify(mockMailboxManager).startProcessingRequest(mockMailboxSession);
+ verify(mockMailboxManager).endProcessingRequest(mockMailboxSession);
+ verify(mockMailboxManager).mailboxExists(inbox, mockMailboxSession);
+ verify(mockMailboxManager).getMailbox(inbox, mockMailboxSession);
+ verify(mockMailboxManager).moveMessages(MessageRange.range(4, 6), selected, inbox, mockMailboxSession);
+ verify(targetMessageManager).getMetaData(false, mockMailboxSession, MessageManager.MetaData.FetchGroup.NO_UNSEEN);
+ verify(mockResponder).respond(okResponse);
+ verifyNoMoreInteractions(mockMailboxManager, targetMessageManager, mockResponder, mockNextProcessor);
+ }
+
+
+ @Test
+ public void processShouldWorkWithMultipleRanges() throws Exception {
+ MoveRequest moveRequest = new MoveRequest(ImapCommand.anyStateCommand("Name"), new IdRange[] {new IdRange(5, 6), new IdRange(1,3)}, ImapConstants.INBOX_NAME, true, TAG);
+
+ MailboxSession.User user = mock(MailboxSession.User.class);
+ when(user.getUserName()).thenReturn("username");
+ when(mockMailboxSession.getPersonalSpace()).thenReturn("");
+ when(mockMailboxSession.getUser()).thenReturn(user);
+ when(mockMailboxSession.getSessionId()).thenReturn(42L);
+ when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED);
+ when(mockImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mockMailboxSession);
+ MailboxPath inbox = MailboxPath.inbox(mockMailboxSession);
+ MailboxPath selected = new MailboxPath(inbox, "selected");
+ SelectedMailbox selectedMailbox = mock(SelectedMailbox.class);
+ when(selectedMailbox.getLastUid()).thenReturn(8L);
+ when(selectedMailbox.existsCount()).thenReturn(8L);
+ when(selectedMailbox.getPath()).thenReturn(selected);
+ when(mockImapSession.getSelected()).thenReturn(selectedMailbox);
+ when(mockMailboxManager.mailboxExists(inbox, mockMailboxSession)).thenReturn(true);
+ MessageManager targetMessageManager = mock(MessageManager.class);
+ when(mockMailboxManager.getMailbox(inbox, mockMailboxSession)).thenReturn(targetMessageManager);
+ when(targetMessageManager.getMetaData(false, mockMailboxSession, MessageManager.MetaData.FetchGroup.NO_UNSEEN)).thenReturn(new MailboxMetaData(null, null, 58L, 18L, 8L, 8L, 8L, 8L, true, true, null));
+ StatusResponse okResponse = mock(StatusResponse.class);
+ when(mockStatusResponseFactory.taggedOk(any(String.class), any(ImapCommand.class), any(HumanReadableText.class), any(StatusResponse.ResponseCode.class))).thenReturn(okResponse);
+
+ testee.process(moveRequest, mockResponder, mockImapSession);
+
+ verify(mockMailboxManager).startProcessingRequest(mockMailboxSession);
+ verify(mockMailboxManager).endProcessingRequest(mockMailboxSession);
+ verify(mockMailboxManager).mailboxExists(inbox, mockMailboxSession);
+ verify(mockMailboxManager).getMailbox(inbox, mockMailboxSession);
+ verify(mockMailboxManager).moveMessages(MessageRange.range(5, 6), selected, inbox, mockMailboxSession);
+ verify(mockMailboxManager).moveMessages(MessageRange.range(1, 3), selected, inbox, mockMailboxSession);
+ verify(targetMessageManager).getMetaData(false, mockMailboxSession, MessageManager.MetaData.FetchGroup.NO_UNSEEN);
+ verify(mockResponder).respond(okResponse);
+ verifyNoMoreInteractions(mockMailboxManager, targetMessageManager, mockResponder, mockNextProcessor);
+ }
+
+ @Test
+ public void processShouldRespondNoOnUnExistingTargetMailbox() throws Exception {
+ MoveRequest moveRequest = new MoveRequest(ImapCommand.anyStateCommand("Name"), new IdRange[] {new IdRange(5, 6), new IdRange(1,3)}, ImapConstants.INBOX_NAME, true, TAG);
+
+ MailboxSession.User user = mock(MailboxSession.User.class);
+ when(user.getUserName()).thenReturn("username");
+ when(mockMailboxSession.getPersonalSpace()).thenReturn("");
+ when(mockMailboxSession.getUser()).thenReturn(user);
+ when(mockMailboxSession.getSessionId()).thenReturn(42L);
+ when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED);
+ when(mockImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mockMailboxSession);
+ MailboxPath inbox = MailboxPath.inbox(mockMailboxSession);
+ MailboxPath selected = new MailboxPath(inbox, "selected");
+ SelectedMailbox selectedMailbox = mock(SelectedMailbox.class);
+ when(selectedMailbox.getLastUid()).thenReturn(8L);
+ when(selectedMailbox.existsCount()).thenReturn(8L);
+ when(selectedMailbox.getPath()).thenReturn(selected);
+ when(mockImapSession.getSelected()).thenReturn(selectedMailbox);
+ when(mockMailboxManager.mailboxExists(inbox, mockMailboxSession)).thenReturn(false);
+
+ StatusResponse noResponse = mock(StatusResponse.class);
+ when(mockStatusResponseFactory.taggedNo(any(String.class), any(ImapCommand.class), any(HumanReadableText.class), any(StatusResponse.ResponseCode.class))).thenReturn(noResponse);
+
+ testee.process(moveRequest, mockResponder, mockImapSession);
+
+ verify(mockMailboxManager).startProcessingRequest(mockMailboxSession);
+ verify(mockMailboxManager).endProcessingRequest(mockMailboxSession);
+ verify(mockMailboxManager).mailboxExists(inbox, mockMailboxSession);
+ verify(mockResponder).respond(noResponse);
+ verifyNoMoreInteractions(mockMailboxManager, mockResponder, mockNextProcessor);
+ }
+
+ @Test
+ public void processShouldRespondNoOnMailboxException() throws Exception {
+ MoveRequest moveRequest = new MoveRequest(ImapCommand.anyStateCommand("Name"), new IdRange[] {new IdRange(5, 6), new IdRange(1,3)}, ImapConstants.INBOX_NAME, true, TAG);
+
+ MailboxSession.User user = mock(MailboxSession.User.class);
+ when(user.getUserName()).thenReturn("username");
+ when(mockMailboxSession.getPersonalSpace()).thenReturn("");
+ when(mockMailboxSession.getUser()).thenReturn(user);
+ when(mockImapSession.getLog()).thenReturn(LOGGER);
+ when(mockMailboxSession.getSessionId()).thenReturn(42L);
+ when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED);
+ when(mockImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mockMailboxSession);
+ MailboxPath inbox = MailboxPath.inbox(mockMailboxSession);
+ MailboxPath selected = new MailboxPath(inbox, "selected");
+ SelectedMailbox selectedMailbox = mock(SelectedMailbox.class);
+ when(selectedMailbox.getLastUid()).thenReturn(8L);
+ when(selectedMailbox.existsCount()).thenReturn(8L);
+ when(selectedMailbox.getPath()).thenReturn(selected);
+ when(mockImapSession.getSelected()).thenReturn(selectedMailbox);
+ when(mockMailboxManager.mailboxExists(inbox, mockMailboxSession)).thenThrow(new MailboxException());
+
+ StatusResponse noResponse = mock(StatusResponse.class);
+ when(mockStatusResponseFactory.taggedNo(any(String.class), any(ImapCommand.class), any(HumanReadableText.class))).thenReturn(noResponse);
+
+ testee.process(moveRequest, mockResponder, mockImapSession);
+
+ verify(mockMailboxManager).startProcessingRequest(mockMailboxSession);
+ verify(mockMailboxManager).endProcessingRequest(mockMailboxSession);
+ verify(mockMailboxManager).mailboxExists(inbox, mockMailboxSession);
+ verify(mockResponder).respond(noResponse);
+ verifyNoMoreInteractions(mockMailboxManager, mockResponder, mockNextProcessor);
+ }
+
+ @Test
+ public void processShouldNotHandleCopyRequests() throws Exception {
+ CopyRequest copyRequest = new CopyRequest(ImapCommand.anyStateCommand("Name"), new IdRange[] {new IdRange(4, 6)}, ImapConstants.INBOX_NAME, true, TAG);
+
+ testee.process(copyRequest, mockResponder, mockImapSession);
+
+ verify(mockNextProcessor).process(copyRequest, mockResponder, mockImapSession);
+ verifyNoMoreInteractions(mockMailboxManager, mockResponder, mockNextProcessor);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[19/20] james-project git commit: IMAP-370 Add MOVE extension to
supported commands in documentation
Posted by bt...@apache.org.
IMAP-370 Add MOVE extension to supported commands in documentation
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/6ffe855a
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/6ffe855a
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/6ffe855a
Branch: refs/heads/master
Commit: 6ffe855a07220f6a45cfbd7bbec0602c5f3327f4
Parents: 33a53fa
Author: Benoit Tellier <bt...@linagora.com>
Authored: Fri Feb 26 11:27:43 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Fri Mar 4 19:35:24 2016 +0700
----------------------------------------------------------------------
protocols/src/site/xdoc/imap4.xml | 7 ++++---
server/src/site/xdoc/feature-protocols.xml | 20 +++++++++++++++++---
2 files changed, 21 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/6ffe855a/protocols/src/site/xdoc/imap4.xml
----------------------------------------------------------------------
diff --git a/protocols/src/site/xdoc/imap4.xml b/protocols/src/site/xdoc/imap4.xml
index 909e5f4..ee37a0a 100644
--- a/protocols/src/site/xdoc/imap4.xml
+++ b/protocols/src/site/xdoc/imap4.xml
@@ -14,7 +14,7 @@
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 govaerning permissions and limitations
+ specific language governing permissions and limitations
under the License.
-->
@@ -56,10 +56,11 @@
<li>ENABLE (in release 0.2.1)</li>
<li>CONDSTORE (RFC 4551 http://www.ietf.org/rfc/rfc4551.txt in release 0.3)</li>
<li>RESYNCH (RFC 5162 http://www.ietf.org/rfc/rfc5162.txt in trunk)</li>
+ <li>MOVE (RFC 6851 https://tools.ietf.org/html/rfc6851 in trunk). This is enabled only if you use a MailboxManager exposing the Move capability</li>
</ul>
- <p>We follow RFC2683 recommandations for our implementations:</p>
+ <p>We follow RFC2683 recommendations for our implementations:</p>
<ul>
- <li>IMAP4 Implementation Recommandations (RFC 2683 http://www.ietf.org/rfc/rfc2683.txt)</li>
+ <li>IMAP4 Implementation Recommendations (RFC 2683 http://www.ietf.org/rfc/rfc2683.txt)</li>
</ul>
<p>Interesting features:</p>
<ul>
http://git-wip-us.apache.org/repos/asf/james-project/blob/6ffe855a/server/src/site/xdoc/feature-protocols.xml
----------------------------------------------------------------------
diff --git a/server/src/site/xdoc/feature-protocols.xml b/server/src/site/xdoc/feature-protocols.xml
index 687ddb3..a479726 100644
--- a/server/src/site/xdoc/feature-protocols.xml
+++ b/server/src/site/xdoc/feature-protocols.xml
@@ -52,7 +52,10 @@
client/server communication.</p>
<p>More information on configuring the SMTP service can be found <a href="config-smtp-lmtp.html">here</a>.</p>
-
+
+ <p>You can find further information about supported protocols and RFCs
+ <a href="http://james.apache.org/protocols/smtp.html">on the JAMES-PROTOCOLS project SMTP page</a>
+ </p>
</subsection>
<subsection name="IMAP4 Protocol">
@@ -66,7 +69,15 @@
IMAP4 client connecting to the server.</p>
<p>More information on configuring the IMAP4 service can be found <a href="config-imap4.html">here</a>.</p>
-
+
+ <p>You can find further information about supported protocols and RFCs
+ <a href="http://james.apache.org/protocols/imap4.html">on the JAMES-PROTOCOLS project IMAP4 page</a>
+ </p>
+
+ <p>
+ Note that MOVE extension (RFC-6851) needs a MailboxManager implementing the move function. For now, this is only done with
+ the CassandraMailboxManager
+ </p>
</subsection>
<subsection name="POP3 Protocol">
@@ -80,7 +91,10 @@
POP3 client connecting to the server.</p>
<p>More information on configuring the POP3 service can be found <a href="config-pop3.html">here</a>.</p>
-
+
+ <p>You can find further information about supported protocols and RFCs
+ <a href="http://james.apache.org/protocols/pop3.html">on the JAMES-PROTOCOLS project POP3 page</a>
+ </p>
</subsection>
<subsection name="FetchMail">
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[06/20] james-project git commit: IMAP-370 Expunge notification
should be sent upon move
Posted by bt...@apache.org.
IMAP-370 Expunge notification should be sent upon move
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/762af8ed
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/762af8ed
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/762af8ed
Branch: refs/heads/master
Commit: 762af8ed3f2309305663caf75d2da2db809645c9
Parents: 792a87a
Author: Benoit Tellier <bt...@linagora.com>
Authored: Wed Feb 24 16:26:02 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Fri Mar 4 19:35:23 2016 +0700
----------------------------------------------------------------------
.../apache/james/mailbox/store/MoveResult.java | 43 ++++++++++++++++++++
.../mailbox/store/StoreMessageManager.java | 15 ++++---
2 files changed, 53 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/762af8ed/mailbox/store/src/main/java/org/apache/james/mailbox/store/MoveResult.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/MoveResult.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/MoveResult.java
new file mode 100644
index 0000000..76bbb86
--- /dev/null
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/MoveResult.java
@@ -0,0 +1,43 @@
+/****************************************************************
+ * 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.store;
+
+import java.util.Iterator;
+
+import org.apache.james.mailbox.model.MessageMetaData;
+
+public class MoveResult {
+
+ private final Iterator<MessageMetaData> movedMessages;
+ private final Iterator<MessageMetaData> originalMessages;
+
+ public MoveResult(Iterator<MessageMetaData> movedMessages, Iterator<MessageMetaData> originalMessages) {
+ this.movedMessages = movedMessages;
+ this.originalMessages = originalMessages;
+ }
+
+ public Iterator<MessageMetaData> getMovedMessages() {
+ return movedMessages;
+ }
+
+ public Iterator<MessageMetaData> getOriginalMessages() {
+ return originalMessages;
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/762af8ed/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
index f0098c3..6b842bb 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
@@ -84,6 +84,9 @@ import org.apache.james.mime4j.stream.MimeConfig;
import org.apache.james.mime4j.stream.MimeTokenStream;
import org.apache.james.mime4j.stream.RecursionMode;
+import com.google.common.base.Function;
+import com.google.common.collect.Iterators;
+
/**
* Base class for {@link org.apache.james.mailbox.MessageManager}
* implementations.
@@ -716,23 +719,23 @@ public class StoreMessageManager<Id extends MailboxId> implements org.apache.jam
return copiedRows.iterator();
}
- private Iterator<MessageMetaData> move(Iterator<MailboxMessage<Id>> originalRows,
- MailboxSession session) throws MailboxException {
+ private MoveResult move(Iterator<MailboxMessage<Id>> originalRows, MailboxSession session) throws MailboxException {
final List<MessageMetaData> movedRows = new ArrayList<MessageMetaData>();
+ final List<MessageMetaData> originalRowsCopy = new ArrayList<MessageMetaData>();
final MessageMapper<Id> messageMapper = mapperFactory.getMessageMapper(session);
while (originalRows.hasNext()) {
final MailboxMessage<Id> originalMessage = originalRows.next();
+ originalRowsCopy.add(new SimpleMessageMetaData(originalMessage));
MessageMetaData data = messageMapper.execute(new Mapper.Transaction<MessageMetaData>() {
public MessageMetaData run() throws MailboxException {
return messageMapper.move(getMailboxEntity(), originalMessage);
-
}
});
movedRows.add(data);
}
- return movedRows.iterator();
+ return new MoveResult(movedRows.iterator(), originalRowsCopy.iterator());
}
@@ -743,7 +746,9 @@ public class StoreMessageManager<Id extends MailboxId> implements org.apache.jam
private SortedMap<Long, MessageMetaData> move(MessageRange set, StoreMessageManager<Id> to, MailboxSession session) throws MailboxException {
Iterator<MailboxMessage<Id>> originalRows = retrieveOriginalRows(set, session);
- return collectMetadata(to.move(originalRows, session));
+ MoveResult moveResult = to.move(originalRows, session);
+ dispatcher.expunged(session, collectMetadata(moveResult.getOriginalMessages()), getMailboxEntity());
+ return collectMetadata(moveResult.getMovedMessages());
}
private Iterator<MailboxMessage<Id>> retrieveOriginalRows(MessageRange set, MailboxSession session) throws MailboxException {
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org