james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [05/10] james-project git commit: JAMES-2370 Mailbox should support attachment fileName search criterion
Date Wed, 18 Apr 2018 00:36:57 GMT
JAMES-2370 Mailbox should support attachment fileName search criterion


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/8063fc25
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/8063fc25
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/8063fc25

Branch: refs/heads/master
Commit: 8063fc25121943fdc9ed018f79e8927563428df2
Parents: 49b6e76
Author: benwa <btellier@linagora.com>
Authored: Mon Apr 9 13:46:34 2018 +0700
Committer: benwa <btellier@linagora.com>
Committed: Wed Apr 18 07:35:38 2018 +0700

----------------------------------------------------------------------
 .../apache/james/mailbox/MailboxManager.java    |  3 +-
 ...lasticSearchListeningMessageSearchIndex.java |  1 +
 .../elasticsearch/query/CriterionConverter.java |  4 +++
 .../mailbox/store/search/MessageSearches.java   |  9 ++++++
 .../store/search/SimpleMessageSearchIndex.java  |  3 +-
 .../search/AbstractMessageSearchIndexTest.java  | 29 ++++++++++++++++++++
 6 files changed, 47 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/8063fc25/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxManager.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxManager.java b/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxManager.java
index e027103..e00deb2 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxManager.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxManager.java
@@ -100,7 +100,8 @@ public interface MailboxManager extends RequestAware, MailboxListenerSupport,
Ri
          */
         Text,
         FullText,
-        Attachment
+        Attachment,
+        AttachmentFileName
     }
     
     EnumSet<SearchCapabilities> getSupportedSearchCapabilities();

http://git-wip-us.apache.org/repos/asf/james-project/blob/8063fc25/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java
b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java
index ed47b44..eaced67 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java
@@ -84,6 +84,7 @@ public class ElasticSearchListeningMessageSearchIndex extends ListeningMessageSe
             SearchCapabilities.Text,
             SearchCapabilities.FullText,
             SearchCapabilities.Attachment,
+            SearchCapabilities.AttachmentFileName,
             SearchCapabilities.PartialEmailMatch);
     }
     

http://git-wip-us.apache.org/repos/asf/james-project/blob/8063fc25/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/CriterionConverter.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/CriterionConverter.java
b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/CriterionConverter.java
index 71ab35b..5499a50 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/CriterionConverter.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/CriterionConverter.java
@@ -168,6 +168,10 @@ public class CriterionConverter {
             return boolQuery()
                     .should(matchQuery(JsonMessageConstants.ATTACHMENTS + "." + JsonMessageConstants.Attachment.TEXT_CONTENT,
                         textCriterion.getOperator().getValue()));
+        case ATTACHMENT_FILE_NAME:
+            return boolQuery()
+                .should(termQuery(JsonMessageConstants.ATTACHMENTS + "." + JsonMessageConstants.Attachment.FILENAME,
+                    textCriterion.getOperator().getValue()));
         }
         throw new RuntimeException("Unknown SCOPE for text criterion");
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/8063fc25/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java
index b8907df..6f98523 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java
@@ -206,6 +206,8 @@ public class MessageSearches implements Iterable<SimpleMessageSearchIndex.Search
                 return messageContains(value, message);
             case ATTACHMENTS:
                 return attachmentsContain(value, message);
+            case ATTACHMENT_FILE_NAME:
+                return hasFileName(value, message);
             }
             throw new UnsupportedSearchException();
         } catch (IOException | MimeException e) {
@@ -243,6 +245,13 @@ public class MessageSearches implements Iterable<SimpleMessageSearchIndex.Search
         return isInAttachments(value, attachments);
     }
 
+    private boolean hasFileName(String value, MailboxMessage message) throws IOException,
MimeException {
+        return message.getAttachments()
+            .stream()
+            .map(MessageAttachment::getName)
+            .anyMatch(nameOptional -> nameOptional.map(value::equals).orElse(false));
+    }
+
     private boolean isInAttachments(String value, List<MessageAttachment> attachments)
{
         return attachments.stream()
             .map(MessageAttachment::getAttachment)

http://git-wip-us.apache.org/repos/asf/james-project/blob/8063fc25/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndex.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndex.java
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndex.java
index d9b4c1d..299e538 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndex.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndex.java
@@ -82,7 +82,8 @@ public class SimpleMessageSearchIndex implements MessageSearchIndex {
             return EnumSet.of(SearchCapabilities.MultimailboxSearch,
                 SearchCapabilities.Text,
                 SearchCapabilities.Attachment,
-                SearchCapabilities.PartialEmailMatch);
+                SearchCapabilities.PartialEmailMatch,
+                SearchCapabilities.AttachmentFileName);
         }
         return EnumSet.of(SearchCapabilities.MultimailboxSearch,
             SearchCapabilities.Text);

http://git-wip-us.apache.org/repos/asf/james-project/blob/8063fc25/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/AbstractMessageSearchIndexTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/AbstractMessageSearchIndexTest.java
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/AbstractMessageSearchIndexTest.java
index 9a3803f..4e0d5b2 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/AbstractMessageSearchIndexTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/AbstractMessageSearchIndexTest.java
@@ -52,6 +52,7 @@ import org.apache.james.mime4j.dom.Message;
 import org.apache.james.mime4j.dom.Multipart;
 import org.apache.james.mime4j.message.BodyPartBuilder;
 import org.apache.james.mime4j.message.MultipartBuilder;
+import org.apache.james.mime4j.message.SingleBodyBuilder;
 import org.apache.james.util.ClassLoaderUtils;
 import org.junit.Assume;
 import org.junit.Before;
@@ -1450,4 +1451,32 @@ public abstract class AbstractMessageSearchIndexTest {
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m3.getUid());
     }
+
+    @Test
+    public void searchShouldRetrieveMailByAttachmentFileName() throws Exception {
+        Assume.assumeTrue(messageSearchIndex.getSupportedCapabilities(storeMailboxManager.getSupportedMessageCapabilities())
+            .contains(MailboxManager.SearchCapabilities.AttachmentFileName));
+
+        String fileName = "matchme.txt";
+        ComposedMessageId mWithFileName = inboxMessageManager.appendMessage(MessageManager.AppendCommand.builder()
+                .build(Message.Builder.of()
+                    .setBody(
+                        MultipartBuilder.create("alternative")
+                            .addBodyPart(BodyPartBuilder.create()
+                                .setContentDisposition("attachment", fileName)
+                                .setBody(SingleBodyBuilder.create()
+                                    .setText("this is the file content...")
+                                    .setCharset(StandardCharsets.UTF_8)
+                                    .build())
+                                .build())
+                            .build())),
+            session);
+
+        await();
+
+        SearchQuery searchQuery = new SearchQuery(SearchQuery.attachmentFileName(fileName));
+
+        assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
+            .containsOnly(mWithFileName.getUid());
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message