Example usage for javax.mail.search HeaderTerm HeaderTerm

List of usage examples for javax.mail.search HeaderTerm HeaderTerm

Introduction

In this page you can find the example usage for javax.mail.search HeaderTerm HeaderTerm.

Prototype

public HeaderTerm(String headerName, String pattern) 

Source Link

Document

Constructor.

Usage

From source file:com.sonicle.webtop.mail.bol.model.ImapQuery.java

public static SearchTerm toSearchTerm(String allFlagStrings[], List<Tag> atags, QueryObj query,
        DateTimeZone timezone) {/*from   www.  j  av a2s .  c o  m*/
    SearchTerm searchTerm = null;
    ArrayList<SearchTerm> terms = new ArrayList<SearchTerm>();

    if (query != null) {
        ArrayList<Condition> conditionsList = query.conditions;
        String allText = query.allText;

        if (allText != null && allText.trim().length() > 0) {
            SearchTerm defaultterms[] = toDefaultSearchTerm(allText);
            terms.add(new OrTerm(defaultterms));
        }

        conditionsList.forEach(condition -> {
            String key = condition.keyword;
            String value = condition.value;

            if (key.equals(FROM)) {
                terms.add(new FromStringTerm(value));
            } else if (key.equals(TO)) {
                terms.add(new RecipientStringTerm(Message.RecipientType.TO, value));
            } else if (key.equals(SUBJECT)) {
                terms.add(new SubjectTerm(value));
            } else if (key.equals(MESSAGE)) {
                terms.add(new BodyTerm(value));
            } else if (key.equals(EVERYWHERE)) {
                SearchTerm anyterms[] = toAnySearchTerm(value);
                terms.add(new OrTerm(anyterms));
            } else if (key.equals(AFTER)) {
                Date afterDate = ImapQuery.parseDate(value, timezone);
                terms.add(new ReceivedDateTerm(DateTerm.GE, afterDate));
                terms.add(new SentDateTerm(DateTerm.GE, afterDate));
            } else if (key.equals(BEFORE)) {
                Date beforeDate = ImapQuery.parseDate(value, timezone);
                terms.add(new ReceivedDateTerm(DateTerm.LE, beforeDate));
                terms.add(new SentDateTerm(DateTerm.LE, beforeDate));

            } else if (value.equals(ATTACHMENT)) {

            } else if (value.equals(UNREAD)) {
                terms.add(new FlagTerm(new Flags(Flag.SEEN), false));
            } else if (value.equals(FLAGGED)) {
                FlagTerm fts[] = new FlagTerm[allFlagStrings.length + 1];
                fts[0] = new FlagTerm(new Flags(Flag.FLAGGED), true);
                for (int i = 0; i < allFlagStrings.length; ++i)
                    fts[i + 1] = new FlagTerm(new Flags(allFlagStrings[i]), true);
                terms.add(new OrTerm(fts));
            } else if (value.equals(TAGGED)) {
                FlagTerm fts[] = new FlagTerm[atags.size()];
                int i = 0;
                for (Tag tag : atags)
                    fts[i++] = new FlagTerm(new Flags(tag.getTagId()), true);
                terms.add(new OrTerm(fts));
            } else if (value.equals(UNANSWERED)) {
                terms.add(new FlagTerm(new Flags(Flag.ANSWERED), false));
            } else if (value.equals(PRIORITY)) {
                HeaderTerm p1 = new HeaderTerm("X-Priority", "1");
                HeaderTerm p2 = new HeaderTerm("X-Priority", "2");
                terms.add(new OrTerm(p1, p2));
            }

        });
    }

    int n = terms.size();
    if (n == 1) {
        searchTerm = terms.get(0);
    } else if (n > 1) {
        SearchTerm vterms[] = new SearchTerm[n];
        terms.toArray(vterms);
        searchTerm = new AndTerm(vterms);
    }
    return searchTerm;
}

From source file:com.sonicle.webtop.mail.MailAccount.java

public void deleteByHeaderValue(String header, String value) throws MessagingException {
    FolderCache fc = getFolderCache(getFolderDrafts());
    fc.open();/*from w  ww .  j  a va  2  s.  c  o m*/
    Folder folder = fc.getFolder();
    Message[] oldmsgs = folder.search(new HeaderTerm(header, value));
    if (oldmsgs != null && oldmsgs.length > 0) {
        for (Message m : oldmsgs)
            m.setFlag(Flags.Flag.DELETED, true);
        folder.expunge();
    }
}

From source file:org.exist.xquery.modules.mail.MessageListFunctions.java

private SearchTerm parseHeaderTerm(Node terms) throws XPathException {
    SearchTerm st = null;/*from   www  . j  ava  2  s.  c  om*/

    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.length() > 0) {
        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);
}

From source file:org.springframework.ws.transport.mail.MailSenderConnection.java

@Override
protected void onReceiveBeforeRead() throws IOException {
    try {// w  w  w . java2s  .c om
        String requestMessageId = requestMessage.getMessageID();
        Assert.hasLength(requestMessageId, "No Message-ID found on request message [" + requestMessage + "]");
        try {
            Thread.sleep(receiveTimeout);
        } catch (InterruptedException e) {
            // Re-interrupt current thread, to allow other threads to react.
            Thread.currentThread().interrupt();
        }
        openFolder();
        SearchTerm searchTerm = new HeaderTerm(MailTransportConstants.HEADER_IN_REPLY_TO, requestMessageId);
        Message[] responses = folder.search(searchTerm);
        if (responses.length > 0) {
            if (responses.length > 1) {
                logger.warn("Received more than one response for request with ID [" + requestMessageId + "]");
            }
            responseMessage = responses[0];
        }
        if (deleteAfterReceive) {
            responseMessage.setFlag(Flags.Flag.DELETED, true);
        }
    } catch (MessagingException ex) {
        throw new MailTransportException(ex);
    }
}