/** * Return a {@link PropertyBuilder} which is created in a lazy fashion if it not exist yet. * This is done as it may be expensive to retrieve the properties of the message. * * @return pbuilder */ private PropertyBuilder getPropertyBuilder() { if (pbuilder == null) { pbuilder = new PropertyBuilder(message.getProperties()); } return pbuilder; }
private PropertyBuilder getPropertyBuilder(Row row) { PropertyBuilder property = new PropertyBuilder( row.getList(PROPERTIES, UDTValue.class).stream() .map(x -> new SimpleProperty(x.getString(Properties.NAMESPACE), x.getString(Properties.NAME), x.getString(Properties.VALUE))) .collect(Collectors.toList())); property.setTextualLineCount(row.getLong(TEXTUAL_LINE_COUNT)); return property; }
@Test void retrieveAllMessageIdAttachmentIdsShouldReturnEmtpyWhenStoredWithoutAttachment() throws Exception { //Given SimpleMailboxMessage message1 = createMessage(messageId, CONTENT, BODY_START, new PropertyBuilder(), NO_ATTACHMENT); testee.save(message1).join(); //When Stream<MessageIdAttachmentIds> actual = testee.retrieveAllMessageIdAttachmentIds().join(); //Then assertThat(actual).isEmpty(); }
private SimpleMailboxMessage createMessage(MailboxId mailboxId) { int size = 45; int bodyStartOctet = 25; byte[] content = "Subject: test\r\n\r\nBody\r\n".getBytes(StandardCharsets.UTF_8); return new SimpleMailboxMessage(TestMessageId.of(58), new Date(), size, bodyStartOctet, new SharedByteArrayInputStream(content), new Flags(), new PropertyBuilder(), mailboxId); } }
@Test void saveShouldStoreMessageWithBodyContent() throws Exception { message = createMessage(messageId, CONTENT, BODY_START, new PropertyBuilder(), NO_ATTACHMENT); testee.save(message).join(); MessageWithoutAttachment attachmentRepresentation = toMessage(testee.retrieveMessages(messageIds, MessageMapper.FetchType.Body, Limit.unlimited())); byte[] expected = Bytes.concat( new byte[BODY_START], CONTENT.substring(BODY_START).getBytes(StandardCharsets.UTF_8)); assertThat(IOUtils.toString(attachmentRepresentation.getContent(), StandardCharsets.UTF_8)) .isEqualTo(IOUtils.toString(new ByteArrayInputStream(expected), StandardCharsets.UTF_8)); }
@Test void saveShouldStoreMessageWithHeaderContent() throws Exception { message = createMessage(messageId, CONTENT, BODY_START, new PropertyBuilder(), NO_ATTACHMENT); testee.save(message).join(); MessageWithoutAttachment attachmentRepresentation = toMessage(testee.retrieveMessages(messageIds, MessageMapper.FetchType.Headers, Limit.unlimited())); assertThat(IOUtils.toString(attachmentRepresentation.getContent(), StandardCharsets.UTF_8)) .isEqualTo(CONTENT.substring(0, BODY_START)); }
@Test void saveShouldStoreMessageWithFullContent() throws Exception { message = createMessage(messageId, CONTENT, BODY_START, new PropertyBuilder(), NO_ATTACHMENT); testee.save(message).join(); MessageWithoutAttachment attachmentRepresentation = toMessage(testee.retrieveMessages(messageIds, MessageMapper.FetchType.Full, Limit.unlimited())); assertThat(IOUtils.toString(attachmentRepresentation.getContent(), StandardCharsets.UTF_8)) .isEqualTo(CONTENT); }
@Test void saveShouldSaveNullValueForTextualLineCountAsZero() throws Exception { message = createMessage(messageId, CONTENT, BODY_START, new PropertyBuilder(), NO_ATTACHMENT); testee.save(message).join(); MessageWithoutAttachment attachmentRepresentation = toMessage(testee.retrieveMessages(messageIds, MessageMapper.FetchType.Metadata, Limit.unlimited())); assertThat(attachmentRepresentation.getPropertyBuilder().getTextualLineCount()) .isEqualTo(0L); }
this.internalDate = original.getInternalDate(); PropertyBuilder pBuilder = new PropertyBuilder(original.getProperties()); this.textualLineCount = original.getTextualLineCount(); this.mediaType = original.getMediaType();
@Test void saveShouldSaveTextualLineCount() throws Exception { long textualLineCount = 10L; PropertyBuilder propertyBuilder = new PropertyBuilder(); propertyBuilder.setTextualLineCount(textualLineCount); message = createMessage(messageId, CONTENT, BODY_START, propertyBuilder, NO_ATTACHMENT); testee.save(message).join(); MessageWithoutAttachment attachmentRepresentation = toMessage(testee.retrieveMessages(messageIds, MessageMapper.FetchType.Metadata, Limit.unlimited())); assertThat(attachmentRepresentation.getPropertyBuilder().getTextualLineCount()).isEqualTo(textualLineCount); }
@Test void retrieveAllMessageIdAttachmentIdsShouldReturnOneWhenStored() throws Exception { //Given MessageAttachment attachment = MessageAttachment.builder() .attachment(Attachment.builder() .bytes("content".getBytes(StandardCharsets.UTF_8)) .type("type") .build()) .build(); SimpleMailboxMessage message1 = createMessage(messageId, CONTENT, BODY_START, new PropertyBuilder(), ImmutableList.of(attachment)); testee.save(message1).join(); MessageIdAttachmentIds expected = new MessageIdAttachmentIds(messageId, ImmutableSet.of(attachment.getAttachmentId())); //When Stream<MessageIdAttachmentIds> actual = testee.retrieveAllMessageIdAttachmentIds().join(); //Then assertThat(actual).containsOnly(expected); }
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); }
.build()) .build(); SimpleMailboxMessage message1 = createMessage(messageId1, CONTENT, BODY_START, new PropertyBuilder(), ImmutableList.of(attachmentFor1)); SimpleMailboxMessage message2 = createMessage(messageId2, CONTENT, BODY_START, new PropertyBuilder(), NO_ATTACHMENT); SimpleMailboxMessage message3 = createMessage(messageId3, CONTENT, BODY_START, new PropertyBuilder(), ImmutableList.of(attachmentFor3)); testee.save(message1).join(); testee.save(message2).join();
.build()) .build(); SimpleMailboxMessage message1 = createMessage(messageId1, CONTENT, BODY_START, new PropertyBuilder(), ImmutableList.of(attachment1)); SimpleMailboxMessage message2 = createMessage(messageId2, CONTENT, BODY_START, new PropertyBuilder(), ImmutableList.of(attachment2)); testee.save(message1).join(); testee.save(message2).join();
@Test void retrieveAllMessageIdAttachmentIdsShouldReturnOneWhenStoredWithTwoAttachments() throws Exception { //Given MessageAttachment attachment1 = MessageAttachment.builder() .attachment(Attachment.builder() .bytes("content".getBytes(StandardCharsets.UTF_8)) .type("type") .build()) .build(); MessageAttachment attachment2 = MessageAttachment.builder() .attachment(Attachment.builder() .bytes("other content".getBytes(StandardCharsets.UTF_8)) .type("type") .build()) .build(); SimpleMailboxMessage message1 = createMessage(messageId, CONTENT, BODY_START, new PropertyBuilder(), ImmutableList.of(attachment1, attachment2)); testee.save(message1).join(); MessageIdAttachmentIds expected = new MessageIdAttachmentIds(messageId, ImmutableSet.of(attachment1.getAttachmentId(), attachment2.getAttachmentId())); //When Stream<MessageIdAttachmentIds> actual = testee.retrieveAllMessageIdAttachmentIds().join(); //Then assertThat(actual).containsOnly(expected); }
private SimpleMailboxMessage createMessage(MessageId messageId, Collection<MessageAttachment> attachments) { MessageUid messageUid = MessageUid.of(1); CassandraId mailboxId = CassandraId.timeBased(); String content = "Subject: Any subject \n\nThis is the body\n.\n"; int bodyStart = 22; return SimpleMailboxMessage.builder() .messageId(messageId) .mailboxId(mailboxId) .uid(messageUid) .internalDate(new Date()) .bodyStartOctet(bodyStart) .size(content.length()) .content(new SharedByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8))) .flags(new Flags()) .propertyBuilder(new PropertyBuilder()) .addAttachments(attachments) .build(); }
@Before public void setUp() throws Exception { textExtractor = new TikaTextExtractor(new NoopMetricFactory(), new TikaHttpClientImpl(TikaConfiguration.builder() .host(tika.getIp()) .port(tika.getPort()) .timeoutInMillis(tika.getTimeoutInMillis()) .build())); // 2015/06/07 00:00:00 0200 (Paris time zone) date = new Date(1433628000000L); propertyBuilder = new PropertyBuilder(); propertyBuilder.setMediaType("plain"); propertyBuilder.setSubType("text"); propertyBuilder.setTextualLineCount(18L); propertyBuilder.setContentDescription("An e-mail"); }
final PropertyBuilder propertyBuilder = new PropertyBuilder(); final String mediaType; final String mediaTypeFromHeader = descriptor.getMediaType();