All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.james.fetchmail.Account Maven / Gradle / Ivy

There is a newer version: 3.8.1
Show newest version
/****************************************************************
 * Licensed to the Apache Software Foundation (ASF) under one   *
 * or more contributor license agreements.  See the NOTICE file *
 * distributed with this work for additional information        *
 * regarding copyright ownership.  The ASF licenses this file   *
 * to you 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.util.ArrayList;
import java.util.List;

import javax.mail.Session;
import javax.mail.internet.ParseException;

import org.apache.commons.configuration.ConfigurationException;
import org.apache.mailet.MailAddress;

/**
 * 

Class Account encapsulates the account details required to * fetch mail from a message store.

* *

Instances are Comparable based on their sequence number.

*/ class Account implements Comparable { private static final int DEFAULT_INITIAL_SIZE_OF_DEFERRED_RECIPIENT_ARRAY = 16; /** * The user password for this account */ private String fieldPassword; /** * The user to send the fetched mail to */ private MailAddress fieldRecipient; /** * The user name for this account */ private String fieldUser; /** * The ParsedConfiguration */ private ParsedConfiguration fieldParsedConfiguration; /** * List of MessageIDs for which processing has been deferred * because the intended recipient could not be found. */ private List fieldDeferredRecipientNotFoundMessageIDs; /** * The sequence number for this account */ private int fieldSequenceNumber; /** * Ignore the recipient deduced from the header and use 'fieldRecipient' */ private boolean fieldIgnoreRecipientHeader; /** * The JavaMail Session for this Account. */ private Session fieldSession; /** * A custom header to be used as the recipient address */ private String customRecipientHeader; /** * Constructor for Account. */ private Account() { super(); } /** * Constructor for Account. * * @param sequenceNumber * @param parsedConfiguration * @param user * @param password * @param recipient * @param ignoreRecipientHeader * @param session * @throws ConfigurationException */ public Account( int sequenceNumber, ParsedConfiguration parsedConfiguration, String user, String password, String recipient, boolean ignoreRecipientHeader, String customRecipientHeader, Session session) throws ConfigurationException { this(); setSequenceNumber(sequenceNumber); setParsedConfiguration(parsedConfiguration); setUser(user); setPassword(password); setRecipient(recipient); setIgnoreRecipientHeader(ignoreRecipientHeader); setCustomRecipientHeader(customRecipientHeader); setSession(session); } /** * Returns the custom recipient header. * @return String */ public String getCustomRecipientHeader() { return this.customRecipientHeader; } /** * Returns the password. * @return String */ public String getPassword() { return fieldPassword; } /** * Returns the recipient. * @return MailAddress */ public MailAddress getRecipient() { return fieldRecipient; } /** * Returns the user. * @return String */ public String getUser() { return fieldUser; } /** * Sets the custom recipient header. * @param customRecipientHeader The header to be used */ public void setCustomRecipientHeader(String customRecipientHeader) { this.customRecipientHeader = customRecipientHeader; } /** * Sets the password. * @param password The password to set */ protected void setPassword(String password) { fieldPassword = password; } /** * Sets the recipient. * @param recipient The recipient to set */ protected void setRecipient(MailAddress recipient) { fieldRecipient = recipient; } /** * Sets the recipient. * @param recipient The recipient to set */ protected void setRecipient(String recipient) throws ConfigurationException { if (null == recipient) { fieldRecipient = null; return; } try { setRecipient(new MailAddress(recipient)); } catch (ParseException pe) { throw new ConfigurationException( "Invalid recipient address specified: " + recipient); } } /** * Sets the user. * @param user The user to set */ protected void setUser(String user) { fieldUser = user; } /** * Sets the ignoreRecipientHeader. * @param ignoreRecipientHeader The ignoreRecipientHeader to set */ protected void setIgnoreRecipientHeader(boolean ignoreRecipientHeader) { fieldIgnoreRecipientHeader = ignoreRecipientHeader; } /** * Returns the ignoreRecipientHeader. * @return boolean */ public boolean isIgnoreRecipientHeader() { return fieldIgnoreRecipientHeader; } /** * Returns the sequenceNumber. * @return int */ public int getSequenceNumber() { return fieldSequenceNumber; } /** * Sets the sequenceNumber. * @param sequenceNumber The sequenceNumber to set */ protected void setSequenceNumber(int sequenceNumber) { fieldSequenceNumber = sequenceNumber; } /** * Compares this object with the specified object for order. Returns a * negative integer, zero, or a positive integer if this object is less * than, equal to, or greater than the specified object. * * @see java.lang.Comparable#compareTo(Object) */ public int compareTo(Account account) { return getSequenceNumber() - account.getSequenceNumber(); } /** * Returns the deferredRecipientNotFoundMessageIDs. lazily initialised. * @return List */ public List getDeferredRecipientNotFoundMessageIDs() { List messageIDs = null; if (null == (messageIDs = getDeferredRecipientNotFoundMessageIDsBasic())) { updateDeferredRecipientNotFoundMessageIDs(); return getDeferredRecipientNotFoundMessageIDs(); } return messageIDs; } /** * Returns the deferredRecipientNotFoundMessageIDs. * @return List */ private List getDeferredRecipientNotFoundMessageIDsBasic() { return fieldDeferredRecipientNotFoundMessageIDs; } /** * Returns a new List of deferredRecipientNotFoundMessageIDs. * @return List */ protected List computeDeferredRecipientNotFoundMessageIDs() { return new ArrayList(DEFAULT_INITIAL_SIZE_OF_DEFERRED_RECIPIENT_ARRAY); } /** * Updates the deferredRecipientNotFoundMessageIDs. */ protected void updateDeferredRecipientNotFoundMessageIDs() { setDeferredRecipientNotFoundMessageIDs(computeDeferredRecipientNotFoundMessageIDs()); } /** * Sets the defferedRecipientNotFoundMessageIDs. * @param defferedRecipientNotFoundMessageIDs The defferedRecipientNotFoundMessageIDs to set */ protected void setDeferredRecipientNotFoundMessageIDs(List defferedRecipientNotFoundMessageIDs) { fieldDeferredRecipientNotFoundMessageIDs = defferedRecipientNotFoundMessageIDs; } /** * Returns the parsedConfiguration. * @return ParsedConfiguration */ public ParsedConfiguration getParsedConfiguration() { return fieldParsedConfiguration; } /** * Sets the parsedConfiguration. * @param parsedConfiguration The parsedConfiguration to set */ protected void setParsedConfiguration(ParsedConfiguration parsedConfiguration) { fieldParsedConfiguration = parsedConfiguration; } /** * Returns the session. * @return Session */ public Session getSession() { return fieldSession; } /** * Sets the session. * @param session The session to set */ protected void setSession(Session session) { fieldSession = session; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy