@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; }
@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; }
public ZAce(Element e) throws ServiceException { mRight = e.getAttribute(MailConstants.A_RIGHT); mDeny = e.getAttributeBool(MailConstants.A_DENY, false); mGranteeName = e.getAttribute(MailConstants.A_DISPLAY, null); mGranteeId = e.getAttribute(MailConstants.A_ZIMBRA_ID, null); mGranteeType = GranteeType.fromString(e.getAttribute(MailConstants.A_GRANT_TYPE)); mSecret = e.getAttribute(MailConstants.A_PASSWORD, null); }
SoapDomain(Element e, Provisioning prov) throws ServiceException { super( e.getAttribute(AdminConstants.A_NAME), e.getAttribute(AdminConstants.A_ID), SoapProvisioning.getAttrs(e), null, prov); }
/** * 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; }
private static void parseComponentIncludeExcludeAttrs(Element backupElem, BackupParams params) throws ServiceException { Server server = Provisioning.getInstance().getLocalServer(); boolean confSkipSearchIndex = server.isBackupSkipSearchIndex(); boolean confSkipBlobs = server.isBackupSkipBlobs(); boolean confSkipSecondaryBlobs = server.isBackupSkipHsmBlobs(); String choice = backupElem.getAttribute("searchIndex", null); params.skipSearchIndex = parseIncludeExcludeAttr(choice, confSkipSearchIndex); choice = backupElem.getAttribute("blobs", null); params.skipBlobs = parseIncludeExcludeAttr(choice, confSkipBlobs); choice = backupElem.getAttribute("secondaryBlobs", null); params.skipSecondaryBlobs = parseIncludeExcludeAttr(choice, confSkipSecondaryBlobs); }
@Override public Element handle(Element request, Map<String, Object> context) throws ServiceException { ZimbraSoapContext zsc = getZimbraSoapContext(context); String action = request.getAttribute(AdminConstants.A_ACTION).toLowerCase(); Element content = request.getElement(MailConstants.E_CONTENT); String aid = content.getAttribute(MailConstants.A_ATTACHMENT_ID, null); boolean flushCache = request.getAttributeBool(AdminConstants.A_FLUSH, false); boolean synchronous = request.getAttributeBool(AdminConstants.A_SYNCHRONOUS, false); if (action.equals(AdminConstants.A_STATUS)) { // just print the status } else if (action.equals(AdminConstants.A_DEPLOYALL)) { for (Server server : Provisioning.getInstance().getAllServers()) { checkRight(zsc, context, server, Admin.R_deployZimlet); } deploy(zsc, aid, zsc.getRawAuthToken(), flushCache, synchronous); if (flushCache) { if (ZimbraLog.misc.isDebugEnabled()) { ZimbraLog.misc.debug("DeployZimlet: flushing zimlet cache"); } checkRight(zsc, context, Provisioning.getInstance().getLocalServer(), Admin.R_flushCache); FlushCache.sendFlushRequest(context, "/service", "/zimlet/res/all.js"); } } else if (action.equals(AdminConstants.A_DEPLOYLOCAL)) { Server localServer = Provisioning.getInstance().getLocalServer(); checkRight(zsc, context, localServer, Admin.R_deployZimlet); deploy(zsc, aid, null, false, synchronous); if (flushCache) { if (ZimbraLog.misc.isDebugEnabled()) { ZimbraLog.misc.debug("DeployZimlet: flushing zimlet cache"); } checkRight(zsc, context, localServer, Admin.R_flushCache); FlushCache.sendFlushRequest(context, "/service", "/zimlet/res/all.js"); } } else { throw ServiceException.INVALID_REQUEST("invalid action " + action, null); } Element response = zsc.createElement(AdminConstants.DEPLOY_ZIMLET_RESPONSE); Progress progress = (Progress) mProgressMap.get(aid); if (progress != null) progress.writeResponse(response); return response; }
/** * Returns comma-separated list of tag ids from element. If the remote server is less than 8.0 * this is read directly from 't' attribute If the remote server is 8.0 or greater this is mapped * from 'tn' attribute to local ids * * @param elt * @param mbox * @throws ServiceException */ public String localTagsFromElement(Element elt, String defaultVal) throws ServiceException { String tags = elt.getAttribute(MailConstants.A_TAGS, defaultVal); if (mappingRequired) { tags = localTagsFromRemote(tags); } return tags; }
/* (non-Javadoc) * @see com.zimbra.soap.DocumentHandler#handle(org.dom4j.Element, java.util.Map) */ 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(); Provisioning prov = Provisioning.getInstance(); Account account = prov.get(AccountBy.fromString(key), value, zsc.getAuthToken()); if (account == null) throw AccountServiceException.NO_SUCH_ACCOUNT(value); if (account.isCalendarResource()) { // need a CalendarResource instance for RightChecker CalendarResource resource = prov.get(CalendarResourceBy.id, account.getId()); checkCalendarResourceRight(zsc, resource, Admin.R_getCalendarResourceInfo); } else checkAccountRight(zsc, account, Admin.R_getAccountInfo); Element response = zsc.createElement(AdminConstants.GET_ACCOUNT_INFO_RESPONSE); response.addElement(AdminConstants.E_NAME).setText(account.getName()); addAttr(response, Provisioning.A_zimbraId, account.getId()); addAttr( response, Provisioning.A_zimbraMailHost, account.getAttr(Provisioning.A_zimbraMailHost)); doCos(account, response); addUrls(response, account); return response; }
public Element handle(Element request, Map<String, Object> context) throws ServiceException { ZimbraSoapContext zsc = getZimbraSoapContext(context); Provisioning prov = Provisioning.getInstance(); String id = request.getAttribute(AdminConstants.E_ID); DistributionList distributionList = prov.get(DistributionListBy.id, id); if (distributionList == null) throw AccountServiceException.NO_SUCH_DISTRIBUTION_LIST(id); checkDistributionListRight(zsc, distributionList, Admin.R_deleteDistributionList); prov.deleteDistributionList(distributionList.getId()); ZimbraLog.security.info( ZimbraLog.encodeAttrs( new String[] { "cmd", "DeleteDistributionList", "name", distributionList.getName(), "id", distributionList.getId() })); Element response = zsc.createElement(AdminConstants.DELETE_DISTRIBUTION_LIST_RESPONSE); return response; }
private void parseServerExtension(Element serverExt) throws ZimletException { assert (serverExt.getName().equals(ZIMLET_TAG_SERVER_EXTENSION)); String val = serverExt.getAttribute(ZIMLET_ATTR_HAS_KEYWORD, ""); if (val.length() > 0) { mKeyword = val; } val = serverExt.getAttribute(ZIMLET_ATTR_EXTENSION_CLASS, ""); if (val.length() > 0) { mExtensionClass = val; } val = serverExt.getAttribute(ZIMLET_ATTR_REGEX, ""); if (val.length() > 0) { mExtensionClass = ZIMLET_REGEX_EXTENSION_CLASS; mRegexString = val; } }
synchronized void fromElement(Element element) throws ServiceException { super.fromElement(element); mRejectFrom = new ArrayList<String>(); for (Element fromEl : element.listElements(VoiceConstants.E_PHONE)) { mRejectFrom.add(fromEl.getAttribute(VoiceConstants.A_PHONE_NUMBER)); } }
public Element handle(Element request, Map<String, Object> context) throws ServiceException { ZimbraSoapContext zsc = getZimbraSoapContext(context); Provisioning prov = Provisioning.getInstance(); boolean applyConfig = request.getAttributeBool(AdminConstants.A_APPLY_CONFIG, true); Set<String> reqAttrs = getReqAttrs(request, AttributeClass.server); Element d = request.getElement(AdminConstants.E_SERVER); String method = d.getAttribute(AdminConstants.A_BY); String name = d.getText(); if (name == null || name.equals("")) throw ServiceException.INVALID_REQUEST("must specify a value for a server", null); Server server = prov.get(ServerBy.fromString(method), name); if (server == null) throw AccountServiceException.NO_SUCH_SERVER(name); AdminAccessControl aac = checkRight(zsc, context, server, AdminRight.PR_ALWAYS_ALLOW); // reload the server prov.reload(server); Element response = zsc.createElement(AdminConstants.GET_SERVER_RESPONSE); encodeServer(response, server, applyConfig, reqAttrs, aac.getAttrRightChecker(server)); return response; }
public Element handle(Element request, Map<String, Object> context) throws ServiceException { ZimbraSoapContext zsc = getZimbraSoapContext(context); Provisioning prov = Provisioning.getInstance(); String id = request.getAttribute(AdminConstants.E_ID); Domain domain = prov.get(DomainBy.id, id); if (domain == null) throw AccountServiceException.NO_SUCH_DOMAIN(id); if (domain.isShutdown()) throw ServiceException.PERM_DENIED( "can not access domain, domain is in " + domain.getDomainStatusAsString() + " status"); checkRight(zsc, context, domain, Admin.R_deleteDomain); String name = domain.getName(); prov.deleteDomain(id); ZimbraLog.security.info( ZimbraLog.encodeAttrs(new String[] {"cmd", "DeleteDomain", "name", name, "id", id})); Element response = zsc.createElement(AdminConstants.DELETE_DOMAIN_RESPONSE); return response; }
@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; }
Entry getTargetEntry(Provisioning prov, Element eTarget, TargetType targetType) throws ServiceException { TargetBy targetBy = TargetBy.fromString(eTarget.getAttribute(AdminConstants.A_BY)); String target = eTarget.getText(); return TargetType.lookupTarget(prov, targetType, targetBy, target); }
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 t = request.getElement(MailConstants.E_SEARCH); ItemId iid = new ItemId(t.getAttribute(MailConstants.A_ID), zsc); String query = t.getAttribute(MailConstants.A_QUERY); String types = t.getAttribute(MailConstants.A_SEARCH_TYPES, null); String sort = t.getAttribute(MailConstants.A_SORTBY, null); mbox.modifySearchFolder(octxt, iid.getId(), query, types, sort); SearchFolder search = mbox.getSearchFolderById(octxt, iid.getId()); Element response = zsc.createElement(MailConstants.MODIFY_SEARCH_FOLDER_RESPONSE); ToXML.encodeSearchFolder(response, ifmt, search); return response; }
NamedEntry getGranteeEntry(Provisioning prov, Element eGrantee, GranteeType granteeType) throws ServiceException { if (!granteeType.allowedForAdminRights()) throw ServiceException.INVALID_REQUEST( "unsupported grantee type: " + granteeType.getCode(), null); GranteeBy granteeBy = GranteeBy.fromString(eGrantee.getAttribute(AdminConstants.A_BY)); String grantee = eGrantee.getText(); return GranteeType.lookupGrantee(prov, granteeType, granteeBy, grantee); }
public static SignatureItem importFromSOAP(Element sig) throws HarnessException { if (sig == null) throw new HarnessException("Element cannot be null"); SignatureItem item = null; try { // Make sure we only have the <tag/> part Element t = ZimbraAccount.SoapClient.selectNode(sig, "//acct:signature"); if (t == null) throw new HarnessException("Element does not contain an <tag/> element"); // Create the object item = new SignatureItem(); // Set the ID item.setId(t.getAttribute("id", null)); // Set tag name item.setName(t.getAttribute("name", null)); Element contentBodyHtml = ZimbraAccount.SoapClient.selectNode(sig, "//acct:content[@type='text/html']"); Element contentBodyText = ZimbraAccount.SoapClient.selectNode(sig, "//acct:content[@type='text/plain']"); if (contentBodyHtml != null) { item.dBodyHtmlText = contentBodyHtml.getText().trim(); } else if (contentBodyText != null) { item.dBodyText = contentBodyText.getText().trim(); } return (item); } catch (Exception e) { throw new HarnessException("Could not parse GetMsgResponse: " + sig.prettyPrint(), e); } finally { if (item != null) logger.info(item.prettyPrint()); } }
public static TaskItem importFromSOAP(Element GetMsgResponse) throws HarnessException { if (GetMsgResponse == null) throw new HarnessException("Element cannot be null"); TaskItem task = null; try { // Make sure we only have the GetMsgResponse part Element getMsgResponse = ZimbraAccount.SoapClient.selectNode(GetMsgResponse, "//mail:GetMsgResponse"); if (getMsgResponse == null) throw new HarnessException("Element does not contain GetMsgResponse"); Element m = ZimbraAccount.SoapClient.selectNode(getMsgResponse, "//mail:comp"); if (m == null) throw new HarnessException("Element does not contain an m element"); // Create the object task = new TaskItem(); // Set task body task.settaskBody(m.getAttribute("desc", null)); // Set task name task.setName(m.getAttribute("name", null)); // Set task id task.setId(m.getAttribute("calItemId", null)); task.setHtmlTaskBody(m.getAttribute("descHtml", null)); // TODO: parse the <m/> element return (task); } catch (Exception e) { throw new HarnessException( "Could not parse GetMsgResponse: " + GetMsgResponse.prettyPrint(), e); } finally { if (task != null) logger.info(task.prettyPrint()); } }
public ZGrant(Element e) throws ServiceException { mPermissions = e.getAttribute(MailConstants.A_RIGHTS); mGranteeName = e.getAttribute(MailConstants.A_DISPLAY, null); mGranteeId = e.getAttribute(MailConstants.A_ZIMBRA_ID, null); mGranteeType = GranteeType.fromString(e.getAttribute(MailConstants.A_GRANT_TYPE)); if (mGranteeType == GranteeType.key) mArgs = e.getAttribute(MailConstants.A_ACCESSKEY, null); else mArgs = e.getAttribute(MailConstants.A_PASSWORD, null); }
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; }
@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); Account account = Provisioning.getInstance().get(AccountBy.id, accountId, zsc.getAuthToken()); if (account == null) { // Note: isDomainAdminOnly *always* returns false for pure ACL based AccessManager if (isDomainAdminOnly(zsc)) { throw ServiceException.PERM_DENIED( "account doesn't exist, unable to determine authorization"); } // still need to check right, since we don't have an account, the // last resort is checking the global grant. Do this for now until // there is complain. checkRight(zsc, context, null, Admin.R_deleteAccount); ZimbraLog.account.warn( "DeleteMailbox: account doesn't exist: " + accountId + " (still deleting mailbox)"); } else { checkAccountRight(zsc, account, Admin.R_deleteAccount); } Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(accountId, false); int mailboxId = -1; if (mbox != null) { mailboxId = mbox.getId(); mbox.deleteMailbox(); } String idString = (mbox == null) ? "<no mailbox for account " + accountId + ">" : Integer.toString(mailboxId); ZimbraLog.security.info( ZimbraLog.encodeAttrs(new String[] {"cmd", "DeleteMailbox", "id", idString})); Element response = zsc.createElement(AdminConstants.DELETE_MAILBOX_RESPONSE); if (mbox != null) response .addElement(AdminConstants.E_MAILBOX) .addAttribute(AdminConstants.A_MAILBOXID, mailboxId); return response; }
protected Pair<Boolean, Boolean> parseExpandAttrs(Element request) throws ServiceException { String expandAttrs = request.getAttribute(AdminConstants.A_EXPAND_ALL_ATTRS, null); boolean expandSetAttrs = false; boolean expandGetAttrs = false; if (expandAttrs != null) { String[] eas = expandAttrs.split(","); for (String e : eas) { String exp = e.trim(); if (exp.equals("setAttrs")) expandSetAttrs = true; else if (exp.equals("getAttrs")) expandGetAttrs = true; else throw ServiceException.INVALID_REQUEST( "invalid " + AdminConstants.A_EXPAND_ALL_ATTRS + " value: " + exp, null); } } return new Pair<Boolean, Boolean>(expandSetAttrs, expandGetAttrs); }
@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; }
public ZConversationHit(Element e) throws ServiceException { mId = e.getAttribute(MailConstants.A_ID); mFlags = e.getAttribute(MailConstants.A_FLAGS, null); mDate = e.getAttributeLong(MailConstants.A_DATE); mTags = e.getAttribute(MailConstants.A_TAGS, null); mFragment = e.getAttribute(MailConstants.E_FRAG, null); mSubject = e.getAttribute(MailConstants.E_SUBJECT, null); mSortField = e.getAttribute(MailConstants.A_SORT_FIELD, null); mMessageCount = (int) e.getAttributeLong(MailConstants.A_NUM); mMessageIds = new ArrayList<String>(); for (Element m : e.listElements(MailConstants.E_MSG)) { mMessageIds.add(m.getAttribute(MailConstants.A_ID)); } mRecipients = new ArrayList<ZEmailAddress>(); for (Element emailEl : e.listElements(MailConstants.E_EMAIL)) { mRecipients.add(new ZEmailAddress(emailEl)); } }
/** * 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); } }
protected List parseAccountNames(List acctElems) throws ServiceException { List a = new ArrayList(acctElems.size()); String name; for(Iterator i$ = acctElems.iterator(); i$.hasNext(); a.add(name.toLowerCase())) { Element elem = (Element)i$.next(); name = elem.getAttribute("name"); if("all".equals(name)) { if(acctElems.size() != 1) throw ServiceException.INVALID_REQUEST("\"all\" cannot be mixed with specific account names", null); continue; } String parts[] = name.split("@"); if(parts.length != 2) throw ServiceException.INVALID_REQUEST((new StringBuilder()).append("invalid account email address: ").append(name).toString(), null); } return a; }
public Element handleNetworkRequest(Element document, Map context) throws ServiceException { Element backup; String method; String bkupTarget; String label; Element response; Log.backup.info("Backup request started"); ZimbraSoapContext lc = getZimbraSoapContext(context); checkRights(lc, context); backup = document.getElement("backup"); method = backup.getAttribute("method"); bkupTarget = backup.getAttribute("target", null); label = backup.getAttribute("label", null); response = lc.createElement(BackupService.BACKUP_RESPONSE); BackupManager mgr; BackupTarget backupTarget; boolean sync; boolean sentReportEmail; ServiceException error; mgr = BackupManager.getInstance(); if(bkupTarget != null && "incremental".equals(method)) throw ServiceException.FAILURE("Custom backup target is not allowed for incremental backup", null); backupTarget = mgr.getBackupTarget(bkupTarget, true); if("abort".equals(method)) { BackupSet bak = backupTarget.getBackupSet(label); bak.abortFullBackup(); break MISSING_BLOCK_LABEL_852; } if("delete".equals(method)) { String val = backup.getAttribute("before"); long cutoffTime = getCutoffTime(val, backupTarget); mgr.deleteBackups(backupTarget, cutoffTime); break MISSING_BLOCK_LABEL_852; } sync = backup.getAttributeBool("sync", false); sentReportEmail = false; error = null; BackupParams params; List syncBackups; BackupSet fullBak; BackupSet incrBak; params = new BackupParams(); params.sync = sync; parseComponentIncludeExcludeAttrs(backup, params); Element fcOptsElem = backup.getOptionalElement("fileCopier"); if(fcOptsElem != null) params.fcOpts = ParseXML.parseFileCopierOptions(fcOptsElem); syncBackups = new ArrayList(); fullBak = null; incrBak = null; int size; try { com.zimbra.cs.backup.BackupManager.BackupMode backupMode = mgr.getBackupMode(); boolean autoGroupedMode = com.zimbra.cs.backup.BackupManager.BackupMode.AUTO_GROUPED.equals(backupMode); if("full".equals(method)) { params.zip = backup.getAttributeBool("zip", true); params.zipStore = backup.getAttributeBool("zipStore", true); List acctElems = backup.listElements("account"); if(acctElems.size() > 0) { params.redologs = false; List acctNames = parseAccountNames(acctElems); boolean all = acctNames.size() == 1 && "all".equals(acctNames.get(0)); if(all) { if(!sync) fullBak = mgr.startBackupFull(backupTarget, params); else fullBak = mgr.backupFull(backupTarget, params, syncBackups); } else { com.zimbra.cs.account.Account accounts[] = mgr.lookupAccounts(acctNames, com.zimbra.cs.account.Provisioning.AccountBy.name, backupTarget); if(!sync) fullBak = mgr.startBackupFull(accounts, backupTarget, params); else fullBak = mgr.backupFull(accounts, backupTarget, params, syncBackups); } } else if(autoGroupedMode) { if(backupTarget.isCustom()) throw ServiceException.FAILURE("Custom backup target is not allowed for auto-grouped backup", null); params.redologs = true; com.zimbra.cs.account.Account accounts[] = mgr.lookupAccountsByOldestBackup(backupTarget); if(accounts == null || accounts.length == 0) throw BackupServiceException.AUTO_GROUPED_BACKUP_TOO_SOON(); if(!sync) fullBak = mgr.startBackupFull(accounts, backupTarget, params); else fullBak = mgr.backupFull(accounts, backupTarget, params, syncBackups); } else { throw ServiceException.INVALID_REQUEST("Missing account list", null); } } else if("incremental".equals(method)) { params.zip = backup.getAttributeBool("zip", true); params.zipStore = backup.getAttributeBool("zipStore", true); BackupSet baks[] = mgr.backupIncremental(backupTarget, params, syncBackups); incrBak = baks[0]; fullBak = baks[1]; } else { throw ServiceException.INVALID_REQUEST((new StringBuilder()).append("Invalid backup method: ").append(method).toString(), null); } } catch(IOException e) { throw ServiceException.FAILURE(e.getMessage(), e); } size = syncBackups.size(); if(size > 0) { BackupSet baks[] = new BackupSet[size]; syncBackups.toArray(baks); mgr.sendReportEmail(baks); sentReportEmail = true; } break MISSING_BLOCK_LABEL_756; Exception exception; exception; int size = syncBackups.size(); if(size > 0) { BackupSet baks[] = new BackupSet[size]; syncBackups.toArray(baks); mgr.sendReportEmail(baks); sentReportEmail = true; } throw exception; Element body = response.addElement("backup"); if(fullBak != null) body.addAttribute("label", fullBak.getLabel()); if(incrBak != null) body.addAttribute("incr-label", incrBak.getLabel()); if(error != null && !sentReportEmail) mgr.sendErrorReportEmail(error); break MISSING_BLOCK_LABEL_852; ServiceException e; e; error = e; throw e; Exception exception1; exception1; if(error != null && !sentReportEmail) mgr.sendErrorReportEmail(error); throw exception1; Log.backup.info("Backup request finished"); return response; IOException e; e; throw ServiceException.FAILURE(e.getMessage(), e); }
@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); int flags = Flag.toBitmask(request.getAttribute(MailConstants.A_FLAGS, null)); String[] tags = TagUtil.parseTags(request, mbox, octxt); mbox.lock.lock(); try { int defaultFolder = getItemType() == MailItem.Type.TASK ? Mailbox.ID_FOLDER_TASKS : Mailbox.ID_FOLDER_CALENDAR; String defaultFolderStr = Integer.toString(defaultFolder); String folderIdStr = request.getAttribute(MailConstants.A_FOLDER, defaultFolderStr); ItemId iidFolder = new ItemId(folderIdStr, zsc); Folder folder = mbox.getFolderById(octxt, iidFolder.getId()); SetCalendarItemParseResult parsed = parseSetAppointmentRequest(request, zsc, octxt, folder, getItemType(), false); CalendarItem calItem = mbox.setCalendarItem( octxt, iidFolder.getId(), flags, tags, parsed.defaultInv, parsed.exceptions, parsed.replies, parsed.nextAlarm); Element response = getResponseElement(zsc); if (parsed.defaultInv != null) { response .addElement(MailConstants.A_DEFAULT) .addAttribute( MailConstants.A_ID, ifmt.formatItemId(parsed.defaultInv.invite.getMailItemId())); } if (parsed.exceptions != null) { for (SetCalendarItemData cur : parsed.exceptions) { Element e = response.addElement(MailConstants.E_CAL_EXCEPT); e.addAttribute(MailConstants.A_CAL_RECURRENCE_ID, cur.invite.getRecurId().toString()); e.addAttribute(MailConstants.A_ID, ifmt.formatItemId(cur.invite.getMailItemId())); } } String itemId = ifmt.formatItemId(calItem == null ? 0 : calItem.getId()); response.addAttribute(MailConstants.A_CAL_ID, itemId); try { Element inv = request .getElement(MailConstants.A_DEFAULT) .getElement(MailConstants.E_MSG) .getElement(MailConstants.E_INVITE); Element comp = inv.getOptionalElement(MailConstants.E_INVITE_COMPONENT); if (comp != null) { inv = comp; } String reqCalItemId = inv.getAttribute(MailConstants.A_CAL_ID); String uid = inv.getAttribute(MailConstants.A_UID); boolean uidSame = (calItem == null || (calItem.getUid() == null && uid == null) || (calItem.getUid() != null && (calItem.getUid().equals(uid) || (Invite.isOutlookUid(calItem.getUid()) && calItem .getUid() .equalsIgnoreCase( uid))))); // new or same as requested, or Outlook and // case-insensitive equal if (ZimbraLog.calendar.isInfoEnabled()) { StringBuilder logBuf = new StringBuilder(); if (!reqCalItemId.equals(itemId)) { logBuf .append("Mapped requested id ") .append(reqCalItemId) .append(" -> ") .append(itemId); } if (!uidSame) { logBuf .append(" ?? requested UID ") .append(uid) .append(" differs from mapped ") .append(calItem.getUid()); ZimbraLog.calendar.warn(logBuf.toString()); } else if (logBuf.length() > 0) { ZimbraLog.calendar.info(logBuf.toString()); } } assert (uidSame); } catch (ServiceException se) { // one of the elements we wanted to use doesn't exist; ignore; no log/assertion possible } if (!parsed.isTodo) response.addAttribute(MailConstants.A_APPT_ID_DEPRECATE_ME, itemId); // for backward compat return response; } finally { mbox.lock.release(); } }