use of jakarta.mail.search.SearchTerm in project exist by eXist-db.
the class MessageListFunctions method parseChildSearchTerms.
private SearchTerm[] parseChildSearchTerms(Node terms) throws XPathException {
// Parent allows multiple child search terms
ArrayList<SearchTerm> st = new ArrayList<>();
NodeList children = terms.getChildNodes();
if (children.getLength() > 0) {
for (int i = 0; i < children.getLength(); i++) {
Node child = children.item(i);
st.add(parseSearchTerms(child));
}
} else {
throw (new XPathException(this, "At least one child term is required for term with type: " + ((Element) terms).getAttribute("type")));
}
return st.toArray(new SearchTerm[0]);
}
use of jakarta.mail.search.SearchTerm 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);
assertThat(searchTerms instanceof AndTerm).isTrue();
AndTerm andTerm = (AndTerm) searchTerms;
SearchTerm[] terms = andTerm.getTerms();
assertThat(terms.length).isEqualTo(2);
NotTerm notTerm = (NotTerm) terms[0];
assertThat(((FlagTerm) notTerm.getTerm()).getFlags().contains(Flag.ANSWERED)).isTrue();
notTerm = (NotTerm) terms[1];
Flags siFlags = new Flags();
siFlags.add(AbstractMailReceiver.DEFAULT_SI_USER_FLAG);
assertThat(((FlagTerm) notTerm.getTerm()).getFlags().contains(siFlags)).isTrue();
}
use of jakarta.mail.search.SearchTerm in project spring-integration by spring-projects.
the class ImapMailSearchTermsTests method validateSearchTermsWhenShouldMarkAsReadNoExistingFlagsGuts.
public void validateSearchTermsWhenShouldMarkAsReadNoExistingFlagsGuts(String userFlag, ImapMailReceiver receiver) throws NoSuchFieldException, IllegalAccessException, InvocationTargetException {
receiver.setShouldMarkMessagesAsRead(true);
receiver.setBeanFactory(mock(BeanFactory.class));
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();
SearchTerm searchTerms = (SearchTerm) compileSearchTerms.invoke(receiver, flags);
assertThat(searchTerms instanceof NotTerm).isTrue();
NotTerm notTerm = (NotTerm) searchTerms;
Flags siFlags = new Flags();
siFlags.add(userFlag);
assertThat(((FlagTerm) notTerm.getTerm()).getFlags()).isEqualTo(siFlags);
}
use of jakarta.mail.search.SearchTerm in project spring-integration by spring-projects.
the class ImapMailReceiver method searchForNewMessages.
/**
* Retrieves new messages from this receiver's folder. This implementation
* creates a {@link SearchTerm} that searches for all messages in the
* folder that are {@link jakarta.mail.Flags.Flag#RECENT RECENT}, not
* {@link jakarta.mail.Flags.Flag#ANSWERED ANSWERED}, and not
* {@link jakarta.mail.Flags.Flag#DELETED DELETED}. The search term is used
* to {@link Folder#search(SearchTerm) search} for new messages.
* @return the new messages
* @throws MessagingException in case of JavaMail errors
*/
@Override
protected Message[] searchForNewMessages() throws MessagingException {
Folder folderToUse = getFolder();
Flags supportedFlags = folderToUse.getPermanentFlags();
SearchTerm searchTerm = compileSearchTerms(supportedFlags);
if (folderToUse.isOpen()) {
return nullSafeMessages(searchTerm != null ? folderToUse.search(searchTerm) : folderToUse.getMessages());
}
throw new MessagingException("Folder is closed");
}
use of jakarta.mail.search.SearchTerm in project exist by eXist-db.
the class MessageListFunctions method parseChildSearchTerm.
private SearchTerm parseChildSearchTerm(Node terms) throws XPathException {
// Parent only allows a single child search term
SearchTerm st = null;
NodeList children = terms.getChildNodes();
if (children.getLength() == 1) {
Node child = children.item(0);
st = parseSearchTerms(child);
} else {
throw (new XPathException(this, "Only one child term is allowed for term with type: " + ((Element) terms).getAttribute("type")));
}
return (st);
}
Aggregations