You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ad...@apache.org on 2016/03/01 14:47:11 UTC
[1/5] james-project git commit: JAMES-1691 Move MailSpool to
jmap.send package
Repository: james-project
Updated Branches:
refs/heads/master ca25b8226 -> 00678d881
JAMES-1691 Move MailSpool to jmap.send package
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/66579d71
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/66579d71
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/66579d71
Branch: refs/heads/master
Commit: 66579d716ce074f3ecca68ce8adbd6ea47ae8c5c
Parents: 813af4a
Author: Raphael Ouazana <ra...@linagora.com>
Authored: Wed Feb 24 15:00:46 2016 +0100
Committer: Raphael Ouazana <ra...@linagora.com>
Committed: Wed Feb 24 15:00:46 2016 +0100
----------------------------------------------------------------------
.../org/apache/james/jmap/JMAPCommonModule.java | 2 +-
.../org/apache/james/jmap/send/MailSpool.java | 43 ++++++++
.../org/apache/james/jmap/utils/MailSpool.java | 43 --------
.../apache/james/jmap/send/MailSpoolTest.java | 106 +++++++++++++++++++
.../apache/james/jmap/utils/MailSpoolTest.java | 106 -------------------
5 files changed, 150 insertions(+), 150 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/66579d71/server/container/cassandra-guice/src/main/java/org/apache/james/jmap/JMAPCommonModule.java
----------------------------------------------------------------------
diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/jmap/JMAPCommonModule.java b/server/container/cassandra-guice/src/main/java/org/apache/james/jmap/JMAPCommonModule.java
index 3d8854a..14c2d9f 100644
--- a/server/container/cassandra-guice/src/main/java/org/apache/james/jmap/JMAPCommonModule.java
+++ b/server/container/cassandra-guice/src/main/java/org/apache/james/jmap/JMAPCommonModule.java
@@ -29,8 +29,8 @@ import org.apache.james.jmap.crypto.JamesSignatureHandler;
import org.apache.james.jmap.crypto.SignatureHandler;
import org.apache.james.jmap.crypto.SignedContinuationTokenManager;
import org.apache.james.jmap.memory.access.MemoryAccessTokenRepository;
+import org.apache.james.jmap.send.MailSpool;
import org.apache.james.jmap.utils.DefaultZonedDateTimeProvider;
-import org.apache.james.jmap.utils.MailSpool;
import org.apache.james.jmap.utils.ZonedDateTimeProvider;
import com.google.common.collect.ImmutableList;
http://git-wip-us.apache.org/repos/asf/james-project/blob/66579d71/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/MailSpool.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/MailSpool.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/MailSpool.java
new file mode 100644
index 0000000..6267890
--- /dev/null
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/MailSpool.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.jmap.send;
+
+import javax.inject.Inject;
+
+import org.apache.james.queue.api.MailQueue;
+import org.apache.james.queue.api.MailQueue.MailQueueException;
+import org.apache.james.queue.api.MailQueueFactory;
+import org.apache.mailet.Mail;
+
+import com.google.common.annotations.VisibleForTesting;
+
+public class MailSpool {
+
+ private final MailQueue queue;
+
+ @Inject
+ @VisibleForTesting MailSpool(MailQueueFactory queueFactory) {
+ queue = queueFactory.getQueue(MailQueueFactory.SPOOL);
+ }
+
+ public void send(Mail mail) throws MailQueueException {
+ queue.enQueue(mail);
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/66579d71/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/MailSpool.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/MailSpool.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/MailSpool.java
deleted file mode 100644
index 340d188..0000000
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/MailSpool.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one *
- * or more contributor license agreements. See the NOTICE file *
- * distributed with this work for additional information *
- * regarding copyright ownership. The ASF licenses this file *
- * to you under the Apache License, Version 2.0 (the *
- * "License"); you may not use this file except in compliance *
- * with the License. You may obtain a copy of the License at *
- * *
- * http://www.apache.org/licenses/LICENSE-2.0 *
- * *
- * Unless required by applicable law or agreed to in writing, *
- * software distributed under the License is distributed on an *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
- * KIND, either express or implied. See the License for the *
- * specific language governing permissions and limitations *
- * under the License. *
- ****************************************************************/
-
-package org.apache.james.jmap.utils;
-
-import javax.inject.Inject;
-
-import org.apache.james.queue.api.MailQueue;
-import org.apache.james.queue.api.MailQueue.MailQueueException;
-import org.apache.james.queue.api.MailQueueFactory;
-import org.apache.mailet.Mail;
-
-import com.google.common.annotations.VisibleForTesting;
-
-public class MailSpool {
-
- private final MailQueue queue;
-
- @Inject
- @VisibleForTesting MailSpool(MailQueueFactory queueFactory) {
- queue = queueFactory.getQueue(MailQueueFactory.SPOOL);
- }
-
- public void send(Mail mail) throws MailQueueException {
- queue.enQueue(mail);
- }
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/66579d71/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/MailSpoolTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/MailSpoolTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/MailSpoolTest.java
new file mode 100644
index 0000000..3687138
--- /dev/null
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/MailSpoolTest.java
@@ -0,0 +1,106 @@
+/****************************************************************
+ * 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.jmap.send;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.james.queue.api.MailQueue;
+import org.apache.james.queue.api.MailQueue.MailQueueException;
+import org.apache.james.queue.api.MailQueue.MailQueueItem;
+import org.apache.james.queue.api.MailQueueFactory;
+import org.apache.mailet.Mail;
+import org.apache.mailet.base.test.FakeMail;
+import org.junit.Before;
+import org.junit.Test;
+
+public class MailSpoolTest {
+
+ private MailSpool mailSpool;
+ private MailQueue myQueue;
+
+ @Before
+ public void setup() {
+ myQueue = new MyQueue();
+
+ mailSpool = new MailSpool(new MailQueueFactory() {
+
+ @Override
+ public MailQueue getQueue(String name) {
+ return myQueue;
+ }
+ });
+ }
+
+ @Test
+ public void sendShouldEnQueueTheMail() throws Exception {
+ FakeMail mail = new FakeMail();
+
+ mailSpool.send(mail);
+
+ assertThat(myQueue.deQueue())
+ .isNotNull()
+ .extracting(MailQueueItem::getMail)
+ .containsExactly(mail);
+ }
+
+ private static class MyQueue implements MailQueue {
+
+ private ConcurrentLinkedQueue<Mail> queue;
+
+ public MyQueue() {
+ queue = new ConcurrentLinkedQueue<Mail>();
+ }
+
+ @Override
+ public void enQueue(Mail mail) throws MailQueueException {
+ queue.add(mail);
+ }
+
+ @Override
+ public void enQueue(Mail mail, long delay, TimeUnit unit) throws MailQueueException {
+ }
+
+ @Override
+ public MailQueueItem deQueue() throws MailQueueException {
+ return new MyMailQueueItem(queue.poll());
+ }
+ }
+
+ private static class MyMailQueueItem implements MailQueueItem {
+
+ private final Mail mail;
+
+ public MyMailQueueItem(Mail mail) {
+ this.mail = mail;
+ }
+
+ @Override
+ public Mail getMail() {
+ return mail;
+ }
+
+ @Override
+ public void done(boolean success) throws MailQueueException {
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/66579d71/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/MailSpoolTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/MailSpoolTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/MailSpoolTest.java
deleted file mode 100644
index 359e649..0000000
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/MailSpoolTest.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one *
- * or more contributor license agreements. See the NOTICE file *
- * distributed with this work for additional information *
- * regarding copyright ownership. The ASF licenses this file *
- * to you under the Apache License, Version 2.0 (the *
- * "License"); you may not use this file except in compliance *
- * with the License. You may obtain a copy of the License at *
- * *
- * http://www.apache.org/licenses/LICENSE-2.0 *
- * *
- * Unless required by applicable law or agreed to in writing, *
- * software distributed under the License is distributed on an *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
- * KIND, either express or implied. See the License for the *
- * specific language governing permissions and limitations *
- * under the License. *
- ****************************************************************/
-
-package org.apache.james.jmap.utils;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import java.util.concurrent.ConcurrentLinkedQueue;
-import java.util.concurrent.TimeUnit;
-
-import org.apache.james.queue.api.MailQueue;
-import org.apache.james.queue.api.MailQueue.MailQueueException;
-import org.apache.james.queue.api.MailQueue.MailQueueItem;
-import org.apache.james.queue.api.MailQueueFactory;
-import org.apache.mailet.Mail;
-import org.apache.mailet.base.test.FakeMail;
-import org.junit.Before;
-import org.junit.Test;
-
-public class MailSpoolTest {
-
- private MailSpool mailSpool;
- private MailQueue myQueue;
-
- @Before
- public void setup() {
- myQueue = new MyQueue();
-
- mailSpool = new MailSpool(new MailQueueFactory() {
-
- @Override
- public MailQueue getQueue(String name) {
- return myQueue;
- }
- });
- }
-
- @Test
- public void sendShouldEnQueueTheMail() throws Exception {
- FakeMail mail = new FakeMail();
-
- mailSpool.send(mail);
-
- assertThat(myQueue.deQueue())
- .isNotNull()
- .extracting(MailQueueItem::getMail)
- .containsExactly(mail);
- }
-
- private static class MyQueue implements MailQueue {
-
- private ConcurrentLinkedQueue<Mail> queue;
-
- public MyQueue() {
- queue = new ConcurrentLinkedQueue<Mail>();
- }
-
- @Override
- public void enQueue(Mail mail) throws MailQueueException {
- queue.add(mail);
- }
-
- @Override
- public void enQueue(Mail mail, long delay, TimeUnit unit) throws MailQueueException {
- }
-
- @Override
- public MailQueueItem deQueue() throws MailQueueException {
- return new MyMailQueueItem(queue.poll());
- }
- }
-
- private static class MyMailQueueItem implements MailQueueItem {
-
- private final Mail mail;
-
- public MyMailQueueItem(Mail mail) {
- this.mail = mail;
- }
-
- @Override
- public Mail getMail() {
- return mail;
- }
-
- @Override
- public void done(boolean success) throws MailQueueException {
- }
- }
-}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[2/5] james-project git commit: JAMES-1691 Add a decorator to
MailQueueItem to be able to launch specific actions
Posted by ad...@apache.org.
JAMES-1691 Add a decorator to MailQueueItem to be able to launch specific actions
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/a5a9ee20
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/a5a9ee20
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/a5a9ee20
Branch: refs/heads/master
Commit: a5a9ee2083f5f28eb370e60211fcd487836f7d8d
Parents: 66579d7
Author: Raphael Ouazana <ra...@linagora.com>
Authored: Wed Feb 17 18:49:42 2016 +0100
Committer: Raphael Ouazana <ra...@linagora.com>
Committed: Wed Feb 24 15:01:09 2016 +0100
----------------------------------------------------------------------
.../modules/server/ActiveMQQueueModule.java | 10 +++-
.../james/queue/activemq/ActiveMQMailQueue.java | 12 ++--
.../activemq/ActiveMQMailQueueFactory.java | 11 +++-
.../META-INF/spring/activemq-queue-context.xml | 10 +++-
.../queue/activemq/ActiveMQMailQueueTest.java | 5 +-
server/queue/queue-api/pom.xml | 25 +++++++-
.../api/MailQueueItemDecoratorFactory.java | 61 ++++++++++++++++++++
.../apache/james/queue/file/FileMailQueue.java | 8 ++-
.../james/queue/file/FileMailQueueFactory.java | 7 ++-
.../apache/james/queue/jms/JMSMailQueue.java | 51 ++++++++--------
.../james/queue/jms/JMSMailQueueFactory.java | 11 +++-
.../queue/jms/AbstractJMSMailQueueTest.java | 43 +++++++-------
12 files changed, 190 insertions(+), 64 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/a5a9ee20/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/ActiveMQQueueModule.java
----------------------------------------------------------------------
diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/ActiveMQQueueModule.java b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/ActiveMQQueueModule.java
index 6825eb6..92d972c 100644
--- a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/ActiveMQQueueModule.java
+++ b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/ActiveMQQueueModule.java
@@ -23,6 +23,7 @@ import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.Singleton;
import org.apache.james.queue.activemq.ActiveMQMailQueueFactory;
+import org.apache.james.queue.api.MailQueueItemDecoratorFactory;
import org.apache.james.queue.api.MailQueueFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -46,12 +47,17 @@ public class ActiveMQQueueModule extends AbstractModule {
@Provides
@Singleton
- public MailQueueFactory createActiveMailQueueFactory(ConnectionFactory connectionFactory, ActiveMQMailQueueFactory activeMQMailQueueFactory) {
+ public MailQueueFactory createActiveMailQueueFactory(ActiveMQMailQueueFactory activeMQMailQueueFactory) {
activeMQMailQueueFactory.setUseJMX(true);
- activeMQMailQueueFactory.setConnectionFactory(connectionFactory);
activeMQMailQueueFactory.setLog(LOGGER);
activeMQMailQueueFactory.init();
return activeMQMailQueueFactory;
}
+
+ @Provides
+ @Singleton
+ public MailQueueItemDecoratorFactory defaultMailQueueItemDecoratorFactory() {
+ return MailQueueItemDecoratorFactory.RAW_FACTORY;
+ }
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a5a9ee20/server/queue/queue-activemq/src/main/java/org/apache/james/queue/activemq/ActiveMQMailQueue.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-activemq/src/main/java/org/apache/james/queue/activemq/ActiveMQMailQueue.java b/server/queue/queue-activemq/src/main/java/org/apache/james/queue/activemq/ActiveMQMailQueue.java
index fc9d54b..dbb507a 100644
--- a/server/queue/queue-activemq/src/main/java/org/apache/james/queue/activemq/ActiveMQMailQueue.java
+++ b/server/queue/queue-activemq/src/main/java/org/apache/james/queue/activemq/ActiveMQMailQueue.java
@@ -44,6 +44,7 @@ import org.apache.james.core.MimeMessageCopyOnWriteProxy;
import org.apache.james.core.MimeMessageInputStream;
import org.apache.james.core.MimeMessageSource;
import org.apache.james.queue.api.MailQueue;
+import org.apache.james.queue.api.MailQueueItemDecoratorFactory;
import org.apache.james.queue.jms.JMSMailQueue;
import org.apache.mailet.Mail;
import org.slf4j.Logger;
@@ -91,8 +92,8 @@ public class ActiveMQMailQueue extends JMSMailQueue implements ActiveMQSupport {
* Construct a {@link ActiveMQMailQueue} which only use {@link BlobMessage}
*
*/
- public ActiveMQMailQueue(final ConnectionFactory connectionFactory, final String queuename, final Logger logger) {
- this(connectionFactory, queuename, true, logger);
+ public ActiveMQMailQueue(final ConnectionFactory connectionFactory, final MailQueueItemDecoratorFactory mailQueueItemDecoratorFactory, final String queuename, final Logger logger) {
+ this(connectionFactory, mailQueueItemDecoratorFactory, queuename, true, logger);
}
/**
@@ -103,8 +104,8 @@ public class ActiveMQMailQueue extends JMSMailQueue implements ActiveMQSupport {
* @param useBlob
* @param logger
*/
- public ActiveMQMailQueue(final ConnectionFactory connectionFactory, final String queuename, boolean useBlob, final Logger logger) {
- super(connectionFactory, queuename, logger);
+ public ActiveMQMailQueue(final ConnectionFactory connectionFactory, final MailQueueItemDecoratorFactory mailQueueItemDecoratorFactory, final String queuename, boolean useBlob, final Logger logger) {
+ super(connectionFactory, mailQueueItemDecoratorFactory, queuename, logger);
this.useBlob = useBlob;
}
@@ -240,7 +241,8 @@ public class ActiveMQMailQueue extends JMSMailQueue implements ActiveMQSupport {
@Override
protected MailQueueItem createMailQueueItem(Connection connection, Session session, MessageConsumer consumer, Message message) throws JMSException, MessagingException {
Mail mail = createMail(message);
- return new ActiveMQMailQueueItem(mail, connection, session, consumer, message, logger);
+ ActiveMQMailQueueItem activeMQMailQueueItem = new ActiveMQMailQueueItem(mail, connection, session, consumer, message, logger);
+ return mailQueueItemDecoratorFactory.decorate(activeMQMailQueueItem);
}
@Override
http://git-wip-us.apache.org/repos/asf/james-project/blob/a5a9ee20/server/queue/queue-activemq/src/main/java/org/apache/james/queue/activemq/ActiveMQMailQueueFactory.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-activemq/src/main/java/org/apache/james/queue/activemq/ActiveMQMailQueueFactory.java b/server/queue/queue-activemq/src/main/java/org/apache/james/queue/activemq/ActiveMQMailQueueFactory.java
index 1b2d777..6547be3 100644
--- a/server/queue/queue-activemq/src/main/java/org/apache/james/queue/activemq/ActiveMQMailQueueFactory.java
+++ b/server/queue/queue-activemq/src/main/java/org/apache/james/queue/activemq/ActiveMQMailQueueFactory.java
@@ -18,7 +18,11 @@
****************************************************************/
package org.apache.james.queue.activemq;
+import javax.inject.Inject;
+import javax.jms.ConnectionFactory;
+
import org.apache.james.queue.api.MailQueue;
+import org.apache.james.queue.api.MailQueueItemDecoratorFactory;
import org.apache.james.queue.api.MailQueueFactory;
import org.apache.james.queue.jms.JMSMailQueueFactory;
@@ -30,12 +34,17 @@ public class ActiveMQMailQueueFactory extends JMSMailQueueFactory {
private boolean useBlob = true;
+ @Inject
+ public ActiveMQMailQueueFactory(ConnectionFactory connectionFactory, MailQueueItemDecoratorFactory mailQueueItemDecoratorFactory) {
+ super(connectionFactory, mailQueueItemDecoratorFactory);
+ }
+
public void setUseBlobMessages(boolean useBlob) {
this.useBlob = useBlob;
}
@Override
protected MailQueue createMailQueue(String name) {
- return new ActiveMQMailQueue(connectionFactory, name, useBlob, log);
+ return new ActiveMQMailQueue(connectionFactory, mailQueueItemDecoratorFactory, name, useBlob, log);
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a5a9ee20/server/queue/queue-activemq/src/main/resources/META-INF/spring/activemq-queue-context.xml
----------------------------------------------------------------------
diff --git a/server/queue/queue-activemq/src/main/resources/META-INF/spring/activemq-queue-context.xml b/server/queue/queue-activemq/src/main/resources/META-INF/spring/activemq-queue-context.xml
index 5f307bd..1545212 100644
--- a/server/queue/queue-activemq/src/main/resources/META-INF/spring/activemq-queue-context.xml
+++ b/server/queue/queue-activemq/src/main/resources/META-INF/spring/activemq-queue-context.xml
@@ -18,14 +18,20 @@
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:amq="http://activemq.apache.org/schema/core"
+ xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://activemq.apache.org/schema/core
- http://activemq.apache.org/schema/core/activemq-core.xsd">
+ http://activemq.apache.org/schema/core/activemq-core.xsd
+ http://www.springframework.org/schema/util
+ http://www.springframework.org/schema/util/spring-util-3.0.xsd">
<!-- James Mail Queue Factory -->
<bean id="mailqueuefactory" class="org.apache.james.queue.activemq.ActiveMQMailQueueFactory" depends-on="broker">
- <property name="connectionFactory" ref="jmsConnectionFactory"/>
+ <constructor-arg index="0" ref="jmsConnectionFactory"/>
+ <constructor-arg index="1">
+ <util:constant static-field="org.apache.james.queue.api.MailQueueItemDecoratorFactory.RAW_FACTORY"/>
+ </constructor-arg>
</bean>
<!--
http://git-wip-us.apache.org/repos/asf/james-project/blob/a5a9ee20/server/queue/queue-activemq/src/test/java/org/apache/james/queue/activemq/ActiveMQMailQueueTest.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-activemq/src/test/java/org/apache/james/queue/activemq/ActiveMQMailQueueTest.java b/server/queue/queue-activemq/src/test/java/org/apache/james/queue/activemq/ActiveMQMailQueueTest.java
index 37b955e..b490d5d 100644
--- a/server/queue/queue-activemq/src/test/java/org/apache/james/queue/activemq/ActiveMQMailQueueTest.java
+++ b/server/queue/queue-activemq/src/test/java/org/apache/james/queue/activemq/ActiveMQMailQueueTest.java
@@ -23,6 +23,7 @@ import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.region.policy.PolicyEntry;
import org.apache.activemq.broker.region.policy.PolicyMap;
import org.apache.activemq.plugin.StatisticsBrokerPlugin;
+import org.apache.james.queue.api.MailQueueItemDecoratorFactory;
import org.apache.james.queue.jms.AbstractJMSMailQueueTest;
import org.apache.james.queue.jms.JMSMailQueue;
import org.junit.AfterClass;
@@ -71,9 +72,9 @@ public abstract class ActiveMQMailQueueTest extends AbstractJMSMailQueueTest {
}
@Override
- protected JMSMailQueue createQueue(ConnectionFactory factory, String queueName) {
+ protected JMSMailQueue createQueue(ConnectionFactory factory, MailQueueItemDecoratorFactory mailQueueItemDecoratorFactory, String queueName) {
Logger log = LoggerFactory.getLogger(ActiveMQMailQueueTest.class);
- return new ActiveMQMailQueue(factory, queueName, useBlobMessages(), log);
+ return new ActiveMQMailQueue(factory, mailQueueItemDecoratorFactory, queueName, useBlobMessages(), log);
}
protected boolean useBlobMessages() {
http://git-wip-us.apache.org/repos/asf/james-project/blob/a5a9ee20/server/queue/queue-api/pom.xml
----------------------------------------------------------------------
diff --git a/server/queue/queue-api/pom.xml b/server/queue/queue-api/pom.xml
index 4a6aa50..6a103b0 100644
--- a/server/queue/queue-api/pom.xml
+++ b/server/queue/queue-api/pom.xml
@@ -39,17 +39,38 @@
<artifactId>apache-mailet-api</artifactId>
</dependency>
<dependency>
+ <groupId>org.apache.james</groupId>
+ <artifactId>james-server-lifecycle-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ </dependency>
+ <dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
</dependency>
+
<dependency>
<groupId>org.apache.james</groupId>
<artifactId>james-server-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.apache.james</groupId>
- <artifactId>james-server-lifecycle-api</artifactId>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <version>${assertj-1.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
</dependency>
</dependencies>
http://git-wip-us.apache.org/repos/asf/james-project/blob/a5a9ee20/server/queue/queue-api/src/main/java/org/apache/james/queue/api/MailQueueItemDecoratorFactory.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-api/src/main/java/org/apache/james/queue/api/MailQueueItemDecoratorFactory.java b/server/queue/queue-api/src/main/java/org/apache/james/queue/api/MailQueueItemDecoratorFactory.java
new file mode 100644
index 0000000..0a08953
--- /dev/null
+++ b/server/queue/queue-api/src/main/java/org/apache/james/queue/api/MailQueueItemDecoratorFactory.java
@@ -0,0 +1,61 @@
+/****************************************************************
+ * 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.queue.api;
+
+import org.apache.james.queue.api.MailQueue.MailQueueException;
+import org.apache.james.queue.api.MailQueue.MailQueueItem;
+import org.apache.mailet.Mail;
+
+public interface MailQueueItemDecoratorFactory {
+
+ MailQueueItemDecorator decorate(MailQueueItem mailQueueItem);
+
+ abstract class MailQueueItemDecorator implements MailQueueItem {
+ protected MailQueueItem mailQueueItem;
+
+ public MailQueueItemDecorator(MailQueueItem mailQueueItem) {
+ this.mailQueueItem = mailQueueItem;
+ }
+ }
+
+ MailQueueItemDecoratorFactory RAW_FACTORY = new MailQueueItemDecoratorFactory() {
+ @Override
+ public MailQueueItemDecorator decorate(MailQueueItem mailQueueItem) {
+ return new RawMailQueueItem(mailQueueItem);
+ }
+ };
+
+ class RawMailQueueItem extends MailQueueItemDecorator {
+
+ public RawMailQueueItem(MailQueueItem mailQueueItem) {
+ super(mailQueueItem);
+ }
+
+ @Override
+ public Mail getMail() {
+ return mailQueueItem.getMail();
+ }
+
+ @Override
+ public void done(boolean success) throws MailQueueException {
+ mailQueueItem.done(success);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a5a9ee20/server/queue/queue-file/src/main/java/org/apache/james/queue/file/FileMailQueue.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-file/src/main/java/org/apache/james/queue/file/FileMailQueue.java b/server/queue/queue-file/src/main/java/org/apache/james/queue/file/FileMailQueue.java
index 2afc46a..ab447a4 100644
--- a/server/queue/queue-file/src/main/java/org/apache/james/queue/file/FileMailQueue.java
+++ b/server/queue/queue-file/src/main/java/org/apache/james/queue/file/FileMailQueue.java
@@ -47,6 +47,7 @@ import org.apache.james.core.MimeMessageCopyOnWriteProxy;
import org.apache.james.core.MimeMessageSource;
import org.apache.james.lifecycle.api.Disposable;
import org.apache.james.lifecycle.api.LifecycleUtil;
+import org.apache.james.queue.api.MailQueueItemDecoratorFactory;
import org.apache.james.queue.api.ManageableMailQueue;
import org.apache.mailet.Mail;
import org.slf4j.Logger;
@@ -67,13 +68,15 @@ public class FileMailQueue implements ManageableMailQueue {
private final File queueDir;
private final Logger log;
+ private final MailQueueItemDecoratorFactory mailQueueItemDecoratorFactory;
private final boolean sync;
private final static String MSG_EXTENSION = ".msg";
private final static String OBJECT_EXTENSION = ".obj";
private final static String NEXT_DELIVERY = "FileQueueNextDelivery";
private final static int SPLITCOUNT = 10;
- public FileMailQueue(File parentDir, String queuename, boolean sync, Logger log) throws IOException {
+ public FileMailQueue(MailQueueItemDecoratorFactory mailQueueItemDecoratorFactory, File parentDir, String queuename, boolean sync, Logger log) throws IOException {
+ this.mailQueueItemDecoratorFactory = mailQueueItemDecoratorFactory;
this.log = log;
this.sync = sync;
this.queueDir = new File(parentDir, queuename);
@@ -269,7 +272,7 @@ public class FileMailQueue implements ManageableMailQueue {
oin = new ObjectInputStream(new FileInputStream(objectFile));
final Mail mail = (Mail) oin.readObject();
mail.setMessage(new MimeMessageCopyOnWriteProxy(new FileMimeMessageSource(msgFile)));
- return new MailQueueItem() {
+ MailQueueItem fileMailQueueItem = new MailQueueItem() {
@Override
public Mail getMail() {
@@ -293,6 +296,7 @@ public class FileMailQueue implements ManageableMailQueue {
LifecycleUtil.dispose(mail);
}
};
+ return mailQueueItemDecoratorFactory.decorate(fileMailQueueItem);
// TODO: Think about exception handling in detail
} catch (FileNotFoundException e) {
http://git-wip-us.apache.org/repos/asf/james-project/blob/a5a9ee20/server/queue/queue-file/src/main/java/org/apache/james/queue/file/FileMailQueueFactory.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-file/src/main/java/org/apache/james/queue/file/FileMailQueueFactory.java b/server/queue/queue-file/src/main/java/org/apache/james/queue/file/FileMailQueueFactory.java
index 238823d..2229e1a 100644
--- a/server/queue/queue-file/src/main/java/org/apache/james/queue/file/FileMailQueueFactory.java
+++ b/server/queue/queue-file/src/main/java/org/apache/james/queue/file/FileMailQueueFactory.java
@@ -20,6 +20,7 @@ package org.apache.james.queue.file;
import org.apache.james.filesystem.api.FileSystem;
import org.apache.james.lifecycle.api.LogEnabled;
+import org.apache.james.queue.api.MailQueueItemDecoratorFactory;
import org.apache.james.queue.api.MailQueue;
import org.apache.james.queue.api.MailQueueFactory;
import org.slf4j.Logger;
@@ -36,13 +37,15 @@ import java.util.Map;
public class FileMailQueueFactory implements MailQueueFactory, LogEnabled {
private final Map<String, MailQueue> queues = new HashMap<String, MailQueue>();
+ private MailQueueItemDecoratorFactory mailQueueActionItemDecoratorFactory;
private FileSystem fs;
private Logger log;
private boolean sync = true;
@Inject
- public void setFileSystem(FileSystem fs) {
+ public FileMailQueueFactory(FileSystem fs, MailQueueItemDecoratorFactory mailQueueItemDecoratorFactory) {
this.fs = fs;
+ this.mailQueueActionItemDecoratorFactory = mailQueueItemDecoratorFactory;
}
/**
@@ -63,7 +66,7 @@ public class FileMailQueueFactory implements MailQueueFactory, LogEnabled {
if (queue == null) {
synchronized (queues) {
try {
- queue = new FileMailQueue(fs.getFile("file://var/store/queue"), name, sync, log);
+ queue = new FileMailQueue(mailQueueActionItemDecoratorFactory, fs.getFile("file://var/store/queue"), name, sync, log);
queues.put(name, queue);
} catch (IOException e) {
throw new RuntimeException("Unable to access queue " + name, e);
http://git-wip-us.apache.org/repos/asf/james-project/blob/a5a9ee20/server/queue/queue-jms/src/main/java/org/apache/james/queue/jms/JMSMailQueue.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-jms/src/main/java/org/apache/james/queue/jms/JMSMailQueue.java b/server/queue/queue-jms/src/main/java/org/apache/james/queue/jms/JMSMailQueue.java
index 80f1308..68ed2f2 100644
--- a/server/queue/queue-jms/src/main/java/org/apache/james/queue/jms/JMSMailQueue.java
+++ b/server/queue/queue-jms/src/main/java/org/apache/james/queue/jms/JMSMailQueue.java
@@ -18,14 +18,19 @@
****************************************************************/
package org.apache.james.queue.jms;
-import org.apache.james.core.MailImpl;
-import org.apache.james.core.MimeMessageCopyOnWriteProxy;
-import org.apache.james.queue.api.MailPrioritySupport;
-import org.apache.james.queue.api.MailQueue;
-import org.apache.james.queue.api.ManageableMailQueue;
-import org.apache.mailet.Mail;
-import org.apache.mailet.MailAddress;
-import org.slf4j.Logger;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.StringTokenizer;
+import java.util.concurrent.TimeUnit;
import javax.jms.BytesMessage;
import javax.jms.Connection;
@@ -41,19 +46,16 @@ import javax.jms.Session;
import javax.mail.MessagingException;
import javax.mail.internet.AddressException;
import javax.mail.internet.MimeMessage;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.NoSuchElementException;
-import java.util.StringTokenizer;
-import java.util.concurrent.TimeUnit;
+
+import org.apache.james.core.MailImpl;
+import org.apache.james.core.MimeMessageCopyOnWriteProxy;
+import org.apache.james.queue.api.MailPrioritySupport;
+import org.apache.james.queue.api.MailQueue;
+import org.apache.james.queue.api.MailQueueItemDecoratorFactory;
+import org.apache.james.queue.api.ManageableMailQueue;
+import org.apache.mailet.Mail;
+import org.apache.mailet.MailAddress;
+import org.slf4j.Logger;
/**
* <p>
@@ -70,11 +72,13 @@ public class JMSMailQueue implements ManageableMailQueue, JMSSupport, MailPriori
protected final String queueName;
protected final ConnectionFactory connectionFactory;
+ protected final MailQueueItemDecoratorFactory mailQueueItemDecoratorFactory;
protected final Logger logger;
public final static String FORCE_DELIVERY = "FORCE_DELIVERY";
- public JMSMailQueue(final ConnectionFactory connectionFactory, final String queueName, final Logger logger) {
+ public JMSMailQueue(final ConnectionFactory connectionFactory, final MailQueueItemDecoratorFactory mailQueueItemDecoratorFactory, final String queueName, final Logger logger) {
this.connectionFactory = connectionFactory;
+ this.mailQueueItemDecoratorFactory = mailQueueItemDecoratorFactory;
this.queueName = queueName;
this.logger = logger;
}
@@ -472,7 +476,8 @@ public class JMSMailQueue implements ManageableMailQueue, JMSSupport, MailPriori
*/
protected MailQueueItem createMailQueueItem(Connection connection, Session session, MessageConsumer consumer, Message message) throws JMSException, MessagingException {
final Mail mail = createMail(message);
- return new JMSMailQueueItem(mail, connection, session, consumer);
+ JMSMailQueueItem jmsMailQueueItem = new JMSMailQueueItem(mail, connection, session, consumer);
+ return mailQueueItemDecoratorFactory.decorate(jmsMailQueueItem);
}
protected String getMessageSelector() {
http://git-wip-us.apache.org/repos/asf/james-project/blob/a5a9ee20/server/queue/queue-jms/src/main/java/org/apache/james/queue/jms/JMSMailQueueFactory.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-jms/src/main/java/org/apache/james/queue/jms/JMSMailQueueFactory.java b/server/queue/queue-jms/src/main/java/org/apache/james/queue/jms/JMSMailQueueFactory.java
index d78c231..897b80a 100644
--- a/server/queue/queue-jms/src/main/java/org/apache/james/queue/jms/JMSMailQueueFactory.java
+++ b/server/queue/queue-jms/src/main/java/org/apache/james/queue/jms/JMSMailQueueFactory.java
@@ -18,8 +18,10 @@
****************************************************************/
package org.apache.james.queue.jms;
+import javax.inject.Inject;
import javax.jms.ConnectionFactory;
+import org.apache.james.queue.api.MailQueueItemDecoratorFactory;
import org.apache.james.queue.api.MailQueue;
import org.apache.james.queue.api.MailQueueFactory;
import org.apache.james.queue.library.AbstractMailQueueFactory;
@@ -30,14 +32,17 @@ import org.apache.james.queue.library.AbstractMailQueueFactory;
public class JMSMailQueueFactory extends AbstractMailQueueFactory {
protected ConnectionFactory connectionFactory;
-
- public void setConnectionFactory(ConnectionFactory connectionFactory) {
+ protected MailQueueItemDecoratorFactory mailQueueItemDecoratorFactory;
+
+ @Inject
+ public JMSMailQueueFactory(ConnectionFactory connectionFactory, MailQueueItemDecoratorFactory mailQueueItemDecoratorFactory) {
this.connectionFactory = connectionFactory;
+ this.mailQueueItemDecoratorFactory = mailQueueItemDecoratorFactory;
}
@Override
protected MailQueue createMailQueue(String name) {
- return new JMSMailQueue(connectionFactory, name, log);
+ return new JMSMailQueue(connectionFactory, mailQueueItemDecoratorFactory, name, log);
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a5a9ee20/server/queue/queue-jms/src/test/java/org/apache/james/queue/jms/AbstractJMSMailQueueTest.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-jms/src/test/java/org/apache/james/queue/jms/AbstractJMSMailQueueTest.java b/server/queue/queue-jms/src/test/java/org/apache/james/queue/jms/AbstractJMSMailQueueTest.java
index 99825ad..7d15da6 100644
--- a/server/queue/queue-jms/src/test/java/org/apache/james/queue/jms/AbstractJMSMailQueueTest.java
+++ b/server/queue/queue-jms/src/test/java/org/apache/james/queue/jms/AbstractJMSMailQueueTest.java
@@ -18,27 +18,11 @@
****************************************************************/
package org.apache.james.queue.jms;
-import org.apache.activemq.ActiveMQConnectionFactory;
-import org.apache.james.core.MailImpl;
-import org.apache.james.protocols.smtp.MailAddressException;
-import org.apache.james.queue.api.MailQueue.MailQueueItem;
-import org.apache.james.queue.api.ManageableMailQueue;
-import org.apache.james.queue.api.ManageableMailQueue.MailQueueIterator;
-import org.apache.mailet.Mail;
-import org.apache.mailet.MailAddress;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import org.junit.Before;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import javax.jms.ConnectionFactory;
-import javax.mail.MessagingException;
-import javax.mail.Session;
-import javax.mail.internet.MimeMessage;
import java.io.IOException;
import java.util.Arrays;
import java.util.Date;
@@ -48,6 +32,25 @@ import java.util.Properties;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
+import javax.jms.ConnectionFactory;
+import javax.mail.MessagingException;
+import javax.mail.Session;
+import javax.mail.internet.MimeMessage;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.james.core.MailImpl;
+import org.apache.james.protocols.smtp.MailAddressException;
+import org.apache.james.queue.api.MailQueue.MailQueueItem;
+import org.apache.james.queue.api.MailQueueItemDecoratorFactory;
+import org.apache.james.queue.api.ManageableMailQueue;
+import org.apache.james.queue.api.ManageableMailQueue.MailQueueIterator;
+import org.apache.mailet.Mail;
+import org.apache.mailet.MailAddress;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
/**
* Basic JMS test class. Extend this class and start the JMS broker in the super class,
* Create a queue and implement the getter and setter for the tests to run.
@@ -63,16 +66,16 @@ public abstract class AbstractJMSMailQueueTest {
protected ActiveMQConnectionFactory createConnectionFactory() {
return new ActiveMQConnectionFactory("vm://localhost?create=false");
}
-
- protected JMSMailQueue createQueue(ConnectionFactory factory, String queueName) {
+
+ protected JMSMailQueue createQueue(ConnectionFactory factory, MailQueueItemDecoratorFactory mailQueueItemDecoratorFactory, String queueName) {
Logger log = LoggerFactory.getLogger(AbstractJMSMailQueueTest.class);
- return new JMSMailQueue(factory, queueName, log);
+ return new JMSMailQueue(factory, mailQueueItemDecoratorFactory, queueName, log);
}
@Before
public void setUp() throws Exception {
ConnectionFactory connectionFactory = createConnectionFactory();
- setQueue(createQueue(connectionFactory, QUEUE_NAME));
+ setQueue(createQueue(connectionFactory, MailQueueItemDecoratorFactory.RAW_FACTORY, QUEUE_NAME));
}
@Test
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[5/5] james-project git commit: Merge remote-tracking branch
'rouazana/JAMES-1691-2'
Posted by ad...@apache.org.
Merge remote-tracking branch 'rouazana/JAMES-1691-2'
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/00678d88
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/00678d88
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/00678d88
Branch: refs/heads/master
Commit: 00678d88135fce013ef6bcec7ac3e813b910a05b
Parents: ca25b82 a7d6601
Author: Antoine Duprat <ad...@linagora.com>
Authored: Tue Mar 1 14:46:43 2016 +0100
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Tue Mar 1 14:46:43 2016 +0100
----------------------------------------------------------------------
.../org/apache/james/jmap/JMAPCommonModule.java | 2 +-
.../modules/server/ActiveMQQueueModule.java | 19 +-
.../james/jmap/methods/GetMessagesMethod.java | 2 +-
.../james/jmap/methods/SetMessagesMethod.java | 2 +-
.../methods/SetMessagesUpdateProcessor.java | 2 +-
.../org/apache/james/jmap/model/MessageId.java | 3 +-
.../apache/james/jmap/send/MailMetadata.java | 64 +++++
.../org/apache/james/jmap/send/MailSpool.java | 45 ++++
.../james/jmap/send/PostDequeueDecorator.java | 159 ++++++++++++
.../jmap/send/PostDequeueDecoratorFactory.java | 51 ++++
.../MailShouldBeInOutboxException.java | 30 +++
.../exception/MailboxRoleNotFoundException.java | 30 +++
.../exception/MessageIdNotFoundException.java | 30 +++
.../org/apache/james/jmap/utils/MailSpool.java | 43 ----
.../james/jmap/send/MailMetadataTest.java | 38 +++
.../apache/james/jmap/send/MailSpoolTest.java | 107 ++++++++
.../jmap/send/PostDequeueDecoratorTest.java | 257 +++++++++++++++++++
.../apache/james/jmap/utils/MailSpoolTest.java | 106 --------
.../james/queue/activemq/ActiveMQMailQueue.java | 12 +-
.../activemq/ActiveMQMailQueueFactory.java | 11 +-
.../META-INF/spring/activemq-queue-context.xml | 10 +-
.../queue/activemq/ActiveMQMailQueueTest.java | 5 +-
server/queue/queue-api/pom.xml | 25 +-
.../api/MailQueueItemDecoratorFactory.java | 61 +++++
.../apache/james/queue/file/FileMailQueue.java | 8 +-
.../james/queue/file/FileMailQueueFactory.java | 7 +-
.../apache/james/queue/jms/JMSMailQueue.java | 51 ++--
.../james/queue/jms/JMSMailQueueFactory.java | 11 +-
.../queue/jms/AbstractJMSMailQueueTest.java | 43 ++--
29 files changed, 1009 insertions(+), 225 deletions(-)
----------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[4/5] james-project git commit: JAMES-1691 After sending a mail,
move it from OUTBOX to SENT
Posted by ad...@apache.org.
JAMES-1691 After sending a mail, move it from OUTBOX to SENT
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/a7d66019
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/a7d66019
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/a7d66019
Branch: refs/heads/master
Commit: a7d660195fc4bb3ac47337bf6c2cde65deafc284
Parents: 6d7e683
Author: Raphael Ouazana <ra...@linagora.com>
Authored: Mon Feb 22 17:08:55 2016 +0100
Committer: Raphael Ouazana <ra...@linagora.com>
Committed: Tue Mar 1 14:44:59 2016 +0100
----------------------------------------------------------------------
.../modules/server/ActiveMQQueueModule.java | 23 +-
.../apache/james/jmap/send/MailMetadata.java | 64 +++++
.../org/apache/james/jmap/send/MailSpool.java | 4 +-
.../james/jmap/send/PostDequeueDecorator.java | 159 ++++++++++++
.../jmap/send/PostDequeueDecoratorFactory.java | 51 ++++
.../MailShouldBeInOutboxException.java | 30 +++
.../exception/MailboxRoleNotFoundException.java | 30 +++
.../exception/MessageIdNotFoundException.java | 30 +++
.../james/jmap/send/MailMetadataTest.java | 38 +++
.../apache/james/jmap/send/MailSpoolTest.java | 3 +-
.../jmap/send/PostDequeueDecoratorTest.java | 257 +++++++++++++++++++
11 files changed, 674 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/a7d66019/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/ActiveMQQueueModule.java
----------------------------------------------------------------------
diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/ActiveMQQueueModule.java b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/ActiveMQQueueModule.java
index 92d972c..e7602bb 100644
--- a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/ActiveMQQueueModule.java
+++ b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/ActiveMQQueueModule.java
@@ -19,16 +19,20 @@
package org.apache.james.modules.server;
-import com.google.inject.AbstractModule;
-import com.google.inject.Provides;
-import com.google.inject.Singleton;
+import javax.jms.ConnectionFactory;
+
+import org.apache.james.jmap.send.PostDequeueDecoratorFactory;
+import org.apache.james.mailbox.cassandra.CassandraId;
import org.apache.james.queue.activemq.ActiveMQMailQueueFactory;
-import org.apache.james.queue.api.MailQueueItemDecoratorFactory;
import org.apache.james.queue.api.MailQueueFactory;
+import org.apache.james.queue.api.MailQueueItemDecoratorFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.jms.ConnectionFactory;
+import com.google.inject.AbstractModule;
+import com.google.inject.Provides;
+import com.google.inject.Singleton;
+import com.google.inject.TypeLiteral;
public class ActiveMQQueueModule extends AbstractModule {
@@ -36,7 +40,7 @@ public class ActiveMQQueueModule extends AbstractModule {
@Override
protected void configure() {
-
+ bind(MailQueueItemDecoratorFactory.class).to(new TypeLiteral<PostDequeueDecoratorFactory<CassandraId>>(){}).in(Singleton.class);
}
@Provides
@@ -53,11 +57,4 @@ public class ActiveMQQueueModule extends AbstractModule {
activeMQMailQueueFactory.init();
return activeMQMailQueueFactory;
}
-
- @Provides
- @Singleton
- public MailQueueItemDecoratorFactory defaultMailQueueItemDecoratorFactory() {
- return MailQueueItemDecoratorFactory.RAW_FACTORY;
- }
-
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a7d66019/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/MailMetadata.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/MailMetadata.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/MailMetadata.java
new file mode 100644
index 0000000..319ba21
--- /dev/null
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/MailMetadata.java
@@ -0,0 +1,64 @@
+/****************************************************************
+ * 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.jmap.send;
+
+import java.util.Objects;
+
+import org.apache.james.jmap.model.MessageId;
+
+import com.google.common.base.Preconditions;
+
+public class MailMetadata {
+ public static final String MAIL_METADATA_MESSAGE_ID_ATTRIBUTE = "org.apache.james.jmap.send.MailMetaData.messageId";
+ public static final String MAIL_METADATA_USERNAME_ATTRIBUTE = "org.apache.james.jmap.send.MailMetaData.username";
+
+ private final MessageId messageId;
+ private final String username;
+
+ public MailMetadata(MessageId messageId, String username) {
+ Preconditions.checkNotNull(messageId);
+ Preconditions.checkNotNull(username);
+ this.messageId = messageId;
+ this.username = username;
+ }
+
+ public MessageId getMessageId() {
+ return messageId;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof MailMetadata) {
+ MailMetadata other = (MailMetadata) obj;
+ return Objects.equals(this.messageId, other.messageId)
+ && Objects.equals(this.username, other.username);
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(messageId, username);
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a7d66019/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/MailSpool.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/MailSpool.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/MailSpool.java
index 6267890..a5b686d 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/MailSpool.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/MailSpool.java
@@ -37,7 +37,9 @@ public class MailSpool {
queue = queueFactory.getQueue(MailQueueFactory.SPOOL);
}
- public void send(Mail mail) throws MailQueueException {
+ public void send(Mail mail, MailMetadata metadata) throws MailQueueException {
+ mail.setAttribute(MailMetadata.MAIL_METADATA_MESSAGE_ID_ATTRIBUTE, metadata.getMessageId().serialize());
+ mail.setAttribute(MailMetadata.MAIL_METADATA_USERNAME_ATTRIBUTE, metadata.getUsername());
queue.enQueue(mail);
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a7d66019/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/PostDequeueDecorator.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/PostDequeueDecorator.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/PostDequeueDecorator.java
new file mode 100644
index 0000000..6722ef7
--- /dev/null
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/PostDequeueDecorator.java
@@ -0,0 +1,159 @@
+/****************************************************************
+ * 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.jmap.send;
+
+import java.io.Serializable;
+import java.util.Iterator;
+
+import org.apache.james.jmap.model.MessageId;
+import org.apache.james.jmap.model.mailbox.Role;
+import org.apache.james.jmap.send.exception.MailShouldBeInOutboxException;
+import org.apache.james.jmap.send.exception.MailboxRoleNotFoundException;
+import org.apache.james.jmap.send.exception.MessageIdNotFoundException;
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
+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.model.MessageRange;
+import org.apache.james.mailbox.store.mail.MailboxMapperFactory;
+import org.apache.james.mailbox.store.mail.MessageMapper;
+import org.apache.james.mailbox.store.mail.MessageMapperFactory;
+import org.apache.james.mailbox.store.mail.model.Mailbox;
+import org.apache.james.mailbox.store.mail.model.MailboxId;
+import org.apache.james.mailbox.store.mail.model.MailboxMessage;
+import org.apache.james.queue.api.MailQueue.MailQueueException;
+import org.apache.james.queue.api.MailQueue.MailQueueItem;
+import org.apache.james.queue.api.MailQueueItemDecoratorFactory.MailQueueItemDecorator;
+import org.apache.mailet.Mail;
+import org.javatuples.Pair;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class PostDequeueDecorator<Id extends MailboxId> extends MailQueueItemDecorator {
+ private static final Logger LOG = LoggerFactory.getLogger(PostDequeueDecorator.class);
+
+ private final MailboxManager mailboxManager;
+ private final MessageMapperFactory<Id> messageMapperFactory;
+ private final MailboxMapperFactory<Id> mailboxMapperFactory;
+
+ public PostDequeueDecorator(MailQueueItem mailQueueItem,
+ MailboxManager mailboxManager,
+ MessageMapperFactory<Id> messageMapperFactory,
+ MailboxMapperFactory<Id> mailboxMapperFactory) {
+ super(mailQueueItem);
+ this.mailboxManager = mailboxManager;
+ this.messageMapperFactory = messageMapperFactory;
+ this.mailboxMapperFactory = mailboxMapperFactory;
+ }
+
+ @Override
+ public Mail getMail() {
+ return mailQueueItem.getMail();
+ }
+
+ @Override
+ public void done(boolean success) throws MailQueueException {
+ mailQueueItem.done(success);
+ if (success && mandatoryJmapMetaDataIsPresent()) {
+ MessageId messageId = MessageId.of((String) getMail().getAttribute(MailMetadata.MAIL_METADATA_MESSAGE_ID_ATTRIBUTE));
+ String username = (String) getMail().getAttribute(MailMetadata.MAIL_METADATA_USERNAME_ATTRIBUTE);
+ try {
+ MailboxSession mailboxSession = mailboxManager.createSystemSession(username, LOG);
+ Pair<MailboxMessage<Id>, MailboxPath> mailboxMessageAndMailboxPath = getMailboxMessageAndMailboxPath(messageId, mailboxSession);
+ moveFromOutboxToSent(mailboxMessageAndMailboxPath, mailboxSession);
+ } catch (MailboxException e) {
+ throw new MailQueueException(e.getMessage(), e);
+ }
+ }
+ }
+
+ private boolean mandatoryJmapMetaDataIsPresent() {
+ return checkMessageIdAttribute()
+ && checkUsernameAttribute();
+ }
+
+ private boolean checkMessageIdAttribute() {
+ Serializable messageId = getMail().getAttribute(MailMetadata.MAIL_METADATA_MESSAGE_ID_ATTRIBUTE);
+ if (messageId == null || ! (messageId instanceof String)) {
+ return false;
+ }
+ try {
+ MessageId.of((String) messageId);
+ } catch (Exception e) {
+ LOG.error("Invalid messageId: " + (String) messageId);
+ return false;
+ }
+ return true;
+ }
+
+ private boolean checkUsernameAttribute() {
+ Serializable username = getMail().getAttribute(MailMetadata.MAIL_METADATA_USERNAME_ATTRIBUTE);
+ return (username != null && username instanceof String);
+ }
+
+ public Pair<MailboxMessage<Id>, MailboxPath> getMailboxMessageAndMailboxPath(MessageId messageId, MailboxSession mailboxSession) throws MailQueueException, MailboxException {
+ MailboxPath mailboxPath = messageId.getMailboxPath();
+ MessageMapper<Id> messageMapper = messageMapperFactory.getMessageMapper(mailboxSession);
+ Mailbox<Id> mailbox = mailboxMapperFactory.getMailboxMapper(mailboxSession).findMailboxByPath(mailboxPath);
+ Iterator<MailboxMessage<Id>> resultIterator = messageMapper.findInMailbox(mailbox, MessageRange.one(messageId.getUid()), MessageMapper.FetchType.Full, 1);
+ if (resultIterator.hasNext()) {
+ return Pair.with(resultIterator.next(), mailboxPath);
+ } else {
+ throw new MessageIdNotFoundException(messageId);
+ }
+ }
+
+ private void moveFromOutboxToSent(Pair<MailboxMessage<Id>, MailboxPath> mailboxMessageAndMailboxPath, MailboxSession mailboxSession) throws MailQueueException, MailboxException {
+ MailboxMessage<Id> mailboxMessage = mailboxMessageAndMailboxPath.getValue0();
+ MailboxPath outboxMailboxPath = mailboxMessageAndMailboxPath.getValue1();
+ ensureMailboxPathIsOutbox(outboxMailboxPath);
+ MailboxPath sentMailboxPath = getSentMailboxPath(mailboxSession);
+
+ // MOVE is not implemented, so COPY and DELETE
+ mailboxManager.copyMessages(MessageRange.one(mailboxMessage.getUid()), outboxMailboxPath, sentMailboxPath, mailboxSession);
+ Mailbox<Id> outboxMailbox = mailboxMapperFactory.getMailboxMapper(mailboxSession).findMailboxByPath(outboxMailboxPath);
+ messageMapperFactory.getMessageMapper(mailboxSession).delete(outboxMailbox, mailboxMessage);
+ }
+
+ private void ensureMailboxPathIsOutbox(MailboxPath outboxMailboxPath) throws MailShouldBeInOutboxException {
+ if (!hasRole(outboxMailboxPath, Role.OUTBOX)) {
+ throw new MailShouldBeInOutboxException(outboxMailboxPath);
+ }
+ }
+
+ private MailboxPath getSentMailboxPath(MailboxSession session) throws MailboxRoleNotFoundException, MailboxException {
+ MailboxQuery allUserMailboxesQuery = MailboxQuery.builder(session)
+ .privateUserMailboxes()
+ .build();
+ return mailboxManager.search(allUserMailboxesQuery, session)
+ .stream()
+ .map(MailboxMetaData::getPath)
+ .filter(path -> hasRole(path, Role.SENT))
+ .findFirst()
+ .orElseThrow(() -> new MailboxRoleNotFoundException(Role.SENT));
+ }
+
+ private boolean hasRole(MailboxPath mailBoxPath, Role role) {
+ return Role.from(mailBoxPath.getName())
+ .map(role::equals)
+ .orElse(false);
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a7d66019/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/PostDequeueDecoratorFactory.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/PostDequeueDecoratorFactory.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/PostDequeueDecoratorFactory.java
new file mode 100644
index 0000000..24797fc
--- /dev/null
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/PostDequeueDecoratorFactory.java
@@ -0,0 +1,51 @@
+/****************************************************************
+ * 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.jmap.send;
+
+import org.apache.james.queue.api.MailQueue.MailQueueItem;
+
+import javax.inject.Inject;
+
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.store.mail.MailboxMapperFactory;
+import org.apache.james.mailbox.store.mail.MessageMapperFactory;
+import org.apache.james.mailbox.store.mail.model.MailboxId;
+import org.apache.james.queue.api.MailQueueItemDecoratorFactory;
+
+public class PostDequeueDecoratorFactory<Id extends MailboxId> implements MailQueueItemDecoratorFactory {
+ private final MailboxManager mailboxManager;
+ private final MessageMapperFactory<Id> messageMapperFactory;
+ private final MailboxMapperFactory<Id> mailboxMapperFactory;
+
+ @Inject
+ public PostDequeueDecoratorFactory(MailboxManager mailboxManager,
+ MessageMapperFactory<Id> messageMapperFactory,
+ MailboxMapperFactory<Id> mailboxMapperFactory) {
+ this.mailboxManager = mailboxManager;
+ this.messageMapperFactory = messageMapperFactory;
+ this.mailboxMapperFactory = mailboxMapperFactory;
+ }
+
+ @Override
+ public MailQueueItemDecorator decorate(MailQueueItem mailQueueItem) {
+ return new PostDequeueDecorator<Id>(mailQueueItem, mailboxManager, messageMapperFactory, mailboxMapperFactory);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a7d66019/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/exception/MailShouldBeInOutboxException.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/exception/MailShouldBeInOutboxException.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/exception/MailShouldBeInOutboxException.java
new file mode 100644
index 0000000..f0e781b
--- /dev/null
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/exception/MailShouldBeInOutboxException.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.jmap.send.exception;
+
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.queue.api.MailQueue.MailQueueException;
+
+public class MailShouldBeInOutboxException extends MailQueueException {
+
+ public MailShouldBeInOutboxException(MailboxPath mailboxPath) {
+ super("Mail to be sent should be in OUTBOX but is in " + mailboxPath.getName());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a7d66019/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/exception/MailboxRoleNotFoundException.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/exception/MailboxRoleNotFoundException.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/exception/MailboxRoleNotFoundException.java
new file mode 100644
index 0000000..39d73e1
--- /dev/null
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/exception/MailboxRoleNotFoundException.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.jmap.send.exception;
+
+import org.apache.james.jmap.model.mailbox.Role;
+import org.apache.james.queue.api.MailQueue.MailQueueException;
+
+public class MailboxRoleNotFoundException extends MailQueueException {
+
+ public MailboxRoleNotFoundException(Role role) {
+ super("Unable to find a mailbox with role " + role.name());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a7d66019/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/exception/MessageIdNotFoundException.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/exception/MessageIdNotFoundException.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/exception/MessageIdNotFoundException.java
new file mode 100644
index 0000000..0db7817
--- /dev/null
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/exception/MessageIdNotFoundException.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.jmap.send.exception;
+
+import org.apache.james.jmap.model.MessageId;
+import org.apache.james.queue.api.MailQueue.MailQueueException;
+
+public class MessageIdNotFoundException extends MailQueueException {
+
+ public MessageIdNotFoundException(MessageId messageId) {
+ super("Unable to find a Mailbox Message matching: " + messageId.serialize());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a7d66019/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/MailMetadataTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/MailMetadataTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/MailMetadataTest.java
new file mode 100644
index 0000000..b080077
--- /dev/null
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/MailMetadataTest.java
@@ -0,0 +1,38 @@
+/****************************************************************
+ * 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.jmap.send;
+
+import org.apache.james.jmap.model.MessageId;
+import org.junit.Test;
+
+public class MailMetadataTest {
+
+ private static final MessageId MESSAGE_ID = MessageId.of("username|path|0");
+ private static final String USERNAME = "username";
+
+ @Test(expected=NullPointerException.class)
+ public void constructorShouldThrowWhenNullMessageId() {
+ new MailMetadata(null, USERNAME);
+ }
+
+ @Test(expected=NullPointerException.class)
+ public void constructorShouldThrowWhenNullUsername() {
+ new MailMetadata(MESSAGE_ID, null);
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a7d66019/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/MailSpoolTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/MailSpoolTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/MailSpoolTest.java
index 3687138..667e0ee 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/MailSpoolTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/MailSpoolTest.java
@@ -24,6 +24,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.TimeUnit;
+import org.apache.james.jmap.model.MessageId;
import org.apache.james.queue.api.MailQueue;
import org.apache.james.queue.api.MailQueue.MailQueueException;
import org.apache.james.queue.api.MailQueue.MailQueueItem;
@@ -55,7 +56,7 @@ public class MailSpoolTest {
public void sendShouldEnQueueTheMail() throws Exception {
FakeMail mail = new FakeMail();
- mailSpool.send(mail);
+ mailSpool.send(mail, new MailMetadata(MessageId.of("a|b|1"), "user"));
assertThat(myQueue.deQueue())
.isNotNull()
http://git-wip-us.apache.org/repos/asf/james-project/blob/a7d66019/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/PostDequeueDecoratorTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/PostDequeueDecoratorTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/PostDequeueDecoratorTest.java
new file mode 100644
index 0000000..fff82f1
--- /dev/null
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/PostDequeueDecoratorTest.java
@@ -0,0 +1,257 @@
+/****************************************************************
+ * 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.jmap.send;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.io.ByteArrayInputStream;
+import java.util.Date;
+import java.util.Iterator;
+
+import javax.mail.Flags;
+
+import org.apache.james.jmap.model.MessageId;
+import org.apache.james.jmap.send.exception.MailShouldBeInOutboxException;
+import org.apache.james.jmap.send.exception.MailboxRoleNotFoundException;
+import org.apache.james.jmap.send.exception.MessageIdNotFoundException;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.MessageManager;
+import org.apache.james.mailbox.acl.GroupMembershipResolver;
+import org.apache.james.mailbox.acl.MailboxACLResolver;
+import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver;
+import org.apache.james.mailbox.acl.UnionMailboxACLResolver;
+import org.apache.james.mailbox.inmemory.InMemoryId;
+import org.apache.james.mailbox.inmemory.InMemoryMailboxSessionMapperFactory;
+import org.apache.james.mailbox.model.MailboxConstants;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.MessageRange;
+import org.apache.james.mailbox.store.MockAuthenticator;
+import org.apache.james.mailbox.store.StoreMailboxManager;
+import org.apache.james.mailbox.store.mail.MessageMapper;
+import org.apache.james.mailbox.store.mail.model.Mailbox;
+import org.apache.james.mailbox.store.mail.model.MailboxMessage;
+import org.apache.james.queue.api.MailQueue.MailQueueItem;
+import org.apache.mailet.Mail;
+import org.apache.mailet.base.test.FakeMail;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class PostDequeueDecoratorTest {
+ private static final Logger LOGGER = LoggerFactory.getLogger(PostDequeueDecoratorTest.class);
+ private static final String OUTBOX = "OUTBOX";
+ private static final String SENT = "SENT";
+ private static final String USERNAME = "username@domain.tld";
+ private static final long UID = 1;
+ private static final MailboxPath OUTBOX_MAILBOX_PATH = new MailboxPath(MailboxConstants.USER_NAMESPACE, USERNAME, OUTBOX);
+ private static final MailboxPath SENT_MAILBOX_PATH = new MailboxPath(MailboxConstants.USER_NAMESPACE, USERNAME, SENT);
+ private static final String MESSAGE_ID = USERNAME + "|" + OUTBOX_MAILBOX_PATH.getName() + "|" + UID;
+
+ private InMemoryMailboxSessionMapperFactory mailboxSessionMapperFactory;
+ private StoreMailboxManager<InMemoryId> mailboxManager;
+ private MailQueueItem mockedMailQueueItem;
+ private Mail mail;
+ private PostDequeueDecorator<InMemoryId> testee;
+
+ @Before
+ public void init() throws Exception {
+ mailboxSessionMapperFactory = new InMemoryMailboxSessionMapperFactory();
+ MailboxACLResolver aclResolver = new UnionMailboxACLResolver();
+ GroupMembershipResolver groupMembershipResolver = new SimpleGroupMembershipResolver();
+ mailboxManager = new StoreMailboxManager<>(mailboxSessionMapperFactory, new MockAuthenticator(), aclResolver, groupMembershipResolver);
+ mailboxManager.init();
+
+ mockedMailQueueItem = mock(MailQueueItem.class);
+ mail = new FakeMail();
+ when(mockedMailQueueItem.getMail()).thenReturn(mail);
+ testee = new PostDequeueDecorator<InMemoryId>(mockedMailQueueItem, mailboxManager, mailboxSessionMapperFactory, mailboxSessionMapperFactory);
+ }
+
+ @Test
+ public void doneShouldCallDecoratedDone() throws Exception {
+ try {
+ testee.done(true);
+ } catch (Exception e) {
+ //Ignore
+ }
+
+ verify(mockedMailQueueItem).done(true);
+ }
+
+ @Test(expected=MessageIdNotFoundException.class)
+ public void doneShouldThrowWhenMetadataHasNotAnExistingMessageId() throws Exception {
+ MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME, LOGGER);
+ mailboxManager.createMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
+ mail.setAttribute(MailMetadata.MAIL_METADATA_MESSAGE_ID_ATTRIBUTE, MESSAGE_ID);
+ mail.setAttribute(MailMetadata.MAIL_METADATA_USERNAME_ATTRIBUTE, USERNAME);
+
+ testee.done(true);
+ }
+
+ @Test(expected=MailShouldBeInOutboxException.class)
+ public void doneShouldThrowWhenMessageIsNotInOutbox() throws Exception {
+ MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME, LOGGER);
+ mailboxManager.createMailbox(SENT_MAILBOX_PATH, mailboxSession);
+ MessageManager messageManager = mailboxManager.getMailbox(SENT_MAILBOX_PATH, mailboxSession);
+ messageManager.appendMessage(new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), mailboxSession, false, new Flags());
+ MessageId inSentMessageId = MessageId.of(USERNAME + "|" + SENT_MAILBOX_PATH.getName() + "|" + UID);
+ mail.setAttribute(MailMetadata.MAIL_METADATA_MESSAGE_ID_ATTRIBUTE, inSentMessageId.serialize());
+ mail.setAttribute(MailMetadata.MAIL_METADATA_USERNAME_ATTRIBUTE, USERNAME);
+
+ testee.done(true);
+ }
+
+ @Test(expected=MailboxRoleNotFoundException.class)
+ public void doneShouldThrowWhenSentDoesNotExist() throws Exception {
+ MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME, LOGGER);
+ mailboxManager.createMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
+ MessageManager messageManager = mailboxManager.getMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
+ messageManager.appendMessage(new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), mailboxSession, false, new Flags());
+ mail.setAttribute(MailMetadata.MAIL_METADATA_MESSAGE_ID_ATTRIBUTE, MESSAGE_ID);
+ mail.setAttribute(MailMetadata.MAIL_METADATA_USERNAME_ATTRIBUTE, USERNAME);
+
+ testee.done(true);
+ }
+
+ @Test
+ public void doneShouldCopyMailFromOutboxToSentWhenSuccess() throws Exception {
+ MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME, LOGGER);
+ mailboxManager.createMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
+ mailboxManager.createMailbox(SENT_MAILBOX_PATH, mailboxSession);
+ MessageManager messageManager = mailboxManager.getMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
+ messageManager.appendMessage(new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), mailboxSession, false, new Flags());
+ mail.setAttribute(MailMetadata.MAIL_METADATA_MESSAGE_ID_ATTRIBUTE, MESSAGE_ID);
+ mail.setAttribute(MailMetadata.MAIL_METADATA_USERNAME_ATTRIBUTE, USERNAME);
+
+ testee.done(true);
+
+ Mailbox<InMemoryId> sentMailbox = mailboxSessionMapperFactory.getMailboxMapper(mailboxSession).findMailboxByPath(SENT_MAILBOX_PATH);
+ MessageMapper<InMemoryId> messageMapper = mailboxSessionMapperFactory.getMessageMapper(mailboxSession);
+ Iterator<MailboxMessage<InMemoryId>> resultIterator = messageMapper.findInMailbox(sentMailbox, MessageRange.one(UID), MessageMapper.FetchType.Full, 1);
+ assertThat(resultIterator).hasSize(1);
+ }
+
+ @Test
+ public void doneShouldDeleteMailFromOutboxWhenSuccess() throws Exception {
+ MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME, LOGGER);
+ mailboxManager.createMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
+ mailboxManager.createMailbox(SENT_MAILBOX_PATH, mailboxSession);
+ MessageManager messageManager = mailboxManager.getMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
+ messageManager.appendMessage(new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), mailboxSession, false, new Flags());
+ mail.setAttribute(MailMetadata.MAIL_METADATA_MESSAGE_ID_ATTRIBUTE, MESSAGE_ID);
+ mail.setAttribute(MailMetadata.MAIL_METADATA_USERNAME_ATTRIBUTE, USERNAME);
+
+ testee.done(true);
+
+ Mailbox<InMemoryId> mailbox = mailboxSessionMapperFactory.getMailboxMapper(mailboxSession).findMailboxByPath(OUTBOX_MAILBOX_PATH);
+ MessageMapper<InMemoryId> messageMapper = mailboxSessionMapperFactory.getMessageMapper(mailboxSession);
+ Iterator<MailboxMessage<InMemoryId>> resultIterator = messageMapper.findInMailbox(mailbox, MessageRange.one(UID), MessageMapper.FetchType.Full, 1);
+ assertThat(resultIterator).hasSize(0);
+ }
+
+ @Test
+ public void doneShouldNotMoveMailFromOutboxToSentWhenSuccessIsFalse() throws Exception {
+ MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME, LOGGER);
+ mailboxManager.createMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
+ mailboxManager.createMailbox(SENT_MAILBOX_PATH, mailboxSession);
+ MessageManager messageManager = mailboxManager.getMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
+ messageManager.appendMessage(new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), mailboxSession, false, new Flags());
+ mail.setAttribute(MailMetadata.MAIL_METADATA_MESSAGE_ID_ATTRIBUTE, MESSAGE_ID);
+ mail.setAttribute(MailMetadata.MAIL_METADATA_USERNAME_ATTRIBUTE, USERNAME);
+
+ testee.done(false);
+
+ Mailbox<InMemoryId> mailbox = mailboxSessionMapperFactory.getMailboxMapper(mailboxSession).findMailboxByPath(OUTBOX_MAILBOX_PATH);
+ MessageMapper<InMemoryId> messageMapper = mailboxSessionMapperFactory.getMessageMapper(mailboxSession);
+ Iterator<MailboxMessage<InMemoryId>> resultIterator = messageMapper.findInMailbox(mailbox, MessageRange.one(UID), MessageMapper.FetchType.Full, 1);
+ assertThat(resultIterator).hasSize(1);
+ }
+
+ @Test
+ public void doneShouldNotMoveMailFromOutboxToSentWhenNoMetadataProvided() throws Exception {
+ MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME, LOGGER);
+ mailboxManager.createMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
+ mailboxManager.createMailbox(SENT_MAILBOX_PATH, mailboxSession);
+ MessageManager messageManager = mailboxManager.getMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
+ messageManager.appendMessage(new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), mailboxSession, false, new Flags());
+
+ testee.done(true);
+
+ Mailbox<InMemoryId> mailbox = mailboxSessionMapperFactory.getMailboxMapper(mailboxSession).findMailboxByPath(OUTBOX_MAILBOX_PATH);
+ MessageMapper<InMemoryId> messageMapper = mailboxSessionMapperFactory.getMessageMapper(mailboxSession);
+ Iterator<MailboxMessage<InMemoryId>> resultIterator = messageMapper.findInMailbox(mailbox, MessageRange.one(UID), MessageMapper.FetchType.Full, 1);
+ assertThat(resultIterator).hasSize(1);
+ }
+
+ @Test
+ public void doneShouldNotMoveMailFromOutboxToSentWhenUsernameNotProvided() throws Exception {
+ MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME, LOGGER);
+ mailboxManager.createMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
+ mailboxManager.createMailbox(SENT_MAILBOX_PATH, mailboxSession);
+ MessageManager messageManager = mailboxManager.getMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
+ messageManager.appendMessage(new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), mailboxSession, false, new Flags());
+ mail.setAttribute(MailMetadata.MAIL_METADATA_MESSAGE_ID_ATTRIBUTE, MESSAGE_ID);
+
+ testee.done(true);
+
+ Mailbox<InMemoryId> mailbox = mailboxSessionMapperFactory.getMailboxMapper(mailboxSession).findMailboxByPath(OUTBOX_MAILBOX_PATH);
+ MessageMapper<InMemoryId> messageMapper = mailboxSessionMapperFactory.getMessageMapper(mailboxSession);
+ Iterator<MailboxMessage<InMemoryId>> resultIterator = messageMapper.findInMailbox(mailbox, MessageRange.one(UID), MessageMapper.FetchType.Full, 1);
+ assertThat(resultIterator).hasSize(1);
+ }
+
+ @Test
+ public void doneShouldNotMoveMailFromOutboxToSentWhenMessageIdNotProvided() throws Exception {
+ MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME, LOGGER);
+ mailboxManager.createMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
+ mailboxManager.createMailbox(SENT_MAILBOX_PATH, mailboxSession);
+ MessageManager messageManager = mailboxManager.getMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
+ messageManager.appendMessage(new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), mailboxSession, false, new Flags());
+ mail.setAttribute(MailMetadata.MAIL_METADATA_USERNAME_ATTRIBUTE, USERNAME);
+
+ testee.done(true);
+
+ Mailbox<InMemoryId> mailbox = mailboxSessionMapperFactory.getMailboxMapper(mailboxSession).findMailboxByPath(OUTBOX_MAILBOX_PATH);
+ MessageMapper<InMemoryId> messageMapper = mailboxSessionMapperFactory.getMessageMapper(mailboxSession);
+ Iterator<MailboxMessage<InMemoryId>> resultIterator = messageMapper.findInMailbox(mailbox, MessageRange.one(UID), MessageMapper.FetchType.Full, 1);
+ assertThat(resultIterator).hasSize(1);
+ }
+
+ @Test
+ public void doneShouldNotMoveMailFromOutboxToSentWhenInvalidMessageIdProvided() throws Exception {
+ MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME, LOGGER);
+ mailboxManager.createMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
+ mailboxManager.createMailbox(SENT_MAILBOX_PATH, mailboxSession);
+ MessageManager messageManager = mailboxManager.getMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
+ messageManager.appendMessage(new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), mailboxSession, false, new Flags());
+ mail.setAttribute(MailMetadata.MAIL_METADATA_USERNAME_ATTRIBUTE, USERNAME);
+ mail.setAttribute(MailMetadata.MAIL_METADATA_MESSAGE_ID_ATTRIBUTE, "invalid");
+
+ testee.done(true);
+
+ Mailbox<InMemoryId> mailbox = mailboxSessionMapperFactory.getMailboxMapper(mailboxSession).findMailboxByPath(OUTBOX_MAILBOX_PATH);
+ MessageMapper<InMemoryId> messageMapper = mailboxSessionMapperFactory.getMessageMapper(mailboxSession);
+ Iterator<MailboxMessage<InMemoryId>> resultIterator = messageMapper.findInMailbox(mailbox, MessageRange.one(UID), MessageMapper.FetchType.Full, 1);
+ assertThat(resultIterator).hasSize(1);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[3/5] james-project git commit: JAMES-1691 MessageId doesn't need a
MailboxSession
Posted by ad...@apache.org.
JAMES-1691 MessageId doesn't need a MailboxSession
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/6d7e6833
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/6d7e6833
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/6d7e6833
Branch: refs/heads/master
Commit: 6d7e68330a4e3b5be526a3dc86ea399f10e75427
Parents: a5a9ee2
Author: Raphael Ouazana <ra...@linagora.com>
Authored: Wed Feb 24 15:03:32 2016 +0100
Committer: Raphael Ouazana <ra...@linagora.com>
Committed: Wed Feb 24 15:03:32 2016 +0100
----------------------------------------------------------------------
.../java/org/apache/james/jmap/methods/GetMessagesMethod.java | 2 +-
.../java/org/apache/james/jmap/methods/SetMessagesMethod.java | 2 +-
.../org/apache/james/jmap/methods/SetMessagesUpdateProcessor.java | 2 +-
.../jmap/src/main/java/org/apache/james/jmap/model/MessageId.java | 3 +--
4 files changed, 4 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/6d7e6833/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java
index a2ad348..08b4de6 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java
@@ -142,7 +142,7 @@ public class GetMessagesMethod<Id extends MailboxId> implements Method {
return Throwing
.function((MessageId messageId) -> {
- MailboxPath mailboxPath = messageId.getMailboxPath(mailboxSession);
+ MailboxPath mailboxPath = messageId.getMailboxPath();
MessageMapper<Id> messageMapper = messageMapperFactory.getMessageMapper(mailboxSession);
Mailbox<Id> mailbox = mailboxMapperFactory.getMailboxMapper(mailboxSession).findMailboxByPath(mailboxPath);
return Pair.with(
http://git-wip-us.apache.org/repos/asf/james-project/blob/6d7e6833/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesMethod.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesMethod.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesMethod.java
index eeb7a65..f14cdba 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesMethod.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesMethod.java
@@ -112,7 +112,7 @@ public class SetMessagesMethod<Id extends MailboxId> implements Method {
try {
Mailbox<Id> mailbox = mailboxMapperFactory
.getMailboxMapper(mailboxSession)
- .findMailboxByPath(messageId.getMailboxPath(mailboxSession));
+ .findMailboxByPath(messageId.getMailboxPath());
MailboxMessage<Id> mailboxMessage = getMailboxMessage(messageMapper, messageId, mailbox);
http://git-wip-us.apache.org/repos/asf/james-project/blob/6d7e6833/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessor.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessor.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessor.java
index 458e748..f62e390 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessor.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessor.java
@@ -87,7 +87,7 @@ public class SetMessagesUpdateProcessor<Id extends MailboxId> {
try {
MessageMapper<Id> messageMapper = mailboxSessionMapperFactory.createMessageMapper(mailboxSession);
Mailbox<Id> mailbox = mailboxMapperFactory.getMailboxMapper(mailboxSession)
- .findMailboxByPath(messageId.getMailboxPath(mailboxSession));
+ .findMailboxByPath(messageId.getMailboxPath());
Iterator<MailboxMessage<Id>> mailboxMessage = messageMapper.findInMailbox(
mailbox, MessageRange.one(messageId.getUid()), MessageMapper.FetchType.Metadata, LIMIT_BY_ONE);
MailboxMessage<Id> messageWithUpdatedFlags = applyMessagePatch(messageId, mailboxMessage.next(), updateMessagePatch, builder);
http://git-wip-us.apache.org/repos/asf/james-project/blob/6d7e6833/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageId.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageId.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageId.java
index b4b08c5..1a93291 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageId.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageId.java
@@ -20,7 +20,6 @@ package org.apache.james.jmap.model;
import java.util.Objects;
-import org.apache.james.mailbox.MailboxSession;
import org.apache.james.mailbox.MailboxSession.User;
import org.apache.james.mailbox.model.MailboxConstants;
import org.apache.james.mailbox.model.MailboxPath;
@@ -67,7 +66,7 @@ public class MessageId {
return uid;
}
- public MailboxPath getMailboxPath(MailboxSession mailboxSession) {
+ public MailboxPath getMailboxPath() {
return new MailboxPath(MailboxConstants.USER_NAMESPACE, username, mailboxPath);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org