Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAILBOX-401 Demonstrate '-' causes address matching to fail #3972

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import org.apache.james.mime4j.dom.Message;
import org.apache.james.mime4j.stream.RawField;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

Expand Down Expand Up @@ -292,4 +293,100 @@ void addressMatchesShouldBeExact() throws Exception {
assertThat(messageManager.search(SearchQuery.of(SearchQuery.address(SearchQuery.AddressType.To, "bob@other.tld")), session))
.containsOnly(messageId2.getUid());
}

@Disabled("MAILBOX-401 '-' causes address matching to fail")
@Test
void localPartShouldBeMatchedWhenHyphen() throws Exception {
MailboxPath mailboxPath = MailboxPath.forUser(USERNAME, INBOX);
MailboxSession session = MailboxSessionUtil.create(USERNAME);
MessageManager messageManager = storeMailboxManager.getMailbox(mailboxPath, session);

Message.Builder messageBuilder = Message.Builder
.of()
.setSubject("test")
.setBody("testmail", StandardCharsets.UTF_8);

ComposedMessageId messageId1 = messageManager.appendMessage(
MessageManager.AppendCommand.builder().build(
messageBuilder
.addField(new RawField("To", "alice-test@domain.tld"))
.build()),
session).getId();

ComposedMessageId messageId2 = messageManager.appendMessage(
MessageManager.AppendCommand.builder().build(
messageBuilder
.addField(new RawField("To", "bob@other.tld"))
.build()),
session).getId();

elasticSearch.awaitForElasticSearch();

assertThat(messageManager.search(SearchQuery.of(SearchQuery.address(SearchQuery.AddressType.To, "alice-test")), session))
.containsOnly(messageId2.getUid());
}

@Disabled("MAILBOX-401 '-' causes address matching to fail")
@Test
void addressShouldBeMatchedWhenHyphen() throws Exception {
MailboxPath mailboxPath = MailboxPath.forUser(USERNAME, INBOX);
MailboxSession session = MailboxSessionUtil.create(USERNAME);
MessageManager messageManager = storeMailboxManager.getMailbox(mailboxPath, session);

Message.Builder messageBuilder = Message.Builder
.of()
.setSubject("test")
.setBody("testmail", StandardCharsets.UTF_8);

ComposedMessageId messageId1 = messageManager.appendMessage(
MessageManager.AppendCommand.builder().build(
messageBuilder
.addField(new RawField("To", "alice-test@domain.tld"))
.build()),
session).getId();

ComposedMessageId messageId2 = messageManager.appendMessage(
MessageManager.AppendCommand.builder().build(
messageBuilder
.addField(new RawField("To", "bob@other.tld"))
.build()),
session).getId();

elasticSearch.awaitForElasticSearch();

assertThat(messageManager.search(SearchQuery.of(SearchQuery.address(SearchQuery.AddressType.To, "alice-test@domain.tld")), session))
.containsOnly(messageId1.getUid());
}

@Disabled("MAILBOX-401 '-' causes address matching to fail")
@Test
void domainPartShouldBeMatchedWhenHyphen() throws Exception {
MailboxPath mailboxPath = MailboxPath.forUser(USERNAME, INBOX);
MailboxSession session = MailboxSessionUtil.create(USERNAME);
MessageManager messageManager = storeMailboxManager.getMailbox(mailboxPath, session);

Message.Builder messageBuilder = Message.Builder
.of()
.setSubject("test")
.setBody("testmail", StandardCharsets.UTF_8);

ComposedMessageId messageId1 = messageManager.appendMessage(
MessageManager.AppendCommand.builder().build(
messageBuilder
.addField(new RawField("To", "alice@domain-test.tld"))
.build()),
session).getId();

ComposedMessageId messageId2 = messageManager.appendMessage(
MessageManager.AppendCommand.builder().build(
messageBuilder
.addField(new RawField("To", "bob@other.tld"))
.build()),
session).getId();

elasticSearch.awaitForElasticSearch();

assertThat(messageManager.search(SearchQuery.of(SearchQuery.address(SearchQuery.AddressType.To, "domain-test.tld")), session))
.containsOnly(messageId1.getUid());
}
}