List of usage examples for javax.mail Flags Flags
public Flags()
From source file:org.apache.james.jmap.methods.integration.cucumber.SetMailboxesMethodStepdefs.java
private void appendMessage(MailboxPath mailboxPath, int i) throws MailboxException { String content = "Subject: test" + i + "\r\n\r\n" + "testBody" + i; mainStepdefs.jmapServer.serverProbe().appendMessage(userStepdefs.lastConnectedUser, mailboxPath, new ByteArrayInputStream(content.getBytes()), new Date(), false, new Flags()); }
From source file:org.apache.james.mailbox.store.ImmutableMailboxMessageTest.java
@Test public void headersMayBeReadMultipleTimes() throws Exception { String fullContent = "Subject: Test1 \n\nBody1\n.\n"; int bodyStartOctet = 16; SimpleMailboxMessage simpleMailboxMessage = new SimpleMailboxMessage(new DefaultMessageId(), new Date(), fullContent.length(), bodyStartOctet, new SharedByteArrayInputStream(fullContent.getBytes(StandardCharsets.UTF_8)), new Flags(), new PropertyBuilder(), TestId.of(1)); ImmutableMailboxMessage message = messageFactory.from(TestId.of(1), simpleMailboxMessage); String expectedHeaders = "Subject: Test1 \n"; softly.assertThat(IOUtils.toString(message.getHeaderContent(), StandardCharsets.UTF_8)) .isEqualTo(expectedHeaders); softly.assertThat(IOUtils.toString(message.getHeaderContent(), StandardCharsets.UTF_8)) .isEqualTo(expectedHeaders); }
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 a 2 s.com*/ ImmutableList<User> users = ImmutableList.of(); assertThatThrownBy(() -> messageToElasticSearchJson.convertToJson(spamMail, users)) .isInstanceOf(IllegalArgumentException.class); }
From source file:org.apache.james.jmap.model.MessageFactoryTest.java
@Test public void flagsShouldBeSetIntoMessage() throws Exception { Flags flags = new Flags(); flags.add(Flag.ANSWERED);//from w ww.j a va2 s .c o m flags.add(Flag.FLAGGED); flags.add(Flag.DRAFT); MetaDataWithContent testMail = MetaDataWithContent.builder().uid(2).flags(flags).size(0) .internalDate(INTERNAL_DATE).content(new ByteArrayInputStream("".getBytes(Charsets.UTF_8))) .attachments(ImmutableList.of()).mailboxId(MAILBOX_ID).messageId(MessageId.of("test|test|2")) .build(); Message testee = messageFactory.fromMetaDataWithContent(testMail); assertThat(testee) .extracting(Message::isIsUnread, Message::isIsFlagged, Message::isIsAnswered, Message::isIsDraft) .containsExactly(true, true, true, true); }
From source file:org.apache.james.mailbox.elasticsearch.json.IndexableMessageTest.java
@Test public void textShouldContainsToWhenTo() throws Exception { MailboxMessage mailboxMessage = mock(MailboxMessage.class); TestId mailboxId = TestId.of(1);/*from www . j a va 2 s. co m*/ when(mailboxMessage.getMailboxId()).thenReturn(mailboxId); when(mailboxMessage.getFullContent()).thenReturn(new ByteArrayInputStream( "To: First to <user@james.org>\nTo: Second to <user2@james.org>".getBytes())); when(mailboxMessage.createFlags()).thenReturn(new Flags()); IndexableMessage indexableMessage = IndexableMessage.from(mailboxMessage, ImmutableList.of(new MockMailboxSession("username").getUser()), new DefaultTextExtractor(), ZoneId.of("Europe/Paris")); assertThat(indexableMessage.getText()).isEqualTo("First to user@james.org Second to user2@james.org"); }
From source file:org.apache.james.mailbox.store.SimpleMailboxMembership.java
public Flags createFlags() { final Flags flags = new Flags(); if (isAnswered()) { flags.add(Flags.Flag.ANSWERED);/*from w w w .j a va 2 s .co m*/ } if (isDeleted()) { flags.add(Flags.Flag.DELETED); } if (isDraft()) { flags.add(Flags.Flag.DRAFT); } if (isFlagged()) { flags.add(Flags.Flag.FLAGGED); } if (isRecent()) { flags.add(Flags.Flag.RECENT); } if (isSeen()) { flags.add(Flags.Flag.SEEN); } return flags; }
From source file:org.apache.james.mailbox.elasticsearch.json.MessageToElasticSearchJsonTest.java
@Test public void convertToJsonShouldThrowWhenNoUser() throws Exception { MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson( new DefaultTextExtractor(), ZoneId.of("Europe/Paris"), IndexAttachments.YES); MailboxMessage spamMail = new SimpleMailboxMessage(MESSAGE_ID, date, SIZE, BODY_START_OCTET, new SharedByteArrayInputStream("message".getBytes(Charsets.UTF_8)), new Flags(), propertyBuilder, MAILBOX_ID);/* w ww. ja va 2 s . co m*/ ImmutableList<User> users = ImmutableList.of(); assertThatThrownBy(() -> messageToElasticSearchJson.convertToJson(spamMail, users)) .isInstanceOf(IllegalStateException.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);/*from w w w . j a 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.jmap.model.UpdateMessagePatch.java
public Flags applyToState(Flags currentFlags) { Flags newStateFlags = new Flags(); if (isFlagged().orElse(currentFlags.contains(Flags.Flag.FLAGGED))) { newStateFlags.add(Flags.Flag.FLAGGED); }/* ww w . ja v a 2 s . c o m*/ if (isAnswered().orElse(currentFlags.contains(Flags.Flag.ANSWERED))) { newStateFlags.add(Flags.Flag.ANSWERED); } boolean shouldMessageBeMarkSeen = isUnread().map(b -> !b).orElse(currentFlags.contains(Flags.Flag.SEEN)); if (shouldMessageBeMarkSeen) { newStateFlags.add(Flags.Flag.SEEN); } return newStateFlags; }
From source file:org.apache.james.mailbox.store.ImmutableMailboxMessageTest.java
@Test public void bodyMayBeReadMultipleTimes() throws Exception { String fullContent = "Subject: Test1 \n\nBody1\n.\n"; int bodyStartOctet = 16; SimpleMailboxMessage simpleMailboxMessage = new SimpleMailboxMessage(new DefaultMessageId(), new Date(), fullContent.length(), bodyStartOctet, new SharedByteArrayInputStream(fullContent.getBytes(StandardCharsets.UTF_8)), new Flags(), new PropertyBuilder(), TestId.of(1)); ImmutableMailboxMessage message = messageFactory.from(TestId.of(1), simpleMailboxMessage); String expectedBody = "\nBody1\n.\n"; softly.assertThat(IOUtils.toString(message.getBodyContent(), StandardCharsets.UTF_8)) .isEqualTo(expectedBody);/*from www .j av a 2s . c om*/ softly.assertThat(IOUtils.toString(message.getBodyContent(), StandardCharsets.UTF_8)) .isEqualTo(expectedBody); }