List of usage examples for javax.mail.util SharedByteArrayInputStream SharedByteArrayInputStream
public SharedByteArrayInputStream(byte[] buf)
From source file:org.apache.james.mailbox.elasticsearch.json.MessageToElasticSearchJsonTest.java
@Test public void emailWithNoInternalDateShouldUseNowDate() throws IOException { MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson( new DefaultTextExtractor(), ZoneId.of("Europe/Paris"), IndexAttachments.YES); MailboxMessage mailWithNoInternalDate = new SimpleMailboxMessage(MESSAGE_ID, null, SIZE, BODY_START_OCTET, new SharedByteArrayInputStream( IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("eml/recursiveMail.eml"))), new FlagsBuilder().add(Flags.Flag.DELETED, Flags.Flag.SEEN).add("debian", "security").build(), propertyBuilder, MAILBOX_ID); mailWithNoInternalDate.setModSeq(MOD_SEQ); mailWithNoInternalDate.setUid(UID); assertThatJson(messageToElasticSearchJson.convertToJson(mailWithNoInternalDate, ImmutableList.of(new MockMailboxSession("username").getUser()))).when(IGNORING_ARRAY_ORDER) .when(IGNORING_VALUES) .isEqualTo(IOUtils.toString(ClassLoader.getSystemResource("eml/recursiveMail.json"))); }
From source file:org.apache.james.mailbox.elasticsearch.json.MessageToElasticSearchJsonTest.java
@Test public void emailWithAttachmentsShouldConvertAttachmentsWhenIndexAttachmentsIsTrue() throws IOException { // Given/*w ww . j a va2 s. co m*/ MailboxMessage mailWithNoInternalDate = new SimpleMailboxMessage(MESSAGE_ID, null, SIZE, BODY_START_OCTET, new SharedByteArrayInputStream( IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("eml/recursiveMail.eml"))), new FlagsBuilder().add(Flags.Flag.DELETED, Flags.Flag.SEEN).add("debian", "security").build(), propertyBuilder, MAILBOX_ID); mailWithNoInternalDate.setModSeq(MOD_SEQ); mailWithNoInternalDate.setUid(UID); // When MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson( new DefaultTextExtractor(), ZoneId.of("Europe/Paris"), IndexAttachments.YES); String convertToJson = messageToElasticSearchJson.convertToJson(mailWithNoInternalDate, ImmutableList.of(new MockMailboxSession("username").getUser())); // Then assertThatJson(convertToJson).when(IGNORING_ARRAY_ORDER).when(IGNORING_VALUES) .isEqualTo(IOUtils.toString(ClassLoader.getSystemResource("eml/recursiveMail.json"))); }
From source file:org.apache.james.mailbox.elasticsearch.json.MessageToElasticSearchJsonTest.java
@Test public void emailWithAttachmentsShouldNotConvertAttachmentsWhenIndexAttachmentsIsFalse() throws IOException { // Given//from ww w . ja v a2 s . c o m MailboxMessage mailWithNoInternalDate = new SimpleMailboxMessage(MESSAGE_ID, null, SIZE, BODY_START_OCTET, new SharedByteArrayInputStream( IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("eml/recursiveMail.eml"))), new FlagsBuilder().add(Flags.Flag.DELETED, Flags.Flag.SEEN).add("debian", "security").build(), propertyBuilder, MAILBOX_ID); mailWithNoInternalDate.setModSeq(MOD_SEQ); mailWithNoInternalDate.setUid(UID); // When MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson( new DefaultTextExtractor(), ZoneId.of("Europe/Paris"), IndexAttachments.NO); String convertToJson = messageToElasticSearchJson.convertToJson(mailWithNoInternalDate, ImmutableList.of(new MockMailboxSession("username").getUser())); // Then assertThatJson(convertToJson).when(IGNORING_ARRAY_ORDER).when(IGNORING_VALUES).isEqualTo( IOUtils.toString(ClassLoader.getSystemResource("eml/recursiveMailWithoutAttachments.json"))); }
From source file:org.apache.james.mailbox.elasticsearch.json.MessageToElasticSearchJsonTest.java
@Test(expected = NullPointerException.class) public void emailWithNoMailboxIdShouldThrow() throws IOException { MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson( new DefaultTextExtractor(), ZoneId.of("Europe/Paris"), IndexAttachments.YES); MailboxMessage mailWithNoMailboxId;//from w ww.ja v a2 s .c om try { mailWithNoMailboxId = new SimpleMailboxMessage(MESSAGE_ID, date, SIZE, BODY_START_OCTET, new SharedByteArrayInputStream( IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("eml/recursiveMail.eml"))), new FlagsBuilder().add(Flags.Flag.DELETED, Flags.Flag.SEEN).add("debian", "security").build(), propertyBuilder, null); mailWithNoMailboxId.setModSeq(MOD_SEQ); mailWithNoMailboxId.setUid(UID); } catch (Exception exception) { throw Throwables.propagate(exception); } messageToElasticSearchJson.convertToJson(mailWithNoMailboxId, ImmutableList.of(new MockMailboxSession("username").getUser())); }
From source file:org.apache.james.mailbox.elasticsearch.json.MessageToElasticSearchJsonTest.java
@Test public void spamEmailShouldBeWellConvertedToJsonWithApacheTika() throws IOException { MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson( new TikaTextExtractor(), ZoneId.of("Europe/Paris"), IndexAttachments.YES); MailboxMessage spamMail = new SimpleMailboxMessage(MESSAGE_ID, date, SIZE, BODY_START_OCTET, new SharedByteArrayInputStream( IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("eml/nonTextual.eml"))), new Flags(), propertyBuilder, MAILBOX_ID); spamMail.setUid(UID);/*from ww w . ja va 2 s. co m*/ spamMail.setModSeq(MOD_SEQ); assertThatJson(messageToElasticSearchJson.convertToJson(spamMail, ImmutableList.of(new MockMailboxSession("username").getUser()))).when(IGNORING_ARRAY_ORDER) .isEqualTo(IOUtils.toString(ClassLoader.getSystemResource("eml/nonTextual.json"), CHARSET)); }
From source file:org.apache.james.mailbox.elasticsearch.json.MessageToElasticSearchJsonTest.java
@Test public void convertToJsonWithoutAttachmentShouldConvertEmailBoby() throws IOException { // Given//from ww w . j av a2 s.co m MailboxMessage message = new SimpleMailboxMessage(MESSAGE_ID, null, SIZE, BODY_START_OCTET, new SharedByteArrayInputStream(IOUtils.toByteArray( ClassLoader.getSystemResourceAsStream("eml/emailWithNonIndexableAttachment.eml"))), new FlagsBuilder().add(Flags.Flag.DELETED, Flags.Flag.SEEN).add("debian", "security").build(), propertyBuilder, MAILBOX_ID); message.setModSeq(MOD_SEQ); message.setUid(UID); // When MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson( new DefaultTextExtractor(), ZoneId.of("Europe/Paris"), IndexAttachments.NO); String convertToJsonWithoutAttachment = messageToElasticSearchJson.convertToJsonWithoutAttachment(message, ImmutableList.of(new MockMailboxSession("username").getUser())); // Then assertThatJson(convertToJsonWithoutAttachment).when(IGNORING_ARRAY_ORDER).when(IGNORING_VALUES) .isEqualTo(IOUtils.toString(ClassLoader .getSystemResource("eml/emailWithNonIndexableAttachmentWithoutAttachment.json"))); }
From source file:org.apache.james.mailbox.jcr.mail.model.JCRMailboxMessage.java
/** * Create a copy of the given message//www . j a v a2s . com */ public JCRMailboxMessage(JCRId mailboxUUID, long uid, long modSeq, JCRMailboxMessage message, Logger logger) throws MailboxException { this.mailboxUUID = mailboxUUID; this.internalDate = message.getInternalDate(); this.size = message.getFullContentOctets(); setFlags(message.createFlags()); this.uid = uid; this.modSeq = modSeq; this.logger = logger; try { this.content = new SharedByteArrayInputStream(IOUtils.toByteArray(message.getFullContent())); } catch (IOException e) { throw new MailboxException("Unable to parse message", e); } this.bodyStartOctet = (int) (message.getFullContentOctets() - message.getBodyOctets()); PropertyBuilder pBuilder = new PropertyBuilder(message.getProperties()); this.textualLineCount = message.getTextualLineCount(); this.mediaType = message.getMediaType(); this.subType = message.getSubType(); final List<Property> properties = pBuilder.toProperties(); this.properties = new ArrayList<JCRProperty>(properties.size()); for (Property property : properties) { this.properties.add(new JCRProperty(property, logger)); } }
From source file:org.apache.james.mailbox.jcr.mail.model.JCRMessage.java
/** * Create a copy of the given message/*from w ww. ja va 2 s .c o m*/ * * @param message * @throws IOException */ public JCRMessage(String mailboxUUID, long uid, long modSeq, JCRMessage message, Logger logger) throws MailboxException { this.mailboxUUID = mailboxUUID; this.internalDate = message.getInternalDate(); this.size = message.getFullContentOctets(); setFlags(message.createFlags()); this.uid = uid; this.modSeq = modSeq; this.logger = logger; try { this.content = new SharedByteArrayInputStream(IOUtils.toByteArray(message.getFullContent())); } catch (IOException e) { throw new MailboxException("Unable to parse message", e); } this.bodyStartOctet = (int) (message.getFullContentOctets() - message.getBodyOctets()); PropertyBuilder pBuilder = new PropertyBuilder(message.getProperties()); this.textualLineCount = message.getTextualLineCount(); this.mediaType = message.getMediaType(); this.subType = message.getSubType(); final List<Property> properties = pBuilder.toProperties(); this.properties = new ArrayList<JCRProperty>(properties.size()); for (final Property property : properties) { this.properties.add(new JCRProperty(property, logger)); } }
From source file:org.apache.james.mailbox.jpa.mail.model.openjpa.JPAStreamingMailboxMessage.java
/** * Create a copy of the given message/*from w ww .j a v a 2 s .co m*/ */ public JPAStreamingMailboxMessage(JPAMailbox mailbox, long uid, long modSeq, MailboxMessage message) throws MailboxException { super(mailbox, uid, modSeq, message); try { this.content = new SharedByteArrayInputStream(IOUtils.toByteArray(message.getFullContent())); this.header = getHeaderContent(); this.body = getBodyContent(); } catch (IOException e) { throw new MailboxException("Unable to parse message", e); } }
From source file:org.apache.james.mailbox.jpa.mail.model.openjpa.JPAStreamingMessage.java
/** * Create a copy of the given message//from w w w . j a v a2 s .com * * @param message * @throws IOException */ public JPAStreamingMessage(JPAMailbox mailbox, long uid, long modSeq, Message<?> message) throws MailboxException { super(mailbox, uid, modSeq, message); try { this.content = new SharedByteArrayInputStream(IOUtils.toByteArray(message.getFullContent())); this.header = getHeaderContent(); this.body = getBodyContent(); } catch (IOException e) { throw new MailboxException("Unable to parse message", e); } }