You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by rc...@apache.org on 2021/04/27 02:53:59 UTC
[james-project] branch master updated (a33b52f -> 049d7cc)
This is an automated email from the ASF dual-hosted git repository.
rcordier pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git.
from a33b52f [Boyscout] trim DockerCassandra container logs
new 28117f9 JAMES-3569 Removes mocks in RecipientRewriteTableProcessorTest
new 049d7cc JAMES-3569 preserves all email propertis on recipient rewrite
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../mailets/RecipientRewriteTableProcessor.java | 10 +--
.../RecipientRewriteTableProcessorTest.java | 77 ++++++++++++++--------
2 files changed, 51 insertions(+), 36 deletions(-)
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[james-project] 02/02: JAMES-3569 preserves all email propertis on
recipient rewrite
Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 049d7cc364f91bbab0b6bee708806724430a8231
Author: Matthieu Baechler <ma...@apache.org>
AuthorDate: Wed Apr 21 22:49:46 2021 +0200
JAMES-3569 preserves all email propertis on recipient rewrite
Co-Authored-By: Jean Helou <jh...@codamens.fr>
---
.../transport/mailets/RecipientRewriteTableProcessor.java | 10 +++-------
.../transport/mailets/RecipientRewriteTableProcessorTest.java | 7 +++++++
2 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/RecipientRewriteTableProcessor.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/RecipientRewriteTableProcessor.java
index 77660c2..db99d59 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/RecipientRewriteTableProcessor.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/RecipientRewriteTableProcessor.java
@@ -277,13 +277,9 @@ public class RecipientRewriteTableProcessor {
private void forwardToRemoteAddress(Mail mail, MailAddress recipient, Collection<MailAddress> remoteRecipients) {
if (!remoteRecipients.isEmpty()) {
try {
- mailetContext.sendMail(
- MailImpl.builder()
- .name(mail.getName())
- .sender(mail.getMaybeSender())
- .addRecipients(ImmutableList.copyOf(remoteRecipients))
- .mimeMessage(mail.getMessage())
- .build());
+ Mail duplicate = mail.duplicate();
+ duplicate.setRecipients(ImmutableList.copyOf(remoteRecipients));
+ mailetContext.sendMail(duplicate);
LOGGER.info("Mail for {} forwarded to {}", recipient, remoteRecipients);
} catch (MessagingException ex) {
LOGGER.warn("Error forwarding mail to {}", remoteRecipients);
diff --git a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/RecipientRewriteTableProcessorTest.java b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/RecipientRewriteTableProcessorTest.java
index c41dd1e..9fee75e 100644
--- a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/RecipientRewriteTableProcessorTest.java
+++ b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/RecipientRewriteTableProcessorTest.java
@@ -48,6 +48,9 @@ import org.apache.james.rrt.lib.Mappings;
import org.apache.james.rrt.lib.MappingsImpl;
import org.apache.james.rrt.memory.MemoryRecipientRewriteTable;
import org.apache.james.util.MimeMessageUtil;
+import org.apache.mailet.Attribute;
+import org.apache.mailet.AttributeName;
+import org.apache.mailet.AttributeValue;
import org.apache.mailet.Mail;
import org.apache.mailet.base.MailAddressFixture;
import org.apache.mailet.base.test.FakeMail;
@@ -169,12 +172,16 @@ class RecipientRewriteTableProcessorTest {
.add(MailAddressFixture.OTHER_AT_JAMES.toString())
.build();
+ Attribute attribute = AttributeName.of("dont-loose-my-attribute").withValue(AttributeValue.of("ok ?"));
+ mail.setAttribute(attribute);
+
processor.handleMappings(mappings, mail, MailAddressFixture.OTHER_AT_JAMES);
FakeMailContext.SentMail expected = FakeMailContext.sentMailBuilder()
.sender(MailAddressFixture.ANY_AT_JAMES)
.recipients(ImmutableList.of(MailAddressFixture.ANY_AT_JAMES, MailAddressFixture.OTHER_AT_JAMES))
.fromMailet()
+ .attribute(attribute)
.message(message)
.build();
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[james-project] 01/02: JAMES-3569 Removes mocks in
RecipientRewriteTableProcessorTest
Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 28117f988668eda59a1ca4938a7a41db98b51955
Author: Matthieu Baechler <ma...@apache.org>
AuthorDate: Wed Apr 21 22:43:24 2021 +0200
JAMES-3569 Removes mocks in RecipientRewriteTableProcessorTest
There is no more need for mock here since both domain list and virtual
table store have memory based implementations that are suited for tests.
Co-Authored-By: Jean Helou <jh...@codamens.fr>
---
.../RecipientRewriteTableProcessorTest.java | 70 +++++++++++++---------
1 file changed, 41 insertions(+), 29 deletions(-)
diff --git a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/RecipientRewriteTableProcessorTest.java b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/RecipientRewriteTableProcessorTest.java
index e3b02d1..c41dd1e 100644
--- a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/RecipientRewriteTableProcessorTest.java
+++ b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/RecipientRewriteTableProcessorTest.java
@@ -32,14 +32,21 @@ import java.util.Collection;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
+import org.apache.commons.configuration2.HierarchicalConfiguration;
+import org.apache.commons.configuration2.ex.ConfigurationException;
import org.apache.james.core.Domain;
import org.apache.james.core.MailAddress;
-import org.apache.james.domainlist.api.DomainList;
-import org.apache.james.domainlist.api.DomainListException;
+import org.apache.james.dnsservice.api.InMemoryDNSService;
+import org.apache.james.domainlist.lib.DomainListConfiguration;
+import org.apache.james.domainlist.memory.MemoryDomainList;
import org.apache.james.rrt.api.RecipientRewriteTable.ErrorMappingException;
+import org.apache.james.rrt.api.RecipientRewriteTableConfiguration;
import org.apache.james.rrt.api.RecipientRewriteTableException;
import org.apache.james.rrt.lib.Mapping;
+import org.apache.james.rrt.lib.MappingSource;
+import org.apache.james.rrt.lib.Mappings;
import org.apache.james.rrt.lib.MappingsImpl;
+import org.apache.james.rrt.memory.MemoryRecipientRewriteTable;
import org.apache.james.util.MimeMessageUtil;
import org.apache.mailet.Mail;
import org.apache.mailet.base.MailAddressFixture;
@@ -59,14 +66,16 @@ class RecipientRewriteTableProcessorTest {
private MappingsImpl mappings;
private FakeMailContext mailetContext;
private MailAddress nonDomainWithDefaultLocal;
- private DomainList domainList;
- private org.apache.james.rrt.api.RecipientRewriteTable virtualTableStore;
+ private MemoryDomainList domainList;
+ private MemoryRecipientRewriteTable virtualTableStore;
private RecipientRewriteTableProcessor processor;
@BeforeEach
void setup() throws Exception {
- domainList = mock(DomainList.class);
- virtualTableStore = mock(org.apache.james.rrt.api.RecipientRewriteTable.class);
+ domainList = new MemoryDomainList(new InMemoryDNSService());
+ virtualTableStore = new MemoryRecipientRewriteTable();
+ virtualTableStore.setConfiguration(RecipientRewriteTableConfiguration.DEFAULT_ENABLED);
+
mailetContext = FakeMailContext.defaultContext();
processor = new RecipientRewriteTableProcessor(virtualTableStore, domainList, mailetContext);
mail = FakeMail.builder().name("mail")
@@ -83,7 +92,6 @@ class RecipientRewriteTableProcessorTest {
@Test
public void handleMappingsShouldThrowExceptionWhenMappingsContainAtLeastOneNoneDomainObjectButCannotGetDefaultDomain() throws Exception {
- when(domainList.getDefaultDomain()).thenThrow(DomainListException.class);
mappings = MappingsImpl.builder()
.add(MailAddressFixture.ANY_AT_JAMES.toString())
.add(NONEDOMAIN)
@@ -97,7 +105,6 @@ class RecipientRewriteTableProcessorTest {
@Test
void handleMappingsShouldDoNotCareDefaultDomainWhenMappingsDoesNotContainAnyNoneDomainObject() throws Exception {
- when(domainList.getDefaultDomain()).thenThrow(DomainListException.class);
mappings = MappingsImpl.builder()
.add(MailAddressFixture.ANY_AT_JAMES.toString())
.add(MailAddressFixture.OTHER_AT_JAMES.toString())
@@ -108,7 +115,7 @@ class RecipientRewriteTableProcessorTest {
@Test
void handleMappingsShouldReturnTheMailAddressBelongToLocalServer() throws Exception {
- when(domainList.getDefaultDomain()).thenReturn(Domain.of(MailAddressFixture.JAMES_LOCAL));
+ defineDefaultDomain(MailAddressFixture.JAMES_LOCAL);
mappings = MappingsImpl.builder()
.add(MailAddressFixture.ANY_AT_JAMES.toString())
.add(NONEDOMAIN)
@@ -122,7 +129,7 @@ class RecipientRewriteTableProcessorTest {
@Test
void handleMappingsShouldReturnTheOnlyMailAddressBelongToLocalServer() throws Exception {
- when(domainList.getDefaultDomain()).thenReturn(Domain.of(MailAddressFixture.JAMES2_APACHE_ORG));
+ defineDefaultDomain(MailAddressFixture.JAMES2_APACHE_ORG);
mappings = MappingsImpl.builder()
.add(MailAddressFixture.ANY_AT_JAMES.toString())
@@ -138,7 +145,7 @@ class RecipientRewriteTableProcessorTest {
@Test
void handleMappingsShouldRemoveMappingElementWhenCannotCreateMailAddress() throws Exception {
- when(domainList.getDefaultDomain()).thenReturn(Domain.of(MailAddressFixture.JAMES_LOCAL));
+ defineDefaultDomain(MailAddressFixture.JAMES_LOCAL);
mappings = MappingsImpl.builder()
.add(MailAddressFixture.ANY_AT_JAMES.toString())
.add(NONEDOMAIN)
@@ -153,7 +160,7 @@ class RecipientRewriteTableProcessorTest {
@Test
void handleMappingsShouldForwardEmailToRemoteServer() throws Exception {
- when(domainList.getDefaultDomain()).thenReturn(Domain.of(MailAddressFixture.JAMES_LOCAL));
+ defineDefaultDomain(MailAddressFixture.JAMES_LOCAL);
mappings = MappingsImpl.builder()
.add(MailAddressFixture.ANY_AT_JAMES.toString())
@@ -176,7 +183,7 @@ class RecipientRewriteTableProcessorTest {
@Test
void handleMappingsShouldNotForwardAnyEmailToRemoteServerWhenNoMoreReomoteAddress() throws Exception {
- when(domainList.getDefaultDomain()).thenReturn(Domain.of(MailAddressFixture.JAMES_LOCAL));
+ defineDefaultDomain(MailAddressFixture.JAMES_LOCAL);
mappings = MappingsImpl.builder()
.add(NONEDOMAIN)
@@ -190,7 +197,7 @@ class RecipientRewriteTableProcessorTest {
@Test
void handleMappingWithOnlyLocalRecipient() throws Exception {
- when(domainList.getDefaultDomain()).thenReturn(Domain.of(MailAddressFixture.JAMES_LOCAL));
+ defineDefaultDomain(MailAddressFixture.JAMES_LOCAL);
mappings = MappingsImpl.builder()
.add(NONEDOMAIN)
@@ -205,7 +212,7 @@ class RecipientRewriteTableProcessorTest {
@Test
void handleMappingWithOnlyRemoteRecipient() throws Exception {
- when(domainList.getDefaultDomain()).thenReturn(Domain.of(MailAddressFixture.JAMES_LOCAL));
+ defineDefaultDomain(MailAddressFixture.JAMES_LOCAL);
mappings = MappingsImpl.builder()
.add(MailAddressFixture.ANY_AT_JAMES.toString())
@@ -227,8 +234,6 @@ class RecipientRewriteTableProcessorTest {
@Test
void processShouldNotRewriteRecipientWhenVirtualTableStoreReturnNullMappings() throws Exception {
- when(virtualTableStore.getResolvedMappings(any(String.class), any(Domain.class))).thenReturn(null);
-
mail = FakeMail.builder()
.name("mail")
.mimeMessage(message)
@@ -242,7 +247,7 @@ class RecipientRewriteTableProcessorTest {
@Test
void processShouldSendMailToAllErrorRecipientsWhenErrorMappingException() throws Exception {
- when(virtualTableStore.getResolvedMappings(eq("other"), eq(Domain.of(MailAddressFixture.JAMES_LOCAL)))).thenThrow(ErrorMappingException.class);
+ virtualTableStore.addMapping(MappingSource.fromMailAddress(MailAddressFixture.OTHER_AT_LOCAL), Mapping.error("bam"));
mail = FakeMail.builder()
.name("mail")
@@ -267,11 +272,12 @@ class RecipientRewriteTableProcessorTest {
@Test
void processShouldNotDuplicateRewrittenMailAddresses() throws Exception {
- when(virtualTableStore.getResolvedMappings(eq("other"), eq(Domain.of(MailAddressFixture.JAMES_LOCAL))))
- .thenReturn(MappingsImpl.builder()
- .add(Mapping.alias(MailAddressFixture.ANY_AT_LOCAL.asString()))
- .add(Mapping.group(MailAddressFixture.ANY_AT_LOCAL.asString()))
- .build());
+ virtualTableStore.addMapping(
+ MappingSource.fromMailAddress(MailAddressFixture.OTHER_AT_LOCAL),
+ Mapping.alias(MailAddressFixture.ANY_AT_LOCAL.asString()));
+ virtualTableStore.addMapping(
+ MappingSource.fromMailAddress(MailAddressFixture.OTHER_AT_LOCAL),
+ Mapping.group(MailAddressFixture.ANY_AT_LOCAL.asString()));
mail = FakeMail.builder()
.name("mail")
@@ -287,7 +293,7 @@ class RecipientRewriteTableProcessorTest {
@Test
void processShouldSendMailToAllErrorRecipientsWhenRecipientRewriteTableException() throws Exception {
- when(virtualTableStore.getResolvedMappings(eq("other"), eq(Domain.of(MailAddressFixture.JAMES_LOCAL)))).thenThrow(RecipientRewriteTableException.class);
+ virtualTableStore.addMapping(MappingSource.fromMailAddress(MailAddressFixture.OTHER_AT_LOCAL), Mapping.error("bam"));
mail = FakeMail.builder()
.name("mail")
@@ -312,8 +318,6 @@ class RecipientRewriteTableProcessorTest {
@Test
void processShouldNotSendMailWhenNoErrorRecipients() throws Exception {
- when(virtualTableStore.getResolvedMappings(any(String.class), any(Domain.class))).thenReturn(null);
-
mail = FakeMail.builder()
.name("mail")
.mimeMessage(message)
@@ -327,13 +331,16 @@ class RecipientRewriteTableProcessorTest {
@Test
void processShouldResetMailStateToGhostWhenCanNotBuildNewRecipient() throws Exception {
- when(virtualTableStore.getResolvedMappings(any(String.class), any(Domain.class))).thenReturn(mappings);
- when(domainList.getDefaultDomain()).thenReturn(Domain.of(MailAddressFixture.JAMES_LOCAL));
+ virtualTableStore.addMapping(
+ MappingSource.fromDomain(MailAddressFixture.JAMES_APACHE_ORG_DOMAIN),
+ Mapping.of(MailAddressFixture.ANY_AT_JAMES2.asString()));
+
+ defineDefaultDomain(MailAddressFixture.JAMES_LOCAL);
mail = FakeMail.builder()
.name("mail")
.mimeMessage(message)
- .recipients(MailAddressFixture.OTHER_AT_JAMES, nonDomainWithDefaultLocal)
+ .recipients(MailAddressFixture.OTHER_AT_JAMES, MailAddressFixture.ANY_AT_JAMES)
.build();
processor.processMail(mail);
@@ -341,4 +348,9 @@ class RecipientRewriteTableProcessorTest {
assertThat(mail.getState()).isEqualTo(Mail.GHOST);
assertThat(mail.getRecipients()).isEmpty();
}
+
+ private void defineDefaultDomain(String jamesLocal) throws ConfigurationException {
+ domainList.configure(DomainListConfiguration.builder().defaultDomain(Domain.of(jamesLocal)));
+ }
+
}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org