List of usage examples for javax.mail.util SharedByteArrayInputStream SharedByteArrayInputStream
public SharedByteArrayInputStream(byte[] buf)
From source file:org.apache.james.jmap.model.MailboxMessageTest.java
@Test public void previewShouldBeLimitedTo256Length() throws Exception { String headers = "Subject: test subject\n"; String body300 = "0000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999" + "0000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999" + "0000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999"; String expectedPreview = "0000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999" + "0000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999" + "00000000001111111111222222222233333333334444444444555..."; assertThat(body300.length()).isEqualTo(300); assertThat(expectedPreview.length()).isEqualTo(256); String mail = headers + "\n" + body300; MailboxMessage testMail = new SimpleMailboxMessage(INTERNAL_DATE, mail.length(), headers.length(), new SharedByteArrayInputStream(mail.getBytes()), new Flags(Flag.SEEN), new PropertyBuilder(), MAILBOX_ID);/* w ww.j av a 2 s . com*/ testMail.setModSeq(MOD_SEQ); Message testee = messageFactory.fromMailboxMessage(testMail, ImmutableList.of(), x -> MessageId.of("user|box|" + x)); assertThat(testee.getPreview()).isEqualTo(expectedPreview); }
From source file:org.apache.james.jmap.model.MailboxMessageTest.java
@Test public void attachmentsShouldBeEmptyWhenNone() throws Exception { MailboxMessage testMail = new SimpleMailboxMessage(INTERNAL_DATE, 0, 0, new SharedByteArrayInputStream( IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("spamMail.eml"))), new Flags(Flag.SEEN), new PropertyBuilder(), MAILBOX_ID); testMail.setModSeq(MOD_SEQ);/*from w ww . j a v a 2s .c o m*/ Message testee = messageFactory.fromMailboxMessage(testMail, ImmutableList.of(), x -> MessageId.of("user|box|" + x)); assertThat(testee.getAttachments()).isEmpty(); }
From source file:org.apache.james.jmap.model.MailboxMessageTest.java
@Test public void attachmentsShouldBeRetrievedWhenSome() throws Exception { MailboxMessage testMail = new SimpleMailboxMessage(INTERNAL_DATE, 0, 0, new SharedByteArrayInputStream( IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("spamMail.eml"))), new Flags(Flag.SEEN), new PropertyBuilder(), MAILBOX_ID); testMail.setModSeq(MOD_SEQ);/*from ww w.j av a 2 s . c o m*/ String payload = "payload"; BlobId blodId = BlobId.of("id1"); String type = "content"; Attachment expectedAttachment = Attachment.builder().blobId(blodId).size(payload.length()).type(type) .cid("cid").isInline(true).build(); Message testee = messageFactory.fromMailboxMessage(testMail, ImmutableList.of(MessageAttachment.builder() .attachment(org.apache.james.mailbox.store.mail.model.Attachment.builder() .attachmentId(AttachmentId.from(blodId.getRawValue())).bytes(payload.getBytes()) .type(type).build()) .cid(Cid.from("cid")).isInline(true).build()), x -> MessageId.of("user|box|" + x)); assertThat(testee.getAttachments()).hasSize(1); assertThat(testee.getAttachments().get(0)).isEqualToComparingFieldByField(expectedAttachment); }
From source file:org.apache.james.mailbox.cassandra.mail.CassandraMessageDAO.java
private SharedByteArrayInputStream buildContent(Row row, FetchType fetchType) { switch (fetchType) { case Full:/*from ww w.j a v a2 s . c om*/ return new SharedByteArrayInputStream(getFullContent(row)); case Headers: return new SharedByteArrayInputStream(getFieldContent(HEADER_CONTENT, row)); case Body: return new SharedByteArrayInputStream(getBodyContent(row)); case Metadata: return new SharedByteArrayInputStream(new byte[] {}); default: throw new RuntimeException("Unknown FetchType " + fetchType); } }
From source file:org.apache.james.mailbox.cassandra.mail.CassandraMessageDAOTest.java
private SimpleMailboxMessage createMessage(MessageId messageId, String content, int bodyStart, PropertyBuilder propertyBuilder, Collection<MessageAttachment> attachments) { return SimpleMailboxMessage.builder().messageId(messageId).mailboxId(MAILBOX_ID).uid(messageUid) .internalDate(new Date()).bodyStartOctet(bodyStart).size(content.length()) .content(new SharedByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8))) .flags(new Flags()).propertyBuilder(propertyBuilder).addAttachments(attachments).build(); }
From source file:org.apache.james.mailbox.elasticsearch.json.MailboxMessageToElasticSearchJsonTest.java
@Test public void convertToJsonShouldThrowWhenNoUser() throws Exception { MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson( new DefaultTextExtractor(), ZoneId.of("Europe/Paris")); MailboxMessage spamMail = new SimpleMailboxMessage(date, SIZE, BODY_START_OCTET, new SharedByteArrayInputStream("message".getBytes(Charsets.UTF_8)), new Flags(), propertyBuilder, MAILBOX_ID);//from ww w . ja v a2s.c o m ImmutableList<User> users = ImmutableList.of(); assertThatThrownBy(() -> messageToElasticSearchJson.convertToJson(spamMail, users)) .isInstanceOf(IllegalArgumentException.class); }
From source file:org.apache.james.mailbox.elasticsearch.json.MailboxMessageToElasticSearchJsonTest.java
@Test public void spamEmailShouldBeWellConvertedToJson() throws IOException { MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson( new DefaultTextExtractor(), ZoneId.of("Europe/Paris")); MailboxMessage spamMail = new SimpleMailboxMessage(date, SIZE, BODY_START_OCTET, new SharedByteArrayInputStream( IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("eml/spamMail.eml"))), new Flags(), propertyBuilder, MAILBOX_ID); spamMail.setModSeq(MOD_SEQ);/* ww w.ja v a 2s. c o m*/ assertThatJson(messageToElasticSearchJson.convertToJson(spamMail, ImmutableList.of(new MockMailboxSession("username").getUser()))).when(IGNORING_ARRAY_ORDER) .isEqualTo(IOUtils.toString(ClassLoader.getSystemResource("eml/spamMail.json"), CHARSET)); }
From source file:org.apache.james.mailbox.elasticsearch.json.MailboxMessageToElasticSearchJsonTest.java
@Test public void htmlEmailShouldBeWellConvertedToJson() throws IOException { MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson( new DefaultTextExtractor(), ZoneId.of("Europe/Paris")); MailboxMessage htmlMail = new SimpleMailboxMessage(date, SIZE, BODY_START_OCTET, new SharedByteArrayInputStream( IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("eml/htmlMail.eml"))), new FlagsBuilder().add(Flags.Flag.DELETED, Flags.Flag.SEEN).add("social", "pocket-money").build(), propertyBuilder, MAILBOX_ID); htmlMail.setModSeq(MOD_SEQ);//from w ww .j ava 2s . c o m htmlMail.setUid(UID); assertThatJson(messageToElasticSearchJson.convertToJson(htmlMail, ImmutableList.of(new MockMailboxSession("username").getUser()))).when(IGNORING_ARRAY_ORDER) .isEqualTo(IOUtils.toString(ClassLoader.getSystemResource("eml/htmlMail.json"))); }
From source file:org.apache.james.mailbox.elasticsearch.json.MailboxMessageToElasticSearchJsonTest.java
@Test public void pgpSignedEmailShouldBeWellConvertedToJson() throws IOException { MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson( new DefaultTextExtractor(), ZoneId.of("Europe/Paris")); MailboxMessage pgpSignedMail = new SimpleMailboxMessage(date, SIZE, BODY_START_OCTET, new SharedByteArrayInputStream( IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("eml/pgpSignedMail.eml"))), new FlagsBuilder().add(Flags.Flag.DELETED, Flags.Flag.SEEN).add("debian", "security").build(), propertyBuilder, MAILBOX_ID); pgpSignedMail.setModSeq(MOD_SEQ);/*from w ww .j a va 2s.com*/ pgpSignedMail.setUid(UID); assertThatJson(messageToElasticSearchJson.convertToJson(pgpSignedMail, ImmutableList.of(new MockMailboxSession("username").getUser()))).when(IGNORING_ARRAY_ORDER) .isEqualTo(IOUtils.toString(ClassLoader.getSystemResource("eml/pgpSignedMail.json"))); }
From source file:org.apache.james.mailbox.elasticsearch.json.MailboxMessageToElasticSearchJsonTest.java
@Test public void simpleEmailShouldBeWellConvertedToJson() throws IOException { MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson( new DefaultTextExtractor(), ZoneId.of("Europe/Paris")); MailboxMessage mail = new SimpleMailboxMessage(date, SIZE, BODY_START_OCTET, new SharedByteArrayInputStream( IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("eml/mail.eml"))), new FlagsBuilder().add(Flags.Flag.DELETED, Flags.Flag.SEEN).add("debian", "security").build(), propertyBuilder, MAILBOX_ID); mail.setModSeq(MOD_SEQ);//from ww w . java 2 s .co m mail.setUid(UID); assertThatJson(messageToElasticSearchJson.convertToJson(mail, ImmutableList.of(new MockMailboxSession("user1").getUser(), new MockMailboxSession("user2").getUser()))).when(IGNORING_ARRAY_ORDER) .when(IGNORING_VALUES) .isEqualTo(IOUtils.toString(ClassLoader.getSystemResource("eml/mail.json"))); }