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
The following commit(s) were added to refs/heads/master by this push:
new d974eef570 URLEncoding for subaddressing (#2439)
d974eef570 is described below
commit d974eef570eac1c29b526d02d734bb1596b4daa0
Author: florentos17 <[email protected]>
AuthorDate: Wed Oct 9 05:25:12 2024 +0200
URLEncoding for subaddressing (#2439)
---
.../org/apache/james/modules/ACLProbeImpl.java | 7 ++--
.../apache/james/mailets/SubAddressingTest.java | 38 ++++++++++++++++++++++
.../james/transport/mailets/SubAddressing.java | 11 ++++---
3 files changed, 49 insertions(+), 7 deletions(-)
diff --git
a/server/container/guice/mailbox/src/main/java/org/apache/james/modules/ACLProbeImpl.java
b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/ACLProbeImpl.java
index 49e6ae77fa..7a259000b7 100644
---
a/server/container/guice/mailbox/src/main/java/org/apache/james/modules/ACLProbeImpl.java
+++
b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/ACLProbeImpl.java
@@ -31,6 +31,7 @@ import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.model.MailboxACL;
import org.apache.james.mailbox.model.MailboxACL.ACLCommand;
import org.apache.james.mailbox.model.MailboxACL.Rfc4314Rights;
+import org.apache.james.mailbox.model.MailboxId;
import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.probe.ACLProbe;
import org.apache.james.utils.GuiceProbe;
@@ -60,9 +61,9 @@ public class ACLProbeImpl implements GuiceProbe, ACLProbe {
mailboxManager.applyRightsCommand(mailboxPath, command,
mailboxSession);
}
- public void executeCommand(MailboxPath mailboxPath, ACLCommand command)
throws MailboxException {
- MailboxSession mailboxSession =
mailboxManager.createSystemSession(mailboxPath.getUser());
- mailboxManager.applyRightsCommand(mailboxPath, command,
mailboxSession);
+ public void executeCommand(MailboxId mailboxId, Username ownerUser,
ACLCommand command) throws MailboxException {
+ MailboxSession mailboxSession =
mailboxManager.createSystemSession(ownerUser);
+ mailboxManager.applyRightsCommand(mailboxId, command, mailboxSession);
}
@Override
diff --git
a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/SubAddressingTest.java
b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/SubAddressingTest.java
index fa1225cd1f..941178d950 100644
---
a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/SubAddressingTest.java
+++
b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/SubAddressingTest.java
@@ -36,10 +36,18 @@ import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
+import org.apache.james.core.Username;
+import org.apache.james.mailbox.model.MailboxACL;
import org.apache.james.mailbox.model.MailboxConstants;
+import org.apache.james.mailbox.model.MailboxId;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.MultimailboxesSearchQuery;
+import org.apache.james.mailbox.model.SearchQuery;
import org.apache.james.mailets.configuration.CommonProcessors;
import org.apache.james.mailets.configuration.MailetConfiguration;
import org.apache.james.mailets.configuration.ProcessorConfiguration;
+import org.apache.james.modules.ACLProbeImpl;
+import org.apache.james.modules.MailboxProbeImpl;
import org.apache.james.modules.protocols.ImapGuiceProbe;
import org.apache.james.modules.protocols.SmtpGuiceProbe;
import org.apache.james.probe.DataProbe;
@@ -58,6 +66,8 @@ class SubAddressingTest {
private static final String TARGETED_MAILBOX = "any";
private static final String TARGETED_MAILBOX_LOWER = TARGETED_MAILBOX;
private static final String TARGETED_MAILBOX_UPPER = "ANY";
+ private static final String TARGETED_MAILBOX_REQUIRING_ENCODING = "Dossier
d'été";
+ private static final String TARGETED_MAILBOX_ENCODED =
"Dossier%20d%27%C3%A9t%C3%A9";
@RegisterExtension
public TestIMAPClient testIMAPClient = new TestIMAPClient();
@@ -196,6 +206,34 @@ class SubAddressingTest {
awaitSubAddressedMail(MailboxConstants.INBOX);
}
+ @Test
+ void
subAddressedEmailShouldBeDeliveredInSpecifiedFolderWhenRequiringEncoding(@TempDir
File temporaryFolder) throws Exception {
+ setup(temporaryFolder);
+
+ MailboxId targetMailboxId =
jamesServer.getProbe(MailboxProbeImpl.class).createMailbox(MailboxPath.forUser(Username.of(RECIPIENT),
TARGETED_MAILBOX_REQUIRING_ENCODING));
+
+ //give posting rights
+ jamesServer.getProbe(ACLProbeImpl.class).executeCommand(
+ targetMailboxId,
+ Username.of(RECIPIENT),
+ MailboxACL.command()
+ .key(MailboxACL.ANYONE_KEY)
+ .rights(MailboxACL.Right.Post)
+ .asAddition());
+
+ sendSubAddressedMail(TARGETED_MAILBOX_ENCODED);
+
+ int loadLimit = 1;
+ awaitAtMostOneMinute.until(() ->
jamesServer.getProbe(MailboxProbeImpl.class)
+ .searchMessage(MultimailboxesSearchQuery
+ .from(SearchQuery.builder().build())
+ .inMailboxes(targetMailboxId)
+ .build(),
+ RECIPIENT,
+ loadLimit)
+ .size() == 1);
+ }
+
@Test
void subAddressedEmailShouldBeDeliveredInINBOXWhenNobodyHasRight(@TempDir
File temporaryFolder) throws Exception {
setup(temporaryFolder);
diff --git
a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/SubAddressing.java
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/SubAddressing.java
index f3d1c5c1c6..9e0cd4b767 100644
---
a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/SubAddressing.java
+++
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/SubAddressing.java
@@ -21,6 +21,8 @@ package org.apache.james.transport.mailets;
import static
org.apache.james.mailbox.MessageManager.MailboxMetaData.RecentMode.IGNORE;
+import java.net.URLDecoder;
+import java.nio.charset.StandardCharsets;
import java.util.Comparator;
import java.util.Optional;
@@ -95,21 +97,22 @@ public class SubAddressing extends GenericMailet {
getPathWithCorrectCase(recipient, targetFolder)))));
}
- private Optional<MailboxPath> getPathWithCorrectCase(MailAddress
recipient, String targetFolder) throws UsersRepositoryException,
MailboxException {
+ private Optional<MailboxPath> getPathWithCorrectCase(MailAddress
recipient, String encodedTargetFolder) throws UsersRepositoryException,
MailboxException {
Username recipientUsername = usersRepository.getUsername(recipient);
MailboxSession session =
mailboxManager.createSystemSession(recipientUsername);
+ String decodedTargetFolder = URLDecoder.decode(encodedTargetFolder,
StandardCharsets.UTF_8);
- Comparator<MailboxPath> exactMatchFirst =
Comparator.comparing(mailboxPath -> mailboxPath.getName().equals(targetFolder)
? 0 : 1);
+ Comparator<MailboxPath> exactMatchFirst =
Comparator.comparing(mailboxPath ->
mailboxPath.getName().equals(decodedTargetFolder) ? 0 : 1);
return mailboxManager.search(
-
MailboxQuery.privateMailboxesBuilder(session).expression(new
ExactNameCaseInsensitive(targetFolder)).build(),
+
MailboxQuery.privateMailboxesBuilder(session).expression(new
ExactNameCaseInsensitive(decodedTargetFolder)).build(),
session)
.toStream()
.map(MailboxMetaData::getPath)
.sorted(exactMatchFirst)
.findFirst()
.or(() -> {
- LOG.info("{}'s subfolder `{}` was tried to be addressed
but it does not exist", recipient, targetFolder);
+ LOG.info("{}'s subfolder `{}` was tried to be addressed
but it does not exist", recipient, decodedTargetFolder);
return Optional.empty();
});
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]