Search in sources :

Example 16 with Mailbox

use of com.zimbra.cs.mailbox.Mailbox in project zm-mailbox by Zimbra.

the class FileBlobStoreConsistencyCheckTest method deleteAllBlobs.

@Override
protected void deleteAllBlobs() throws ServiceException, IOException {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    Volume vol = VolumeManager.getInstance().getCurrentMessageVolume();
    String dir = vol.getMailboxDir(mbox.getId(), Volume.TYPE_MESSAGE);
    log.info("mailbox dir is %s", dir);
    File blobDir = new File(dir);
    FileUtil.deleteDirContents(blobDir);
}
Also used : Mailbox(com.zimbra.cs.mailbox.Mailbox) Volume(com.zimbra.cs.volume.Volume) File(java.io.File)

Example 17 with Mailbox

use of com.zimbra.cs.mailbox.Mailbox in project zm-mailbox by Zimbra.

the class HttpStoreManagerTest method fail.

@Test
public void fail() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    int count = countMailItems(mbox);
    MockHttpStore.setFail();
    try {
        mbox.addMessage(null, MailboxTestUtil.generateMessage("test"), MailboxTest.STANDARD_DELIVERY_OPTIONS, null).getId();
        Assert.fail("expected exception not thrown");
    } catch (ServiceException expected) {
    }
    Assert.assertEquals(count, countMailItems(mbox));
}
Also used : Mailbox(com.zimbra.cs.mailbox.Mailbox) ServiceException(com.zimbra.common.service.ServiceException) Test(org.junit.Test) MailboxTest(com.zimbra.cs.mailbox.MailboxTest) AbstractExternalStoreManagerTest(com.zimbra.cs.store.external.AbstractExternalStoreManagerTest)

Example 18 with Mailbox

use of com.zimbra.cs.mailbox.Mailbox in project zm-mailbox by Zimbra.

the class ExternalAccountManagerTask method run.

@Override
public void run() {
    ZimbraLog.misc.info("Starting external virtual account status manager task");
    Provisioning prov = Provisioning.getInstance();
    SearchAccountsOptions searchOpts = new SearchAccountsOptions();
    try {
        searchOpts.setFilter(ZLdapFilterFactory.getInstance().externalAccountsHomedOnServer(prov.getLocalServer().getServiceHostname()));
        List<NamedEntry> accounts = prov.searchDirectory(searchOpts);
        for (NamedEntry ne : accounts) {
            Account account = (Account) ne;
            Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
            if (mbox == null) {
                ZimbraLog.misc.error("Mailbox for external virtual account %s is unexpectedly null", account.getId());
                continue;
            }
            List<Folder> folders = mbox.getFolderList(null, SortBy.NONE);
            List<Mountpoint> mountpoints = new LinkedList<Mountpoint>();
            for (Folder folder : folders) {
                if (folder instanceof Mountpoint) {
                    mountpoints.add((Mountpoint) folder);
                }
            }
            if (mountpoints.isEmpty()) {
                disableOrDeleteAccount(prov, account, mbox);
                continue;
            }
            // Get all shares granted to the external user
            ShareInfoVisitor shareInfoVisitor = new ShareInfoVisitor(mountpoints);
            ShareInfo.Published.get(prov, account, ACL.GRANTEE_GUEST, null, shareInfoVisitor);
            boolean hasValidMountpoint = shareInfoVisitor.getResult();
            if (!hasValidMountpoint) {
                disableOrDeleteAccount(prov, account, mbox);
            } else if (account.getAccountStatus() == AccountStatus.closed) {
                // re-enable account
                account.setAccountStatus(AccountStatus.active);
            }
        }
    } catch (Throwable e) {
        ZimbraLog.misc.warn("Error during external virtual account status manager task run", e);
    }
    ZimbraLog.misc.info("Finished external virtual account status manager task");
}
Also used : Folder(com.zimbra.cs.mailbox.Folder) LinkedList(java.util.LinkedList) Mailbox(com.zimbra.cs.mailbox.Mailbox) Mountpoint(com.zimbra.cs.mailbox.Mountpoint)

Example 19 with Mailbox

use of com.zimbra.cs.mailbox.Mailbox in project zm-mailbox by Zimbra.

the class LdapProvisioning method autoProvZMGProxyAccount.

@Override
public Pair<Account, Boolean> autoProvZMGProxyAccount(String emailAddr, String password) throws ServiceException {
    Account acct = getAccountByForeignPrincipal(ZMG_PROXY_ACCT_FOREIGN_PRINCIPAL_PREFIX + emailAddr);
    if (acct != null) {
        return new Pair<>(acct, false);
    }
    String domainId = getConfig().getMobileGatewayDefaultProxyAccountDomainId();
    if (domainId == null) {
        return new Pair<>(null, false);
    }
    Domain domain = getDomainById(domainId);
    if (domain == null) {
        ZimbraLog.account.error("Domain corresponding to" + A_zimbraMobileGatewayDefaultProxyAccountDomainId + "not found ");
        throw ServiceException.FAILURE("Missing server configuration", null);
    }
    String testDsId = "TestId";
    Map<String, Object> testAttrs = getZMGProxyDataSourceAttrs(emailAddr, password, true, testDsId);
    DataSource dsToTest = new DataSource(null, DataSourceType.imap, "Test", testDsId, testAttrs, this);
    try {
        DataSourceManager.test(dsToTest);
    } catch (ServiceException e) {
        ZimbraLog.account.debug("ZMG Proxy account auto provisioning failed", e);
        throw AuthFailedServiceException.AUTH_FAILED(emailAddr, SystemUtil.getInnermostException(e).getMessage(), e);
    }
    Map<String, Object> acctAttrs = new HashMap<String, Object>();
    acctAttrs.put(Provisioning.A_zimbraIsMobileGatewayProxyAccount, ProvisioningConstants.TRUE);
    acctAttrs.put(Provisioning.A_zimbraForeignPrincipal, ZMG_PROXY_ACCT_FOREIGN_PRINCIPAL_PREFIX + emailAddr);
    acctAttrs.put(Provisioning.A_zimbraHideInGal, ProvisioningConstants.TRUE);
    acctAttrs.put(Provisioning.A_zimbraMailStatus, Provisioning.MailStatus.disabled.toString());
    acctAttrs.put(Provisioning.A_zimbraMailHost, getLocalServer().getServiceHostname());
    acct = createDummyAccount(acctAttrs, password, domain);
    DataSource ds;
    try {
        Map<String, Object> dsAttrs = getZMGProxyDataSourceAttrs(emailAddr, password, false, null);
        Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
        dsAttrs.put(Provisioning.A_zimbraDataSourceFolderId, Integer.toString(mbox.createFolder(null, "/" + emailAddr, new Folder.FolderOptions()).getId()));
        ds = createDataSource(acct, DataSourceType.imap, emailAddr, dsAttrs);
    } catch (ServiceException e) {
        try {
            deleteAccount(acct.getId());
        } catch (ServiceException e1) {
            if (!AccountServiceException.NO_SUCH_ACCOUNT.equals(e1.getCode())) {
                throw e1;
            }
        }
        throw e;
    }
    DataSourceManager.asyncImportData(ds);
    return new Pair<>(acct, true);
}
Also used : Account(com.zimbra.cs.account.Account) GuestAccount(com.zimbra.cs.account.GuestAccount) LdapAccount(com.zimbra.cs.account.ldap.entry.LdapAccount) AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException) Mailbox(com.zimbra.cs.mailbox.Mailbox) HashMap(java.util.HashMap) LdapDomain(com.zimbra.cs.account.ldap.entry.LdapDomain) Domain(com.zimbra.cs.account.Domain) Pair(com.zimbra.common.util.Pair) DataSource(com.zimbra.cs.account.DataSource) LdapDataSource(com.zimbra.cs.account.ldap.entry.LdapDataSource)

Example 20 with Mailbox

use of com.zimbra.cs.mailbox.Mailbox in project zm-mailbox by Zimbra.

the class DataSourceTask method call.

@Override
public Void call() {
    ZimbraLog.clearContext();
    ZimbraLog.addMboxToContext(getMailboxId());
    ZimbraLog.datasource.debug("Running scheduled import for DataSource %s", getDataSourceId());
    Mailbox mbox = null;
    try {
        // Look up mailbox, account and data source
        mbox = MailboxManager.getInstance().getMailboxById(getMailboxId());
        Account account = mbox.getAccount();
        ZimbraLog.addAccountNameToContext(account.getName());
        Provisioning prov = Provisioning.getInstance();
        DataSource ds = prov.get(account, Key.DataSourceBy.id, getDataSourceId());
        if (ds != null) {
            ZimbraLog.addDataSourceNameToContext(ds.getName());
            if (!ds.isEnabled()) {
                ZimbraLog.datasource.info("DataSource is disabled.  Cancelling future tasks.");
                DataSourceManager.cancelTask(mbox, getDataSourceId());
                return null;
            }
            // Do the work
            DataSourceManager.importData(ds);
        } else {
            ZimbraLog.datasource.info("DataSource %s was deleted.  Cancelling future tasks.", getDataSourceId());
            DataSourceManager.cancelTask(mbox, getDataSourceId());
        }
    } catch (ServiceException e) {
        ZimbraLog.datasource.warn("Scheduled DataSource import failed.", e);
        return null;
    }
    ZimbraLog.clearContext();
    return null;
}
Also used : Account(com.zimbra.cs.account.Account) Mailbox(com.zimbra.cs.mailbox.Mailbox) ServiceException(com.zimbra.common.service.ServiceException) Provisioning(com.zimbra.cs.account.Provisioning) DataSource(com.zimbra.cs.account.DataSource)

Aggregations

Mailbox (com.zimbra.cs.mailbox.Mailbox)817 Account (com.zimbra.cs.account.Account)389 Test (org.junit.Test)376 OperationContext (com.zimbra.cs.mailbox.OperationContext)365 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)306 Message (com.zimbra.cs.mailbox.Message)303 DeliveryContext (com.zimbra.cs.mailbox.DeliveryContext)243 ItemId (com.zimbra.cs.service.util.ItemId)243 Element (com.zimbra.common.soap.Element)138 ServiceException (com.zimbra.common.service.ServiceException)127 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)127 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)106 MimeMessage (javax.mail.internet.MimeMessage)104 Folder (com.zimbra.cs.mailbox.Folder)82 ArrayList (java.util.ArrayList)81 ZMailbox (com.zimbra.client.ZMailbox)73 DbConnection (com.zimbra.cs.db.DbPool.DbConnection)71 PreparedStatement (java.sql.PreparedStatement)67 SQLException (java.sql.SQLException)67 Header (javax.mail.Header)66