use of jakarta.mail.search.AndTerm in project spring-integration by spring-projects.
the class ImapMailSearchTermsTests method validateSearchTermsWhenShouldMarkAsReadWithExistingFlags.
@Test
public void validateSearchTermsWhenShouldMarkAsReadWithExistingFlags() throws Exception {
ImapMailReceiver receiver = new ImapMailReceiver();
receiver.setShouldMarkMessagesAsRead(true);
receiver.setBeanFactory(mock(BeanFactory.class));
receiver.afterPropertiesSet();
Field folderField = AbstractMailReceiver.class.getDeclaredField("folder");
folderField.setAccessible(true);
Folder folder = mock(Folder.class);
when(folder.getPermanentFlags()).thenReturn(new Flags(Flags.Flag.USER));
folderField.set(receiver, folder);
Method compileSearchTerms = ReflectionUtils.findMethod(receiver.getClass(), "compileSearchTerms", Flags.class);
compileSearchTerms.setAccessible(true);
Flags flags = new Flags();
flags.add(Flag.ANSWERED);
SearchTerm searchTerms = (SearchTerm) compileSearchTerms.invoke(receiver, flags);
assertThat(searchTerms instanceof AndTerm).isTrue();
AndTerm andTerm = (AndTerm) searchTerms;
SearchTerm[] terms = andTerm.getTerms();
assertThat(terms.length).isEqualTo(2);
NotTerm notTerm = (NotTerm) terms[0];
assertThat(((FlagTerm) notTerm.getTerm()).getFlags().contains(Flag.ANSWERED)).isTrue();
notTerm = (NotTerm) terms[1];
Flags siFlags = new Flags();
siFlags.add(AbstractMailReceiver.DEFAULT_SI_USER_FLAG);
assertThat(((FlagTerm) notTerm.getTerm()).getFlags().contains(siFlags)).isTrue();
}
use of jakarta.mail.search.AndTerm in project spring-integration by spring-projects.
the class ImapMailReceiverTests method testIdleWithServerCustomSearch.
@Test
public void testIdleWithServerCustomSearch() throws Exception {
ImapMailReceiver receiver = new ImapMailReceiver("imap://user:pw@localhost:" + this.imapIdleServer.getImap().getPort() + "/INBOX");
receiver.setSearchTermStrategy((supportedFlags, folder) -> {
try {
FromTerm fromTerm = new FromTerm(new InternetAddress("bar@baz"));
return new AndTerm(fromTerm, new FlagTerm(new Flags(Flag.SEEN), false));
} catch (AddressException e) {
throw new RuntimeException(e);
}
});
testIdleWithServerGuts(receiver, false);
}
Aggregations