Search in sources :

Example 1 with PurgeMessagesResponse

use of com.zimbra.soap.admin.message.PurgeMessagesResponse in project zm-mailbox by Zimbra.

the class PurgeMessages method handle.

public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Element mreq = request.getOptionalElement(AdminConstants.E_MAILBOX);
    String[] accounts;
    if (mreq != null) {
        accounts = new String[] { mreq.getAttribute(AdminConstants.A_ACCOUNTID) };
        // accounts are specified, check right or each account
        Provisioning prov = Provisioning.getInstance();
        for (String acctId : accounts) {
            Account acct = prov.get(AccountBy.id, acctId);
            if (acct == null)
                throw AccountServiceException.NO_SUCH_ACCOUNT(acctId);
            checkAccountRight(zsc, acct, Admin.R_purgeMessages);
        }
    } else {
        // all accounts on the system, has to be a system admin
        checkRight(zsc, context, null, AdminRight.PR_SYSTEM_ADMIN_ONLY);
        accounts = MailboxManager.getInstance().getAccountIds();
    }
    PurgeMessagesResponse purgeResponse = new PurgeMessagesResponse();
    for (int i = 0; i < accounts.length; i++) {
        Account account = Provisioning.getInstance().getAccountById(accounts[i]);
        if (account == null)
            continue;
        MailboxWithMailboxId mboxResp;
        if (Provisioning.onLocalServer(account)) {
            // local
            Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account, false);
            if (mbox == null)
                continue;
            mbox.purgeMessages(null);
            mboxResp = new MailboxWithMailboxId(mbox.getId(), account.getId(), Long.valueOf(mbox.getSize()));
        } else {
            // remote
            Server server = account.getServer();
            if (server == null)
                continue;
            SoapProvisioning soapProvisioning = SoapProvisioning.getAdminInstance();
            mboxResp = soapProvisioning.purgeMessages(account);
            if (mboxResp == null)
                continue;
            mboxResp.setAccountId(account.getId());
        }
        purgeResponse.addMailbox(mboxResp);
    }
    return JaxbUtil.jaxbToElement(purgeResponse);
}
Also used : Account(com.zimbra.cs.account.Account) MailboxWithMailboxId(com.zimbra.soap.admin.type.MailboxWithMailboxId) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) Server(com.zimbra.cs.account.Server) SoapProvisioning(com.zimbra.cs.account.soap.SoapProvisioning) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) PurgeMessagesResponse(com.zimbra.soap.admin.message.PurgeMessagesResponse) Provisioning(com.zimbra.cs.account.Provisioning) SoapProvisioning(com.zimbra.cs.account.soap.SoapProvisioning)

Aggregations

ZMailbox (com.zimbra.client.ZMailbox)1 Element (com.zimbra.common.soap.Element)1 Account (com.zimbra.cs.account.Account)1 Provisioning (com.zimbra.cs.account.Provisioning)1 Server (com.zimbra.cs.account.Server)1 SoapProvisioning (com.zimbra.cs.account.soap.SoapProvisioning)1 Mailbox (com.zimbra.cs.mailbox.Mailbox)1 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)1 PurgeMessagesResponse (com.zimbra.soap.admin.message.PurgeMessagesResponse)1 MailboxWithMailboxId (com.zimbra.soap.admin.type.MailboxWithMailboxId)1