private boolean computeHasAttachment(MailboxMessage message) { return message.getProperties() .stream() .anyMatch(property -> property.equals(HAS_ATTACHMENT_PROPERTY)); }
private boolean matches(SearchQuery.AttachmentCriterion criterion, MailboxMessage message) throws UnsupportedSearchException { boolean mailHasAttachments = message.getProperties() .stream() .anyMatch(PropertyBuilder.isHasAttachmentProperty()); return mailHasAttachments == criterion.getOperator().isSet(); }
private List<UDTValue> buildPropertiesUdt(MailboxMessage message) { return message.getProperties().stream() .map(x -> typesProvider.getDefinedUserType(PROPERTIES) .newValue() .setString(Properties.NAMESPACE, x.getNamespace()) .setString(Properties.NAME, x.getLocalName()) .setString(Properties.VALUE, x.getValue())) .collect(Guavate.toImmutableList()); }
this.internalDate = original.getInternalDate(); PropertyBuilder pBuilder = new PropertyBuilder(original.getProperties()); this.textualLineCount = original.getTextualLineCount(); this.mediaType = original.getMediaType();
@Test public void hasAttachmentsShouldReturnTrueWhenPropertyIsPresentAndTrue() throws IOException { //Given MailboxMessage mailboxMessage = mock(MailboxMessage.class); TestId mailboxId = TestId.of(1); when(mailboxMessage.getMailboxId()) .thenReturn(mailboxId); when(mailboxMessage.getMessageId()) .thenReturn(InMemoryMessageId.of(42)); when(mailboxMessage.getFullContent()) .thenReturn(ClassLoader.getSystemResourceAsStream("eml/mailWithHeaders.eml")); when(mailboxMessage.createFlags()) .thenReturn(new Flags()); when(mailboxMessage.getUid()) .thenReturn(MESSAGE_UID); when(mailboxMessage.getProperties()).thenReturn(ImmutableList.of(IndexableMessage.HAS_ATTACHMENT_PROPERTY)); // When IndexableMessage indexableMessage = IndexableMessage.builder() .message(mailboxMessage) .users(ImmutableList.of(new MockMailboxSession("username").getUser())) .extractor(new DefaultTextExtractor()) .zoneId(ZoneId.of("Europe/Paris")) .indexAttachments(IndexAttachments.YES) .build(); // Then assertThat(indexableMessage.getHasAttachment()).isTrue(); }
@Test public void hasAttachmentsShouldReturnFalseWhenPropertyIsPresentButFalse() throws IOException { //Given MailboxMessage mailboxMessage = mock(MailboxMessage.class); TestId mailboxId = TestId.of(1); when(mailboxMessage.getMailboxId()) .thenReturn(mailboxId); when(mailboxMessage.getMessageId()) .thenReturn(InMemoryMessageId.of(42)); when(mailboxMessage.getFullContent()) .thenReturn(ClassLoader.getSystemResourceAsStream("eml/mailWithHeaders.eml")); when(mailboxMessage.createFlags()) .thenReturn(new Flags()); when(mailboxMessage.getUid()) .thenReturn(MESSAGE_UID); when(mailboxMessage.getProperties()) .thenReturn(ImmutableList.of(new SimpleProperty(PropertyBuilder.JAMES_INTERNALS, PropertyBuilder.HAS_ATTACHMENT, "false"))); // When IndexableMessage indexableMessage = IndexableMessage.builder() .message(mailboxMessage) .users(ImmutableList.of(new MockMailboxSession("username").getUser())) .extractor(new DefaultTextExtractor()) .zoneId(ZoneId.of("Europe/Paris")) .indexAttachments(IndexAttachments.NO) .build(); // Then assertThat(indexableMessage.getHasAttachment()).isFalse(); }
@Test public void hasAttachmentsShouldReturnFalseWhenPropertyIsAbsent() throws IOException { //Given MailboxMessage mailboxMessage = mock(MailboxMessage.class); TestId mailboxId = TestId.of(1); when(mailboxMessage.getMailboxId()) .thenReturn(mailboxId); when(mailboxMessage.getMessageId()) .thenReturn(InMemoryMessageId.of(42)); when(mailboxMessage.getFullContent()) .thenReturn(ClassLoader.getSystemResourceAsStream("eml/mailWithHeaders.eml")); when(mailboxMessage.createFlags()) .thenReturn(new Flags()); when(mailboxMessage.getUid()) .thenReturn(MESSAGE_UID); when(mailboxMessage.getProperties()) .thenReturn(ImmutableList.of()); // When IndexableMessage indexableMessage = IndexableMessage.builder() .message(mailboxMessage) .users(ImmutableList.of(new MockMailboxSession("username").getUser())) .extractor(new DefaultTextExtractor()) .zoneId(ZoneId.of("Europe/Paris")) .indexAttachments(IndexAttachments.NO) .build(); // Then assertThat(indexableMessage.getHasAttachment()).isFalse(); }
public static Builder fromWithoutAttachments(MailboxMessage original) throws MailboxException { PropertyBuilder propertyBuilder = new PropertyBuilder(original.getProperties()); propertyBuilder.setTextualLineCount(original.getTextualLineCount()); return builder() .bodyStartOctet(Ints.checkedCast(original.getFullContentOctets() - original.getBodyOctets())) .content(copyFullContent(original)) .messageId(original.getMessageId()) .internalDate(original.getInternalDate()) .size(original.getFullContentOctets()) .flags(original.createFlags()) .propertyBuilder(propertyBuilder); }
boolean isUnRead = !message.isSeen(); String[] userFlags = message.createFlags().getUserFlags(); List<Property> properties = message.getProperties();
public ImmutableMailboxMessage from(MailboxId mailboxId, MailboxMessage message) throws MailboxException { try { return new ImmutableMailboxMessage(message.getMessageId(), message.getInternalDate(), IOUtils.toByteArray(message.getBodyContent()), message.getMediaType(), message.getSubType(), message.getBodyOctets(), message.getFullContentOctets(), message.getFullContentOctets() - message.getBodyOctets(), message.getTextualLineCount(), IOUtils.toByteArray(message.getHeaderContent()), ImmutableList.copyOf(message.getProperties()), attachments(message), mailboxId, message.getUid(), message.getModSeq(), message.isAnswered(), message.isDeleted(), message.isDraft(), message.isFlagged(), message.isRecent(), message.isSeen(), message.createFlags().getUserFlags()); } catch (IOException e) { throw new MailboxException("Unable to parse message", e); } }