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

📄 fetchmail.java

📁 邮件服务器系统 支持SMTP POP3 是著名的Apache写 有一定的参考价值
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            {                getLogger().debug("Session properties:");                Properties properties = getSession().getProperties();                Enumeration e = properties.keys();                while (e.hasMoreElements())                {                    String key = (String) e.nextElement();                    String val = (String) properties.get(key);                    if (val.length() > 40)                    {                        val = val.substring(0, 37) + "...";                    }                    getLogger().debug(key + "=" + val);                }            }            // Update the dynamic accounts,            // merge with the static accounts and            // sort the accounts so they are in the order            // they were entered in config.xml            updateDynamicAccounts();            ArrayList mergedAccounts =                new ArrayList(                    getDynamicAccounts().size() + getStaticAccounts().size());            mergedAccounts.addAll(getDynamicAccounts().values());            mergedAccounts.addAll(getStaticAccounts());            Collections.sort(mergedAccounts);            StringBuffer logMessage = new StringBuffer(64);            logMessage.append("Processing ");            logMessage.append(getStaticAccounts().size());            logMessage.append(" static accounts and ");            logMessage.append(getDynamicAccounts().size());            logMessage.append(" dynamic accounts.");            getLogger().info(logMessage.toString());            // Fetch each account            Iterator accounts = mergedAccounts.iterator();            while (accounts.hasNext())            {                try                {                    new StoreProcessor((Account) accounts.next()).process();                }                catch (MessagingException ex)                {                    getLogger().error(                        "A MessagingException has terminated processing of this Account",                        ex);                }            }        }        catch (Exception ex)        {            getLogger().error("An Exception has terminated this fetch.", ex);        }        finally        {            getLogger().info("Fetcher completed fetches");            // Exit Fetching State            setFetching(false);        }    }    /**     * Returns the fetching.     * @return boolean     */    protected boolean isFetching()    {        return fieldFetching;    }    /**     * @see org.apache.avalon.framework.service.Serviceable#service(ServiceManager)     */    public void service(final ServiceManager manager) throws ServiceException    {        try        {            setServer((MailServer) manager.lookup(MailServer.ROLE));        }        catch (ClassCastException cce)        {            StringBuffer errorBuffer =                new StringBuffer(128).append("Component ").append(                    MailServer.ROLE).append(                    "does not implement the required interface.");            throw new ServiceException("", errorBuffer.toString());        }        UsersStore usersStore =            (UsersStore) manager.lookup("org.apache.james.services.UsersStore");        setLocalUsers(usersStore.getRepository("LocalUsers"));        if (getLocalUsers() == null)            throw new ServiceException(                "",                "The user repository could not be found.");    }                /**     * Sets the fetching.     * @param fetching The fetching to set     */    protected void setFetching(boolean fetching)    {        fieldFetching = fetching;    }    /**     * Returns the server.     * @return MailServer     */    protected MailServer getServer()    {        return fieldServer;    }    /**     * Returns the configuration.     * @return ParsedConfiguration     */    protected ParsedConfiguration getConfiguration()    {        return fieldConfiguration;    }    /**     * Sets the configuration.     * @param configuration The configuration to set     */    protected void setConfiguration(ParsedConfiguration configuration)    {        fieldConfiguration = configuration;    }/** * Sets the server. * @param server The server to set */protected void setServer(MailServer server){    fieldServer = server;}/** * Returns the localUsers. * @return UsersRepository */protected UsersRepository getLocalUsers(){    return fieldLocalUsers;}/** * Sets the localUsers. * @param localUsers The localUsers to set */protected void setLocalUsers(UsersRepository localUsers){    fieldLocalUsers = localUsers;}    /**     * Returns the accounts. Initializes if required.     * @return List     */    protected List getStaticAccounts()    {        List accounts = null;        if (null == (accounts = getStaticAccountsBasic()))        {            updateStaticAccounts();            return getStaticAccounts();        }           return fieldStaticAccounts;    }        /**     * Returns the staticAccounts.     * @return List     */    private List getStaticAccountsBasic()    {        return fieldStaticAccounts;    }       /**     * Sets the accounts.     * @param accounts The accounts to set     */    protected void setStaticAccounts(List accounts)    {        fieldStaticAccounts = accounts;    }        /**     * Updates the staticAccounts.     */    protected void updateStaticAccounts()    {        setStaticAccounts(computeStaticAccounts());    }        /**     * Updates the ParsedDynamicAccountParameters.     */    protected void updateParsedDynamicAccountParameters()    {        setParsedDynamicAccountParameters(computeParsedDynamicAccountParameters());    }           /**     * Updates the dynamicAccounts.     */    protected void updateDynamicAccounts() throws ConfigurationException    {        setDynamicAccounts(computeDynamicAccounts());    }           /**     * Computes the staticAccounts.     */    protected List computeStaticAccounts()    {        return new ArrayList();    }        /**     * Computes the ParsedDynamicAccountParameters.     */    protected List computeParsedDynamicAccountParameters()    {        return new ArrayList();    }           /**     * Computes the dynamicAccounts.     */    protected Map computeDynamicAccounts() throws ConfigurationException    {        Map newAccounts =            new HashMap(                getLocalUsers().countUsers()                    * getParsedDynamicAccountParameters().size());        Map oldAccounts = getDynamicAccountsBasic();        if (null == oldAccounts)            oldAccounts = new HashMap(0);        Iterator parameterIterator =            getParsedDynamicAccountParameters().iterator();        // Process each ParsedDynamicParameters        while (parameterIterator.hasNext())        {            Map accounts =                computeDynamicAccounts(                    oldAccounts,                    (ParsedDynamicAccountParameters) parameterIterator.next());            // Remove accounts from oldAccounts.            // This avoids an average 2*N increase in heapspace used as the             // newAccounts are created.             Iterator oldAccountsIterator = oldAccounts.keySet().iterator();            while (oldAccountsIterator.hasNext())            {                if (accounts.containsKey(oldAccountsIterator.next()))                    oldAccountsIterator.remove();            }            // Add this parameter's accounts to newAccounts            newAccounts.putAll(accounts);        }        return newAccounts;    }        /**     * Returns the dynamicAccounts. Initializes if required.     * @return Map     */    protected Map getDynamicAccounts() throws ConfigurationException    {        Map accounts = null;        if (null == (accounts = getDynamicAccountsBasic()))        {            updateDynamicAccounts();            return getDynamicAccounts();        }           return fieldDynamicAccounts;    }        /**     * Returns the dynamicAccounts.     * @return Map     */    private Map getDynamicAccountsBasic()    {        return fieldDynamicAccounts;    }       /**     * Sets the dynamicAccounts.     * @param dynamicAccounts The dynamicAccounts to set     */    protected void setDynamicAccounts(Map dynamicAccounts)    {        fieldDynamicAccounts = dynamicAccounts;    }        /**     * Compute the dynamicAccounts for the passed parameters.     * Accounts for existing users are copied and accounts for new users are      * created.     * @param oldAccounts     * @param parameters     * @return Map - The current Accounts     * @throws ConfigurationException     */    protected Map computeDynamicAccounts(        Map oldAccounts,        ParsedDynamicAccountParameters parameters)        throws ConfigurationException    {        Map accounts = new HashMap(getLocalUsers().countUsers());        Iterator usersIterator = getLocalUsers().list();        while (usersIterator.hasNext())        {            String userName = (String) usersIterator.next();            DynamicAccountKey key =                new DynamicAccountKey(userName, parameters.getSequenceNumber());            Account account = (Account) oldAccounts.get(key);            if (null == account)            {                // Create a new DynamicAccount                account =                    new DynamicAccount(                        parameters.getSequenceNumber(),                        getConfiguration(),                        userName,                        parameters.getUserPrefix(),                        parameters.getUserSuffix(),                        parameters.getPassword(),                        parameters.getRecipientPrefix(),                        parameters.getRecipientSuffix(),                        parameters.isIgnoreRecipientHeader(),                        getSession());            }            accounts.put(key, account);        }        return accounts;    }    /**     * Resets the dynamicAccounts.     */    protected void resetDynamicAccounts()    {        setDynamicAccounts(null);    }       /**     * Returns the ParsedDynamicAccountParameters.     * @return List     */    protected List getParsedDynamicAccountParameters()    {        List accounts = null;        if (null == (accounts = getParsedDynamicAccountParametersBasic()))        {            updateParsedDynamicAccountParameters();            return getParsedDynamicAccountParameters();        }           return fieldParsedDynamicAccountParameters;    }        /**     * Returns the ParsedDynamicAccountParameters.     * @return List     */    private List getParsedDynamicAccountParametersBasic()    {        return fieldParsedDynamicAccountParameters;    }       /**     * Sets the ParsedDynamicAccountParameters.     * @param ParsedDynamicAccountParameters The ParsedDynamicAccountParametersto set     */    protected void setParsedDynamicAccountParameters(List parsedDynamicAccountParameters)    {        fieldParsedDynamicAccountParameters = parsedDynamicAccountParameters;    }    /**     * Returns the session, lazily initialized if required.     * @return Session     */    protected Session getSession()    {        Session session = null;        if (null == (session = getSessionBasic()))        {            updateSession();            return getSession();        }            return session;    }        /**     * Returns the session.     * @return Session     */    private Session getSessionBasic()    {        return fieldSession;    }        /**     * Answers a new Session.     * @return Session     */    protected Session computeSession()    {        return Session.getInstance(System.getProperties());    }        /**     * Updates the current Session.     */    protected void updateSession()    {        setSession(computeSession());    }        /**     * Sets the session.     * @param session The session to set     */    protected void setSession(Session session)    {        fieldSession = session;    }            /**     * Propogate any Session parameters in the configuration to the Session.     * @param configuration The configuration containing the parameters     * @throws ConfigurationException     */    protected void setSessionParameters(Configuration configuration)        throws ConfigurationException    {        Configuration javaMailProperties =            configuration.getChild("javaMailProperties", false);        if (null != javaMailProperties)        {            Properties properties = getSession().getProperties();            Configuration[] allProperties =                javaMailProperties.getChildren("property");            for (int i = 0; i < allProperties.length; i++)            {                properties.setProperty(                    allProperties[i].getAttribute("name"),                    allProperties[i].getAttribute("value"));                if (getLogger().isDebugEnabled())                {                    StringBuffer messageBuffer =                        new StringBuffer("Set property name: ");                    messageBuffer.append(allProperties[i].getAttribute("name"));                    messageBuffer.append(" to: ");                    messageBuffer.append(                        allProperties[i].getAttribute("value"));                    getLogger().debug(messageBuffer.toString());                }            }        }    }    }

⌨️ 快捷键说明

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