use of javax.mail.search.AndTerm in project jodd by oblac.
the class EmailFilterTest method testAnd2.
@Test
public void testAnd2() {
EmailFilter emailFilter = filter().from("from").to("to");
SearchTerm expected = new AndTerm(new FromStringTerm("from"), new RecipientStringTerm(Message.RecipientType.TO, "to"));
assertEquals(expected, emailFilter.searchTerm);
}
use of javax.mail.search.AndTerm in project jodd by oblac.
the class EmailFilterTest method testAndOrNotAlt.
@Test
public void testAndOrNotAlt() {
EmailFilter emailFilter = filter().or(filter().and(filter().from("from"), filter().to("to")), filter().not(filter().subject("subject")), filter().from("from2"));
SearchTerm expected = new OrTerm(new SearchTerm[] { new AndTerm(new FromStringTerm("from"), new RecipientStringTerm(Message.RecipientType.TO, "to")), new NotTerm(new SubjectTerm("subject")), new FromStringTerm("from2") });
assertEquals(expected, emailFilter.searchTerm);
}
use of javax.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);
assertTrue(searchTerms instanceof AndTerm);
AndTerm andTerm = (AndTerm) searchTerms;
SearchTerm[] terms = andTerm.getTerms();
assertEquals(2, terms.length);
NotTerm notTerm = (NotTerm) terms[0];
assertTrue(((FlagTerm) notTerm.getTerm()).getFlags().contains(Flag.ANSWERED));
notTerm = (NotTerm) terms[1];
Flags siFlags = new Flags();
siFlags.add(AbstractMailReceiver.DEFAULT_SI_USER_FLAG);
assertTrue(((FlagTerm) notTerm.getTerm()).getFlags().contains(siFlags));
}
use of javax.mail.search.AndTerm in project jodd by oblac.
the class EmailFilterTest method testReceivedDate.
@Test
public void testReceivedDate() {
EmailFilter emailFilter = EmailFilter.filter().receivedDate(EmailFilter.Operator.EQ, 1000).sentDate(EmailFilter.Operator.GT, 2000);
SearchTerm expected = new AndTerm(new ReceivedDateTerm(3, new Date(1000)), new SentDateTerm(5, new Date(2000)));
assertEquals(expected, emailFilter.searchTerm);
}
use of javax.mail.search.AndTerm in project jodd by oblac.
the class EmailFilterTest method testAndOrNot.
@Test
public void testAndOrNot() {
EmailFilter emailFilter = filter().from("from").to("to").or().not().subject("subject").from("from2");
SearchTerm expected = new OrTerm(new OrTerm(new AndTerm(new FromStringTerm("from"), new RecipientStringTerm(Message.RecipientType.TO, "to")), new NotTerm(new SubjectTerm("subject"))), new FromStringTerm("from2"));
assertEquals(expected, emailFilter.searchTerm);
}
Aggregations