public void doTag() throws JspException, IOException {
   JspContext jctxt = getJspContext();
   try {
     ZMailbox mbox = getMailbox();
     ZContact group = mbox.getContact(id);
     if (json) {
       JSONArray jsonArray = new JSONArray();
       Map<String, ZContact> members = group.getMembers();
       for (ZContact contact : members.values()) {
         Map<String, String> attrs = contact.getAttrs();
         String addr = attrs.get("email");
         if (addr != null) {
           jsonArray.put(addr);
         }
       }
       JSONObject top = new JSONObject();
       top.put("Result", jsonArray);
       top.write(jctxt.getOut());
     }
   } catch (JSONException e) {
     throw new JspTagException(e);
   } catch (ServiceException e) {
     throw new JspTagException(e);
   }
 }
 public void doTag() throws JspException, IOException {
   try {
     ZMailbox mbox = getMailbox();
     ZMailbox.ZActionResult result = mbox.markVoiceMailHeard(mPhone, mId, mHeard);
     getJspContext().setAttribute(mVar, new ZActionResultBean(result), PageContext.PAGE_SCOPE);
   } catch (ServiceException e) {
     throw new JspTagException(e);
   }
 }
示例#3
0
  /**
   * Sends a message with the specified attachment, waits for the message to arrives, and runs a
   * query.
   *
   * @param subject the subject of the message
   * @param attData attachment data
   * @param attName attachment name
   * @param attContentType attachment content type
   * @param query query to run after message arrives
   * @return <tt>true</tt> if the query returns the message
   */
  private ZMessage sendMessage(
      String subject, byte[] attData, String attName, String attContentType) throws Exception {

    // Send message
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    String attachmentId = mbox.uploadAttachment(attName, attData, attContentType, 5000);
    TestUtil.sendMessage(mbox, USER_NAME, subject, "Cranberry sauce", attachmentId);
    String query = "in:inbox subject:\"" + subject + "\"";
    return TestUtil.waitForMessage(mbox, query);
  }
  public void doTag() throws JspException, IOException {
    JspContext jctxt = getJspContext();
    try {
      ZMailbox mbox = mMailbox != null ? mMailbox.getMailbox() : getMailbox();

      List<ZAppointmentHit> appts;
      if (mFolderId == null || mFolderId.length() == 0) {
        // if non are checked, return no appointments (to match behavior of ajax client
        appts = new ArrayList<ZAppointmentHit>();
      } else if (mFolderId.indexOf(',') == -1) {
        List<ZApptSummaryResult> result =
            mbox.getApptSummaries(
                mQuery,
                mStart,
                mEnd,
                new String[] {mFolderId},
                mTimeZone,
                ZSearchParams.TYPE_APPOINTMENT);
        // appts = mbox.getApptSummaries(mStart, mEnd, mFolderId);
        if (result.size() != 1) {
          appts = new ArrayList<ZAppointmentHit>();
          for (ZApptSummaryResult r : result) {
            appts.addAll(r.getAppointments());
          }
        } else {
          ZApptSummaryResult asr = result.get(0);
          appts = asr.getAppointments();
        }
      } else {
        appts = new ArrayList<ZAppointmentHit>();
        List<ZApptSummaryResult> result =
            mbox.getApptSummaries(
                mQuery,
                mStart,
                mEnd,
                mFolderId.split(","),
                mTimeZone,
                ZSearchParams.TYPE_APPOINTMENT);
        for (ZApptSummaryResult sum : result) {
          appts.addAll(sum.getAppointments());
        }
      }
      jctxt.setAttribute(mVar, new ZApptSummariesBean(appts), PageContext.PAGE_SCOPE);

    } catch (ServiceException e) {
      if (mVarException != null) {
        jctxt.setAttribute(mVarException, e, PageContext.PAGE_SCOPE);
        jctxt.setAttribute(
            mVar, new ZApptSummariesBean(new ArrayList<ZAppointmentHit>()), PageContext.PAGE_SCOPE);
      } else {
        throw new JspTagException(e);
      }
    }
  }
 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());
 }
示例#6
0
  private static void searchRemoteAccountCalendars(
      Element parent,
      SearchParams params,
      ZimbraSoapContext zsc,
      Account authAcct,
      Map<String, List<Integer>> accountFolders)
      throws ServiceException {
    String nominalTargetAcctId = null; // mail service soap requests want to see a target account
    StringBuilder queryStr = new StringBuilder();
    for (Map.Entry<String, List<Integer>> entry : accountFolders.entrySet()) {
      String acctId = entry.getKey();
      if (nominalTargetAcctId == null) nominalTargetAcctId = acctId;
      ItemIdFormatter ifmt = new ItemIdFormatter(authAcct.getId(), acctId, false);
      List<Integer> folderIds = entry.getValue();
      for (int folderId : folderIds) {
        if (queryStr.length() > 0) queryStr.append(" OR ");
        // must quote the qualified folder id
        queryStr.append("inid:\"").append(ifmt.formatItemId(folderId)).append("\"");
      }
    }
    Element req = zsc.createElement(MailConstants.SEARCH_REQUEST);
    req.addAttribute(MailConstants.A_SEARCH_TYPES, MailItem.Type.toString(params.getTypes()));
    if (params.getSortBy() != null) {
      req.addAttribute(MailConstants.A_SORTBY, params.getSortBy().toString());
    }
    req.addAttribute(MailConstants.A_QUERY_OFFSET, params.getOffset());
    if (params.getLimit() != 0) req.addAttribute(MailConstants.A_QUERY_LIMIT, params.getLimit());
    req.addAttribute(MailConstants.A_CAL_EXPAND_INST_START, params.getCalItemExpandStart());
    req.addAttribute(MailConstants.A_CAL_EXPAND_INST_END, params.getCalItemExpandEnd());
    req.addAttribute(MailConstants.E_QUERY, queryStr.toString(), Element.Disposition.CONTENT);

    Account target = Provisioning.getInstance().get(Key.AccountBy.id, nominalTargetAcctId);
    String pxyAuthToken = zsc.getAuthToken().getProxyAuthToken();
    ZAuthToken zat = pxyAuthToken == null ? zsc.getRawAuthToken() : new ZAuthToken(pxyAuthToken);
    ZMailbox.Options zoptions = new ZMailbox.Options(zat, AccountUtil.getSoapUri(target));
    zoptions.setTargetAccount(nominalTargetAcctId);
    zoptions.setTargetAccountBy(AccountBy.id);
    zoptions.setNoSession(true);
    ZMailbox zmbx = ZMailbox.getMailbox(zoptions);

    Element resp = zmbx.invoke(req);
    for (Element hit : resp.listElements()) {
      hit.detach();
      parent.addElement(hit);
    }
  }
 static ZMailbox getRemoteMailbox(ZAuthToken zat, String ownerId) throws ServiceException {
   Account target = Provisioning.getInstance().get(Key.AccountBy.id, ownerId);
   if (target == null) return null;
   ZMailbox.Options zoptions = new ZMailbox.Options(zat, AccountUtil.getSoapUri(target));
   zoptions.setNoSession(true);
   zoptions.setTargetAccount(ownerId);
   zoptions.setTargetAccountBy(Key.AccountBy.id);
   return ZMailbox.getMailbox(zoptions);
 }
 protected void getMountpointTarget(DavContext ctxt) throws ServiceException {
   ZAuthToken zat = AuthProvider.getAuthToken(ctxt.getAuthAccount()).toZAuthToken();
   ZMailbox zmbx = getRemoteMailbox(zat, mRemoteOwnerId);
   if (zmbx == null) return;
   ZFolder folder = zmbx.getFolder(new ItemId(mRemoteOwnerId, mRemoteId).toString(mOwnerId));
   if (folder == null) return;
   mCtag = CtagInfo.makeCtag(folder);
   setProperty(DavElements.E_GETCTAG, mCtag);
   mRights = ACL.stringToRights(folder.getEffectivePerms());
   addProperty(Acl.getCurrentUserPrivilegeSet(mRights));
   addProperty(Acl.getMountpointTargetPrivilegeSet(mRights));
   String targetUrl =
       UrlNamespace.getResourceUrl(
           Provisioning.getInstance().get(Key.AccountBy.id, mRemoteOwnerId),
           folder.getPath() + "/");
   ResourceProperty mp = new ResourceProperty(DavElements.E_MOUNTPOINT_TARGET_URL);
   mp.addChild(DavElements.E_HREF).setText(targetUrl);
   addProperty(mp);
 }
  public void doTag() throws JspException, IOException {
    JspFragment body = getJspBody();
    if (body == null) return;

    try {
      ZMailbox mbox = getMailbox();
      JspContext jctxt = getJspContext();
      ZFolder folder;
      if (mParentId != null) {
        folder = mbox.getFolderById(mParentId);
      } else if (mParentFolder != null) {
        folder = mParentFolder.folderObject();
      } else {
        folder = mbox.getUserRoot();
      }
      handleFolder(folder, body, jctxt, mSkipRoot, mSkipSystem);
    } catch (ServiceException e) {
      throw new JspTagException(e);
    }
  }