List of usage examples for javax.mail.search OrTerm OrTerm
public OrTerm(SearchTerm[] t)
From source file:com.sonicle.webtop.mail.bol.model.ImapQuery.java
public static SearchTerm toSearchTerm(String allFlagStrings[], List<Tag> atags, QueryObj query, DateTimeZone timezone) {/* w w w . ja v 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.cubusmail.server.mail.util.MessageUtils.java
/** * Create a search term for filtering messages. * /*from w w w.j a v a2s.c o m*/ * @param searchFields * @param searchValues * @return */ public static SearchTerm createSearchTerm(MessageListFields[] searchFields, String[] searchValues) { SearchTerm[] terms = new SearchTerm[searchFields.length]; for (int i = 0; i < searchFields.length; i++) { terms[i] = createSearchTerm(searchFields[i], searchValues); } if (searchFields.length > 1) { return new OrTerm(terms); } else { return terms[0]; } }
From source file:com.sonicle.webtop.mail.Service.java
public void processRunSmartSearch(HttpServletRequest request, HttpServletResponse response, PrintWriter out) { try {//from w w w . j a v a2 s . c om if (sst != null && sst.isRunning()) sst.cancel(); UserProfile profile = environment.getProfile(); MailAccount account = getAccount(request); String pattern = ServletUtils.getStringParameter(request, "pattern", true); String folder = ServletUtils.getStringParameter(request, "folder", false); boolean trashspam = ServletUtils.getBooleanParameter(request, "trashspam", false); boolean fromme = ServletUtils.getBooleanParameter(request, "fromme", false); boolean tome = ServletUtils.getBooleanParameter(request, "tome", false); boolean attachments = ServletUtils.getBooleanParameter(request, "attachments", false); int year = ServletUtils.getIntParameter(request, "year", 0); int month = ServletUtils.getIntParameter(request, "month", 0); int day = ServletUtils.getIntParameter(request, "day", 0); ArrayList<String> ispersonfilters = ServletUtils.getStringParameters(request, "ispersonfilters"); ArrayList<String> isnotpersonfilters = ServletUtils.getStringParameters(request, "isnotpersonfilters"); ArrayList<String> isfolderfilters = ServletUtils.getStringParameters(request, "isfolderfilters"); ArrayList<String> isnotfolderfilters = ServletUtils.getStringParameters(request, "isnotfolderfilters"); Set<String> _folderIds = account.getFolderCacheKeys(); ArrayList<SearchTerm> terms = new ArrayList<>(); SearchTerm searchTerm = null; //sort folders, placing first interesting ones ArrayList<String> folderIds = new ArrayList<>(); Collections.sort(folderIds); String firstFolders[] = { account.getInboxFolderFullName(), account.getFolderSent() }; for (String folderId : firstFolders) folderIds.add(folderId); for (String folderId : _folderIds) { //if folder selected, look only under that folder if (folder != null && folder.trim().length() > 0) { if (!folder.equals(folderId) && !account.isUnderFolder(folder, folderId)) continue; } else { //else skip shared if (account.isUnderSharedFolder(folderId)) continue; } //skip trash & spam unless selected if (!trashspam && (account.isTrashFolder(folderId) || account.isSpamFolder(folderId))) continue; boolean skip = false; for (String skipfolder : firstFolders) { if (skipfolder.equals(folderId)) { skip = true; break; } } if (!skip) folderIds.add(folderId); } terms.add(new OrTerm(ImapQuery.toAnySearchTerm(pattern))); 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); } sst = new SmartSearchThread(this, account, folderIds, fromme, tome, attachments, ispersonfilters, isnotpersonfilters, isfolderfilters, isnotfolderfilters, year, month, day, searchTerm, false); sst.start(); new JsonResult().printTo(out); } catch (Exception exc) { Service.logger.error("Exception", exc); new JsonResult(false, exc.getMessage()).printTo(out); } }
From source file:com.sonicle.webtop.mail.Service.java
public void processPortletRunSearch(HttpServletRequest request, HttpServletResponse response, PrintWriter out) { try {// www . j av a 2 s . c o m UserProfile profile = environment.getProfile(); boolean trash = false; boolean spam = false; ArrayList<SearchTerm> terms = new ArrayList<SearchTerm>(); SearchTerm searchTerm = null; if (pst != null && pst.isRunning()) pst.cancel(); MailAccount account = getAccount(request); String pattern = ServletUtils.getStringParameter(request, "pattern", true); Set<String> _folderIds = account.getFolderCacheKeys(); //sort folders, placing first interesting ones ArrayList<String> folderIds = new ArrayList<>(); Collections.sort(folderIds); String firstFolders[] = { account.getInboxFolderFullName(), account.getFolderSent() }; for (String folderId : firstFolders) folderIds.add(folderId); for (String folderId : _folderIds) { if (account.isUnderSharedFolder(folderId)) continue; //skip trash & spam unless selected if (!trash && account.isTrashFolder(folderId)) continue; if (!spam && account.isSpamFolder(folderId)) continue; folderIds.add(folderId); } terms.add(new OrTerm(ImapQuery.toAnySearchTerm(pattern))); 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); } pst = new PortletSearchThread(this, account, folderIds, searchTerm, false); pst.start(); new JsonResult().printTo(out); } catch (Exception exc) { Service.logger.error("Exception", exc); new JsonResult(false, exc.getMessage()).printTo(out); } }
From source file:org.apache.hupa.server.handler.FetchMessagesHandler.java
@Override protected MessageConvertArray getMessagesToConvert(com.sun.mail.imap.IMAPFolder f, FetchMessages action) throws MessagingException, ActionException { String searchString = action.getSearchString(); int start = action.getStart(); int offset = action.getOffset(); int end = start + offset; Message[] messages;/*from w ww .j av a 2 s.c o m*/ int exists; // check if a searchString was given, and if so use it if (searchString == null) { exists = f.getMessageCount(); if (end > exists) { end = exists; } int firstIndex = exists - end + 1; if (firstIndex < 1) { firstIndex = 1; } int lastIndex = exists - start; messages = f.getMessages(firstIndex, lastIndex); } else { SearchTerm subjectTerm = new SubjectTerm(searchString); SearchTerm fromTerm = new FromStringTerm(searchString); SearchTerm bodyTerm = new BodyTerm(searchString); SearchTerm orTerm = new OrTerm(new SearchTerm[] { subjectTerm, fromTerm, bodyTerm }); Message[] tmpMessages = f.search(orTerm); if (end > tmpMessages.length) { end = tmpMessages.length; } exists = tmpMessages.length; int firstIndex = exists - end; if (tmpMessages.length > firstIndex) { List<Message> mList = new ArrayList<Message>(); for (int i = firstIndex; i < tmpMessages.length; i++) { if (i == end) break; mList.add(tmpMessages[i]); } messages = mList.toArray(new Message[mList.size()]); } else { messages = new Message[0]; } } logger.debug("Fetching messages for user: " + getUser() + " returns: " + messages.length + " messages in " + f.getFullName()); return new MessageConvertArray(exists, messages); }
From source file:org.exist.xquery.modules.mail.MessageListFunctions.java
private SearchTerm parseSearchTerms(Node terms) throws XPathException { SearchTerm st = null;// w w w .j av a 2s.co m if (terms.getNodeType() == Node.ELEMENT_NODE && terms.getLocalName().equalsIgnoreCase("searchTerm")) { String type = ((Element) terms).getAttribute("type"); if (type != null) { if (type.equalsIgnoreCase("not")) { st = new NotTerm(parseChildSearchTerm(terms)); } else if (type.equalsIgnoreCase("and")) { st = new AndTerm(parseChildSearchTerms(terms)); } else if (type.equalsIgnoreCase("or")) { st = new OrTerm(parseChildSearchTerms(terms)); } else if (type.equalsIgnoreCase("from")) { st = parseFromTerm(terms); } else if (type.equalsIgnoreCase("subject")) { st = parseSubjectTerm(terms); } else if (type.equalsIgnoreCase("body")) { st = parseBodyTerm(terms); } else if (type.equalsIgnoreCase("to") || type.equalsIgnoreCase("recipient")) { st = parseRecipientTerm(terms); } else if (type.equalsIgnoreCase("header")) { st = parseHeaderTerm(terms); } else if (type.equalsIgnoreCase("flag")) { st = parseFlagTerm(terms); } else if (type.equalsIgnoreCase("sent")) { st = parseSentDateTerm(terms); } else if (type.equalsIgnoreCase("received")) { st = parseReceivedDateTerm(terms); } else { throw (new XPathException(this, "Invalid Search Term type specified: " + type)); } } else { throw (new XPathException(this, "Invalid Search Term type specified: null")); } } if (st == null) { throw (new XPathException(this, "Invalid Search Terms specified")); } return (st); }