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

📄 domncommand.java

📁 Java Mail Server JAVA编写的邮件服务器
💻 JAVA
字号:
/**************************************************************** * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.     * *                                                              * * Copyright 2008 Jun Li(SiChuan University, the School of      * * Software Enginerring). All rights reserved.                  * *                                                              * * Licensed to the JMS under one  or more contributor license   * * agreements.  See the LICENCE file  distributed with this     * * work for additional information regarding copyright          * * ownership.  The JMS licenses this file  you may not use this * * file except in compliance  with the License.                 * *                                                              * * Unless required by applicable law or agreed to in writing,   * * software distributed under the License is distributed on an  * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       * * KIND, either express or implied.  See the License for the    * * specific language governing permissions and limitations      * * under the License.                                           * ****************************************************************/package org.jpxx.mail.plugin.console.command;import org.jpxx.mail.Domain.DomainHandler;import org.jpxx.mail.Exception.ArgumentException;import org.jpxx.mail.Service.CommandHandler;import org.jpxx.mail.Service.Session;import org.jpxx.mail.plugin.console.ConsoleStates;/** * * This command manages domains. *  * Syntax: * DOMN [Command] [domain] [……] *   * @author Jun Li * @version $Revision: 0.0.3 $, $Date: 2008/10/25 $ * @since JMS 0.0.3 */public class DomnCommand implements CommandHandler, ConsoleStates {    /**     * Manages domains.     *      * @see org.jpxx.mail.Service.CommandHandler#onCommand(Session session)     * @param session The Session of Server and client     */    public void onCommand(Session session) {        int state = session.getLastAction();        if (state == AUTHENTICATION || state == TRANSACTION) {            session.setLastAction(TRANSACTION);            try {                StringBuffer buffer = new StringBuffer(64);                                String action = session.getCommandLine().getArgument(0).toUpperCase().trim();                DomainHandler dh = new DomainHandler();                // List all domains                if (action.equals("LIS")) {                    String domains[] = dh.getDomains();                    if (domains == null || domains.length == 0) {                        buffer.append(OK);                        buffer.append(" ");                        buffer.append("There is no domains.");                        session.writeResponse(buffer.toString());                        session.writeResponse(".");                    } else {                        int size = domains.length;                        buffer.append(OK);                        buffer.append(" ");                        buffer.append(                                "There " + (size > 1 ? "are " : "is ") +                                size + " domain" + (size > 1 ? "s" : "") + ".");                        session.writeResponse(buffer.toString());                        for (int i = 0; i < size; i++) {                            session.writeResponse(domains[i]);                        }                        session.writeResponse(".");                    }                } else if (action.equals("ADD")) {                    try {                        String domain = session.getCommandLine().getArgument(1).trim();                                                boolean result = dh.addDomain(domain);                        if (result) {                            buffer.append(OK);                            buffer.append(" ");                            buffer.append("Add new domain successfully");                            session.writeResponse(buffer.toString());                        } else {                            buffer.append(ERR);                            buffer.append(" ");                            buffer.append("Error, add unsuccessfully. ");                            buffer.append("\"" + domain + "\" may exist.");                            session.writeResponse(buffer.toString());                        }                    } catch (ArgumentException e) {                        buffer.append(ERR);                        buffer.append(" ");                        buffer.append("Usage: DOMN ADD <domain>");                        session.writeResponse(buffer.toString());                        return;                    }                } else if (action.equals("MOD")) {                    try {                        String domain = session.getCommandLine().getArgument(1).trim();                        String domainNew = session.getCommandLine().getArgument(2).trim();                                                boolean result = dh.modifyDomain(domain, domainNew);                        if (result) {                            buffer.append(OK);                            buffer.append(" ");                            buffer.append("Modify domain successfully");                            session.writeResponse(buffer.toString());                        } else {                            buffer.append(ERR);                            buffer.append(" ");                            buffer.append("Error, modify unsuccessfully. ");                            buffer.append("\"" + domainNew + "\" may exist.");                            session.writeResponse(buffer.toString());                        }                    } catch (ArgumentException e) {                        buffer.append(ERR);                        buffer.append(" ");                        buffer.append("Usage: DOMN MOD <oldDomain> <newDomain>");                        session.writeResponse(buffer.toString());                    }                } else if (action.equals("DEL")) {                    try {                        String domain = session.getCommandLine().getArgument(1).trim();                        boolean result = dh.deleteDoamin(domain);                        if (result) {                            buffer.append(OK);                            buffer.append(" ");                            buffer.append("Delete domain successfully");                            session.writeResponse(buffer.toString());                        } else {                            buffer.append(ERR);                            buffer.append(" ");                            buffer.append("Error, delete unsuccessfully. ");                            session.writeResponse(buffer.toString());                        }                    } catch (ArgumentException e) {                        buffer.append(ERR);                        buffer.append(" ");                        buffer.append("Usage: DOMN DEL <domain>");                        session.writeResponse(buffer.toString());                    }                }            } catch (ArgumentException ae) {                StringBuffer buffer = new StringBuffer(64);                buffer.append(ERR);                buffer.append(" ");                buffer.append(                        "Usage: DOMN <action> [……]");                session.writeResponse(buffer.toString());                return;            }        } else {            StringBuffer buffer = new StringBuffer(64);            buffer.append(ERR);            buffer.append(" ");            buffer.append("USER not allowed here");            session.writeResponse(buffer.toString());        }    }}

⌨️ 快捷键说明

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