Search in sources :

Example 6 with ImapConnection

use of com.zimbra.cs.mailclient.imap.ImapConnection in project zm-mailbox by Zimbra.

the class AddAccountLogger method addAccountLoggerOnImapServer.

public static void addAccountLoggerOnImapServer(Server server, Account account, String category, String level) {
    ImapConnection connection = null;
    try {
        connection = ImapConnection.getZimbraConnection(server, LC.zimbra_ldap_user.value(), AuthProvider.getAdminAuthToken());
    } catch (ServiceException e) {
        ZimbraLog.imap.warn("unable to connect to imapd server '%s' to issue X-ZIMBRA-ADD-ACCOUNT-LOGGER request", server.getServiceHostname(), e);
        return;
    }
    try {
        ZimbraLog.imap.debug("issuing X-ZIMBRA-ADD-ACCOUNT-LOGGER request to imapd server '%s' for account '%s'", server.getServiceHostname(), account.getName());
        connection.addAccountLogger(account, category, level);
    } catch (IOException e) {
        ZimbraLog.imap.warn("failed to enable account level logging for account '%s' on server '%s'", account.getName(), server.getServiceHostname(), e);
    } finally {
        connection.close();
    }
}
Also used : AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) IOException(java.io.IOException) ImapConnection(com.zimbra.cs.mailclient.imap.ImapConnection)

Example 7 with ImapConnection

use of com.zimbra.cs.mailclient.imap.ImapConnection in project zm-mailbox by Zimbra.

the class ImapTestBase method connectAndLogin.

protected ImapConnection connectAndLogin(String user) throws IOException {
    ImapConnection imapConn = connect(user);
    imapConn.login(PASS);
    return imapConn;
}
Also used : ImapConnection(com.zimbra.cs.mailclient.imap.ImapConnection)

Example 8 with ImapConnection

use of com.zimbra.cs.mailclient.imap.ImapConnection in project zm-mailbox by Zimbra.

the class TestImapViaImapDaemon method testClearDaemonCache.

// checking done in called methods
@SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert")
@Test
public void testClearDaemonCache() throws Exception {
    // loads the account into the imapd cache
    tryConnect(true, "should be able to log in initially");
    Account acct = TestUtil.getAccount(USER);
    CacheEntry acctByName = new CacheEntry(CacheEntryBy.name, acct.getName());
    CacheEntry acctById = new CacheEntry(CacheEntryBy.id, acct.getId());
    ImapConnection adminConn = getAdminConnection();
    // verify that we can flush an account cache by name
    disableImapAndCheckCachedValue(acct);
    adminConn.flushCache("account", new CacheEntry[] { acctByName });
    tryConnect(false, "should not be able to log in after flushing LDAP cache by account name");
    // verify that we can flush an account cache by ID
    enableImapAndCheckCachedValue(acct);
    adminConn.flushCache("account", new CacheEntry[] { acctById });
    tryConnect(true, "should be able to log in after flushing LDAP cache by account ID");
    // verify that we can flush an account cache with multiple CacheEntries
    disableImapAndCheckCachedValue(acct);
    adminConn.flushCache("account", new CacheEntry[] { acctByName, acctById });
    tryConnect(false, "should not be able to log in after flushing LDAP cache by account name and ID");
    // verify that we can flush an account cache without a CacheEntry value
    enableImapAndCheckCachedValue(acct);
    adminConn.flushCache("account");
    tryConnect(true, "should be able to log in after flushing entire LDAP account cache");
    // verify that we can flush multiple cache types at once
    disableImapAndCheckCachedValue(acct);
    adminConn.flushCache("config,account");
    tryConnect(false, "should not be able to log in after flushing multiple cache types");
    // verify that we can flush all caches
    enableImapAndCheckCachedValue(acct);
    adminConn.flushCache("all");
    tryConnect(true, "should be able to log in after flushing all caches");
}
Also used : Account(com.zimbra.cs.account.Account) CacheEntry(com.zimbra.cs.account.Provisioning.CacheEntry) ImapConnection(com.zimbra.cs.mailclient.imap.ImapConnection) Test(org.junit.Test)

Example 9 with ImapConnection

use of com.zimbra.cs.mailclient.imap.ImapConnection in project zm-mailbox by Zimbra.

the class TestImapViaImapDaemon method flushNonImapCacheTypes.

@Test
public void flushNonImapCacheTypes() throws Exception {
    // Flushing these cache types won't do anything on the imapd server, but
    // we want to make sure that this does not fail;
    ImapConnection adminConn = getAdminConnection();
    Set<CacheEntryType> allTypes = new HashSet<CacheEntryType>(Arrays.asList(CacheEntryType.values()));
    Set<CacheEntryType> nonImapTypes = Sets.difference(allTypes, ImapHandler.IMAP_CACHE_TYPES);
    for (CacheEntryType type : nonImapTypes) {
        try {
            adminConn.flushCache(CacheEntryType.license.toString());
        } catch (CommandFailedException e) {
            fail("should be able issue X-ZIMBRA-FLUSHCACHE command for cache type " + type.toString());
        }
    }
}
Also used : CacheEntryType(com.zimbra.soap.admin.type.CacheEntryType) ImapConnection(com.zimbra.cs.mailclient.imap.ImapConnection) CommandFailedException(com.zimbra.cs.mailclient.CommandFailedException) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with ImapConnection

use of com.zimbra.cs.mailclient.imap.ImapConnection in project zm-mailbox by Zimbra.

the class TestImapViaImapDaemon method testReloadLocalConfig.

@Test
public void testReloadLocalConfig() throws Exception {
    // to test this, we set imap_max_consecutive_error to 1 and make sure imapd disconnects after
    // the first failure
    ImapConnection adminConn = getAdminConnection();
    int savedMaxConsecutiveError = LC.imap_max_consecutive_error.intValue();
    // don't use TestUtil.setLCValue, since it issues a ReloadLocalConfigRequest, which will
    // send out its own RELOADLC request
    LocalConfig lc = new LocalConfig(null);
    lc.set(LC.imap_max_consecutive_error.key(), "1");
    lc.save();
    connection = connect(USER);
    connection.login(PASS);
    try {
        // sanity check: even though the LC value is changed, imapd should still be using the old value
        for (int i = 0; i < savedMaxConsecutiveError; i++) {
            try {
                connection.select("BAD");
            } catch (CommandFailedException e) {
                assertEquals("expected 'SELECT failed' error", "SELECT failed", e.getError());
            }
        }
        try {
            connection.select("INBOX");
            fail("session should be disconnected due to too many consecutive errors");
        } catch (CommandFailedException e) {
        }
        // reload LC and reconnect; imapd should now be using the new value
        adminConn.reloadLocalConfig();
        connection = connect(USER);
        connection.login(PASS);
        try {
            connection.select("BAD");
        } catch (CommandFailedException e) {
            assertEquals("expected 'SELECT failed' error", "SELECT failed", e.getError());
        }
        try {
            connection.select("INBOX");
            fail("session should be disconnected after 1 error");
        } catch (CommandFailedException e) {
        }
    } finally {
        TestUtil.setLCValue(LC.imap_max_consecutive_error, String.valueOf(savedMaxConsecutiveError));
        adminConn.reloadLocalConfig();
    }
}
Also used : LocalConfig(com.zimbra.common.localconfig.LocalConfig) ImapConnection(com.zimbra.cs.mailclient.imap.ImapConnection) CommandFailedException(com.zimbra.cs.mailclient.CommandFailedException) Test(org.junit.Test)

Aggregations

ImapConnection (com.zimbra.cs.mailclient.imap.ImapConnection)27 ImapConfig (com.zimbra.cs.mailclient.imap.ImapConfig)11 IOException (java.io.IOException)7 CommandFailedException (com.zimbra.cs.mailclient.CommandFailedException)5 ServiceException (com.zimbra.common.service.ServiceException)4 Test (org.junit.Test)4 Account (com.zimbra.cs.account.Account)2 AuthenticatorFactory (com.zimbra.cs.mailclient.auth.AuthenticatorFactory)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 OutputStream (java.io.OutputStream)2 Ignore (org.junit.Ignore)2 LocalConfig (com.zimbra.common.localconfig.LocalConfig)1 RemoteServiceException (com.zimbra.common.service.RemoteServiceException)1 ZMimeMessage (com.zimbra.common.zmime.ZMimeMessage)1 AccountServiceException (com.zimbra.cs.account.AccountServiceException)1 CacheEntry (com.zimbra.cs.account.Provisioning.CacheEntry)1 ImapAppender (com.zimbra.cs.datasource.imap.ImapAppender)1 PurgedConversation (com.zimbra.cs.db.DbDataSource.PurgedConversation)1 PurgedMessage (com.zimbra.cs.db.DbDataSource.PurgedMessage)1 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)1