Search in sources :

Example 1 with FlagTerm

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

Example 2 with FlagTerm

use of jakarta.mail.search.FlagTerm in project exist by eXist-db.

the class MessageListFunctions method parseFlagTerm.

private SearchTerm parseFlagTerm(Node terms) throws XPathException {
    SearchTerm st = null;
    String flag = ((Element) terms).getAttribute("flag");
    String value = ((Element) terms).getAttribute("value");
    if (StringUtils.isEmpty(value)) {
        throw (new XPathException(this, "value not specified for term with type: " + ((Element) terms).getAttribute("type")));
    }
    if (flag != null && !flag.isEmpty()) {
        Flags flags = null;
        if (flag.equalsIgnoreCase("answered")) {
            flags = new Flags(Flags.Flag.ANSWERED);
        } else if (flag.equalsIgnoreCase("deleted")) {
            flags = new Flags(Flags.Flag.DELETED);
        } else if (flag.equalsIgnoreCase("draft")) {
            flags = new Flags(Flags.Flag.DRAFT);
        } else if (flag.equalsIgnoreCase("recent")) {
            flags = new Flags(Flags.Flag.RECENT);
        } else if (flag.equalsIgnoreCase("seen")) {
            flags = new Flags(Flags.Flag.SEEN);
        } else {
            throw (new XPathException(this, "Invalid flag: " + flag + ", for term with type: " + ((Element) terms).getAttribute("type")));
        }
        st = new FlagTerm(flags, value.equalsIgnoreCase("true"));
    } else {
        throw (new XPathException(this, "flag attribute must be specified for term with type: " + ((Element) terms).getAttribute("type")));
    }
    return (st);
}
Also used : FlagTerm(jakarta.mail.search.FlagTerm) XPathException(org.exist.xquery.XPathException) Element(org.w3c.dom.Element) Flags(jakarta.mail.Flags) SearchTerm(jakarta.mail.search.SearchTerm)

Example 3 with FlagTerm

use of jakarta.mail.search.FlagTerm in project spring-integration by spring-projects.

the class ImapMailReceiverTests method testIdleWithServerCustomSearch.

@Test
public void testIdleWithServerCustomSearch() throws Exception {
    ImapMailReceiver receiver = new ImapMailReceiver("imap://user:pw@localhost:" + this.imapIdleServer.getImap().getPort() + "/INBOX");
    receiver.setSearchTermStrategy((supportedFlags, folder) -> {
        try {
            FromTerm fromTerm = new FromTerm(new InternetAddress("bar@baz"));
            return new AndTerm(fromTerm, new FlagTerm(new Flags(Flag.SEEN), false));
        } catch (AddressException e) {
            throw new RuntimeException(e);
        }
    });
    testIdleWithServerGuts(receiver, false);
}
Also used : AndTerm(jakarta.mail.search.AndTerm) InternetAddress(jakarta.mail.internet.InternetAddress) FlagTerm(jakarta.mail.search.FlagTerm) AddressException(jakarta.mail.internet.AddressException) Flags(jakarta.mail.Flags) FromTerm(jakarta.mail.search.FromTerm) Test(org.junit.jupiter.api.Test) ServerSetupTest(com.icegreen.greenmail.util.ServerSetupTest)

Aggregations

Flags (jakarta.mail.Flags)3 FlagTerm (jakarta.mail.search.FlagTerm)3 SearchTerm (jakarta.mail.search.SearchTerm)2 ServerSetupTest (com.icegreen.greenmail.util.ServerSetupTest)1 Folder (jakarta.mail.Folder)1 AddressException (jakarta.mail.internet.AddressException)1 InternetAddress (jakarta.mail.internet.InternetAddress)1 AndTerm (jakarta.mail.search.AndTerm)1 FromTerm (jakarta.mail.search.FromTerm)1 NotTerm (jakarta.mail.search.NotTerm)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 XPathException (org.exist.xquery.XPathException)1 Test (org.junit.jupiter.api.Test)1 BeanFactory (org.springframework.beans.factory.BeanFactory)1 Element (org.w3c.dom.Element)1