ImapProxy(final ImapHandler handler, final ImapPath path) throws ServiceException { mHandler = handler; mPath = path; Account acct = handler.getCredentials().getAccount(); Server server = Provisioning.getInstance().getServer(path.getOwnerAccount()); String host = server.getServiceHostname(); if (acct == null) throw ServiceException.PROXY_ERROR( new Exception("no such authenticated user"), path.asImapPath()); ImapConfig config = new ImapConfig(); config.setAuthenticationId(acct.getName()); config.setMechanism(ZimbraAuthenticator.MECHANISM); config.setAuthenticatorFactory(sAuthenticatorFactory); config.setReadTimeout(LC.javamail_imap_timeout.intValue()); config.setConnectTimeout(config.getReadTimeout()); config.setHost(host); if (server.isImapServerEnabled()) { config.setPort(server.getIntAttr(Provisioning.A_zimbraImapBindPort, ImapConfig.DEFAULT_PORT)); } else if (server.isImapSSLServerEnabled()) { config.setPort( server.getIntAttr(Provisioning.A_zimbraImapSSLBindPort, ImapConfig.DEFAULT_SSL_PORT)); config.setSecurity(MailConfig.Security.SSL); } else { throw ServiceException.PROXY_ERROR( new Exception("no open IMAP port for server " + host), path.asImapPath()); } ZimbraLog.imap.info( "opening proxy connection (user="******", host=" + host + ", path=" + path.getReferent().asImapPath() + ')'); ImapConnection conn = mConnection = new ImapConnection(config); try { conn.connect(); conn.authenticate(AuthProvider.getAuthToken(acct).getEncoded()); } catch (Exception e) { dropConnection(); throw ServiceException.PROXY_ERROR(e, null); } }