Пример #1
0
 @Override
 public MailItem next() {
   if (results == null) {
     return null;
   }
   try {
     ZimbraHit hit = results.getNext();
     if (hit != null) {
       return hit.getMailItem();
     }
   } catch (ServiceException e) {
     ZimbraLog.misc.warn("caught exception", e);
   }
   return null;
 }
Пример #2
0
  /**
   * initialize the Pop3Mailbox, without keeping a reference to either the Mailbox object or any of
   * the Message objects in the inbox.
   */
  Pop3Mailbox(Mailbox mbox, Account acct, String query) throws ServiceException {
    id = mbox.getId();
    numDeleted = 0;
    opContext = new OperationContext(acct);
    deleteOption = acct.getPrefPop3DeleteOption();

    if (Strings.isNullOrEmpty(query)) {
      Set<Integer> folderIds =
          acct.isPrefPop3IncludeSpam()
              ? ImmutableSet.of(Mailbox.ID_FOLDER_INBOX, Mailbox.ID_FOLDER_SPAM)
              : Collections.singleton(Mailbox.ID_FOLDER_INBOX);
      String dateConstraint = acct.getAttr(Provisioning.A_zimbraPrefPop3DownloadSince);
      Date popSince = dateConstraint == null ? null : DateUtil.parseGeneralizedTime(dateConstraint);
      messages = mbox.openPop3Folder(opContext, folderIds, popSince);
      for (Pop3Message p3m : messages) {
        totalSize += p3m.getSize();
      }
    } else {
      ZimbraQueryResults results = null;
      messages = new ArrayList<Pop3Message>(500);
      try {
        results = mbox.index.search(opContext, query, POP3_TYPES, SortBy.DATE_DESC, 500);

        while (results.hasNext()) {
          ZimbraHit hit = results.getNext();
          if (hit instanceof MessageHit) {
            MessageHit mh = (MessageHit) hit;
            Message msg = mh.getMessage();
            if (!msg.isTagged(Flag.FlagInfo.POPPED)) {
              totalSize += msg.getSize();
              messages.add(new Pop3Message(msg));
            }
          }
        }
      } finally {
        Closeables.closeQuietly(results);
      }
    }
  }
Пример #3
0
    @Override
    public Collection<AddressObject> match(DavContext ctxt, AddressbookCollection folder) {
      // search the folder for #key:val where key is mName and val is mTextMatch.mText.
      // boolean ignoreCase = mCollation.equals(DavElements.ASCII);
      ArrayList<AddressObject> result = new ArrayList<AddressObject>();
      StringBuilder search = new StringBuilder();
      if (mNegate) search.append("!");
      AttrMapping mapping = sAttrMappings.get(mEnclosingFilter.getName().toUpperCase());
      if (mapping == null) return result;
      String[] attrs = mapping.getAttrs();
      search.append("(");
      boolean first = true;
      for (String key : attrs) {
        if (!first) search.append(" OR ");
        search.append("#").append(key).append(":");
        if (mMatch == MatchType.contains || mMatch == MatchType.ends_with) search.append("*");
        search.append(mText);
        if (mMatch == MatchType.contains || mMatch == MatchType.starts_with) search.append("*");
        first = false;
      }
      search.append(")");
      String filter = search.toString();
      ZimbraLog.dav.debug("Search Filter: %s", filter);
      ZimbraQueryResults zqr = null;
      try {
        Mailbox mbox = ctxt.getTargetMailbox();
        if (mbox == null) {
          ZimbraLog.dav.debug("Can't get target mailbox for %s", ctxt.getUser());
          return result;
        }
        zqr =
            mbox.index.search(
                ctxt.getOperationContext(),
                filter,
                EnumSet.of(MailItem.Type.CONTACT),
                SortBy.NAME_ASC,
                100);
        while (zqr.hasNext()) {
          ZimbraHit hit = zqr.getNext();
          if (hit instanceof ContactHit) {
            result.add(new AddressObject(ctxt, ((ContactHit) hit).getContact()));
          }
        }
      } catch (Exception e) {
        ZimbraLog.dav.warn("can't get target mailbox", e);
        return result;
      } finally {
        Closeables.closeQuietly(zqr);
      }
      boolean includeGal = true;
      if (includeGal) {
        StringBuilder query = new StringBuilder();
        if (mMatch == MatchType.contains || mMatch == MatchType.ends_with) query.append("*");
        query.append(mText);
        if (mMatch == MatchType.contains || mMatch == MatchType.starts_with) query.append("*");
        ZimbraLog.dav.debug("Gal query: %s", query.toString());

        GalSearchParams params = new GalSearchParams(ctxt.getAuthAccount());
        params.setType(GalSearchType.account);
        params.setQuery(query.toString());
        params.setResultCallback(new Callback(ctxt, result, params));
        GalSearchControl gal = new GalSearchControl(params);
        try {
          gal.search();
        } catch (ServiceException e) {
          if (ServiceException.PERM_DENIED.equals(e.getCode()))
            ZimbraLog.dav.debug(
                "Can't get gal search result for %s (%s)", ctxt.getUser(), e.getMessage());
          else ZimbraLog.dav.error("Can't get gal search result for %s", ctxt.getUser());
        }
      }
      return result;
    }