List of usage examples for javax.mail Flags Flags
public Flags(String flag)
From source file:org.apache.james.mailbox.store.mail.model.MessageIdMapperTest.java
@Test public void setFlagsShouldWorkWhenCalledOnDuplicatedMailbox() throws Exception { message1.setUid(mapperProvider.generateMessageUid()); message1.setModSeq(mapperProvider.generateModSeq(benwaInboxMailbox)); sut.save(message1);//from w w w . java 2 s.c om message2.setUid(mapperProvider.generateMessageUid()); message2.setModSeq(mapperProvider.generateModSeq(benwaInboxMailbox)); sut.save(message2); message3.setUid(mapperProvider.generateMessageUid()); message3.setModSeq(mapperProvider.generateModSeq(benwaInboxMailbox)); sut.save(message3); message4.setUid(mapperProvider.generateMessageUid()); message4.setModSeq(mapperProvider.generateModSeq(benwaInboxMailbox)); sut.save(message4); MessageId messageId = message1.getMessageId(); sut.setFlags(messageId, ImmutableList.of(message1.getMailboxId(), message1.getMailboxId()), new Flags(Flag.ANSWERED), FlagsUpdateMode.ADD); List<MailboxMessage> messages = sut.find(ImmutableList.of(messageId), MessageMapper.FetchType.Body); assertThat(messages).hasSize(1); assertThat(messages.get(0).isAnswered()).isTrue(); }
From source file:org.springframework.integration.mail.ImapMailReceiverTests.java
@Test // see INT-1801 public void testImapLifecycleForRaceCondition() throws Exception { for (int i = 0; i < 1000; i++) { final ImapMailReceiver receiver = new ImapMailReceiver("imap://foo"); Store store = mock(Store.class); Folder folder = mock(Folder.class); given(folder.exists()).willReturn(true); given(folder.isOpen()).willReturn(true); given(folder.search((SearchTerm) Mockito.any())).willReturn(new Message[] {}); given(store.getFolder(Mockito.any(URLName.class))).willReturn(folder); given(folder.getPermanentFlags()).willReturn(new Flags(Flags.Flag.USER)); DirectFieldAccessor df = new DirectFieldAccessor(receiver); df.setPropertyValue("store", store); receiver.setBeanFactory(mock(BeanFactory.class)); receiver.afterPropertiesSet();// w ww . j ava2 s. co m new Thread(() -> { try { receiver.receive(); } catch (javax.mail.MessagingException e) { if (e.getCause() instanceof NullPointerException) { failed.getAndIncrement(); } } }).start(); new Thread(() -> { try { receiver.destroy(); } catch (Exception ignore) { // ignore } }).start(); } assertEquals(0, failed.get()); }
From source file:org.apache.james.mailbox.store.mail.model.MessageIdMapperTest.java
@Test public void setFlagsShouldWorkWithConcurrencyWithAdd() throws Exception { Assume.assumeTrue(mapperProvider.getSupportedCapabilities() .contains(MapperProvider.Capabilities.THREAD_SAFE_FLAGS_UPDATE)); message1.setUid(mapperProvider.generateMessageUid()); message1.setModSeq(mapperProvider.generateModSeq(benwaInboxMailbox)); sut.save(message1);/*from ww w. java 2 s . c o m*/ int threadCount = 2; int updateCount = 10; ConcurrentTestRunner.builder() .operation((threadNumber, step) -> sut.setFlags(message1.getMessageId(), ImmutableList.of(message1.getMailboxId()), new Flags("custom-" + threadNumber + "-" + step), FlagsUpdateMode.ADD)) .threadCount(threadCount).operationCount(updateCount).runSuccessfullyWithin(Duration.ofMinutes(1)); List<MailboxMessage> messages = sut.find(ImmutableList.of(message1.getMessageId()), MessageMapper.FetchType.Body); assertThat(messages).hasSize(1); assertThat(messages.get(0).createFlags().getUserFlags()).hasSize(threadCount * updateCount); }
From source file:org.apache.james.mailbox.store.mail.model.MessageIdMapperTest.java
@Test public void setFlagsShouldWorkWithConcurrencyWithRemove() throws Exception { Assume.assumeTrue(mapperProvider.getSupportedCapabilities() .contains(MapperProvider.Capabilities.THREAD_SAFE_FLAGS_UPDATE)); message1.setUid(mapperProvider.generateMessageUid()); message1.setModSeq(mapperProvider.generateModSeq(benwaInboxMailbox)); sut.save(message1);//from w ww . j ava 2 s . co m int threadCount = 4; int updateCount = 20; ConcurrentTestRunner.builder().operation((threadNumber, step) -> { if (step < updateCount / 2) { sut.setFlags(message1.getMessageId(), ImmutableList.of(message1.getMailboxId()), new Flags("custom-" + threadNumber + "-" + step), FlagsUpdateMode.ADD); } else { sut.setFlags(message1.getMessageId(), ImmutableList.of(message1.getMailboxId()), new Flags("custom-" + threadNumber + "-" + (updateCount - step - 1)), FlagsUpdateMode.REMOVE); } }).threadCount(threadCount).operationCount(updateCount).runSuccessfullyWithin(Duration.ofMinutes(1)); List<MailboxMessage> messages = sut.find(ImmutableList.of(message1.getMessageId()), MessageMapper.FetchType.Body); assertThat(messages).hasSize(1); assertThat(messages.get(0).createFlags().getUserFlags()).isEmpty(); }
From source file:org.apache.james.mailbox.store.mail.model.MessageIdMapperTest.java
@Test public void countUnseenMessageShouldBeEmptyWhenMessageIsSeen() throws Exception { message1.setUid(mapperProvider.generateMessageUid()); message1.setModSeq(mapperProvider.generateModSeq(benwaInboxMailbox)); message1.setFlags(new Flags(Flag.SEEN)); sut.save(message1);//w ww .j ava 2 s . co m assertThat(messageMapper.countUnseenMessagesInMailbox(benwaInboxMailbox)).isEqualTo(0); }
From source file:org.springframework.integration.mail.ImapMailReceiverTests.java
private Folder testAttachmentsGuts(final ImapMailReceiver receiver) throws MessagingException, IOException { Store store = mock(Store.class); Folder folder = mock(Folder.class); given(folder.exists()).willReturn(true); given(folder.isOpen()).willReturn(true); Message message = new MimeMessage(null, new ClassPathResource("test.mail").getInputStream()); given(folder.search((SearchTerm) Mockito.any())).willReturn(new Message[] { message }); given(store.getFolder(Mockito.any(URLName.class))).willReturn(folder); given(folder.getPermanentFlags()).willReturn(new Flags(Flags.Flag.USER)); DirectFieldAccessor df = new DirectFieldAccessor(receiver); df.setPropertyValue("store", store); receiver.setBeanFactory(mock(BeanFactory.class)); receiver.afterPropertiesSet();/*from www. j av a 2 s . c o m*/ return folder; }
From source file:org.apache.james.mailbox.store.mail.model.MessageIdMapperTest.java
@Test public void countUnseenMessageShouldReturnWhenDeleteMessage() throws Exception { message1.setUid(mapperProvider.generateMessageUid()); message1.setModSeq(mapperProvider.generateModSeq(benwaInboxMailbox)); message1.setFlags(new Flags(Flag.SEEN)); sut.save(message1);//from w w w .j a va2 s .c o m message2.setUid(mapperProvider.generateMessageUid()); message2.setModSeq(mapperProvider.generateModSeq(benwaInboxMailbox)); sut.save(message2); sut.delete(message1.getMessageId(), ImmutableList.of(benwaInboxMailbox.getMailboxId())); assertThat(messageMapper.countUnseenMessagesInMailbox(benwaInboxMailbox)).isEqualTo(1); }
From source file:org.apache.james.mailbox.store.mail.model.MessageIdMapperTest.java
@Test public void countUnseenMessageShouldTakeCareOfMessagesMarkedAsRead() throws Exception { message1.setUid(mapperProvider.generateMessageUid()); message1.setModSeq(mapperProvider.generateModSeq(benwaInboxMailbox)); sut.save(message1);/*from w w w .j a v a2 s. co m*/ sut.setFlags(message1.getMessageId(), ImmutableList.of(message1.getMailboxId()), new Flags(Flag.SEEN), FlagsUpdateMode.ADD); assertThat(messageMapper.countUnseenMessagesInMailbox(benwaInboxMailbox)).isEqualTo(0); }
From source file:org.pentaho.di.job.entries.getpop.MailConnection.java
/** * Delete messages.//from w w w . j av a 2 s . c o m * * @throws KettleException */ public void deleteMessages(boolean setCounter) throws KettleException { try { this.folder.setFlags(this.messages, new Flags(Flags.Flag.DELETED), true); if (setCounter) { setDeletedMessagesCounter(); } } catch (Exception e) { throw new KettleException(BaseMessages.getString(PKG, "MailConnection.Error.DeletingMessage"), e); } }
From source file:org.apache.james.mailbox.store.mail.model.MessageIdMapperTest.java
@Test public void countUnseenMessageShouldTakeCareOfMessagesMarkedAsUnread() throws Exception { message1.setUid(mapperProvider.generateMessageUid()); message1.setModSeq(mapperProvider.generateModSeq(benwaInboxMailbox)); message1.setFlags(new Flags(Flag.SEEN)); sut.save(message1);/*from w w w . jav a 2 s.c o m*/ sut.setFlags(message1.getMessageId(), ImmutableList.of(message1.getMailboxId()), new Flags(Flag.SEEN), FlagsUpdateMode.REMOVE); assertThat(messageMapper.countUnseenMessagesInMailbox(benwaInboxMailbox)).isEqualTo(1); }