Search in sources :

Example 1 with AndTerm

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);
}
Also used : AndTerm(javax.mail.search.AndTerm) FromStringTerm(javax.mail.search.FromStringTerm) RecipientStringTerm(javax.mail.search.RecipientStringTerm) SearchTerm(javax.mail.search.SearchTerm) Test(org.junit.Test)

Example 2 with AndTerm

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);
}
Also used : AndTerm(javax.mail.search.AndTerm) OrTerm(javax.mail.search.OrTerm) FromStringTerm(javax.mail.search.FromStringTerm) RecipientStringTerm(javax.mail.search.RecipientStringTerm) NotTerm(javax.mail.search.NotTerm) SearchTerm(javax.mail.search.SearchTerm) SubjectTerm(javax.mail.search.SubjectTerm) Test(org.junit.Test)

Example 3 with AndTerm

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));
}
Also used : AndTerm(javax.mail.search.AndTerm) Field(java.lang.reflect.Field) FlagTerm(javax.mail.search.FlagTerm) NotTerm(javax.mail.search.NotTerm) BeanFactory(org.springframework.beans.factory.BeanFactory) Flags(javax.mail.Flags) Method(java.lang.reflect.Method) Folder(javax.mail.Folder) SearchTerm(javax.mail.search.SearchTerm) Test(org.junit.Test)

Example 4 with AndTerm

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);
}
Also used : AndTerm(javax.mail.search.AndTerm) ReceivedDateTerm(javax.mail.search.ReceivedDateTerm) SentDateTerm(javax.mail.search.SentDateTerm) SearchTerm(javax.mail.search.SearchTerm) Date(java.util.Date) Test(org.junit.Test)

Example 5 with AndTerm

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);
}
Also used : AndTerm(javax.mail.search.AndTerm) OrTerm(javax.mail.search.OrTerm) FromStringTerm(javax.mail.search.FromStringTerm) RecipientStringTerm(javax.mail.search.RecipientStringTerm) NotTerm(javax.mail.search.NotTerm) SearchTerm(javax.mail.search.SearchTerm) SubjectTerm(javax.mail.search.SubjectTerm) Test(org.junit.Test)

Aggregations

AndTerm (javax.mail.search.AndTerm)12 SearchTerm (javax.mail.search.SearchTerm)11 FromStringTerm (javax.mail.search.FromStringTerm)7 SubjectTerm (javax.mail.search.SubjectTerm)7 Test (org.junit.Test)6 InternetAddress (javax.mail.internet.InternetAddress)5 URISyntaxException (java.net.URISyntaxException)3 DateFormat (java.text.DateFormat)3 ParseException (java.text.ParseException)3 SimpleDateFormat (java.text.SimpleDateFormat)3 Flags (javax.mail.Flags)3 Folder (javax.mail.Folder)3 MimeMessage (javax.mail.internet.MimeMessage)3 FlagTerm (javax.mail.search.FlagTerm)3 Message (javax.mail.Message)2 MessagingException (javax.mail.MessagingException)2 Session (javax.mail.Session)2 Store (javax.mail.Store)2 FromTerm (javax.mail.search.FromTerm)2 NotTerm (javax.mail.search.NotTerm)2