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

📄 james.java

📁 java 开发的邮件服务器平台。支持以下协议。 协议可以修改为自己的专门标识
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*********************************************************************** * Copyright (c) 2000-2004 The Apache Software Foundation.             * * All rights reserved.                                                * * ------------------------------------------------------------------- * * Licensed under the Apache License, Version 2.0 (the "License"); you * * may not use this file except in compliance with the License. You    * * may obtain a copy of the License at:                                * *                                                                     * *     http://www.apache.org/licenses/LICENSE-2.0                      * *                                                                     * * 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.apache.james;import org.apache.avalon.framework.activity.Initializable;import org.apache.avalon.framework.component.*;import org.apache.avalon.framework.configuration.Configurable;import org.apache.avalon.framework.configuration.Configuration;import org.apache.avalon.framework.configuration.ConfigurationException;import org.apache.avalon.framework.configuration.DefaultConfiguration;import org.apache.avalon.framework.context.Context;import org.apache.avalon.framework.context.Contextualizable;import org.apache.avalon.framework.context.DefaultContext;import org.apache.avalon.framework.logger.AbstractLogEnabled;import org.apache.avalon.framework.logger.Logger;import org.apache.james.core.MailHeaders;import org.apache.james.core.MailImpl;import org.apache.james.imapserver.ACLMailbox;import org.apache.james.imapserver.Host;import org.apache.james.services.*;import org.apache.james.userrepository.DefaultJamesUser;import org.apache.james.util.RFC2822Headers;import org.apache.james.util.RFC822DateFormat;import org.apache.mailet.Mail;import org.apache.mailet.MailAddress;import org.apache.mailet.MailetContext;import javax.mail.Address;import javax.mail.MessagingException;import javax.mail.internet.InternetAddress;import javax.mail.internet.MimeBodyPart;import javax.mail.internet.MimeMessage;import javax.mail.internet.MimeMultipart;import java.io.ByteArrayInputStream;import java.io.IOException;import java.io.InputStream;import java.io.SequenceInputStream;import java.net.InetAddress;import java.net.UnknownHostException;import java.util.*;/** * Core class for JAMES. Provides three primary services: * <br> 1) Instantiates resources, such as user repository, and protocol * handlers * <br> 2) Handles interactions between components * <br> 3) Provides container services for Mailets * * * @version This is $Revision: 1.6.2.3 $ */public class James    extends AbstractLogEnabled    implements Contextualizable, Composable, Configurable, JamesMBean,               Initializable, MailServer, MailetContext, Component {    /**     * The software name and version     */    private final static String SOFTWARE_NAME_VERSION = Constants.SOFTWARE_NAME + " " + Constants.SOFTWARE_VERSION;    /**     * The component manager used both internally by James and by Mailets.     */    private DefaultComponentManager compMgr; //Components shared    /**     * TODO: Investigate what this is supposed to do.  Looks like it     *       was supposed to be the Mailet context.     */    private DefaultContext context;    /**     * The top level configuration object for this server.     */    private Configuration conf;    /**     * The logger used by the Mailet API.     */    private Logger mailetLogger = null;    /**     * The mail store containing the inbox repository and the spool.     */    private MailStore mailstore;    /**     * The store containing the local user repository.     */    private UsersStore usersStore;    /**     * The spool used for processing mail handled by this server.     */    private SpoolRepository spool;    /**     * The repository that stores the user inboxes.     */    private MailRepository localInbox;    /**     * The root URL used to get mailboxes from the repository     */    private String inboxRootURL;    /**     * The user repository for this mail server.  Contains all the users with inboxes     * on this server.     */    private UsersRepository localusers;    /**     * The collection of domain/server names for which this instance of James     * will receive and process mail.     */    private Collection serverNames;    /**     * Whether to ignore case when looking up user names on this server     */    private boolean ignoreCase;    /**     * Whether to enable aliasing for users on this server     */    private boolean enableAliases;    /**     * Whether to enable forwarding for users on this server     */    private boolean enableForwarding;    /**     * The number of mails generated.  Access needs to be synchronized for     * thread safety and to ensure that all threads see the latest value.     */    private static long count;    /**     * The address of the postmaster for this server     */    private MailAddress postmaster;    /**     * A map used to store mailboxes and reduce the cost of lookup of individual     * mailboxes.     */    private Map mailboxes; //Not to be shared!    /**     * A hash table of server attributes     * These are the MailetContext attributes     */    private Hashtable attributes = new Hashtable();    /**     * The Avalon context used by the instance     */    protected Context           myContext;    /**     * An RFC822 date formatter used to format dates in mail headers     */    private RFC822DateFormat rfc822DateFormat = new RFC822DateFormat();    /**     * Whether James should use IMAP storage     */    private boolean useIMAPstorage = false;    /**     * The host to be used for IMAP storage     */    private Host imapHost;    /**     * @see org.apache.avalon.framework.context.Contextualizable#contextualize(Context)     */    public void contextualize(final Context context) {        this.myContext = context;    }    /**     * @see org.apache.avalon.framework.component.Composable#compose(ComponentManager)     */    public void compose(ComponentManager comp) {        compMgr = new DefaultComponentManager(comp);        mailboxes = new HashMap(31);    }    /**     * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)     */    public void configure(Configuration conf) {        this.conf = conf;    }    /**     * @see org.apache.avalon.framework.activity.Initializable#initialize()     */    public void initialize() throws Exception {        getLogger().info("JAMES init...");        // TODO: This should retrieve a more specific named thread pool from        // Context that is set up in server.xml        try {            mailstore = (MailStore) compMgr.lookup( MailStore.ROLE );        } catch (Exception e) {            if (getLogger().isWarnEnabled()) {                getLogger().warn("Can't get Store: " + e);            }        }        if (getLogger().isDebugEnabled()) {            getLogger().debug("Using MailStore: " + mailstore.toString());        }        try {            usersStore = (UsersStore) compMgr.lookup( UsersStore.ROLE );        } catch (Exception e) {            if (getLogger().isWarnEnabled()) {                getLogger().warn("Can't get Store: " + e);            }        }        if (getLogger().isDebugEnabled()) {            getLogger().debug("Using UsersStore: " + usersStore.toString());        }        String hostName = null;        try {            hostName = InetAddress.getLocalHost().getHostName();        } catch  (UnknownHostException ue) {            hostName = "localhost";        }        context = new DefaultContext();        context.put("HostName", hostName);        getLogger().info("Local host is: " + hostName);        // Get the domains and hosts served by this instance        serverNames = new HashSet();        Configuration serverConf = conf.getChild("servernames");        if (serverConf.getAttributeAsBoolean("autodetect") && (!hostName.equals("localhost"))) {            serverNames.add(hostName.toLowerCase(Locale.US));        }        final Configuration[] serverNameConfs =            conf.getChild( "servernames" ).getChildren( "servername" );        for ( int i = 0; i < serverNameConfs.length; i++ ) {            serverNames.add( serverNameConfs[i].getValue().toLowerCase(Locale.US));            if (serverConf.getAttributeAsBoolean("autodetectIP", true)) {                try {                    /* This adds the IP address(es) for each host to support                     * support <user@address-literal> - RFC 2821, sec 4.1.3.                     * It might be proper to use the actual IP addresses                     * available on this server, but we can't do that                     * without NetworkInterface from JDK 1.4.  Because of                     * Virtual Hosting considerations, we may need to modify                     * this to keep hostname and IP associated, rather than                     * just both in the set.                     */                    InetAddress[] addrs = InetAddress.getAllByName(serverNameConfs[i].getValue());                    for (int j = 0; j < addrs.length ; j++) {                        serverNames.add(addrs[j].getHostAddress());                    }                }                catch(Exception genericException) {                    getLogger().error("Cannot get IP address(es) for " + serverNameConfs[i].getValue());                }            }        }        if (serverNames.isEmpty()) {            throw new ConfigurationException( "Fatal configuration error: no servernames specified!");        }        if (getLogger().isInfoEnabled()) {            for (Iterator i = serverNames.iterator(); i.hasNext(); ) {                getLogger().info("Handling mail for: " + i.next());            }        }        context.put(Constants.SERVER_NAMES, this.serverNames);        attributes.put(Constants.SERVER_NAMES, this.serverNames);

⌨️ 快捷键说明

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