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);
}
use of javax.mail.search.SearchTerm in project jodd by oblac.
the class EmailFilterTest method testOr2Alt.
@Test
public void testOr2Alt() {
EmailFilter emailFilter = filter().or().from("from").to("to");
SearchTerm expected = new OrTerm(new FromStringTerm("from"), new RecipientStringTerm(Message.RecipientType.TO, "to"));
assertEquals(expected, emailFilter.searchTerm);
}
use of javax.mail.search.SearchTerm in project nhin-d by DirectProject.
the class MessageServiceImplService method requestStatus.
@Override
public StatusResponseType requestStatus(StatusRefType body) {
List<String> msgs = body.getMessageID();
StatusResponseType response = new StatusResponseType();
try {
checkAuth(response);
Authenticator auth = new SMTPAuthenticator();
Session session = Session.getInstance(imapProps, auth);
session.setDebug(true);
if (msgs.size() > 0) {
Store store = session.getStore(new javax.mail.URLName("imaps://" + username));
store.connect(getImapHost(), Integer.valueOf(getImapPort()).intValue(), username, password);
for (int x = 0; x < msgs.size(); x++) {
String msgid = msgs.get(x);
MessageIDTerm messageIdTerm = new MessageIDTerm(msgid);
IMAPFolder folder = (IMAPFolder) store.getFolder("INBOX");
folder.open(Folder.READ_ONLY);
SearchTerm st = messageIdTerm;
IMAPMessage[] msgsearch = (IMAPMessage[]) folder.search(st);
if (msgsearch.length > 0) {
Flags flags = msgsearch[0].getFlags();
Flag[] inboxflags = flags.getSystemFlags();
String[] listofflags = new String[inboxflags.length];
listofflags = setSystemFlags(inboxflags);
setMessageIdStatus(msgid, listofflags, response.getMessageIDAndStatus());
}
}
}
} catch (AddressException e) {
log.error(e);
} catch (MessagingException e) {
log.error(e);
} catch (Exception e) {
log.error(e);
}
return response;
}
use of javax.mail.search.SearchTerm in project opennms by OpenNMS.
the class MailTransportMonitor method processMailSubject.
/**
* After a mailbox has been opened, search through the retrieved messages
* for a matching subject.
*
* @param mailParms
* @param mailFolder
* @return a PollStatus indicative of the success of matching a subject or just retieving
* mail folder contents... dependent on configuration.
*/
private PollStatus processMailSubject(final MailTransportParameters mailParms, final Folder mailFolder) {
PollStatus status = PollStatus.unknown();
try {
final String subject = computeMatchingSubject(mailParms);
if (mailFolder.isOpen() && subject != null) {
final Message[] mailMessages = mailFolder.getMessages();
final SearchTerm searchTerm = new SubjectTerm(subject);
final SearchTerm deleteTerm = new HeaderTerm(MTM_HEADER_KEY, m_headerValue);
LOG.debug("searchMailSubject: searching {} message(s) for subject '{}'", mailMessages.length, subject);
boolean delete = false;
boolean found = false;
for (int i = 1; i <= mailMessages.length; i++) {
final Message mailMessage = mailFolder.getMessage(i);
LOG.debug("searchMailSubject: retrieved message subject '{}'", mailMessage.getSubject());
if (mailMessage.match(searchTerm)) {
found = true;
LOG.debug("searchMailSubject: message with subject '{}' found.", subject);
if (mailParms.isEnd2EndTestInProgress()) {
if (!delete)
LOG.debug("searchMailSubject: flagging message with subject '{}' for deletion for end2end test.", subject);
delete = true;
}
}
final boolean deleteAllMail = mailParms.getReadTest().getDeleteAllMail();
final boolean foundMTMHeader = mailMessage.match(deleteTerm);
LOG.debug("searchMailSubject: deleteAllMail = {}, MTM header found = {}", Boolean.toString(deleteAllMail), Boolean.toString(foundMTMHeader));
if (deleteAllMail) {
if (!delete)
LOG.debug("searchMailSubject: flagging message with subject '{}' for deletion because deleteAllMail is set.", subject);
delete = true;
} else if (foundMTMHeader) {
if (!delete)
LOG.debug("searchMailSubject: flagging message with subject '{}' for deletion because we sent it (found header {}={})", subject, MTM_HEADER_KEY, m_headerValue);
delete = true;
}
if (delete) {
mailMessage.setFlag(Flag.DELETED, true);
}
// since we want to delete old messages matchin MTM_HEADER_KEY, we can't break early
// if (found) break;
}
if (!found) {
LOG.debug("searchMailSubject: message with subject: '{}' NOT found.", subject);
status = PollStatus.down("searchMailSubject: matching test message: '" + subject + "', not found.");
} else {
status = PollStatus.available();
}
}
} catch (final MessagingException e) {
return PollStatus.down(e.getLocalizedMessage());
}
return status;
}
Aggregations