use of javax.mail.search.SearchTerm in project camel by apache.
the class MailComponent method createEndpoint.
@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
URI url = new URI(uri);
// must use copy as each endpoint can have different options
MailConfiguration config = getConfiguration().copy();
// only configure if we have a url with a known protocol
config.configure(url);
configureAdditionalJavaMailProperties(config, parameters);
MailEndpoint endpoint = new MailEndpoint(uri, this, config);
// special for search term bean reference
Object searchTerm = getAndRemoveOrResolveReferenceParameter(parameters, "searchTerm", Object.class);
if (searchTerm != null) {
SearchTerm st;
if (searchTerm instanceof SimpleSearchTerm) {
// okay its a SimpleSearchTerm then lets convert that to SearchTerm
st = MailConverters.toSearchTerm((SimpleSearchTerm) searchTerm, getCamelContext().getTypeConverter());
} else {
st = getCamelContext().getTypeConverter().mandatoryConvertTo(SearchTerm.class, searchTerm);
}
endpoint.setSearchTerm(st);
}
endpoint.setContentTypeResolver(contentTypeResolver);
setProperties(endpoint.getConfiguration(), parameters);
setProperties(endpoint, parameters);
// special for searchTerm.xxx options
Map<String, Object> sstParams = IntrospectionSupport.extractProperties(parameters, "searchTerm.");
if (!sstParams.isEmpty()) {
// use SimpleSearchTerm as POJO to store the configuration and then convert that to the actual SearchTerm
SimpleSearchTerm sst = new SimpleSearchTerm();
setProperties(sst, sstParams);
SearchTerm st = MailConverters.toSearchTerm(sst, getCamelContext().getTypeConverter());
endpoint.setSearchTerm(st);
}
// sanity check that we know the mail server
ObjectHelper.notEmpty(config.getHost(), "host");
ObjectHelper.notEmpty(config.getProtocol(), "protocol");
return endpoint;
}
use of javax.mail.search.SearchTerm in project camel by apache.
the class SearchTermBuilder method subject.
public SearchTermBuilder subject(Op op, String pattern) {
SearchTerm st = new SubjectTerm(pattern);
addTerm(op, st);
return this;
}
use of javax.mail.search.SearchTerm in project camel by apache.
the class SearchTermBuilderTest method testSearchTermSentLast24Hours.
public void testSearchTermSentLast24Hours() throws Exception {
SearchTermBuilder build = new SearchTermBuilder();
long offset = -1 * (24 * 60 * 60 * 1000L);
SearchTerm st = build.subject("Camel").sentNow(Comparison.GE, offset).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"));
msg.setSentDate(new Date());
assertTrue("Should match message", st.match(msg));
MimeMessage msg2 = new MimeMessage(sender.getSession());
msg2.setSubject("Camel in Action");
msg2.setText("Hey great book");
msg2.setFrom(new InternetAddress("dude@apache.org"));
// mark it as sent 2 days ago
long twoDays = 2 * 24 * 60 * 60 * 1000L;
long time = new Date().getTime() - twoDays;
msg2.setSentDate(new Date(time));
assertFalse("Should not match message as its too old", st.match(msg2));
}
use of javax.mail.search.SearchTerm 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.SearchTerm 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);
}
Aggregations