@Override
  public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Mailbox mbox = getRequestedMailbox(zsc);

    String browseBy = request.getAttribute(MailConstants.A_BROWSE_BY);
    BrowseBy parsedBrowseBy = BrowseBy.valueOf(browseBy.toLowerCase());
    String regex = request.getAttribute(MailConstants.A_REGEX, "").toLowerCase();
    int max = (int) (request.getAttributeLong(MailConstants.A_MAX_TO_RETURN, 0));

    List<BrowseTerm> terms;
    try {
      terms = mbox.browse(getOperationContext(zsc, context), parsedBrowseBy, regex, max);
    } catch (IOException e) {
      throw ServiceException.FAILURE("Failed to browse terms", e);
    }

    Element response = zsc.createElement(MailConstants.BROWSE_RESPONSE);

    for (BrowseTerm term : terms) {
      if (term instanceof DomainBrowseTerm) {
        DomainBrowseTerm domain = (DomainBrowseTerm) term;
        Element e = response.addElement(MailConstants.E_BROWSE_DATA).setText(domain.getText());
        String flags = domain.getHeaderFlags();
        if (!flags.isEmpty()) {
          e.addAttribute(MailConstants.A_BROWSE_DOMAIN_HEADER, flags);
        }
        e.addAttribute(MailConstants.A_FREQUENCY, domain.getFreq());
      } else {
        Element e = response.addElement(MailConstants.E_BROWSE_DATA).setText(term.getText());
        e.addAttribute(MailConstants.A_FREQUENCY, term.getFreq());
      }
    }
    return response;
  }
Beispiel #2
0
 static void doCos(Account acct, Element response) throws ServiceException {
   Cos cos = Provisioning.getInstance().getCOS(acct);
   if (cos != null) {
     Element eCos = response.addUniqueElement(AdminConstants.E_COS);
     eCos.addAttribute(AdminConstants.A_ID, cos.getId());
     eCos.addAttribute(AdminConstants.A_NAME, cos.getName());
   }
 }
Beispiel #3
0
 /**
  * Add remote tags attribute corresponding to list of local tags
  *
  * @throws ServiceException
  */
 public Element addOutboundTagsAttr(Element req, String tagStr) throws ServiceException {
   if (mappingRequired) {
     req.addAttribute(MailConstants.A_TAGS, remoteAttrFromTags(tagStr));
   } else {
     req.addAttribute(MailConstants.A_TAGS, tagStr);
   }
   return req;
 }
 void toElement(Element element) throws ServiceException {
   super.toElement(element);
   for (String name : mRejectFrom) {
     Element fromEl = element.addElement(VoiceConstants.E_PHONE);
     fromEl.addAttribute(VoiceConstants.A_PHONE_NUMBER, name);
     fromEl.addAttribute(VoiceConstants.A_ACTIVE, "true");
   }
 }
Beispiel #5
0
 @Override
 Element toElement(Element parent) {
   Element test = parent.addElement(MailConstants.E_CURRENT_DAY_OF_WEEK_TEST);
   test.addAttribute(MailConstants.A_VALUE, days);
   if (op == SimpleOp.NOT_IS) {
     test.addAttribute(MailConstants.A_NEGATIVE, true);
   }
   return test;
 }
Beispiel #6
0
 @Override
 Element toElement(Element parent) {
   Element test = parent.addElement(MailConstants.E_HEADER_EXISTS_TEST);
   test.addAttribute(MailConstants.A_HEADER, mHeaderName);
   if (!mExists) {
     test.addAttribute(MailConstants.A_NEGATIVE, true);
   }
   return test;
 }
Beispiel #7
0
 @Override
 Element toElement(Element parent) {
   Element test = parent.addElement(MailConstants.E_ADDRESS_BOOK_TEST);
   test.addAttribute(MailConstants.A_HEADER, mHeader);
   test.addAttribute(MailConstants.A_FOLDER_PATH, "contacts");
   if (mAddressBookOp == AddressBookOp.NOT_IN) {
     test.addAttribute(MailConstants.A_NEGATIVE, true);
   }
   return test;
 }
Beispiel #8
0
 @Override
 Element toElement(Element parent) {
   Element test = parent.addElement(MailConstants.E_CURRENT_TIME_TEST);
   test.addAttribute(MailConstants.A_DATE_COMPARISON, dateOp.toDateComparison().toString());
   if (dateOp.isNegative()) {
     test.addAttribute(MailConstants.A_NEGATIVE, true);
   }
   test.addAttribute(MailConstants.A_TIME, timeStr);
   return test;
 }
Beispiel #9
0
 @Override
 Element toElement(Element parent) {
   Element test = parent.addElement(MailConstants.E_DATE_TEST);
   test.addAttribute(MailConstants.A_DATE_COMPARISON, mDateOp.toDateComparison().toString());
   if (mDateOp.isNegative()) {
     test.addAttribute(MailConstants.A_NEGATIVE, true);
   }
   test.addAttribute(MailConstants.A_DATE, mDate.getTime() / 1000);
   return test;
 }
Beispiel #10
0
 @Override
 Element toElement(Element parent) {
   Element test = parent.addElement(MailConstants.E_SIZE_TEST);
   test.addAttribute(MailConstants.A_NUMBER_COMPARISON, mSizeOp.toNumberComparison().toString());
   if (mSizeOp.isNegative()) {
     test.addAttribute(MailConstants.A_NEGATIVE, true);
   }
   test.addAttribute(MailConstants.A_SIZE, mSize);
   return test;
 }
Beispiel #11
0
 void toElement(Element element) throws ServiceException {
   element.addAttribute(VoiceConstants.A_SUBSCRIBED, true);
   element.addAttribute(VoiceConstants.A_ACTIVE, mIsActive);
   for (String key : mData.keySet()) {
     Element subEl = element.addElement(key);
     String value = mData.get(key);
     if (value != null) {
       subEl.setText(value);
     }
   }
 }
Beispiel #12
0
 public void writeResponse(Element resp) {
   for (Map.Entry<String, Status> entry : mStatus.entrySet()) {
     Element progress = resp.addElement(AdminConstants.E_PROGRESS);
     progress.addAttribute(AdminConstants.A_SERVER, entry.getKey());
     progress.addAttribute(AdminConstants.A_STATUS, entry.getValue().value);
     Exception e = entry.getValue().error;
     if (e != null) {
       progress.addAttribute(AdminConstants.A_ERROR, e.getMessage());
     }
   }
 }
Beispiel #13
0
 @Override
 Element toElement(Element parent) {
   Element test = parent.addElement(MailConstants.E_BODY_TEST);
   if (caseSensitive) test.addAttribute(MailConstants.A_CASE_SENSITIVE, caseSensitive);
   if (!StringUtil.isNullOrEmpty(text)) {
     test.addAttribute(MailConstants.A_VALUE, text);
   }
   if (bodyOp == BodyOp.NOT_CONTAINS) {
     test.addAttribute(MailConstants.A_NEGATIVE, true);
   }
   return test;
 }
Beispiel #14
0
 /**
  * Add the appropriate tags attribute depending on direction of request and remote version
  *
  * @throws ServiceException
  */
 public Element addTagsAttr(Element req, Element resp, boolean outbound) throws ServiceException {
   if (outbound) {
     req = addOutboundTagsAttr(req, resp.getAttribute(MailConstants.A_TAGS, ""));
   } else {
     if (mappingRequired) {
       req.addAttribute(MailConstants.A_TAGS, localTagsFromElement(resp, ""));
     } else {
       req.addAttribute(MailConstants.A_TAGS, resp.getAttribute(MailConstants.A_TAGS, ""));
     }
   }
   return req;
 }
 /** Done like this rather than using JAXB for performance reasons */
 public Element toElement(Element parent) {
   Element mel =
       parent.addNonUniqueElement(MailConstants.E_MSG).addAttribute(MailConstants.A_ID, id);
   if (size != null) {
     mel.addAttribute(MailConstants.A_SIZE, size);
   }
   if (folderId != null) {
     mel.addAttribute(MailConstants.A_FOLDER, folderId);
   }
   if (autoSendTime != null) {
     mel.addAttribute(MailConstants.A_AUTO_SEND_TIME, autoSendTime);
   }
   return mel;
 }
Beispiel #16
0
  public static void encodeServer(
      Element e,
      Server s,
      boolean applyConfig,
      Set<String> reqAttrs,
      AttrRightChecker attrRightChecker)
      throws ServiceException {
    Element server = e.addElement(AdminConstants.E_SERVER);
    server.addAttribute(AdminConstants.A_NAME, s.getName());
    server.addAttribute(AdminConstants.A_ID, s.getId());
    Map<String, Object> attrs = s.getUnicodeAttrs(applyConfig);

    ToXML.encodeAttrs(server, attrs, reqAttrs, attrRightChecker);
  }
  private void doit(ZAuthToken zat, String[] accts, boolean sync)
      throws SoapFaultException, IOException, ServiceException {
    Element req = new Element.XMLElement(AdminConstants.FIX_CALENDAR_PRIORITY_REQUEST);
    if (accts == null || accts.length == 0)
      throw ServiceException.INVALID_REQUEST("Missing -" + O_ACCOUNT + " option", null);
    for (String acct : accts) {
      Element acctElem = req.addElement(AdminConstants.E_ACCOUNT);
      acctElem.addAttribute(AdminConstants.A_NAME, acct);
    }
    if (sync) req.addAttribute(AdminConstants.A_TZFIXUP_SYNC, true);

    auth(zat);
    getTransport().invokeWithoutSession(req);
  }
Beispiel #18
0
 @Override
 Element toElement(Element parent) {
   Element test = parent.addElement(MailConstants.E_MIME_HEADER_TEST);
   test.addAttribute(MailConstants.A_HEADER, headerName);
   test.addAttribute(
       MailConstants.A_STRING_COMPARISON, headerOp.toStringComparison().toString());
   if (caseSensitive) test.addAttribute(MailConstants.A_CASE_SENSITIVE, caseSensitive);
   if (headerOp.isNegative()) {
     test.addAttribute(MailConstants.A_NEGATIVE, true);
   }
   if (!StringUtil.isNullOrEmpty(value)) {
     test.addAttribute(MailConstants.A_VALUE, value);
   }
   return test;
 }
Beispiel #19
0
  @Override
  public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Mailbox mbox = getRequestedMailbox(zsc);
    OperationContext octxt = getOperationContext(zsc, context);
    ItemIdFormatter ifmt = new ItemIdFormatter(zsc);

    Element meta = request.getElement(MailConstants.E_METADATA);
    String section = meta.getAttribute(MailConstants.A_SECTION);
    section = section.trim();
    if (section.length() == 0 || section.length() > 36)
      throw ServiceException.INVALID_REQUEST(
          "invalid length for custom metadata section name", null);

    CustomMetadata custom = new CustomMetadata(section);
    for (Element.KeyValuePair kvp : meta.listKeyValuePairs())
      custom.put(kvp.getKey(), kvp.getValue());

    ItemId iid = new ItemId(request.getAttribute(MailConstants.A_ID), zsc);
    mbox.setCustomData(octxt, iid.getId(), MailItem.Type.UNKNOWN, custom);

    Element response = zsc.createElement(MailConstants.SET_METADATA_RESPONSE);
    response.addAttribute(MailConstants.A_ID, ifmt.formatItemId(iid));
    return response;
  }
Beispiel #20
0
 public void reload(SoapProvisioning prov) throws ServiceException {
   XMLElement req = new XMLElement(AdminConstants.GET_DOMAIN_REQUEST);
   Element a = req.addElement(AdminConstants.E_DOMAIN);
   a.setText(getId());
   a.addAttribute(AdminConstants.A_BY, Key.DomainBy.id.name());
   setAttrs(SoapProvisioning.getAttrs(prov.invoke(req).getElement(AdminConstants.E_DOMAIN)));
 }
Beispiel #21
0
 private static void addAttr(Element response, String name, String value) {
   if (value != null && !value.equals("")) {
     Element e = response.addElement(AdminConstants.E_A);
     e.addAttribute(AdminConstants.A_N, name);
     e.setText(value);
   }
 }
Beispiel #22
0
  private List<Appointement> getSortedRdv() {
    try {
      client = ZMailbox.getByName(login, pass, "https://zimbra.inria.fr/service/soap/");
      XMLElement req = new XMLElement(ZimbraNamespace.E_BATCH_REQUEST);
      Element gas = req.addElement(MailConstants.GET_APPT_SUMMARIES_REQUEST);

      Calendar cal = Calendar.getInstance();
      Date today = cal.getTime();
      //		cal.add(Calendar.HOUR, -1); // to get previous year add -1
      gas.addAttribute(MailConstants.A_CAL_START_TIME, today.getTime());

      cal.add(Calendar.MONTH, 1); // to get previous year add -1
      Date nextYear = cal.getTime();

      gas.addAttribute(MailConstants.A_CAL_END_TIME, nextYear.getTime());
      gas.addAttribute(MailConstants.A_FOLDER, zimbraFolderId);
      Element resp = client.invoke(req);
      List<Appointement> lists = new ArrayList<Appointement>();

      for (Element e : resp.listElements()) {
        for (Element appt : e.listElements(MailConstants.E_APPOINTMENT)) {
          Appointement a = new Appointement();
          a.setLabel("" + appt.toXML().attribute("name").getData());
          a.setLocation("" + appt.toXML().attribute("loc").getData());
          String duration = "" + appt.toXML().attribute("d").getData();
          a.setDuration(Long.parseLong(duration) / 1000);
          ZDateTime dated =
              new ZDateTime("" + appt.toXML().element("inst").attribute("ridZ").getData());
          a.setDate(dated.getDate());
          lists.add(a);
        }
      }
      Collections.sort(
          lists,
          new Comparator<Appointement>() {

            public int compare(Appointement appt1, Appointement appt2) {
              return appt1.getDate().compareTo(appt2.getDate());
            }
          });

      return lists;
    } catch (ServiceException e) {
      e.printStackTrace();
    }
    return new ArrayList<Appointement>();
  }
Beispiel #23
0
 @Override
 Element toElement(Element parent) {
   Element test = parent.addElement(MailConstants.E_ATTACHMENT_TEST);
   if (!mExists) {
     test.addAttribute(MailConstants.A_NEGATIVE, true);
   }
   return test;
 }
  @Override
  public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Mailbox mbox = getRequestedMailbox(zsc);
    OperationContext octxt = getOperationContext(zsc, context);
    ItemIdFormatter ifmt = new ItemIdFormatter(zsc);

    Element doc = request.getElement(MailConstants.E_DOC);
    String id = doc.getAttribute(MailConstants.A_ID);
    int version = (int) doc.getAttributeLong(MailConstants.A_VERSION, -1);
    int count = (int) doc.getAttributeLong(MailConstants.A_COUNT, 1);

    Element response = zsc.createElement(MailConstants.LIST_DOCUMENT_REVISIONS_RESPONSE);

    Document item;

    ItemId iid = new ItemId(id, zsc);
    item = mbox.getDocumentById(octxt, iid.getId());

    if (version < 0) {
      version = item.getVersion();
    }
    MailItem.Type type = item.getType();
    HashSet<Account> accounts = new HashSet<Account>();
    Provisioning prov = Provisioning.getInstance();
    while (version > 0 && count > 0) {
      item = (Document) mbox.getItemRevision(octxt, iid.getId(), type, version);
      if (item != null) {
        ToXML.encodeDocument(response, ifmt, octxt, item);
        Account a = prov.getAccountByName(item.getCreator());
        if (a != null) accounts.add(a);
      }
      version--;
      count--;
    }
    for (Account a : accounts) {
      Element user = response.addElement(MailConstants.A_USER);
      user.addAttribute(MailConstants.A_ID, a.getId());
      user.addAttribute(MailConstants.A_EMAIL, a.getName());
      user.addAttribute(MailConstants.A_NAME, a.getDisplayName());
    }

    return response;
  }
Beispiel #25
0
 public Element handle(Element request, Map<String, Object> context) throws ServiceException {
   HttpServletRequest servletRequest =
       (HttpServletRequest) context.get(SoapServlet.SERVLET_REQUEST);
   boolean isResumed = !ContinuationSupport.getContinuation(servletRequest).isInitial();
   if (!isResumed) {
     OfflineSyncManager.getInstance().clientPing();
   }
   boolean wait = request.getAttributeBool(MailConstants.A_WAIT, false);
   long start = System.currentTimeMillis();
   if (!isResumed) {
     servletRequest.setAttribute(TIME_KEY, start);
   }
   Element response = super.handle(request, context);
   response.addAttribute(MailConstants.A_WAIT, wait);
   response.addAttribute(
       MailConstants.A_TIME,
       System.currentTimeMillis() - (Long) servletRequest.getAttribute(TIME_KEY));
   return response;
 }
  public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    if (!AccessControlUtil.isGlobalAdmin(getAuthenticatedAccount(zsc))) {
      throw ServiceException.PERM_DENIED("only global admin is allowed");
    }

    Map<String, Long> domainAggrQuotaUsed = new HashMap<String, Long>();

    SearchAccountsOptions searchOpts = new SearchAccountsOptions();
    searchOpts.setIncludeType(IncludeType.ACCOUNTS_ONLY);
    searchOpts.setMakeObjectOpt(MakeObjectOpt.NO_DEFAULTS);

    Provisioning prov = Provisioning.getInstance();
    List<NamedEntry> accounts = prov.searchAccountsOnServer(prov.getLocalServer(), searchOpts);
    Map<String, Long> acctQuotaUsed = MailboxManager.getInstance().getMailboxSizes(accounts);
    for (NamedEntry ne : accounts) {
      if (!(ne instanceof Account)) {
        continue;
      }
      Account acct = (Account) ne;
      Long acctQuota = acctQuotaUsed.get(acct.getId());
      if (acctQuota == null) {
        acctQuota = 0L;
      }
      String domainId = acct.getDomainId();
      if (domainId == null) {
        continue;
      }
      Long aggrQuota = domainAggrQuotaUsed.get(domainId);
      domainAggrQuotaUsed.put(domainId, aggrQuota == null ? acctQuota : aggrQuota + acctQuota);
    }

    Element response = zsc.createElement(AdminConstants.GET_AGGR_QUOTA_USAGE_ON_SERVER_RESPONSE);
    for (String domainId : domainAggrQuotaUsed.keySet()) {
      Domain domain = prov.getDomainById(domainId);
      Element domainElt = response.addElement(AdminConstants.E_DOMAIN);
      domainElt.addAttribute(AdminConstants.A_NAME, domain.getName());
      domainElt.addAttribute(AdminConstants.A_ID, domainId);
      domainElt.addAttribute(AdminConstants.A_QUOTA_USED, domainAggrQuotaUsed.get(domainId));
    }
    return response;
  }
Beispiel #27
0
 @Override
 Element toElement(Element parent) {
   Element test = parent.addElement(MailConstants.E_INVITE_TEST);
   if (!mIsInvite) {
     test.addAttribute(MailConstants.A_NEGATIVE, true);
   }
   for (String method : mMethods) {
     test.addElement(MailConstants.E_METHOD).setText(method);
   }
   return test;
 }
Beispiel #28
0
  /**
   * Authenticates using the username and password from the local config.
   *
   * @throws IOException
   * @throws com.zimbra.common.soap.SoapFaultException
   * @throws ServiceException
   */
  protected LmcSession auth() throws SoapFaultException, IOException, ServiceException {
    URL url = new URL("https", mHost, mPort, AdminConstants.ADMIN_SERVICE_URI);
    mServerUrl = url.toExternalForm();
    SoapTransport trans = getTransport();
    mAuth = false;

    Element authReq = new Element.XMLElement(AdminConstants.AUTH_REQUEST);
    authReq.addAttribute(AdminConstants.E_NAME, mUser, Element.Disposition.CONTENT);
    authReq.addAttribute(AdminConstants.E_PASSWORD, mPassword, Element.Disposition.CONTENT);
    try {
      Element authResp = trans.invokeWithoutSession(authReq);
      String authToken = authResp.getAttribute(AdminConstants.E_AUTH_TOKEN);
      ZAuthToken zat = new ZAuthToken(null, authToken, null);
      trans.setAuthToken(authToken);
      mAuth = true;
      return new LmcSession(zat, null);
    } catch (UnknownHostException e) {
      // UnknownHostException's error message is not clear; rethrow with a more descriptive message
      throw new IOException("Unknown host: " + mHost);
    }
  }
Beispiel #29
0
  private void putHits(
      ZimbraSoapContext zsc,
      OperationContext octxt,
      Element el,
      ZimbraQueryResults results,
      SearchParams params)
      throws ServiceException {

    if (params.getInlineRule() == ExpandResults.HITS) {
      // "hits" is not a valid value for Search...
      params.setInlineRule(ExpandResults.NONE);
    }

    ResultsPager pager = ResultsPager.create(results, params);
    if (params.getCursor() != null) {
      if (params.getCursor().isIncludeOffset()) {
        long offset = pager.getCursorOffset();
        if (offset >= 0) {
          el.addAttribute(MailConstants.A_QUERY_OFFSET, offset);
        }
      }
    } else {
      el.addAttribute(MailConstants.A_QUERY_OFFSET, params.getOffset());
    }

    SearchResponse resp = new SearchResponse(zsc, octxt, el, params);
    resp.setIncludeMailbox(false);
    resp.setSortOrder(pager.getSortOrder());

    while (pager.hasNext() && resp.size() < params.getLimit()) {
      ZimbraHit hit = pager.getNextHit();
      resp.add(hit);
    }

    resp.addHasMore(pager.hasNext());
    resp.add(results.getResultInfo());
  }
Beispiel #30
0
  public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);

    Element a = request.getElement(AdminConstants.E_ACCOUNT);
    String key = a.getAttribute(AdminConstants.A_BY);
    String value = a.getText();

    long lifetime =
        request.getAttributeLong(AdminConstants.A_DURATION, DEFAULT_AUTH_LIFETIME) * 1000;

    Provisioning prov = Provisioning.getInstance();

    Account account = null;

    if (key.equals(BY_NAME)) {
      account = prov.get(AccountBy.name, value, zsc.getAuthToken());
    } else if (key.equals(BY_ID)) {
      account = prov.get(AccountBy.id, value, zsc.getAuthToken());
    } else {
      throw ServiceException.INVALID_REQUEST("unknown value for by: " + key, null);
    }

    if (account == null) throw AccountServiceException.NO_SUCH_ACCOUNT(value);

    checkAdminLoginAsRight(zsc, prov, account);

    ZimbraLog.security.info(
        ZimbraLog.encodeAttrs(
            new String[] {
              "cmd", "DelegateAuth", "accountId", account.getId(), "accountName", account.getName()
            }));

    Element response = zsc.createElement(AdminConstants.DELEGATE_AUTH_RESPONSE);
    long maxLifetime =
        account.getTimeInterval(
            Provisioning.A_zimbraAuthTokenLifetime, DEFAULT_AUTH_LIFETIME * 1000);

    // take the min of requested lifetime vs maxLifetime
    long expires = System.currentTimeMillis() + Math.min(lifetime, maxLifetime);
    String token;
    Account adminAcct = prov.get(AccountBy.id, zsc.getAuthtokenAccountId(), zsc.getAuthToken());
    if (adminAcct == null)
      throw AccountServiceException.NO_SUCH_ACCOUNT(zsc.getAuthtokenAccountId());

    AuthToken at = AuthProvider.getAuthToken(account, expires, false, adminAcct);
    at.encodeAuthResp(response, true);
    response.addAttribute(AdminConstants.E_LIFETIME, lifetime, Element.Disposition.CONTENT);
    return response;
  }