Search in sources :

Example 11 with SearchTerm

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

the class MessageListFunctions method parseReceivedDateTerm.

private SearchTerm parseReceivedDateTerm(Node terms) throws XPathException {
    SearchTerm st = null;
    String value = ((Element) terms).getAttribute("date");
    String format = ((Element) terms).getAttribute("format");
    if (StringUtils.isEmpty(value)) {
        throw (new XPathException(this, "value not specified for term with type: " + ((Element) terms).getAttribute("type")));
    }
    if (StringUtils.isEmpty(format)) {
        throw (new XPathException(this, "format not specified for term with type: " + ((Element) terms).getAttribute("type")));
    }
    int cp = parseComparisonAttribute(terms);
    try {
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        Date date = sdf.parse(value);
        st = new ReceivedDateTerm(cp, date);
    } catch (ParseException pe) {
        throw (new XPathException(this, "Cannot parse date value: " + value + ", using format: " + format + ", for term with type: " + ((Element) terms).getAttribute("type")));
    }
    return (st);
}
Also used : XPathException(org.exist.xquery.XPathException) Element(org.w3c.dom.Element) ReceivedDateTerm(jakarta.mail.search.ReceivedDateTerm) ParseException(java.text.ParseException) SearchTerm(jakarta.mail.search.SearchTerm) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 12 with SearchTerm

use of jakarta.mail.search.SearchTerm 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 13 with SearchTerm

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

the class MessageListFunctions method parseHeaderTerm.

private SearchTerm parseHeaderTerm(Node terms) throws XPathException {
    SearchTerm st = null;
    String pattern = ((Element) terms).getAttribute("pattern");
    String name = ((Element) terms).getAttribute("name");
    if (StringUtils.isEmpty(name)) {
        throw (new XPathException(this, "name not specified for term with type: " + ((Element) terms).getAttribute("type")));
    }
    if (pattern != null && !pattern.isEmpty()) {
        st = new HeaderTerm(name, pattern);
    } else {
        throw (new XPathException(this, "pattern attribute must be specified for term with type: " + ((Element) terms).getAttribute("type")));
    }
    return (st);
}
Also used : XPathException(org.exist.xquery.XPathException) Element(org.w3c.dom.Element) HeaderTerm(jakarta.mail.search.HeaderTerm) SearchTerm(jakarta.mail.search.SearchTerm)

Example 14 with SearchTerm

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

the class ImapMailSearchTermsTests method validateSearchTermsWhenShouldNotMarkAsReadNoExistingFlags.

@Test
public void validateSearchTermsWhenShouldNotMarkAsReadNoExistingFlags() throws Exception {
    ImapMailReceiver receiver = new ImapMailReceiver();
    receiver.setShouldMarkMessagesAsRead(false);
    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();
    SearchTerm searchTerms = (SearchTerm) compileSearchTerms.invoke(receiver, flags);
    assertThat(searchTerms instanceof NotTerm).isTrue();
}
Also used : Field(java.lang.reflect.Field) 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) Test(org.junit.jupiter.api.Test)

Aggregations

SearchTerm (jakarta.mail.search.SearchTerm)14 XPathException (org.exist.xquery.XPathException)10 Element (org.w3c.dom.Element)8 Flags (jakarta.mail.Flags)5 Folder (jakarta.mail.Folder)4 NotTerm (jakarta.mail.search.NotTerm)3 Field (java.lang.reflect.Field)3 Method (java.lang.reflect.Method)3 BeanFactory (org.springframework.beans.factory.BeanFactory)3 FlagTerm (jakarta.mail.search.FlagTerm)2 ParseException (java.text.ParseException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 Test (org.junit.jupiter.api.Test)2 Node (org.w3c.dom.Node)2 NodeList (org.w3c.dom.NodeList)2 IMAPFolder (com.sun.mail.imap.IMAPFolder)1 Message (jakarta.mail.Message)1 MessagingException (jakarta.mail.MessagingException)1 AndTerm (jakarta.mail.search.AndTerm)1