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

📄 domainhandler.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 Engineering). 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.Domain;import java.io.File;import org.jpxx.mail.Config.Config;import org.jpxx.mail.Constants;import org.jpxx.mail.Util.FileUtils;/** * The current mail server domain config. *  * @author Jun Li * @version $Revision: 0.0.1 $, $Date: 2008/04/22 19:57:00 $ */public class DomainHandler extends Config {    /**     * Add a new domain to this server     *      * @param domain Server domain(Host name or IP address)     * @return If add successfully ten return true, else return true.     */    public boolean addDomain(String domain) {        if (domain == null) {            return false;        }        domain = domain.replace(" ", "");        File f = new File(Constants.HOME_DIR + domain + File.separator);        if (!f.exists()) {            f.mkdirs();        }        String theDomain = config.getValue("Domain");        if (theDomain.equals("")) {            return config.add("Domain", domain);        }        if (theDomain.contains(domain)) {            return false;        } else {            return config.modifyValue("Domain", theDomain + "," + domain);        }    }    /**     * Modify domain     * @param oldDomain The domain you want to modify     * @param newDomain new domain     * @return If modify successfully ten return true, else return true.     */    public boolean modifyDomain(String oldDomain, String newDomain) {        if (oldDomain == null || newDomain == null) {            return false;        }        newDomain = newDomain.replace(" ", "");        String theDomain = config.getValue("Domain");        if (theDomain.equals("")) {            return false;        }        if (!theDomain.contains(oldDomain)) {            return false;        } else {            theDomain = theDomain.replace(oldDomain, newDomain);            File f = new File(Constants.HOME_DIR + oldDomain);            f.renameTo(new File(Constants.HOME_DIR + newDomain));            return config.modifyValue("Domain", theDomain);        }    }    /**     *      * @param domain The domain you want to delete     * @return If delete successfully ten return true, else return true.     */    public boolean deleteDoamin(String domain) {        String theDomain = config.getValue("Domain");        if (theDomain.equals("")) {            return false;        }        if (!theDomain.contains(domain)) {            return false;        } else {            /**             * Delete all user and and their files             */            FileUtils.delete(Constants.HOME_DIR + domain);            if (theDomain.lastIndexOf(",") == -1) {                /**                 * Delete the last domain                 */                return config.modifyValue("Domain", "");            }            if (theDomain.startsWith(domain)) {                theDomain = theDomain.replace(domain + ",", "");                return config.modifyValue("Domain", theDomain);            } else {                theDomain = theDomain.replace("," + domain, "");                return config.modifyValue("Domain", theDomain);            }        }    }    /**     * Get a set of domains     * @return Current server domains. If no dimain, return NULL.      */    public String[] getDomains() {        String theDomain = config.getValue("Domain");        if (theDomain.equals("")) {            /**            config.add("DomainConfig", Constants.DEFAULT_TEST_DOMAIN);            String domains[] = {Constants.DEFAULT_TEST_DOMAIN};            return domains;             */            return null;        } else {            if (theDomain.lastIndexOf(",") == -1) {                String domains[] = new String[1];                domains[0] = theDomain;                return domains;            } else {                return theDomain.split(",");            }        }    }    /**     * Get server default domain     *      * @return server default domain     */    public String getDefaultDomain() {        String domains[] = getDomains();        if (domains == null) {            return null;        } else {            return domains[0];        }    }    /**     * Check domain exist or not     * @param domain The domain you want to check.     * @return domain exist return true, otherwise return false     */    public boolean isExist(String domain) {        String domains[] = getDomains();        if (domains == null) {            return false;        } else {            for (int i = 0; i < domains.length; i++) {                if (domains[i].equals(domain)) {                    return true;                }            }            return false;        }    }}

⌨️ 快捷键说明

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