Search in sources :

Example 36 with SearchTerm

use of javax.mail.search.SearchTerm in project jodd by oblac.

the class EmailFilter method header.

/**
	 * Defines filter for header.
	 */
public EmailFilter header(String headerName, String pattern) {
    SearchTerm term = new HeaderTerm(headerName, pattern);
    concat(term);
    return this;
}
Also used : HeaderTerm(javax.mail.search.HeaderTerm) SearchTerm(javax.mail.search.SearchTerm)

Example 37 with SearchTerm

use of javax.mail.search.SearchTerm in project camel by apache.

the class SearchTermBuilderTest method testSearchTermBuilderFromOrSubject.

public void testSearchTermBuilderFromOrSubject() throws Exception {
    SearchTermBuilder build = new SearchTermBuilder();
    SearchTerm st = build.subject("Camel").from(or, "admin@apache.org").build();
    assertNotNull(st);
    // create dummy message
    Mailbox.clearAll();
    JavaMailSender sender = new DefaultJavaMailSender();
    MimeMessage msg = new MimeMessage(sender.getSession());
    msg.setSubject("Yeah Camel rocks");
    msg.setText("Apache Camel is a cool project. Have a fun ride.");
    msg.setFrom(new InternetAddress("someone@somewhere.com"));
    assertTrue("Should match message", st.match(msg));
    MimeMessage msg2 = new MimeMessage(sender.getSession());
    msg2.setSubject("Beware");
    msg2.setText("This is from the administrator.");
    msg2.setFrom(new InternetAddress("admin@apache.org"));
    assertTrue("Should match message, as its from admin", st.match(msg2));
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) MimeMessage(javax.mail.internet.MimeMessage) SearchTerm(javax.mail.search.SearchTerm)

Example 38 with SearchTerm

use of javax.mail.search.SearchTerm in project camel by apache.

the class SearchTermBuilderTest method testSearchTermBuilderFromAndSubject.

public void testSearchTermBuilderFromAndSubject() throws Exception {
    SearchTermBuilder build = new SearchTermBuilder();
    SearchTerm st = build.from("someone@somewhere.com").subject("Camel").build();
    assertNotNull(st);
    // create dummy message
    Mailbox.clearAll();
    JavaMailSender sender = new DefaultJavaMailSender();
    MimeMessage msg = new MimeMessage(sender.getSession());
    msg.setSubject("Yeah Camel rocks");
    msg.setText("Apache Camel is a cool project. Have a fun ride.");
    msg.setFrom(new InternetAddress("someone@somewhere.com"));
    assertTrue("Should match message", st.match(msg));
    MimeMessage msg2 = new MimeMessage(sender.getSession());
    msg2.setSubject("Apache Camel is fantastic");
    msg2.setText("I like Camel.");
    msg2.setFrom(new InternetAddress("donotreply@somewhere.com"));
    assertFalse("Should not match message, as from doesn't match", st.match(msg2));
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) MimeMessage(javax.mail.internet.MimeMessage) SearchTerm(javax.mail.search.SearchTerm)

Aggregations

SearchTerm (javax.mail.search.SearchTerm)38 RecipientStringTerm (javax.mail.search.RecipientStringTerm)9 FromStringTerm (javax.mail.search.FromStringTerm)8 Test (org.junit.Test)8 OrTerm (javax.mail.search.OrTerm)6 SubjectTerm (javax.mail.search.SubjectTerm)6 AndTerm (javax.mail.search.AndTerm)5 Message (javax.mail.Message)3 InternetAddress (javax.mail.internet.InternetAddress)3 MimeMessage (javax.mail.internet.MimeMessage)3 FlagTerm (javax.mail.search.FlagTerm)3 HeaderTerm (javax.mail.search.HeaderTerm)3 NotTerm (javax.mail.search.NotTerm)3 IMAPFolder (com.sun.mail.imap.IMAPFolder)2 Date (java.util.Date)2 Flags (javax.mail.Flags)2 MessagingException (javax.mail.MessagingException)2 BodyTerm (javax.mail.search.BodyTerm)2 MessageIDTerm (javax.mail.search.MessageIDTerm)2 ReceivedDateTerm (javax.mail.search.ReceivedDateTerm)2