⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 remotemanagerhandler.java

📁 java 开发的邮件服务器平台。支持以下协议。 协议可以修改为自己的专门标识
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        }        JamesUser aliasUser = (JamesUser) users.getUserByName(alias);        if (aliasUser == null) {            writeLoggedFlushedResponse("Alias unknown to server - create that user first.");            return true;        }        boolean success = user.setAlias(alias);        if (success) {            user.setAliasing(true);            users.updateUser(user);            StringBuffer responseBuffer =                new StringBuffer(64)                        .append("Alias for ")                        .append(username)                        .append(" set to:")                        .append(alias);            String response = responseBuffer.toString();            out.println(response);            getLogger().info(response);        } else {            out.println("Error setting alias");            getLogger().error("Error setting alias");        }        out.flush();        return true;    }    /**     * Handler method called upon receipt of an SETFORWARDING command.     * Returns whether further commands should be read off the wire.     *     * @param argument the argument passed in with the command     */    private boolean doSETFORWARDING(String argument) {        int breakIndex = -1;        if ((argument == null) ||            (argument.equals("")) ||            ((breakIndex = argument.indexOf(" ")) < 0)) {            writeLoggedFlushedResponse("Usage: setforwarding [username] [emailaddress]");            return true;        }        String username = argument.substring(0,breakIndex);        String forward = argument.substring(breakIndex + 1);        if (username.equals("") || forward.equals("")) {           writeLoggedFlushedResponse("Usage: setforwarding [username] [emailaddress]");           return true;        }        // Verify user exists        User baseuser = users.getUserByName(username);        if (baseuser == null) {            writeLoggedFlushedResponse("No such user " + username);            return true;        } else if (! (baseuser instanceof JamesUser ) ) {            writeLoggedFlushedResponse("Can't set forwarding for this user type.");            return true;        }        JamesUser user = (JamesUser)baseuser;        // Verify acceptable email address        MailAddress forwardAddr;        try {             forwardAddr = new MailAddress(forward);        } catch(ParseException pe) {            writeLoggedResponse("Parse exception with that email address: " + pe.getMessage());            writeLoggedFlushedResponse("Forwarding address not added for " + username);            return true;        }        boolean success = user.setForwardingDestination(forwardAddr);        if (success) {            user.setForwarding(true);            users.updateUser(user);            StringBuffer responseBuffer =                new StringBuffer(64)                        .append("Forwarding destination for ")                        .append(username)                        .append(" set to:")                        .append(forwardAddr.toString());            String response = responseBuffer.toString();            out.println(response);            getLogger().info(response);        } else {            out.println("Error setting forwarding");            getLogger().error("Error setting forwarding");        }        out.flush();        return true;    }    /**     * Handler method called upon receipt of an SHOWALIAS command.     * Returns whether further commands should be read off the wire.     *     * @param argument the user name     */    private boolean doSHOWALIAS(String username) {        if ( username == null || username.equals("") ) {            writeLoggedFlushedResponse("Usage: showalias [username]");            return true;        }        JamesUser user = (JamesUser)users.getUserByName(username);        if ( user == null ) {            writeLoggedFlushedResponse("No such user " + username);            return true;        }        if ( !user.getAliasing() ) {            writeLoggedFlushedResponse("User " + username + " does not currently have an alias");            return true;        }        String alias = user.getAlias();        if ( alias == null || alias.equals("") ) {    //  defensive programming -- neither should occur            String errmsg = "For user " + username + ", the system indicates that aliasing is set but no alias was found";            out.println(errmsg);            getLogger().error(errmsg);            return true;        }        writeLoggedFlushedResponse("Current alias for " + username + " is: " + alias);        return true;    }    /**     * Handler method called upon receipt of an SHOWFORWARDING command.     * Returns whether further commands should be read off the wire.     *     * @param argument the user name     */    private boolean doSHOWFORWARDING(String username) {        if ( username == null || username.equals("") ) {            writeLoggedFlushedResponse("Usage: showforwarding [username]");            return true;        }        JamesUser user = (JamesUser)users.getUserByName(username);        if ( user == null ) {            writeLoggedFlushedResponse("No such user " + username);            return true;        }        if ( !user.getForwarding() ) {            writeLoggedFlushedResponse("User " + username + " is not currently being forwarded");            return true;        }        MailAddress fwdAddr = user.getForwardingDestination();        if ( fwdAddr == null ) {    //  defensive programming -- should not occur            String errmsg = "For user " + username + ", the system indicates that forwarding is set but no forwarding destination was found";            out.println(errmsg);            getLogger().error(errmsg);            return true;        }        writeLoggedFlushedResponse("Current forwarding destination for " + username + " is: " + fwdAddr);        return true;    }    /**     * Handler method called upon receipt of an UNSETALIAS command.     * Returns whether further commands should be read off the wire.     *     * @param argument the argument passed in with the command     */    private boolean doUNSETALIAS(String argument) {        if ((argument == null) || (argument.equals(""))) {            writeLoggedFlushedResponse("Usage: unsetalias [username]");            return true;        }        String username = argument;        JamesUser user = (JamesUser) users.getUserByName(username);        if (user == null) {            writeLoggedResponse("No such user " + username);        } else if (user.getAliasing()){            user.setAliasing(false);            users.updateUser(user);            StringBuffer responseBuffer =                new StringBuffer(64)                        .append("Alias for ")                        .append(username)                        .append(" unset");            String response = responseBuffer.toString();            out.println(response);            getLogger().info(response);        } else {            writeLoggedResponse("Aliasing not active for" + username);        }        out.flush();        return true;    }    /**     * Handler method called upon receipt of an UNSETFORWARDING command.     * Returns whether further commands should be read off the wire.     *     * @param argument the argument passed in with the command     */    private boolean doUNSETFORWARDING(String argument) {        if ((argument == null) || (argument.equals(""))) {            writeLoggedFlushedResponse("Usage: unsetforwarding [username]");            return true;        }        String username = argument;        JamesUser user = (JamesUser) users.getUserByName(username);        if (user == null) {            writeLoggedFlushedResponse("No such user " + username);        } else if (user.getForwarding()){            user.setForwarding(false);            users.updateUser(user);            StringBuffer responseBuffer =                new StringBuffer(64)                        .append("Forward for ")                        .append(username)                        .append(" unset");            String response = responseBuffer.toString();            out.println(response);            out.flush();            getLogger().info(response);        } else {            writeLoggedFlushedResponse("Forwarding not active for" + username);        }        return true;    }    /**     * Handler method called upon receipt of a USER command.     * Returns whether further commands should be read off the wire.     *     * @param argument the argument passed in with the command     */    private boolean doUSER(String argument) {        if (argument == null || argument.equals("")) {            writeLoggedFlushedResponse("Usage: user [repositoryName]");            return true;        }        String repositoryName = argument.toLowerCase(Locale.US);        UsersRepository repos = theConfigData.getUserStore().getRepository(repositoryName);        if ( repos == null ) {            writeLoggedFlushedResponse("No such repository: " + repositoryName);        } else {            users = repos;            StringBuffer responseBuffer =                new StringBuffer(64)                        .append("Changed to repository '")                        .append(repositoryName)                        .append("'.");            writeLoggedFlushedResponse(responseBuffer.toString());            if ( repositoryName.equals("localusers") ) {                inLocalUsers = true;            } else {                inLocalUsers = false;            }        }        return true;    }    /**     * Handler method called upon receipt of a QUIT command.     * Returns whether further commands should be read off the wire.     *     * @param argument the argument passed in with the command     */    private boolean doQUIT(String argument) {        writeLoggedFlushedResponse("Bye");        return false;    }    /**     * Handler method called upon receipt of a SHUTDOWN command.     * Returns whether further commands should be read off the wire.     *     * @param argument the argument passed in with the command     */    private boolean doSHUTDOWN(String argument) {        writeLoggedFlushedResponse("Shutting down, bye bye");        System.exit(0);        return false;    }    /**     * Handler method called upon receipt of an unrecognized command.     * Returns whether further commands should be read off the wire.     *     * @param argument the unknown command     */    private boolean doUnknownCommand(String argument) {        writeLoggedFlushedResponse("Unknown command " + argument);        return true;    }    /**     * This method logs at a "DEBUG" level the response string that     * was sent to the RemoteManager client.  The method is provided largely     * as syntactic sugar to neaten up the code base.  It is declared     * private and final to encourage compiler inlining.     *     * @param responseString the response string sent to the client     */    private final void logResponseString(String responseString) {        if (getLogger().isDebugEnabled()) {            getLogger().debug("Sent: " + responseString);        }    }    /**     * Write and flush a response string.  The response is also logged.     * Should be used for the last line of a multi-line response or     * for a single line response.     *     * @param responseString the response string sent to the client     */    final void writeLoggedFlushedResponse(String responseString) {        out.println(responseString);        out.flush();        logResponseString(responseString);    }    /**     * Write a response string.  The response is also logged.     * Used for multi-line responses.     *     * @param responseString the response string sent to the client     */    final void writeLoggedResponse(String responseString) {        out.println(responseString);        logResponseString(responseString);    }    /**     * A private inner class which serves as an adaptor     * between the WatchdogTarget interface and this     * handler class.     */    private class RemoteManagerWatchdogTarget        implements WatchdogTarget {        /**         * @see org.apache.james.util.watchdog.WatchdogTarget#execute()         */        public void execute() {            RemoteManagerHandler.this.idleClose();        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -