This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
The following commit(s) were added to refs/heads/master by this push:
new 58b11b9 JAMES-3585 Allow customizing the POP3 mailbox
58b11b9 is described below
commit 58b11b9ed682ffddd039a7ccfd156e193b3b3cb0
Author: Benoit Tellier <[email protected]>
AuthorDate: Fri May 14 16:00:26 2021 +0700
JAMES-3585 Allow customizing the POP3 mailbox
---
.../james/protocols/pop3/mailbox/ImapMailbox.java | 10 ------
.../james/protocols/pop3/mailbox/Mailbox.java | 13 -------
.../james/modules/protocols/POP3ServerModule.java | 5 +++
.../james/pop3server/core/PassCmdHandler.java | 9 ++---
.../mailbox/DefaultMailboxAdapterFactory.java | 42 ++++++++++++++++++++++
.../james/pop3server/mailbox/MailboxAdapter.java | 37 -------------------
.../pop3server/mailbox/MailboxAdapterFactory.java | 28 +++++++++++++++
.../META-INF/spring/pop3server-context.xml | 4 +++
.../apache/james/pop3server/POP3ServerTest.java | 9 +++--
9 files changed, 90 insertions(+), 67 deletions(-)
diff --git
a/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/mailbox/ImapMailbox.java
b/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/mailbox/ImapMailbox.java
index 2c46dcd..9c83ed3 100644
---
a/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/mailbox/ImapMailbox.java
+++
b/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/mailbox/ImapMailbox.java
@@ -34,22 +34,12 @@ public abstract class ImapMailbox implements Mailbox {
*/
public abstract InputStream getMessageBody(long uid) throws IOException;
- @Override
- public InputStream getMessageBody(String uid) throws
NumberFormatException, IOException {
- return this.getMessageBody(Long.parseLong(uid));
- }
-
/**
* Returns the message headers as {@link InputStream} or <code>null</code>
* if no message can be found for the given <code>uid</code>
*/
public abstract InputStream getMessageHeaders(long uid) throws IOException;
- @Override
- public InputStream getMessageHeaders(String uid) throws
NumberFormatException, IOException {
- return this.getMessageHeaders(Long.parseLong(uid));
- }
-
/**
* Return the full message (headers + body) as {@link InputStream} or
* <code>null</code> if no message can be found for the given
diff --git
a/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/mailbox/Mailbox.java
b/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/mailbox/Mailbox.java
index ec3b5ef..58d73b9 100644
---
a/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/mailbox/Mailbox.java
+++
b/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/mailbox/Mailbox.java
@@ -26,19 +26,6 @@ import java.util.List;
* A Mailbox which is used in POP3 to retrieve messages
*/
public interface Mailbox {
-
- /**
- * Returns the message body as {@link InputStream} or <code>null</code> if
- * no message can be found for the given <code>uid</code>
- */
- InputStream getMessageBody(String uid) throws IOException;
-
- /**
- * Returns the message headers as {@link InputStream} or <code>null</code>
- * if no message can be found for the given <code>uid</code>
- */
- InputStream getMessageHeaders(String uid) throws IOException;
-
/**
* Return the full message (headers + body) as {@link InputStream} or
* <code>null</code> if no message can be found for the given
diff --git
a/server/container/guice/protocols/pop/src/main/java/org/apache/james/modules/protocols/POP3ServerModule.java
b/server/container/guice/protocols/pop/src/main/java/org/apache/james/modules/protocols/POP3ServerModule.java
index ad1a808..a48bd64 100644
---
a/server/container/guice/protocols/pop/src/main/java/org/apache/james/modules/protocols/POP3ServerModule.java
+++
b/server/container/guice/protocols/pop/src/main/java/org/apache/james/modules/protocols/POP3ServerModule.java
@@ -19,6 +19,8 @@
package org.apache.james.modules.protocols;
+import org.apache.james.pop3server.mailbox.DefaultMailboxAdapterFactory;
+import org.apache.james.pop3server.mailbox.MailboxAdapterFactory;
import org.apache.james.pop3server.netty.OioPOP3ServerFactory;
import org.apache.james.pop3server.netty.POP3ServerFactory;
import org.apache.james.server.core.configuration.ConfigurationProvider;
@@ -36,6 +38,9 @@ public class POP3ServerModule extends AbstractModule {
protected void configure() {
bind(POP3ServerFactory.class).in(Scopes.SINGLETON);
bind(OioPOP3ServerFactory.class).in(Scopes.SINGLETON);
+ bind(DefaultMailboxAdapterFactory.class).in(Scopes.SINGLETON);
+
+
bind(MailboxAdapterFactory.class).to(DefaultMailboxAdapterFactory.class);
Multibinder.newSetBinder(binder(),
GuiceProbe.class).addBinding().to(Pop3GuiceProbe.class);
}
diff --git
a/server/protocols/protocols-pop3/src/main/java/org/apache/james/pop3server/core/PassCmdHandler.java
b/server/protocols/protocols-pop3/src/main/java/org/apache/james/pop3server/core/PassCmdHandler.java
index 0e4fffe..ebef5f4 100644
---
a/server/protocols/protocols-pop3/src/main/java/org/apache/james/pop3server/core/PassCmdHandler.java
+++
b/server/protocols/protocols-pop3/src/main/java/org/apache/james/pop3server/core/PassCmdHandler.java
@@ -33,7 +33,7 @@ import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.model.MailboxId;
import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.metrics.api.MetricFactory;
-import org.apache.james.pop3server.mailbox.MailboxAdapter;
+import org.apache.james.pop3server.mailbox.MailboxAdapterFactory;
import org.apache.james.protocols.api.Request;
import org.apache.james.protocols.api.Response;
import org.apache.james.protocols.lib.POP3BeforeSMTPHelper;
@@ -57,11 +57,13 @@ public class PassCmdHandler extends AbstractPassCmdHandler
{
private static final Logger LOGGER =
LoggerFactory.getLogger(PassCmdHandler.class);
private final MailboxManager manager;
+ private final MailboxAdapterFactory mailboxAdapterFactory;
@Inject
- public PassCmdHandler(@Named("mailboxmanager") MailboxManager manager,
MetricFactory metricFactory) {
+ public PassCmdHandler(@Named("mailboxmanager") MailboxManager manager,
MailboxAdapterFactory mailboxAdapterFactory, MetricFactory metricFactory) {
super(metricFactory);
this.manager = manager;
+ this.mailboxAdapterFactory = mailboxAdapterFactory;
}
@Override
@@ -95,12 +97,11 @@ public class PassCmdHandler extends AbstractPassCmdHandler
{
LOGGER.info("Provisioning INBOX. {} created.", mailboxId);
}
MessageManager mailbox =
manager.getMailbox(MailboxPath.inbox(mSession), mSession);
- MailboxAdapter mailboxAdapter = new MailboxAdapter(manager,
mailbox, mSession);
LOGGER.info("Opening mailbox {} {} with mailbox session {}",
mailbox.getId().serialize(),
mailbox.getMailboxPath().asString(),
mSession.getSessionId().getValue());
- return mailboxAdapter;
+ return mailboxAdapterFactory.create(mailbox, mSession);
} catch (BadCredentialsException e) {
LOGGER.info("Bad credential supplied for {} with remote address
{}",
session.getUsername().asString(),
diff --git
a/server/protocols/protocols-pop3/src/main/java/org/apache/james/pop3server/mailbox/DefaultMailboxAdapterFactory.java
b/server/protocols/protocols-pop3/src/main/java/org/apache/james/pop3server/mailbox/DefaultMailboxAdapterFactory.java
new file mode 100644
index 0000000..1af1a47
--- /dev/null
+++
b/server/protocols/protocols-pop3/src/main/java/org/apache/james/pop3server/mailbox/DefaultMailboxAdapterFactory.java
@@ -0,0 +1,42 @@
+/****************************************************************
+ * 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.pop3server.mailbox;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.MessageManager;
+import org.apache.james.protocols.pop3.mailbox.Mailbox;
+
+public class DefaultMailboxAdapterFactory implements MailboxAdapterFactory {
+ private final MailboxManager mailboxManager;
+
+ @Inject
+ public DefaultMailboxAdapterFactory(@Named("mailboxmanager")
MailboxManager mailboxManager) {
+ this.mailboxManager = mailboxManager;
+ }
+
+ @Override
+ public Mailbox create(MessageManager manager, MailboxSession session) {
+ return new MailboxAdapter(mailboxManager, manager, session);
+ }
+}
diff --git
a/server/protocols/protocols-pop3/src/main/java/org/apache/james/pop3server/mailbox/MailboxAdapter.java
b/server/protocols/protocols-pop3/src/main/java/org/apache/james/pop3server/mailbox/MailboxAdapter.java
index 9d66b9b..6f19182 100644
---
a/server/protocols/protocols-pop3/src/main/java/org/apache/james/pop3server/mailbox/MailboxAdapter.java
+++
b/server/protocols/protocols-pop3/src/main/java/org/apache/james/pop3server/mailbox/MailboxAdapter.java
@@ -42,8 +42,6 @@ import com.google.common.collect.ImmutableList;
public class MailboxAdapter implements Mailbox {
private static final FetchGroup FULL_GROUP = FetchGroup.FULL_CONTENT;
- private static final FetchGroup BODY_GROUP = FetchGroup.BODY_CONTENT;
- private static final FetchGroup HEADERS_GROUP = FetchGroup.HEADERS;
private static final FetchGroup METADATA_GROUP = FetchGroup.MINIMAL;
private final MessageManager manager;
@@ -58,41 +56,6 @@ public class MailboxAdapter implements Mailbox {
}
@Override
- public InputStream getMessageBody(String uid) throws IOException {
- try {
- mailboxManager.startProcessingRequest(session);
- Iterator<MessageResult> results =
manager.getMessages(MessageUid.of(Long.parseLong(uid)).toRange(), BODY_GROUP,
session);
- if (results.hasNext()) {
- return results.next().getBody().getInputStream();
- } else {
- return null;
- }
- } catch (MailboxException e) {
- throw new IOException("Unable to retrieve message body for uid " +
uid, e);
- } finally {
- mailboxManager.endProcessingRequest(session);
- }
- }
-
- @Override
- public InputStream getMessageHeaders(String uid) throws IOException {
- try {
- mailboxManager.startProcessingRequest(session);
- Iterator<MessageResult> results =
manager.getMessages(MessageUid.of(Long.parseLong(uid)).toRange(), HEADERS_GROUP,
- session);
- if (results.hasNext()) {
- return results.next().getHeaders().getInputStream();
- } else {
- return null;
- }
- } catch (MailboxException e) {
- throw new IOException("Unable to retrieve message header for uid "
+ uid, e);
- } finally {
- mailboxManager.endProcessingRequest(session);
- }
- }
-
- @Override
public InputStream getMessage(String uid) throws IOException {
try {
mailboxManager.startProcessingRequest(session);
diff --git
a/server/protocols/protocols-pop3/src/main/java/org/apache/james/pop3server/mailbox/MailboxAdapterFactory.java
b/server/protocols/protocols-pop3/src/main/java/org/apache/james/pop3server/mailbox/MailboxAdapterFactory.java
new file mode 100644
index 0000000..665057e
--- /dev/null
+++
b/server/protocols/protocols-pop3/src/main/java/org/apache/james/pop3server/mailbox/MailboxAdapterFactory.java
@@ -0,0 +1,28 @@
+/****************************************************************
+ * 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.pop3server.mailbox;
+
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.MessageManager;
+import org.apache.james.protocols.pop3.mailbox.Mailbox;
+
+public interface MailboxAdapterFactory {
+ Mailbox create(MessageManager manager, MailboxSession session);
+}
diff --git
a/server/protocols/protocols-pop3/src/main/resources/META-INF/spring/pop3server-context.xml
b/server/protocols/protocols-pop3/src/main/resources/META-INF/spring/pop3server-context.xml
index f3c2983..93d795b 100644
---
a/server/protocols/protocols-pop3/src/main/resources/META-INF/spring/pop3server-context.xml
+++
b/server/protocols/protocols-pop3/src/main/resources/META-INF/spring/pop3server-context.xml
@@ -23,4 +23,8 @@
<property name="fileSystem" ref="filesystem"/>
</bean>
+ <bean id="mailboxAdapter"
class="org.apache.james.pop3server.mailbox.DefaultMailboxAdapterFactory">
+ <constructor-arg index="0" ref="mailboxmanager"/>
+ </bean>
+
</beans>
diff --git
a/server/protocols/protocols-pop3/src/test/java/org/apache/james/pop3server/POP3ServerTest.java
b/server/protocols/protocols-pop3/src/test/java/org/apache/james/pop3server/POP3ServerTest.java
index 0eaa19c..4e2651b 100644
---
a/server/protocols/protocols-pop3/src/test/java/org/apache/james/pop3server/POP3ServerTest.java
+++
b/server/protocols/protocols-pop3/src/test/java/org/apache/james/pop3server/POP3ServerTest.java
@@ -44,6 +44,8 @@ import org.apache.james.mailbox.store.StoreMailboxManager;
import org.apache.james.metrics.api.MetricFactory;
import org.apache.james.metrics.tests.RecordingMetricFactory;
import org.apache.james.mime4j.dom.Message;
+import org.apache.james.pop3server.mailbox.DefaultMailboxAdapterFactory;
+import org.apache.james.pop3server.mailbox.MailboxAdapterFactory;
import org.apache.james.pop3server.netty.POP3Server;
import org.apache.james.protocols.api.utils.ProtocolServerUtils;
import org.apache.james.protocols.lib.POP3BeforeSMTPHelper;
@@ -59,15 +61,15 @@ import org.junit.jupiter.api.Test;
import com.google.inject.name.Names;
-class POP3ServerTest {
+public class POP3ServerTest {
private static final DomainList NO_DOMAIN_LIST = null;
private POP3TestConfiguration pop3Configuration;
- private final MemoryUsersRepository usersRepository =
MemoryUsersRepository.withoutVirtualHosting(NO_DOMAIN_LIST);
+ protected final MemoryUsersRepository usersRepository =
MemoryUsersRepository.withoutVirtualHosting(NO_DOMAIN_LIST);
private POP3Client pop3Client = null;
protected MockFileSystem fileSystem;
protected MockProtocolHandlerLoader protocolHandlerChain;
- private StoreMailboxManager mailboxManager;
+ protected StoreMailboxManager mailboxManager;
private final byte[] content = ("Return-path: [email protected]\r\n"
+ "Content-Transfer-Encoding: plain\r\n"
+ "Subject: test\r\n\r\n"
@@ -741,6 +743,7 @@ class POP3ServerTest {
.put(binder ->
binder.bind(MailboxManager.class).annotatedWith(Names.named("mailboxmanager")).toInstance(mailboxManager))
.put(binder ->
binder.bind(FileSystem.class).toInstance(fileSystem))
.put(binder -> binder.bind(MetricFactory.class).toInstance(new
RecordingMetricFactory()))
+ .put(binder ->
binder.bind(MailboxAdapterFactory.class).to(DefaultMailboxAdapterFactory.class))
.build();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]