📄 parsedconfiguration.java
字号:
/*********************************************************************** * Copyright (c) 2003-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.fetchmail;import java.net.InetAddress;import java.net.UnknownHostException;import java.util.HashSet;import java.util.Set;import java.util.StringTokenizer;import javax.mail.internet.ParseException;import org.apache.avalon.framework.configuration.Configuration;import org.apache.avalon.framework.configuration.ConfigurationException;import org.apache.avalon.framework.logger.Logger;import org.apache.james.services.MailServer;import org.apache.mailet.MailAddress;import org.apache.james.services.UsersRepository;/** * <p>Parses and validates an * <code>org.apache.avalon.framework.configuration.Configuration</code>.</p> * * <p>Creation Date: 27-May-03</p> * */class ParsedConfiguration{ /** * The logger. */ private Logger fieldLogger; /** * The name of the folder to fetch from the javamail provider * */ private String fieldJavaMailFolderName = "INBOX"; /** * The name of the javamail provider we want to user (pop3,imap,nntp,etc...) * */ private String fieldJavaMailProviderName = "pop3"; /** * Returns the javaMailFolderName. * @return String */ public String getJavaMailFolderName() { return fieldJavaMailFolderName; } /** * Returns the javaMailProviderName. * @return String */ public String getJavaMailProviderName() { return fieldJavaMailProviderName; } /** * Sets the javaMailFolderName. * @param javaMailFolderName The javaMailFolderName to set */ protected void setJavaMailFolderName(String javaMailFolderName) { fieldJavaMailFolderName = javaMailFolderName; } /** * Sets the javaMailProviderName. * @param javaMailProviderName The javaMailProviderName to set */ protected void setJavaMailProviderName(String javaMailProviderName) { fieldJavaMailProviderName = javaMailProviderName; } /** * Fetch both old (seen) and new messages from the mailserver. The default * is to fetch only messages the server are not marked as seen. */ private boolean fieldFetchAll = false; /** * The unique, identifying name for this task */ private String fieldFetchTaskName; /** * The server host name for this fetch task */ private String fieldHost; /** * Keep retrieved messages on the remote mailserver. Normally, messages * are deleted from the folder on the mailserver after they have been retrieved */ private boolean fieldLeave = false; /** * Keep blacklisted messages on the remote mailserver. Normally, messages * are kept in the folder on the mailserver if they have been rejected */ private boolean fieldLeaveBlacklisted = true; /** * Keep messages for remote recipients on the remote mailserver. Normally, * messages are kept in the folder on the mailserver if they have been * rejected. */ private boolean fieldLeaveRemoteRecipient = true; /** * Keep messages for undefined users on the remote mailserver. Normally, * messages are kept in the folder on the mailserver if they have been * rejected. */ private boolean fieldLeaveUserUndefined = true; /** * Keep undeliverable messages on the remote mailserver. Normally, * messages are kept in the folder on the mailserver if they cannot * be delivered. */ private boolean fieldLeaveUndeliverable = true; /** * Mark retrieved messages on the remote mailserver as seen. Normally, * messages are marked as seen after they have been retrieved */ private boolean fieldMarkSeen = true; /** * Mark blacklisted messages on the remote mailserver as seen. Normally, * messages are not marked as seen if they have been rejected */ private boolean fieldMarkBlacklistedSeen = false; /** * Mark remote recipient messages on the remote mailserver as seen. Normally, * messages are not marked as seen if they have been rejected */ private boolean fieldMarkRemoteRecipientSeen = false; /** * Mark messages for undefined users on the remote mail server as seen. * Normally, messages are not marked as seen if they have been rejected. */ private boolean fieldMarkUserUndefinedSeen = false; /** * Mark undeliverable messages on the remote mail server as seen. * Normally, messages are not marked as seen if they are undeliverable. */ private boolean fieldMarkUndeliverableSeen = false; /** * Defer processing of messages for which the intended recipient cannot * be determined to the next pass. */ private boolean fieldDeferRecipientNotFound = false; /** * Recurse folders if available? */ private boolean fieldRecurse = false; /** * The MailServer service */ private MailServer fieldServer; /** * The domain part to use to complete partial addresses */ private String fieldDefaultDomainName; /** * Only accept mail for defined recipients. * All other mail is rejected. */ private boolean fieldRejectUserUndefined; /** * The index of the received header to use to compute the remote address * and remote host name for a message. This is 0 based and defaults to -1. */ private int fieldRemoteReceivedHeaderIndex = -1; /** * Keep messages with an invalid received header on the remote mailserver. * Normally, messages are kept in the folder on the mailserver if they have been * rejected */ private boolean fieldLeaveRemoteReceivedHeaderInvalid = true; /** * Mark messages with an invalid received header on the remote mailserver as * seen. Normally, messages are not marked as seen if they have been rejected. */ private boolean fieldMarkRemoteReceivedHeaderInvalidSeen = false; /** * Reject messages with an invalid received header. */ private boolean fieldRejectRemoteReceivedHeaderInvalid; /** * Reject messages for which a recipient could not be determined. */ private boolean fieldRejectRecipientNotFound; /** * Leave messages on the server for which a recipient could not be * determined. */ private boolean fieldLeaveRecipientNotFound; /** * Mark as seen messages on the server for which a recipient could not be * determined. */ private boolean fieldMarkRecipientNotFoundSeen; /** * Reject mail for blacklisted users */ private boolean fieldRejectBlacklisted; /** * Only accept mail for local recipients. * All other mail is rejected. */ private boolean fieldRejectRemoteRecipient; /** * The Set of MailAddresses for whom mail should be rejected */ private Set fieldBlacklist; /** * The maximum message size limit * 0 means no limit. */ private int fieldMaxMessageSizeLimit = 0; /** * Reject mail exceeding the maximum message size limit */ private boolean fieldRejectMaxMessageSizeExceeded; /** * Leave messages on the server that exceed the maximum message size limit. */ private boolean fieldLeaveMaxMessageSizeExceeded; /** * Mark as seen messages on the server that exceed the maximum message size * limit. */ private boolean fieldMarkMaxMessageSizeExceededSeen; /** * The Local Users repository */ private UsersRepository fieldLocalUsers; /** * Constructor for ParsedConfiguration. */ private ParsedConfiguration() { super(); } /** * Constructor for ParsedConfiguration. * @param configuration * @param logger * @param server * @param localUsers * @throws ConfigurationException */ public ParsedConfiguration(Configuration configuration, Logger logger, MailServer server, UsersRepository localUsers) throws ConfigurationException { this(); setLogger(logger); setServer(server); setLocalUsers(localUsers); configure(configuration); } /** * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration) */ protected void configure(Configuration conf) throws ConfigurationException { setHost(conf.getChild("host").getValue()); setFetchTaskName(conf.getAttribute("name")); setJavaMailProviderName( conf.getChild("javaMailProviderName").getValue()); setJavaMailFolderName(conf.getChild("javaMailFolderName").getValue()); setRecurse(conf.getChild("recursesubfolders").getValueAsBoolean()); Configuration recipientNotFound = conf.getChild("recipientnotfound"); setDeferRecipientNotFound( recipientNotFound.getAttributeAsBoolean("defer")); setRejectRecipientNotFound( recipientNotFound.getAttributeAsBoolean("reject")); setLeaveRecipientNotFound( recipientNotFound.getAttributeAsBoolean("leaveonserver")); setMarkRecipientNotFoundSeen( recipientNotFound.getAttributeAsBoolean("markseen")); Configuration defaultDomainName = conf.getChild("defaultdomain", false); if (null != defaultDomainName) setDefaultDomainName(defaultDomainName.getValue()); setFetchAll(conf.getChild("fetchall").getValueAsBoolean()); Configuration fetched = conf.getChild("fetched"); setLeave(fetched.getAttributeAsBoolean("leaveonserver")); setMarkSeen(fetched.getAttributeAsBoolean("markseen")); Configuration remoterecipient = conf.getChild("remoterecipient"); setRejectRemoteRecipient( remoterecipient.getAttributeAsBoolean("reject")); setLeaveRemoteRecipient( remoterecipient.getAttributeAsBoolean("leaveonserver")); setMarkRemoteRecipientSeen( remoterecipient.getAttributeAsBoolean("markseen")); Configuration blacklist = conf.getChild("blacklist"); setBlacklist(blacklist.getValue("")); setRejectBlacklisted(blacklist.getAttributeAsBoolean("reject")); setLeaveBlacklisted(blacklist.getAttributeAsBoolean("leaveonserver")); setMarkBlacklistedSeen(blacklist.getAttributeAsBoolean("markseen")); Configuration userundefined = conf.getChild("userundefined"); setRejectUserUndefined(userundefined.getAttributeAsBoolean("reject")); setLeaveUserUndefined( userundefined.getAttributeAsBoolean("leaveonserver")); setMarkUserUndefinedSeen( userundefined.getAttributeAsBoolean("markseen")); Configuration undeliverable = conf.getChild("undeliverable"); setLeaveUndeliverable( undeliverable.getAttributeAsBoolean("leaveonserver")); setMarkUndeliverableSeen( undeliverable.getAttributeAsBoolean("markseen"));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -