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

    Element mreq = request.getElement(AdminConstants.E_MAILBOX);
    String accountId = mreq.getAttribute(AdminConstants.A_ACCOUNTID);

    Provisioning prov = Provisioning.getInstance();
    Account account = prov.get(AccountBy.id, accountId, zsc.getAuthToken());
    if (account == null) {
      throw AccountServiceException.NO_SUCH_ACCOUNT(accountId);
    }
    checkAdminLoginAsRight(zsc, prov, account);

    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account, false);
    if (mbox == null) {
      throw MailServiceException.NO_SUCH_MBOX(accountId);
    }

    mbox.recalculateFolderAndTagCounts();

    Element response = zsc.createElement(AdminConstants.RECALCULATE_MAILBOX_COUNTS_RESPONSE);
    response
        .addElement(AdminConstants.E_MAILBOX)
        .addAttribute(AdminConstants.A_ACCOUNTID, accountId)
        .addAttribute(AdminConstants.A_QUOTA_USED, mbox.getSize());
    return response;
  }
Пример #2
0
 public RemoteCollection(DavContext ctxt, String path, Account user)
     throws DavException, ServiceException {
   super(path, user.getName());
   ZAuthToken zat = AuthProvider.getAuthToken(ctxt.getAuthAccount()).toZAuthToken();
   ZMailbox mbox = getRemoteMailbox(zat, user.getId());
   ZFolder folder = mbox.getFolderByPath(path);
   if (folder == null) throw MailServiceException.NO_SUCH_FOLDER(path);
   mOwnerId = user.getId();
   mId = new ItemId(folder.getId(), mOwnerId).getId();
   mPath = path;
   mSubject = folder.getName();
   type = MailItem.Type.FOLDER;
   ZFolder.View zview = folder.getDefaultView();
   if (zview != null) view = MailItem.Type.of(zview.name());
 }
Пример #3
0
  // Caller is responsible for filtering out Appointments/Tasks marked private if the requester
  // is not the mailbox owner.
  public Iterator<? extends MailItem> getMailItems(
      UserServletContext context, long startTime, long endTime, long chunkSize)
      throws ServiceException {
    if (context.requestedItems != null) {
      return context.getRequestedItems();
    }

    assert (context.target != null);
    String query = context.getQueryString();
    if (query != null) {
      if (context.target instanceof Folder) {
        Folder f = (Folder) context.target;
        if (f.getId() != Mailbox.ID_FOLDER_USER_ROOT) {
          query = "in:" + f.getPath() + " " + query;
        }
      }
      Set<MailItem.Type> types;
      if (context.getTypesString() == null) {
        types = getDefaultSearchTypes();
      } else {
        try {
          types = MailItem.Type.setOf(context.getTypesString());
        } catch (IllegalArgumentException e) {
          throw MailServiceException.INVALID_TYPE(e.getMessage());
        }
      }
      ZimbraQueryResults results =
          context.targetMailbox.index.search(
              context.opContext,
              query,
              types,
              SortBy.DATE_DESC,
              context.getOffset() + context.getLimit());
      return new QueryResultIterator(results);
    } else if (context.target instanceof Folder) {
      Collection<? extends MailItem> items =
          getMailItemsFromFolder(context, (Folder) context.target, startTime, endTime, chunkSize);
      return items != null ? items.iterator() : null;
    } else {
      ArrayList<MailItem> result = new ArrayList<MailItem>();
      result.add(context.target);
      return result.iterator();
    }
  }
Пример #4
0
  private void deploy(
      ZimbraSoapContext lc, String aid, ZAuthToken auth, boolean flushCache, boolean synchronous)
      throws ServiceException {
    Upload up = FileUploadServlet.fetchUpload(lc.getAuthtokenAccountId(), aid, lc.getAuthToken());
    if (up == null) throw MailServiceException.NO_SUCH_UPLOAD(aid);

    Progress pr = new Progress((auth != null));
    mProgressMap.put(aid, pr);
    Runnable action = new DeployThread(up, pr, auth, flushCache);
    Thread t = new Thread(action);
    t.start();
    if (synchronous) {
      try {
        t.join(DEPLOY_TIMEOUT);
      } catch (InterruptedException e) {
        ZimbraLog.zimlet.warn("error while deploying Zimlet", e);
      }
    }
  }
Пример #5
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);

    ExportContactsRequest req = JaxbUtil.elementToJaxb(request);
    String folder = req.getFolderId();
    ItemId iidFolder = folder == null ? null : new ItemId(folder, zsc);

    String ct = req.getContentType();
    if (ct == null) throw ServiceException.INVALID_REQUEST("content type missing", null);
    if (!ct.equals("csv"))
      throw ServiceException.INVALID_REQUEST("unsupported content type: " + ct, null);

    String format = req.getCsvFormat();
    String locale = req.getCsvLocale();
    String separator = req.getCsvDelimiter();
    Character sepChar = null;
    if ((separator != null) && (separator.length() > 0)) sepChar = separator.charAt(0);

    List<Contact> contacts = mbox.getContactList(octxt, iidFolder != null ? iidFolder.getId() : -1);

    StringBuilder sb = new StringBuilder();
    if (contacts == null) contacts = new ArrayList<Contact>();

    try {
      ContactCSV contactCSV = new ContactCSV(mbox, octxt);
      contactCSV.toCSV(format, locale, sepChar, contacts.iterator(), sb);
    } catch (ContactCSV.ParseException e) {
      throw MailServiceException.UNABLE_TO_EXPORT_CONTACTS(e.getMessage(), e);
    }

    ExportContactsResponse resp = new ExportContactsResponse(sb.toString());
    return zsc.jaxbToElement(resp);
  }
Пример #6
0
  @Override
  public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    if (true) throw WikiServiceException.ERROR("Deprecated");
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    OperationContext octxt = getOperationContext(zsc, context);

    Element msgElem = request.getElement(MailConstants.E_WIKIWORD);
    String subject = msgElem.getAttribute(MailConstants.A_NAME, null);
    String id = msgElem.getAttribute(MailConstants.A_ID, null);
    int ver = (int) msgElem.getAttributeLong(MailConstants.A_VERSION, 0);
    int itemId;
    if (id == null) {
      itemId = 0;
    } else {
      ItemId iid = new ItemId(id, zsc);
      itemId = iid.getId();
    }

    ItemId fid = getRequestedFolder(request, zsc);
    ByteArrayInputStream is = null;
    try {
      byte[] rawData = msgElem.getText().getBytes("UTF-8");
      is = new ByteArrayInputStream(rawData);
    } catch (IOException ioe) {
      throw ServiceException.FAILURE("can't get the content", ioe);
    }
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(zsc.getRequestedAccountId());
    Document wikiItem = null;
    WikiPage.WikiContext ctxt = new WikiPage.WikiContext(octxt, zsc.getAuthToken());
    if (itemId == 0) {
      // create a new page
      wikiItem =
          mbox.createDocument(
              octxt,
              fid.getId(),
              subject,
              WikiItem.WIKI_CONTENT_TYPE,
              getAuthor(zsc),
              null,
              true,
              is,
              MailItem.TYPE_WIKI);
    } else {
      // add a new revision
      WikiPage oldPage = WikiPage.findPage(ctxt, zsc.getRequestedAccountId(), itemId);
      if (oldPage == null)
        throw new WikiServiceException.NoSuchWikiException("page id=" + id + " not found");
      if (oldPage.getLastVersion() != ver) {
        throw MailServiceException.MODIFY_CONFLICT(
            new Argument(MailConstants.A_NAME, subject, Argument.Type.STR),
            new Argument(MailConstants.A_ID, oldPage.getId(), Argument.Type.IID),
            new Argument(MailConstants.A_VERSION, oldPage.getLastVersion(), Argument.Type.NUM));
      }
      wikiItem = mbox.addDocumentRevision(octxt, itemId, getAuthor(zsc), subject, null, true, is);
    }

    Element response = zsc.createElement(MailConstants.SAVE_WIKI_RESPONSE);
    Element m = response.addElement(MailConstants.E_WIKIWORD);
    m.addAttribute(MailConstants.A_ID, new ItemIdFormatter(zsc).formatItemId(wikiItem));
    m.addAttribute(MailConstants.A_VERSION, wikiItem.getVersion());
    return response;
  }