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 setFlagsShouldNotUpdateModSeqWhenNoop() throws Exception { message1.setUid(mapperProvider.generateMessageUid()); long modSeq = mapperProvider.generateModSeq(benwaInboxMailbox); message1.setModSeq(modSeq);/* ww w .j av a2s .c o m*/ message1.setFlags(new Flags(Flag.SEEN)); sut.save(message1); sut.setFlags(message1.getMessageId(), ImmutableList.of(message1.getMailboxId()), new Flags(Flag.SEEN), FlagsUpdateMode.ADD); List<MailboxMessage> messages = sut.find(ImmutableList.of(message1.getMessageId()), MessageMapper.FetchType.Body); assertThat(messages).hasSize(1); assertThat(messages.get(0).getModSeq()).isEqualTo(modSeq); }
From source file:org.springframework.integration.mail.ImapMailReceiverTests.java
@Test public void testIdleReconnects() throws Exception { ImapMailReceiver receiver = spy(new ImapMailReceiver("imap:foo")); receiver.setBeanFactory(mock(BeanFactory.class)); receiver.afterPropertiesSet();/*from w w w . j av a 2s.c o m*/ IMAPFolder folder = mock(IMAPFolder.class); given(folder.getPermanentFlags()).willReturn(new Flags(Flags.Flag.USER)); given(folder.isOpen()).willReturn(false).willReturn(true); given(folder.exists()).willReturn(true); given(folder.hasNewMessages()).willReturn(true); Field storeField = AbstractMailReceiver.class.getDeclaredField("store"); storeField.setAccessible(true); Store store = mock(Store.class); given(store.isConnected()).willReturn(false); given(store.getFolder(Mockito.any(URLName.class))).willReturn(folder); storeField.set(receiver, store); ImapIdleChannelAdapter adapter = new ImapIdleChannelAdapter(receiver); Log logger = spy(TestUtils.getPropertyValue(adapter, "logger", Log.class)); new DirectFieldAccessor(adapter).setPropertyValue("logger", logger); willDoNothing().given(logger).warn(anyString(), any(Throwable.class)); willAnswer(i -> { i.callRealMethod(); throw new FolderClosedException(folder, "test"); }).given(receiver).waitForNewMessages(); ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler(); taskScheduler.initialize(); adapter.setTaskScheduler(taskScheduler); adapter.setReconnectDelay(50); adapter.afterPropertiesSet(); final CountDownLatch latch = new CountDownLatch(3); adapter.setApplicationEventPublisher(e -> { latch.countDown(); }); adapter.start(); assertTrue(latch.await(60, TimeUnit.SECONDS)); verify(store, atLeast(3)).connect(); taskScheduler.shutdown(); }
From source file:org.apache.james.mailbox.store.mail.model.MessageIdMapperTest.java
@Test public void addingFlagToAMessageThatAlreadyHasThisFlagShouldResultInNoChange() throws Exception { message1.setUid(mapperProvider.generateMessageUid()); long modSeq = mapperProvider.generateModSeq(benwaInboxMailbox); message1.setModSeq(modSeq);/*from ww w.ja v a 2 s .co m*/ Flags flags = new Flags(Flag.SEEN); message1.setFlags(flags); sut.save(message1); sut.setFlags(message1.getMessageId(), ImmutableList.of(message1.getMailboxId()), flags, FlagsUpdateMode.ADD); List<MailboxMessage> messages = sut.find(ImmutableList.of(message1.getMessageId()), MessageMapper.FetchType.Body); assertThat(messages).hasSize(1); assertThat(messages.get(0).createFlags()).isEqualTo(flags); }
From source file:org.apache.james.mailbox.store.mail.model.MessageIdMapperTest.java
@Test public void setFlagsShouldReturnUpdatedFlagsWhenNoop() throws Exception { message1.setUid(mapperProvider.generateMessageUid()); long modSeq = mapperProvider.generateModSeq(benwaInboxMailbox); message1.setModSeq(modSeq);/*from ww w . ja va 2 s . c o m*/ Flags flags = new Flags(Flag.SEEN); message1.setFlags(flags); sut.save(message1); Map<MailboxId, UpdatedFlags> mailboxIdUpdatedFlagsMap = sut.setFlags(message1.getMessageId(), ImmutableList.of(message1.getMailboxId()), flags, FlagsUpdateMode.ADD); assertThat(mailboxIdUpdatedFlagsMap).containsOnly(MapEntry.entry(message1.getMailboxId(), UpdatedFlags .builder().modSeq(modSeq).uid(message1.getUid()).newFlags(flags).oldFlags(flags).build())); }
From source file:org.apache.james.mailbox.store.mail.model.MessageIdMapperTest.java
@Test public void countUnseenMessageShouldNotTakeCareOfOtherFlagsUpdates() throws Exception { message1.setUid(mapperProvider.generateMessageUid()); message1.setModSeq(mapperProvider.generateModSeq(benwaInboxMailbox)); message1.setFlags(new Flags(Flag.RECENT)); sut.save(message1);/* www. j ava 2 s.c o m*/ sut.setFlags(message1.getMessageId(), ImmutableList.of(message1.getMailboxId()), new Flags(Flag.ANSWERED), FlagsUpdateMode.REMOVE); assertThat(messageMapper.countUnseenMessagesInMailbox(benwaInboxMailbox)).isEqualTo(1); }
From source file:org.apache.james.mailbox.store.mail.model.MessageIdMapperTest.java
@Test public void deletesShouldUpdateUnreadCount() 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 ava 2 s . c om message2.setUid(mapperProvider.generateMessageUid()); message2.setModSeq(mapperProvider.generateModSeq(benwaInboxMailbox)); sut.save(message2); sut.delete(ImmutableMultimap.<MessageId, MailboxId>builder() .put(message1.getMessageId(), benwaInboxMailbox.getMailboxId()) .put(message2.getMessageId(), benwaInboxMailbox.getMailboxId()).build()); assertThat(messageMapper.countUnseenMessagesInMailbox(benwaInboxMailbox)).isEqualTo(0); }
From source file:org.obm.opush.MailBackendGetChangedTest.java
@Test public void testGetChangedWithReadFlag() throws Exception { SyncKey initialSyncKey = SyncKey.INITIAL_SYNC_KEY; SyncKey firstAllocatedSyncKey = new SyncKey("e05fe721-adf6-416d-a2d9-657347096aa1"); SyncKey secondAllocatedSyncKey = new SyncKey("64dd1fc0-3519-480a-850f-b84c0153855d"); SyncKey newAllocatedSyncKey = new SyncKey("720fc208-1e70-43a1-bfad-112d64548c7b"); int allocatedStateId = 3; int allocatedStateId2 = 4; int newAllocatedStateId = 5; userAccessUtils.mockUsersAccess(user); syncKeyTestUtils.mockNextGeneratedSyncKey(firstAllocatedSyncKey, secondAllocatedSyncKey, newAllocatedSyncKey);// w w w. j av a2 s. co m Date initialDate = DateUtils.getEpochPlusOneSecondCalendar().getTime(); ItemSyncState firstAllocatedState = ItemSyncState.builder().syncDate(initialDate) .syncKey(firstAllocatedSyncKey).id(allocatedStateId).build(); ItemSyncState currentAllocatedState = ItemSyncState.builder().syncDate(date("2012-10-10T16:22:53")) .syncKey(secondAllocatedSyncKey).id(allocatedStateId2).build(); ItemSyncState newAllocatedState = ItemSyncState.builder().syncDate(date("2012-10-10T18:17:26")) .syncKey(newAllocatedSyncKey).id(newAllocatedStateId).build(); expect(dateService.getEpochPlusOneSecondDate()).andReturn(initialDate).once(); expect(dateService.getCurrentDate()).andReturn(currentAllocatedState.getSyncDate()).times(2); expect(dateService.getCurrentDate()).andReturn(newAllocatedState.getSyncDate()).times(2); expectCollectionDaoPerformInitialSync(firstAllocatedState, inboxCollectionId); expectCollectionDaoPerformSync(firstAllocatedSyncKey, firstAllocatedState, currentAllocatedState, inboxCollectionId); expectCollectionDaoPerformSync(secondAllocatedSyncKey, currentAllocatedState, newAllocatedState, inboxCollectionId); expect(itemTrackingDao.isServerIdSynced(firstAllocatedState, inboxCollectionId.serverId(1))) .andReturn(false); expect(itemTrackingDao.isServerIdSynced(currentAllocatedState, inboxCollectionId.serverId(1))) .andReturn(true); itemTrackingDao.markAsSynced(anyObject(ItemSyncState.class), anyObject(Set.class)); expectLastCall().anyTimes(); mocksControl.replay(); opushServer.start(); OPClient opClient = testUtils.buildWBXMLOpushClient(user, opushServer.getHttpPort(), httpClient); GreenMailUtil.sendTextEmail(mailbox, mailbox, "subject2", "body", greenMail.getSmtp().getServerSetup()); greenMail.waitForIncomingEmail(1); opClient.syncEmail(decoder, initialSyncKey, inboxCollectionId, THREE_DAYS_BACK, 25); opClient.syncEmail(decoder, firstAllocatedSyncKey, inboxCollectionId, THREE_DAYS_BACK, 25); MailFolder folder = imapHostManager.getFolder(greenMailUser, OpushEmailConfiguration.IMAP_INBOX_NAME); folder.setFlags(new Flags(Flag.SEEN), true, 1, null, true); SyncResponse syncResponse = opClient.syncEmail(decoder, secondAllocatedSyncKey, inboxCollectionId, THREE_DAYS_BACK, 25); mocksControl.verify(); SyncCollectionResponse inboxResponse = syncTestUtils.getCollectionWithId(syncResponse, inboxCollectionId); syncTestUtils.assertEqualsWithoutApplicationData(inboxResponse.getItemChanges(), ImmutableList .of(ItemChange.builder().serverId(inboxCollectionId.serverId(1)).isNew(false).build())); assertEmailCountInMailbox(OpushEmailConfiguration.IMAP_INBOX_NAME, 1); assertThat(pendingQueries.waitingClose(10, TimeUnit.SECONDS)).isTrue(); assertThat(imapConnectionCounter.loginCounter.get()).isEqualTo(2); assertThat(imapConnectionCounter.closeCounter.get()).isEqualTo(2); assertThat(imapConnectionCounter.selectCounter.get()).isEqualTo(2); assertThat(imapConnectionCounter.listMailboxesCounter.get()).isEqualTo(0); }
From source file:org.obm.opush.MailBackendGetChangedTest.java
@Test public void testGetChangedWithDeletedFlag() throws Exception { SyncKey initialSyncKey = SyncKey.INITIAL_SYNC_KEY; SyncKey firstAllocatedSyncKey = new SyncKey("e05fe721-adf6-416d-a2d9-657347096aa1"); SyncKey secondAllocatedSyncKey = new SyncKey("64dd1fc0-3519-480a-850f-b84c0153855d"); SyncKey newAllocatedSyncKey = new SyncKey("720fc208-1e70-43a1-bfad-112d64548c7b"); int allocatedStateId = 3; int allocatedStateId2 = 4; int newAllocatedStateId = 5; userAccessUtils.mockUsersAccess(user); syncKeyTestUtils.mockNextGeneratedSyncKey(firstAllocatedSyncKey, secondAllocatedSyncKey, newAllocatedSyncKey);//ww w . ja v a2 s. c o m Date initialDate = DateUtils.getEpochPlusOneSecondCalendar().getTime(); ItemSyncState firstAllocatedState = ItemSyncState.builder().syncDate(initialDate) .syncKey(firstAllocatedSyncKey).id(allocatedStateId).build(); ItemSyncState currentAllocatedState = ItemSyncState.builder().syncDate(date("2012-10-10T16:22:53")) .syncKey(secondAllocatedSyncKey).id(allocatedStateId2).build(); ItemSyncState newAllocatedState = ItemSyncState.builder().syncDate(date("2012-10-10T18:17:26")) .syncKey(newAllocatedSyncKey).id(newAllocatedStateId).build(); expect(dateService.getEpochPlusOneSecondDate()).andReturn(initialDate).once(); expect(dateService.getCurrentDate()).andReturn(currentAllocatedState.getSyncDate()).times(2); expect(dateService.getCurrentDate()).andReturn(newAllocatedState.getSyncDate()).times(2); expectCollectionDaoPerformInitialSync(firstAllocatedState, inboxCollectionId); expectCollectionDaoPerformSync(firstAllocatedSyncKey, firstAllocatedState, currentAllocatedState, inboxCollectionId); expectCollectionDaoPerformSync(secondAllocatedSyncKey, currentAllocatedState, newAllocatedState, inboxCollectionId); ServerId serverId = inboxCollectionId.serverId(1); expect(itemTrackingDao.isServerIdSynced(firstAllocatedState, serverId)).andReturn(false); itemTrackingDao.markAsSynced(anyObject(ItemSyncState.class), anyObject(Set.class)); expectLastCall().anyTimes(); itemTrackingDao.markAsDeleted(newAllocatedState, ImmutableSet.of(serverId)); expectLastCall().once(); mocksControl.replay(); opushServer.start(); OPClient opClient = testUtils.buildWBXMLOpushClient(user, opushServer.getHttpPort(), httpClient); GreenMailUtil.sendTextEmail(mailbox, mailbox, "subject2", "body", greenMail.getSmtp().getServerSetup()); greenMail.waitForIncomingEmail(1); opClient.syncEmail(decoder, initialSyncKey, inboxCollectionId, THREE_DAYS_BACK, 100); opClient.syncEmail(decoder, firstAllocatedSyncKey, inboxCollectionId, THREE_DAYS_BACK, 100); MailFolder folder = imapHostManager.getFolder(greenMailUser, OpushEmailConfiguration.IMAP_INBOX_NAME); folder.setFlags(new Flags(Flag.DELETED), true, 1, null, true); SyncResponse syncResponse = opClient.syncEmail(decoder, secondAllocatedSyncKey, inboxCollectionId, THREE_DAYS_BACK, 100); mocksControl.verify(); SyncCollectionResponse inboxResponse = syncTestUtils.getCollectionWithId(syncResponse, inboxCollectionId); assertThat(inboxResponse.getItemDeletions()) .containsOnly(ItemDeletion.builder().serverId(serverId).build()); assertEmailCountInMailbox(OpushEmailConfiguration.IMAP_INBOX_NAME, 1); assertThat(pendingQueries.waitingClose(10, TimeUnit.SECONDS)).isTrue(); assertThat(imapConnectionCounter.loginCounter.get()).isEqualTo(2); assertThat(imapConnectionCounter.closeCounter.get()).isEqualTo(2); assertThat(imapConnectionCounter.selectCounter.get()).isEqualTo(2); assertThat(imapConnectionCounter.listMailboxesCounter.get()).isEqualTo(0); }
From source file:net.wastl.webmail.server.WebMailSession.java
/** Change the Flags of the messages the user selected. //from w w w.j a v a2 s. com */ public void setFlags(String folderhash, HTTPRequestHeader head) throws MessagingException { if (head.isContentSet("copymovemsgs") && head.getContent("COPYMOVE").equals("COPY")) { copyMoveMessage(folderhash, head.getContent("TO"), head, false); } else if (head.isContentSet("copymovemsgs") && head.getContent("COPYMOVE").equals("MOVE")) { copyMoveMessage(folderhash, head.getContent("TO"), head, true); } else if (head.isContentSet("flagmsgs")) { log.debug("setting message flags"); Folder folder = getFolder(folderhash); //log.debug("Processing Request Header..."); /* Get selected messages */ int msgs[] = getSelectedMessages(head, folder.getMessageCount()); //log.debug("get flags..."); /* Get selected flags */ Flags fl = new Flags(Flags.Flag.USER); if (head.getContent("MESSAGE FLAG").equals("DELETED")) { fl = new Flags(Flags.Flag.DELETED); if (need_expunge_folders == null) { need_expunge_folders = new Vector<String>(); } need_expunge_folders.addElement(folderhash); } else if (head.getContent("MESSAGE FLAG").equals("SEEN")) { fl = new Flags(Flags.Flag.SEEN); } else if (head.getContent("MESSAGE FLAG").equals("RECENT")) { fl = new Flags(Flags.Flag.RECENT); } else if (head.getContent("MESSAGE FLAG").equals("ANSWERED")) { fl = new Flags(Flags.Flag.ANSWERED); } else if (head.getContent("MESSAGE FLAG").equals("DRAFT")) { fl = new Flags(Flags.Flag.DRAFT); } boolean value = true; if (head.getContent("MARK").equals("UNMARK")) { value = false; } //log.debug("Done!"); //log.debug("Setting flags..."); if (user.wantsSetFlags()) { if (folder.isOpen() && folder.getMode() == Folder.READ_ONLY) { folder.close(false); folder.open(Folder.READ_WRITE); } else if (!folder.isOpen()) { folder.open(Folder.READ_WRITE); } folder.setFlags(msgs, fl, value); if (user.getBoolVar("autoexpunge")) { folder.close(true); if (need_expunge_folders != null) { need_expunge_folders.removeElement(folderhash); } } else { folder.close(false); } } folder.open(Folder.READ_WRITE); refreshFolderInformation(folderhash); } }
From source file:net.wastl.webmail.server.WebMailSession.java
/** * Copy or move the selected messages from folder fromfolder to folder tofolder. *///from w ww. j a v a2s. co m public void copyMoveMessage(String fromfolder, String tofolder, HTTPRequestHeader head, boolean move) throws MessagingException { Folder from = getFolder(fromfolder); Folder to = getFolder(tofolder); if (user.wantsSetFlags()) { if (from.isOpen() && from.getMode() == Folder.READ_ONLY) { from.close(false); from.open(Folder.READ_WRITE); } else if (!from.isOpen()) { from.open(Folder.READ_WRITE); } if (to.isOpen() && to.getMode() == Folder.READ_ONLY) { to.close(false); to.open(Folder.READ_WRITE); } else if (!to.isOpen()) { to.open(Folder.READ_WRITE); } } else { if (!from.isOpen()) { from.open(Folder.READ_ONLY); } if (to.isOpen() && to.getMode() == Folder.READ_ONLY) { to.close(false); to.open(Folder.READ_WRITE); } else if (!to.isOpen()) { to.open(Folder.READ_WRITE); } } int m[] = getSelectedMessages(head, from.getMessageCount()); Message msgs[] = from.getMessages(m); from.copyMessages(msgs, to); if (move && user.wantsSetFlags()) { from.setFlags(m, new Flags(Flags.Flag.DELETED), true); if (user.getBoolVar("autoexpunge")) { from.close(true); to.close(true); } else { if (need_expunge_folders == null) { need_expunge_folders = new Vector<String>(); } need_expunge_folders.addElement(fromfolder); from.close(false); to.close(false); } } else { from.close(false); if (user.getBoolVar("autoexpunge")) { to.close(true); } else { to.close(false); } } from.open(Folder.READ_WRITE); to.open(Folder.READ_WRITE); refreshFolderInformation(fromfolder); refreshFolderInformation(tofolder); }