You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jl...@apache.org on 2022/05/03 12:22:12 UTC

svn commit: r1900504 [6/22] - in /geronimo/specs/trunk: ./ geronimo-activation_2.0_spec/ geronimo-activation_2.0_spec/src/ geronimo-activation_2.0_spec/src/main/ geronimo-activation_2.0_spec/src/main/java/ geronimo-activation_2.0_spec/src/main/java/jak...

Added: geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/Service.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/Service.java?rev=1900504&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/Service.java (added)
+++ geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/Service.java Tue May  3 12:22:08 2022
@@ -0,0 +1,440 @@
+/*
+ * 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 jakarta.mail;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.EventListener;
+import java.util.List;
+import java.util.Vector;
+
+import jakarta.mail.event.ConnectionEvent;
+import jakarta.mail.event.ConnectionListener;
+import jakarta.mail.event.MailEvent;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public abstract class Service implements AutoCloseable {
+    /**
+     * The session from which this service was created.
+     */
+    protected Session session;
+    /**
+     * The URLName of this service
+     */
+    protected URLName url;
+    /**
+     * Debug flag for this service, set from the Session's debug flag.
+     */
+    protected boolean debug;
+
+    private boolean connected;
+    private final Vector connectionListeners = new Vector(2);
+    // the EventQueue spins off a new thread, so we only create this
+    // if we have actual listeners to dispatch an event to.
+    private EventQueue queue = null;
+    // when returning the URL, we need to ensure that the password and file information is
+    // stripped out.
+    private URLName exposedUrl;
+
+    /**
+     * Construct a new Service.
+     * @param session the session from which this service was created
+     * @param url the URLName of this service
+     */
+    protected Service(final Session session, final URLName url) {
+        this.session = session;
+        this.url = url;
+        this.debug = session.getDebug();
+    }
+
+    /**
+     * A generic connect method that takes no parameters allowing subclasses
+     * to implement an appropriate authentication scheme.
+     * The default implementation calls <code>connect(null, null, null)</code>
+     * @throws AuthenticationFailedException if authentication fails
+     * @throws MessagingException for other failures
+     */
+    public void connect() throws MessagingException {
+        connect(null, null, null);
+    }
+
+    /**
+     * Connect to the specified host using a simple username/password authenticaion scheme
+     * and the default port.
+     * The default implementation calls <code>connect(host, -1, user, password)</code>
+     *
+     * @param host the host to connect to
+     * @param user the user name
+     * @param password the user's password
+     * @throws AuthenticationFailedException if authentication fails
+     * @throws MessagingException for other failures
+     */
+    public void connect(final String host, final String user, final String password) throws MessagingException {
+        connect(host, -1, user, password);
+    }
+
+    /**
+     * Connect to the specified host using a simple username/password authenticaion scheme
+     * and the default host and port.
+     * The default implementation calls <code>connect(host, -1, user, password)</code>
+     *
+     * @param user the user name
+     * @param password the user's password
+     * @throws AuthenticationFailedException if authentication fails
+     * @throws MessagingException for other failures
+     */
+    public void connect(final String user, final String password) throws MessagingException {
+        connect(null, -1, user, password);
+    }
+
+    /**
+     * Connect to the specified host at the specified port using a simple username/password authenticaion scheme.
+     *
+     * If this Service is already connected, an IllegalStateException is thrown.
+     *
+     * @param host the host to connect to
+     * @param port the port to connect to; pass -1 to use the default for the protocol
+     * @param user the user name
+     * @param password the user's password
+     * @throws AuthenticationFailedException if authentication fails
+     * @throws MessagingException for other failures
+     * @throws IllegalStateException if this service is already connected
+     */
+    public void connect(String host, int port, String user, String password) throws MessagingException {
+
+        if (isConnected()) {
+            throw new IllegalStateException("Already connected");
+        }
+
+        // before we try to connect, we need to derive values for some parameters that may not have
+        // been explicitly specified.  For example, the normal connect() method leaves us to derive all
+        // of these from other sources.  Some of the values are derived from our URLName value, others
+        // from session parameters.  We need to go through all of these to develop a set of values we
+        // can connect with.
+
+        // this is the protocol we're connecting with.  We use this largely to derive configured values from
+        // session properties.
+        String protocol = null;
+
+        // if we're working with the URL form, then we can retrieve the protocol from the URL.
+        if (url != null) {
+            protocol = url.getProtocol();
+        }
+
+        // if the port is -1, see if we have an override from url.
+        if (port == -1) {
+            if (protocol != null) {
+                port = url.getPort();
+            }
+        }
+
+        // now try to derive values for any of the arguments we've been given as defaults
+        if (host == null) {
+            // first choice is from the url, if we have
+            if (url != null) {
+                host = url.getHost();
+                // it is possible that this could return null (rare).  If it does, try to get a
+                // value from a protocol specific session variable.
+                if (host == null) {
+                	if (protocol != null) {
+                		host = session.getProperty("mail." + protocol + ".host");
+                	}
+                }
+            }
+            // this may still be null...get the global mail property
+            if (host == null) {
+                host = session.getProperty("mail.host");
+            }
+        }
+
+        // ok, go after userid information next.
+        if (user == null) {
+            // first choice is from the url, if we have
+            if (url != null) {
+                user = url.getUsername();
+                // make sure we get the password from the url, if we can.
+                if (password == null) {
+                    password = url.getPassword();
+                }
+            }
+
+            // user still null?  We have several levels of properties to try yet
+            if (user == null) {
+                if (protocol != null) {
+                    user = session.getProperty("mail." + protocol + ".user");
+                }
+
+                // this may still be null...get the global mail property
+                if (user == null) {
+                    user = session.getProperty("mail.user");
+                    // still null, try using the user.name system property
+                    if (user == null) {
+                        // finally, we try getting the system defined user name
+                        try {
+                            user = System.getProperty("user.name");
+                        } catch (final SecurityException e) {
+                            // we ignore this, and just us a null username.
+                        }
+                    }
+                }
+            }
+        }
+        // if we have an explicitly given user name, we need to see if this matches the url one and
+        // grab the password from there.
+        else {
+            if (url != null && user.equals(url.getUsername())) {
+                password = url.getPassword();
+            }
+        }
+
+        // we need to update the URLName associated with this connection once we have all of the information,
+        // which means we also need to propogate the file portion of the URLName if we have this form when
+        // we start.
+        String file = null;
+        if (url != null) {
+            file = url.getFile();
+        }
+
+        // see if we have cached security information to use.  If this is not cached, we'll save it
+        // after we successfully connect.
+        boolean cachePassword = false;
+
+
+        // still have a null password to this point, and using a url form?
+        if (password == null && url != null) {
+            // construct a new URL, filling in any pieces that may have been explicitly specified.
+            setURLName(new URLName(protocol, host, port, file, user, password));
+            // now see if we have a saved password from a previous request.
+            final PasswordAuthentication cachedPassword = session.getPasswordAuthentication(getURLName());
+
+            // if we found a saved one, see if we need to get any the pieces from here.
+            if (cachedPassword != null) {
+                // not even a resolved userid?  Then use both bits.
+                if (user == null) {
+                    user = cachedPassword.getUserName();
+                    password = cachedPassword.getPassword();
+                }
+                // our user name must match the cached name to be valid.
+                else if (user.equals(cachedPassword.getUserName())) {
+                    password = cachedPassword.getPassword();
+                }
+            }
+            else
+            {
+                // nothing found in the cache, so we need to save this if we can connect successfully.
+                cachePassword = true;
+            }
+        }
+
+        // we've done our best up to this point to obtain all of the information needed to make the
+        // connection.  Now we pass this off to the protocol handler to see if it works.  If we get a
+        // connection failure, we may need to prompt for a password before continuing.
+        try {
+            connected = protocolConnect(host, port, user, password);
+        }
+        catch (final AuthenticationFailedException e) {
+        }
+
+        if (!connected) {
+            InetAddress ipAddress = null;
+
+            try {
+                ipAddress = InetAddress.getByName(host);
+            } catch (final UnknownHostException e) {
+            }
+
+            // now ask the session to try prompting for a password.
+            final PasswordAuthentication promptPassword = session.requestPasswordAuthentication(ipAddress, port, protocol, null, user);
+
+            // if we were able to obtain new information from the session, then try again using the
+            // provided information .
+            if (promptPassword != null) {
+                user = promptPassword.getUserName();
+                password = promptPassword.getPassword();
+            }
+
+            connected = protocolConnect(host, port, user, password);
+        }
+
+
+        // if we're still not connected, then this is an exception.
+        if (!connected) {
+            throw new AuthenticationFailedException();
+        }
+
+        // the URL name needs to reflect the most recent information.
+        setURLName(new URLName(protocol, host, port, file, user, password));
+
+        // we need to update the global password cache with this information.
+        if (cachePassword) {
+            session.setPasswordAuthentication(getURLName(), new PasswordAuthentication(user, password));
+        }
+
+        // we're now connected....broadcast this to any interested parties.
+        setConnected(connected);
+        notifyConnectionListeners(ConnectionEvent.OPENED);
+    }
+
+    /**
+     * Attempt the protocol-specific connection; subclasses should override this to establish
+     * a connection in the appropriate manner.
+     *
+     * This method should return true if the connection was established.
+     * It may return false to cause the {@link #connect(String, int, String, String)} method to
+     * reattempt the connection after trying to obtain user and password information from the user.
+     * Alternatively it may throw a AuthenticatedFailedException to abandon the conection attempt.
+     *
+     * @param host     The target host name of the service.
+     * @param port     The connection port for the service.
+     * @param user     The user name used for the connection.
+     * @param password The password used for the connection.
+     *
+     * @return true if a connection was established, false if there was authentication
+     *         error with the connection.
+     * @throws AuthenticationFailedException
+     *                if authentication fails
+     * @throws MessagingException
+     *                for other failures
+     */
+    protected boolean protocolConnect(final String host, final int port, final String user, final String password) throws MessagingException {
+        return false;
+    }
+
+    /**
+     * Check if this service is currently connected.
+     * The default implementation simply returns the value of a private boolean field;
+     * subclasses may wish to override this method to verify the physical connection.
+     *
+     * @return true if this service is connected
+     */
+    public boolean isConnected() {
+        return connected;
+    }
+
+    /**
+     * Notification to subclasses that the connection state has changed.
+     * This method is called by the connect() and close() methods to indicate state change;
+     * subclasses should also call this method if the connection is automatically closed
+     * for some reason.
+     *
+     * @param connected the connection state
+     */
+    protected void setConnected(final boolean connected) {
+        this.connected = connected;
+    }
+
+    /**
+     * Close this service and terminate its physical connection.
+     * The default implementation simply calls setConnected(false) and then
+     * sends a CLOSED event to all registered ConnectionListeners.
+     * Subclasses overriding this method should still ensure it is closed; they should
+     * also ensure that it is called if the connection is closed automatically, for
+     * for example in a finalizer.
+     *
+     *@throws MessagingException if there were errors closing; the connection is still closed
+     */
+    public void close() throws MessagingException {
+        setConnected(false);
+        notifyConnectionListeners(ConnectionEvent.CLOSED);
+    }
+
+    /**
+     * Return a copy of the URLName representing this service with the password and file information removed.
+     *
+     * @return the URLName for this service
+     */
+    public URLName getURLName() {
+        // if we haven't composed the URL version we hand out, create it now.  But only if we really
+        // have a URL.
+        if (exposedUrl == null) {
+            if (url != null) {
+                exposedUrl = new URLName(url.getProtocol(), url.getHost(), url.getPort(), null, url.getUsername(), null);
+            }
+        }
+        return exposedUrl;
+    }
+
+    /**
+     * Set the url field.
+     * @param url the new value
+     */
+    protected void setURLName(final URLName url) {
+        this.url = url;
+    }
+
+    public void addConnectionListener(final ConnectionListener listener) {
+        connectionListeners.add(listener);
+    }
+
+    public void removeConnectionListener(final ConnectionListener listener) {
+        connectionListeners.remove(listener);
+    }
+
+    protected void notifyConnectionListeners(final int type) {
+        queueEvent(new ConnectionEvent(this, type), connectionListeners);
+    }
+
+    @Override
+    public String toString() {
+        // NOTE:  We call getURLName() rather than use the URL directly
+        // because the get method strips out the password information.
+        final URLName url = getURLName();
+
+        return url == null ? super.toString() : url.toString();
+    }
+
+    protected void queueEvent(final MailEvent event, final Vector<? extends EventListener> listeners) {
+        // if there are no listeners to dispatch this to, don't put it on the queue.
+        // This allows us to delay creating the queue (and its new thread) until
+        // we
+        if (listeners.isEmpty()) {
+            return;
+        }
+        // first real event?  Time to get the queue kicked off.
+        if (queue == null) {
+            queue = new EventQueue();
+        }
+        // tee it up and let it rip.
+        queue.queueEvent(event, (List)listeners.clone());
+    }
+
+    @Override
+    protected void finalize() throws Throwable {
+        // stop our event queue if we had to create one
+        if (queue != null) {
+            queue.stop();
+        }
+        connectionListeners.clear();
+        super.finalize();
+    }
+
+
+    /**
+     * Package scope utility method to allow Message instances
+     * access to the Service's session.
+     *
+     * @return The Session the service is associated with.
+     */
+    Session getSession() {
+        return session;
+    }
+}

Added: geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/Session.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/Session.java?rev=1900504&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/Session.java (added)
+++ geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/Session.java Tue May  3 12:22:08 2022
@@ -0,0 +1,877 @@
+/*
+ * 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 jakarta.mail;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.PrintStream;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.net.InetAddress;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.StringTokenizer;
+import java.util.WeakHashMap;
+
+import org.apache.geronimo.mail.MailProviderRegistry;
+import org.apache.geronimo.osgi.locator.ProviderLocator;
+
+/**
+ * OK, so we have a final class in the API with a heck of a lot of implementation required...
+ * let's try and figure out what it is meant to do.
+ * <p/>
+ * It is supposed to collect together properties and defaults so that they can be
+ * shared by multiple applications on a desktop; with process isolation and no
+ * real concept of shared memory, this seems challenging. These properties and
+ * defaults rely on system properties, making management in a app server harder,
+ * and on resources loaded from "mail.jar" which may lead to skew between
+ * differnet independent implementations of this API.
+ *
+ * @version $Rev$ $Date$
+ */
+public final class Session {
+    private static final Class[] PARAM_TYPES = {Session.class, URLName.class};
+    private static final WeakHashMap addressMapsByClassLoader = new WeakHashMap();
+    private static Session DEFAULT_SESSION;
+
+    private final Map passwordAuthentications = new HashMap();
+
+    private final Properties properties;
+    private final Authenticator authenticator;
+    private boolean debug;
+    private PrintStream debugOut = System.out;
+
+    private static final WeakHashMap providersByClassLoader = new WeakHashMap();
+
+    /**
+     * No public constrcutor allowed.
+     */
+    private Session(final Properties properties, final Authenticator authenticator) {
+        this.properties = properties;
+        this.authenticator = authenticator;
+        debug = Boolean.valueOf(properties.getProperty("mail.debug")).booleanValue();
+    }
+
+    /**
+     * Create a new session initialized with the supplied properties which uses the supplied authenticator.
+     * Clients should ensure the properties listed in Appendix A of the JavaMail specification are
+     * set as the defaults are unlikey to work in most scenarios; particular attention should be given
+     * to:
+     * <ul>
+     * <li>mail.store.protocol</li>
+     * <li>mail.transport.protocol</li>
+     * <li>mail.host</li>
+     * <li>mail.user</li>
+     * <li>mail.from</li>
+     * </ul>
+     *
+     * @param properties    the session properties
+     * @param authenticator an authenticator for callbacks to the user
+     * @return a new session
+     */
+    public static Session getInstance(Properties properties, final Authenticator authenticator) {
+        // if we have a properties bundle, we need a copy of the provided one
+        if (properties != null) {
+            properties = (Properties)properties.clone();
+        }
+
+        return new Session(properties, authenticator);
+    }
+
+    /**
+     * Create a new session initialized with the supplied properties with no authenticator.
+     *
+     * @param properties the session properties
+     * @return a new session
+     * @see #getInstance(java.util.Properties, Authenticator)
+     */
+    public static Session getInstance(final Properties properties) {
+        return getInstance(properties, null);
+    }
+
+    /**
+     * Get the "default" instance assuming no authenticator is required.
+     *
+     * @param properties the session properties
+     * @return if "default" session
+     * @throws SecurityException if the does not have permission to access the default session
+     */
+    public synchronized static Session getDefaultInstance(final Properties properties) {
+        return getDefaultInstance(properties, null);
+    }
+
+    /**
+     * Get the "default" session.
+     * If there is not current "default", a new Session is created and installed as the default.
+     *
+     * @param properties
+     * @param authenticator
+     * @return if "default" session
+     * @throws SecurityException if the does not have permission to access the default session
+     */
+    public synchronized static Session getDefaultInstance(final Properties properties, final Authenticator authenticator) {
+        if (DEFAULT_SESSION == null) {
+            DEFAULT_SESSION = getInstance(properties, authenticator);
+        } else {
+            if (authenticator != DEFAULT_SESSION.authenticator) {
+                if (authenticator == null || DEFAULT_SESSION.authenticator == null || authenticator.getClass().getClassLoader() != DEFAULT_SESSION.authenticator.getClass().getClassLoader()) {
+                    throw new SecurityException();
+                }
+            }
+            // todo we should check with the SecurityManager here as well
+        }
+        return DEFAULT_SESSION;
+    }
+
+    /**
+     * Enable debugging for this session.
+     * Debugging can also be enabled by setting the "mail.debug" property to true when
+     * the session is being created.
+     *
+     * @param debug the debug setting
+     */
+    public void setDebug(final boolean debug) {
+        this.debug = debug;
+    }
+
+    /**
+     * Get the debug setting for this session.
+     *
+     * @return the debug setting
+     */
+    public boolean getDebug() {
+        return debug;
+    }
+
+    /**
+     * Set the output stream where debug information should be sent.
+     * If set to null, System.out will be used.
+     *
+     * @param out the stream to write debug information to
+     */
+    public void setDebugOut(final PrintStream out) {
+        debugOut = out == null ? System.out : out;
+    }
+
+    /**
+     * Return the debug output stream.
+     *
+     * @return the debug output stream
+     */
+    public PrintStream getDebugOut() {
+        return debugOut;
+    }
+
+    /**
+     * Return the list of providers available to this application.
+     * This method searches for providers that are defined in the javamail.providers
+     * and javamail.default.providers resources available through the current context
+     * classloader, or if that is not available, the classloader that loaded this class.
+     * <p/>
+     * As searching for providers is potentially expensive, this implementation maintains
+     * a WeakHashMap of providers indexed by ClassLoader.
+     *
+     * @return an array of providers
+     */
+    public Provider[] getProviders() {
+        final ProviderInfo info = getProviderInfo();
+        return (Provider[]) info.all.toArray(new Provider[info.all.size()]);
+    }
+
+    /**
+     * Return the provider for a specific protocol.
+     * This implementation initially looks in the Session properties for an property with the name
+     * "mail.<protocol>.class"; if found it attempts to create an instance of the class named in that
+     * property throwing a NoSuchProviderException if the class cannot be loaded.
+     * If this property is not found, it searches the providers returned by {@link #getProviders()}
+     * for a entry for the specified protocol.
+     *
+     * @param protocol the protocol to get a provider for
+     * @return a provider for that protocol
+     * @throws NoSuchProviderException
+     */
+    public Provider getProvider(final String protocol) throws NoSuchProviderException {
+        final ProviderInfo info = getProviderInfo();
+        Provider provider = null;
+        final String providerName = properties.getProperty("mail." + protocol + ".class");
+        if (providerName != null) {
+            provider = (Provider) info.byClassName.get(providerName);
+            if (debug) {
+                writeDebug("DEBUG: new provider loaded: " + provider.toString());
+            }
+        }
+
+        // if not able to locate this by class name, just grab a registered protocol.
+        if (provider == null) {
+            provider = (Provider) info.byProtocol.get(protocol);
+        }
+
+        if (provider == null) {
+            throw new NoSuchProviderException("Unable to locate provider for protocol: " + protocol);
+        }
+        if (debug) {
+            writeDebug("DEBUG: getProvider() returning provider " + provider.toString());
+        }
+        return provider;
+    }
+
+    /**
+     * Make the supplied Provider the default for its protocol.
+     *
+     * @param provider the new default Provider
+     * @throws NoSuchProviderException
+     */
+    public void setProvider(final Provider provider) throws NoSuchProviderException {
+        final ProviderInfo info = getProviderInfo();
+        info.byProtocol.put(provider.getProtocol(), provider);
+    }
+
+    /**
+     * Return a Store for the default protocol defined by the mail.store.protocol property.
+     *
+     * @return the store for the default protocol
+     * @throws NoSuchProviderException
+     */
+    public Store getStore() throws NoSuchProviderException {
+        final String protocol = properties.getProperty("mail.store.protocol");
+        if (protocol == null) {
+            throw new NoSuchProviderException("mail.store.protocol property is not set");
+        }
+        return getStore(protocol);
+    }
+
+    /**
+     * Return a Store for the specified protocol.
+     *
+     * @param protocol the protocol to get a Store for
+     * @return a Store
+     * @throws NoSuchProviderException if no provider is defined for the specified protocol
+     */
+    public Store getStore(final String protocol) throws NoSuchProviderException {
+        final Provider provider = getProvider(protocol);
+        return getStore(provider);
+    }
+
+    /**
+     * Return a Store for the protocol specified in the given URL
+     *
+     * @param url the URL of the Store
+     * @return a Store
+     * @throws NoSuchProviderException if no provider is defined for the specified protocol
+     */
+    public Store getStore(final URLName url) throws NoSuchProviderException {
+        return (Store) getService(getProvider(url.getProtocol()), url);
+    }
+
+    /**
+     * Return the Store specified by the given provider.
+     *
+     * @param provider the provider to create from
+     * @return a Store
+     * @throws NoSuchProviderException if there was a problem creating the Store
+     */
+    public Store getStore(final Provider provider) throws NoSuchProviderException {
+        if (Provider.Type.STORE != provider.getType()) {
+            throw new NoSuchProviderException("Not a Store Provider: " + provider);
+        }
+        return (Store) getService(provider, null);
+    }
+
+    /**
+     * Return a closed folder for the supplied URLName, or null if it cannot be obtained.
+     * <p/>
+     * The scheme portion of the URL is used to locate the Provider and create the Store;
+     * the returned Store is then used to obtain the folder.
+     *
+     * @param name the location of the folder
+     * @return the requested folder, or null if it is unavailable
+     * @throws NoSuchProviderException if there is no provider
+     * @throws MessagingException      if there was a problem accessing the Store
+     */
+    public Folder getFolder(final URLName name) throws MessagingException {
+        final Store store = getStore(name);
+        return store.getFolder(name);
+    }
+
+    /**
+     * Return a Transport for the default protocol specified by the
+     * <code>mail.transport.protocol</code> property.
+     *
+     * @return a Transport
+     * @throws NoSuchProviderException
+     */
+    public Transport getTransport() throws NoSuchProviderException {
+        final String protocol = properties.getProperty("mail.transport.protocol");
+        if (protocol == null) {
+            throw new NoSuchProviderException("mail.transport.protocol property is not set");
+        }
+        return getTransport(protocol);
+    }
+
+    /**
+     * Return a Transport for the specified protocol.
+     *
+     * @param protocol the protocol to use
+     * @return a Transport
+     * @throws NoSuchProviderException
+     */
+    public Transport getTransport(final String protocol) throws NoSuchProviderException {
+        final Provider provider = getProvider(protocol);
+        return getTransport(provider);
+    }
+
+    /**
+     * Return a transport for the protocol specified in the URL.
+     *
+     * @param name the URL whose scheme specifies the protocol
+     * @return a Transport
+     * @throws NoSuchProviderException
+     */
+    public Transport getTransport(final URLName name) throws NoSuchProviderException {
+        return (Transport) getService(getProvider(name.getProtocol()), name);
+    }
+
+    /**
+     * Return a transport for the protocol associated with the type of this address.
+     *
+     * @param address the address we are trying to deliver to
+     * @return a Transport
+     * @throws NoSuchProviderException
+     */
+    public Transport getTransport(final Address address) throws NoSuchProviderException {
+        final String type = address.getType();
+        // load the address map from the resource files.
+        final Map addressMap = getAddressMap();
+        final String protocolName = (String)addressMap.get(type);
+        if (protocolName == null) {
+            throw new NoSuchProviderException("No provider for address type " + type);
+        }
+        return getTransport(protocolName);
+    }
+
+    /**
+     * Return the Transport specified by a Provider
+     *
+     * @param provider the defining Provider
+     * @return a Transport
+     * @throws NoSuchProviderException
+     */
+    public Transport getTransport(final Provider provider) throws NoSuchProviderException {
+        return (Transport) getService(provider, null);
+    }
+
+    /**
+     * Set the password authentication associated with a URL.
+     *
+     * @param name          the url
+     * @param authenticator the authenticator
+     */
+    public void setPasswordAuthentication(final URLName name, final PasswordAuthentication authenticator) {
+        if (authenticator == null) {
+            passwordAuthentications.remove(name);
+        } else {
+            passwordAuthentications.put(name, authenticator);
+        }
+    }
+
+    /**
+     * Get the password authentication associated with a URL
+     *
+     * @param name the URL
+     * @return any authenticator for that url, or null if none
+     */
+    public PasswordAuthentication getPasswordAuthentication(final URLName name) {
+        return (PasswordAuthentication) passwordAuthentications.get(name);
+    }
+
+    /**
+     * Call back to the application supplied authenticator to get the needed username add password.
+     *
+     * @param host            the host we are trying to connect to, may be null
+     * @param port            the port on that host
+     * @param protocol        the protocol trying to be used
+     * @param prompt          a String to show as part of the prompt, may be null
+     * @param defaultUserName the default username, may be null
+     * @return the authentication information collected by the authenticator; may be null
+     */
+    public PasswordAuthentication requestPasswordAuthentication(final InetAddress host, final int port, final String protocol, final String prompt, final String defaultUserName) {
+        if (authenticator == null) {
+            return null;
+        }
+        return authenticator.authenticate(host, port, protocol, prompt, defaultUserName);
+    }
+
+    /**
+     * Return the properties object for this Session; this is a live collection.
+     *
+     * @return the properties for the Session
+     */
+    public Properties getProperties() {
+        return properties;
+    }
+
+    /**
+     * Return the specified property.
+     *
+     * @param property the property to get
+     * @return its value, or null if not present
+     */
+    public String getProperty(final String property) {
+        return getProperties().getProperty(property);
+    }
+
+
+    /**
+     * Add a provider to the Session managed provider list.
+     *
+     * @param provider The new provider to add.
+     */
+    public synchronized void addProvider(final Provider provider) {
+        final ProviderInfo info = getProviderInfo();
+        info.addProvider(provider);
+    }
+
+
+
+    /**
+     * Add a mapping between an address type and a protocol used
+     * to process that address type.
+     *
+     * @param addressType
+     *                 The address type identifier.
+     * @param protocol The protocol name mapping.
+     */
+    public void setProtocolForAddress(final String addressType, final String protocol) {
+        final Map addressMap = getAddressMap();
+
+        // no protocol specified is a removal
+        if (protocol == null) {
+            addressMap.remove(addressType);
+        }
+        else {
+            addressMap.put(addressType, protocol);
+        }
+    }
+
+
+    private Service getService(final Provider provider, URLName name) throws NoSuchProviderException {
+        try {
+            if (name == null) {
+                name = new URLName(provider.getProtocol(), null, -1, null, null, null);
+            }
+            final ClassLoader cl = getClassLoader();
+            Class clazz = null;
+            try {
+                clazz = ProviderLocator.loadClass(provider.getClassName(), this.getClass(), cl);
+            } catch (final ClassNotFoundException e) {
+                throw (NoSuchProviderException) new NoSuchProviderException("Unable to load class for provider: " + provider).initCause(e);
+            }
+            final Constructor ctr = clazz.getConstructor(PARAM_TYPES);
+            return(Service) ctr.newInstance(new Object[]{this, name});
+        } catch (final NoSuchMethodException e) {
+            throw (NoSuchProviderException) new NoSuchProviderException("Provider class does not have a constructor(Session, URLName): " + provider).initCause(e);
+        } catch (final InstantiationException e) {
+            throw (NoSuchProviderException) new NoSuchProviderException("Unable to instantiate provider class: " + provider).initCause(e);
+        } catch (final IllegalAccessException e) {
+            throw (NoSuchProviderException) new NoSuchProviderException("Unable to instantiate provider class: " + provider).initCause(e);
+        } catch (final InvocationTargetException e) {
+            throw (NoSuchProviderException) new NoSuchProviderException("Exception from constructor of provider class: " + provider).initCause(e.getCause());
+        }
+    }
+
+    private ProviderInfo getProviderInfo() {
+        final ClassLoader cl = getClassLoader();
+        synchronized (providersByClassLoader) {
+            ProviderInfo info = (ProviderInfo) providersByClassLoader.get(cl);
+            if (info == null) {
+                info = loadProviders(cl);
+            }
+            return info;
+        }
+    }
+
+    private Map getAddressMap() {
+        final ClassLoader cl = getClassLoader();
+        Map addressMap = (Map)addressMapsByClassLoader.get(cl);
+        if (addressMap == null) {
+            addressMap = loadAddressMap(cl);
+        }
+        return addressMap;
+    }
+
+
+    /**
+     * Resolve a class loader used to resolve context resources.  The
+     * class loader used is either a current thread context class
+     * loader (if set), the class loader used to load an authenticator
+     * we've been initialized with, or the class loader used to load
+     * this class instance (which may be a subclass of Session).
+     *
+     * @return The class loader used to load resources.
+     */
+    private ClassLoader getClassLoader() {
+        ClassLoader cl = Thread.currentThread().getContextClassLoader();
+        if (cl == null) {
+            if (authenticator != null) {
+                cl = authenticator.getClass().getClassLoader();
+            }
+            else {
+                cl = this.getClass().getClassLoader();
+            }
+        }
+        return cl;
+    }
+
+    private ProviderInfo loadProviders(final ClassLoader cl) {
+        // we create a merged map from reading all of the potential address map entries.  The locations
+        // searched are:
+        //   0. java.home/conf/javamail.address.map
+        //   1. java.home/lib/javamail.address.map
+        //   2. META-INF/javamail.address.map
+        //   3. META-INF/javamail.default.address.map
+        //
+        // JDK 1.9 adds a new <java.home>/conf directory to hold configuration
+        // files that were previously stored in <java.home>/lib.  When using
+        // JavaMail on JDK 1.9, it should look for its (optional) configuration
+        // files in the <java.home>/conf directory.
+        final ProviderInfo info = new ProviderInfo();
+
+        // NOTE:  Unlike the addressMap, we process these in the defined order.  The loading routine
+        // will not overwrite entries if they already exist in the map.
+
+        try {
+            File file = new File(System.getProperty("java.home"), "conf/javamail.providers");
+            if (!file.exists()){
+                file = new File(System.getProperty("java.home"), "lib/javamail.providers");
+            }
+            final InputStream is = new FileInputStream(file);
+            try {
+                loadProviders(info, is);
+                if (debug) {
+                    writeDebug("Loaded lib/javamail.providers from " + file.toString());
+                }
+            } finally{
+                is.close();
+            }
+        } catch (final SecurityException e) {
+            // ignore
+        } catch (final IOException e) {
+            // ignore
+        }
+
+        try {
+            final Enumeration e = cl.getResources("META-INF/javamail.providers");
+            while (e.hasMoreElements()) {
+                final URL url = (URL) e.nextElement();
+                if (debug) {
+                    writeDebug("Loading META-INF/javamail.providers from " + url.toString());
+                }
+                final InputStream is = url.openStream();
+                try {
+                    loadProviders(info, is);
+                } finally{
+                    is.close();
+                }
+            }
+        } catch (final SecurityException e) {
+            // ignore
+        } catch (final IOException e) {
+            // ignore
+        }
+
+        // we could be running in an OSGi environment, so there might be some globally defined
+        // providers
+        try {
+            final Collection<URL> l = MailProviderRegistry.getProviders();
+            for (final URL url : l) {
+                if (debug) {
+                    writeDebug("Loading META-INF/javamail.providers from " + url.toString());
+                }
+                final InputStream is = url.openStream();
+                try {
+                    loadProviders(info, is);
+                } finally{
+                    is.close();
+                }
+            }
+        } catch (final SecurityException e) {
+            // ignore
+        } catch (final IOException e) {
+            // ignore
+        }
+
+        try {
+            final Enumeration e = cl.getResources("META-INF/javamail.default.providers");
+            while (e.hasMoreElements()) {
+                final URL url = (URL) e.nextElement();
+                if (debug) {
+                    writeDebug("Loading javamail.default.providers from " + url.toString());
+                }
+
+                final InputStream is = url.openStream();
+                try {
+                    loadProviders(info, is);
+                } finally{
+                    is.close();
+                }
+            }
+        } catch (final SecurityException e) {
+            // ignore
+        } catch (final IOException e) {
+            // ignore
+        }
+
+        // we could be running in an OSGi environment, so there might be some globally defined
+        // providers
+        try {
+            final Collection<URL> l = MailProviderRegistry.getDefaultProviders();
+            for (final URL url : l) {
+                if (debug) {
+                    writeDebug("Loading META-INF/javamail.providers from " + url.toString());
+                }
+                final InputStream is = url.openStream();
+                try {
+                    loadProviders(info, is);
+                } finally{
+                    is.close();
+                }
+            }
+        } catch (final SecurityException e) {
+            // ignore
+        } catch (final IOException e) {
+            // ignore
+        }
+
+        // make sure this is added to the global map.
+        providersByClassLoader.put(cl, info);
+
+        return info;
+    }
+
+    private void loadProviders(final ProviderInfo info, final InputStream is) throws IOException {
+        final BufferedReader reader = new BufferedReader(new InputStreamReader(is));
+        String line;
+        while ((line = reader.readLine()) != null) {
+            // Lines beginning with "#" are just comments.
+            if (line.startsWith("#")) {
+                continue;
+            }
+
+            final StringTokenizer tok = new StringTokenizer(line, ";");
+            String protocol = null;
+            Provider.Type type = null;
+            String className = null;
+            String vendor = null;
+            String version = null;
+            while (tok.hasMoreTokens()) {
+                final String property = tok.nextToken();
+                final int index = property.indexOf('=');
+                if (index == -1) {
+                    continue;
+                }
+                final String key = property.substring(0, index).trim().toLowerCase();
+                final String value = property.substring(index+1).trim();
+                if (protocol == null && "protocol".equals(key)) {
+                    protocol = value;
+                } else if (type == null && "type".equals(key)) {
+                    if ("store".equals(value)) {
+                        type = Provider.Type.STORE;
+                    } else if ("transport".equals(value)) {
+                        type = Provider.Type.TRANSPORT;
+                    }
+                } else if (className == null && "class".equals(key)) {
+                    className = value;
+                } else if ("vendor".equals(key)) {
+                    vendor = value;
+                } else if ("version".equals(key)) {
+                    version = value;
+                }
+            }
+            if (protocol == null || type == null || className == null) {
+                //todo should we log a warning?
+                continue;
+            }
+
+            if (debug) {
+                writeDebug("DEBUG: loading new provider protocol=" + protocol + ", className=" + className + ", vendor=" + vendor + ", version=" + version);
+            }
+            final Provider provider = new Provider(type, protocol, className, vendor, version);
+            // add to the info list.
+            info.addProvider(provider);
+        }
+    }
+
+    /**
+     * Load up an address map associated with a using class loader
+     * instance.
+     *
+     * @param cl     The class loader used to resolve the address map.
+     *
+     * @return A map containing the entries associated with this classloader
+     *         instance.
+     */
+    private static Map loadAddressMap(final ClassLoader cl) {
+        // we create a merged map from reading all of the potential address map entries.  The locations
+        // searched are:
+        //   0. java.home/conf/javamail.address.map
+        //   1. java.home/lib/javamail.address.map
+        //   2. META-INF/javamail.address.map
+        //   3. META-INF/javamail.default.address.map
+        // 
+        // JDK 1.9 adds a new <java.home>/conf directory to hold configuration
+        // files that were previously stored in <java.home>/lib.  When using
+        // JavaMail on JDK 1.9, it should look for its (optional) configuration
+        // files in the <java.home>/conf directory.
+        //
+        // if all of the above searches fail, we just set up some "default" defaults.
+
+        // the format of the address.map file is defined as a property file.  We can cheat and
+        // just use Properties.load() to read in the files.
+        final Properties addressMap = new Properties();
+
+        // add this to the tracking map.
+        addressMapsByClassLoader.put(cl, addressMap);
+
+        // NOTE:  We are reading these resources in reverse order of what's cited above.  This allows
+        // user defined entries to overwrite default entries if there are similarly named items.
+
+        try {
+            final Enumeration e = cl.getResources("META-INF/javamail.default.address.map");
+            while (e.hasMoreElements()) {
+                final URL url = (URL) e.nextElement();
+                final InputStream is = url.openStream();
+                try {
+                    // load as a property file
+                    addressMap.load(is);
+                } finally{
+                    is.close();
+                }
+            }
+        } catch (final SecurityException e) {
+            // ignore
+        } catch (final IOException e) {
+            // ignore
+        }
+
+
+        try {
+            final Enumeration e = cl.getResources("META-INF/javamail.address.map");
+            while (e.hasMoreElements()) {
+                final URL url = (URL) e.nextElement();
+                final InputStream is = url.openStream();
+                try {
+                    // load as a property file
+                    addressMap.load(is);
+                } finally{
+                    is.close();
+                }
+            }
+        } catch (final SecurityException e) {
+            // ignore
+        } catch (final IOException e) {
+            // ignore
+        }
+
+
+        try {
+            File file = new File(System.getProperty("java.home"), "conf/javamail.address.map");
+            if (!file.exists()) {
+                file = new File(System.getProperty("java.home"), "lib/javamail.address.map");
+            }
+            final InputStream is = new FileInputStream(file);
+            try {
+                // load as a property file
+                addressMap.load(is);
+            } finally{
+                is.close();
+            }
+        } catch (final SecurityException e) {
+            // ignore
+        } catch (final IOException e) {
+            // ignore
+        }
+
+        try {
+            final Enumeration e = cl.getResources("META-INF/javamail.address.map");
+            while (e.hasMoreElements()) {
+                final URL url = (URL) e.nextElement();
+                final InputStream is = url.openStream();
+                try {
+                    // load as a property file
+                    addressMap.load(is);
+                } finally{
+                    is.close();
+                }
+            }
+        } catch (final SecurityException e) {
+            // ignore
+        } catch (final IOException e) {
+            // ignore
+        }
+
+
+        // if unable to load anything, at least create the MimeMessage-smtp protocol mapping.
+        if (addressMap.isEmpty()) {
+            addressMap.put("rfc822", "smtp");
+        }
+
+        return addressMap;
+    }
+
+    /**
+     * Private convenience routine for debug output.
+     *
+     * @param msg    The message to write out to the debug stream.
+     */
+    private void writeDebug(final String msg) {
+        debugOut.println(msg);
+    }
+
+
+    private static class ProviderInfo {
+        private final Map byClassName = new HashMap();
+        private final Map byProtocol = new HashMap();
+        private final List all = new ArrayList();
+
+        public void addProvider(final Provider provider) {
+            final String className = provider.getClassName();
+
+            if (!byClassName.containsKey(className)) {
+                byClassName.put(className, provider);
+            }
+
+            final String protocol = provider.getProtocol();
+            if (!byProtocol.containsKey(protocol)) {
+                byProtocol.put(protocol, provider);
+            }
+            all.add(provider);
+        }
+    }
+}

Added: geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/Store.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/Store.java?rev=1900504&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/Store.java (added)
+++ geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/Store.java Tue May  3 12:22:08 2022
@@ -0,0 +1,145 @@
+/*
+ * 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 jakarta.mail;
+
+import java.util.Vector;
+
+import jakarta.mail.event.FolderEvent;
+import jakarta.mail.event.FolderListener;
+import jakarta.mail.event.StoreEvent;
+import jakarta.mail.event.StoreListener;
+
+/**
+ * Abstract class that represents a message store.
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class Store extends Service {
+    private static final Folder[] FOLDER_ARRAY = new Folder[0];
+    private final Vector folderListeners = new Vector(2);
+    private final Vector storeListeners = new Vector(2);
+
+    /**
+     * Constructor specifying session and url of this store.
+     * Subclasses MUST provide a constructor with this signature.
+     *
+     * @param session the session associated with this store
+     * @param name the URL of the store
+     */
+    protected Store(final Session session, final URLName name) {
+        super(session, name);
+    }
+
+    /**
+     * Return a Folder object that represents the root of the namespace for the current user.
+     *
+     * Note that in some store configurations (such as IMAP4) the root folder might
+     * not be the INBOX folder.
+     *
+     * @return the root Folder
+     * @throws MessagingException if there was a problem accessing the store
+     */
+    public abstract Folder getDefaultFolder() throws MessagingException;
+
+    /**
+     * Return the Folder corresponding to the given name.
+     * The folder might not physically exist; the {@link Folder#exists()} method can be used
+     * to determine if it is real.
+     * @param name the name of the Folder to return
+     * @return the corresponding folder
+     * @throws MessagingException if there was a problem accessing the store
+     */
+    public abstract Folder getFolder(String name) throws MessagingException;
+
+    /**
+     * Return the folder identified by the URLName; the URLName must refer to this Store.
+     * Implementations may use the {@link URLName#getFile()} method to determined the folder name.
+     *
+     * @param name the folder to return
+     * @return the corresponding folder
+     * @throws MessagingException if there was a problem accessing the store
+     */
+    public abstract Folder getFolder(URLName name) throws MessagingException;
+
+    /**
+     * Return the root folders of the personal namespace belonging to the current user.
+     *
+     * The default implementation simply returns an array containing the folder returned by {@link #getDefaultFolder()}.
+     * @return the root folders of the user's peronal namespaces
+     * @throws MessagingException if there was a problem accessing the store
+     */
+    public Folder[] getPersonalNamespaces() throws MessagingException {
+        return new Folder[]{getDefaultFolder()};
+    }
+
+    /**
+     * Return the root folders of the personal namespaces belonging to the supplied user.
+     *
+     * The default implementation simply returns an empty array.
+     *
+     * @param user the user whose namespaces should be returned
+     * @return the root folders of the given user's peronal namespaces
+     * @throws MessagingException if there was a problem accessing the store
+     */
+    public Folder[] getUserNamespaces(final String user) throws MessagingException {
+        return FOLDER_ARRAY;
+    }
+
+    /**
+     * Return the root folders of namespaces that are intended to be shared between users.
+     *
+     * The default implementation simply returns an empty array.
+     * @return the root folders of all shared namespaces
+     * @throws MessagingException if there was a problem accessing the store
+     */
+    public Folder[] getSharedNamespaces() throws MessagingException {
+        return FOLDER_ARRAY;
+    }
+
+
+    public void addStoreListener(final StoreListener listener) {
+        storeListeners.add(listener);
+    }
+
+    public void removeStoreListener(final StoreListener listener) {
+        storeListeners.remove(listener);
+    }
+
+    protected void notifyStoreListeners(final int type, final String message) {
+        queueEvent(new StoreEvent(this, type, message), storeListeners);
+    }
+
+
+    public void addFolderListener(final FolderListener listener) {
+        folderListeners.add(listener);
+    }
+
+    public void removeFolderListener(final FolderListener listener) {
+        folderListeners.remove(listener);
+    }
+
+    protected void notifyFolderListeners(final int type, final Folder folder) {
+        queueEvent(new FolderEvent(this, folder, type), folderListeners);
+    }
+
+    protected void notifyFolderRenamedListeners(final Folder oldFolder, final Folder newFolder) {
+        queueEvent(new FolderEvent(this, oldFolder, newFolder, FolderEvent.RENAMED), folderListeners);
+    }
+}

Added: geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/StoreClosedException.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/StoreClosedException.java?rev=1900504&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/StoreClosedException.java (added)
+++ geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/StoreClosedException.java Tue May  3 12:22:08 2022
@@ -0,0 +1,59 @@
+/*
+ * 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 jakarta.mail;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class StoreClosedException extends MessagingException {
+	
+	private static final long serialVersionUID = -3145392336120082655L;
+	
+    private transient Store _store;
+
+    public StoreClosedException(final Store store) {
+        super();
+        _store = store;
+    }
+
+    public StoreClosedException(final Store store, final String message) {
+        super(message);
+        _store = store;
+    }
+    
+    /**
+     * Constructs a StoreClosedException with the specified
+     * detail message and embedded exception.  The exception is chained
+     * to this exception.
+     *
+     * @param store  The dead Store object
+     * @param message    The detailed error message
+     * @param e      The embedded exception
+     * @since        JavaMail 1.5
+     */
+    public StoreClosedException(final Store store, final String message, final Exception e) {
+        super(message, e);
+        _store = store;
+    }
+
+    public Store getStore() {
+        return _store;
+    }
+}

Added: geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/Transport.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/Transport.java?rev=1900504&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/Transport.java (added)
+++ geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/Transport.java Tue May  3 12:22:08 2022
@@ -0,0 +1,279 @@
+/*
+ * 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 jakarta.mail;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Vector;
+
+import jakarta.mail.event.TransportEvent;
+import jakarta.mail.event.TransportListener;
+
+/**
+ * Abstract class modeling a message transport.
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class Transport extends Service {
+    /**
+     * Send a message to all recipient addresses the message contains (as returned by {@link Message#getAllRecipients()})
+     * using message transports appropriate for each address. Message addresses are checked during submission,
+     * but there is no guarantee that the ultimate address is valid or that the message will ever be delivered.
+     * <p/>
+     * {@link Message#saveChanges()} will be called before the message is actually sent.
+     *
+     * @param message the message to send
+     * @throws MessagingException if there was a problem sending the message
+     */
+    public static void send(final Message message) throws MessagingException {
+        send(message, message.getAllRecipients());
+    }
+
+    /**
+     * Send a message to all addresses provided irrespective of any recipients contained in the message, 
+     * using message transports appropriate for each address. Message addresses are checked during submission,
+     * but there is no guarantee that the ultimate address is valid or that the message will ever be delivered.
+     * <p/>
+     * {@link Message#saveChanges()} will be called before the message is actually sent.
+     *
+     * @param message   the message to send
+     * @param addresses the addesses to send to
+     * @throws MessagingException if there was a problem sending the message
+     */
+    public static void send(final Message message, final Address[] addresses) throws MessagingException {
+        sendInternal(message, addresses, null, null);
+    }
+    
+    
+    private static void sendInternal(final Message message, final Address[] addresses, final String user, final String password) throws MessagingException {
+        
+        if (addresses == null || addresses.length == 0) {
+            throw new SendFailedException("No recipient addresses");
+        }
+        
+        final Session session = message.session;
+        final Map<Transport, List<Address>> msgsByTransport = new HashMap<Transport, List<Address>>();
+        for (int i = 0; i < addresses.length; i++) {
+            final Address address = addresses[i];
+            final Transport transport = session.getTransport(address);
+            List<Address> addrs = msgsByTransport.get(transport);
+            if (addrs == null) {
+                addrs = new ArrayList<Address>();
+                msgsByTransport.put(transport, addrs);
+            }
+            addrs.add(address);
+        }
+
+        message.saveChanges();
+
+        // Since we might be sending to multiple protocols, we need to catch and process each exception
+        // when we send and then throw a new SendFailedException when everything is done.  Unfortunately, this
+        // also means unwrapping the information in any SendFailedExceptions we receive and building
+        // composite failed list.
+        MessagingException chainedException = null;
+        final List<Address> sentAddresses = new ArrayList<Address>();
+        final List<Address> unsentAddresses = new ArrayList<Address>();
+        final List<Address> invalidAddresses = new ArrayList<Address>();
+
+
+        for (final Iterator<Entry<Transport, List<Address>>> i = msgsByTransport.entrySet().iterator(); i.hasNext();) {
+            final Entry<Transport, List<Address>> entry = i.next();
+            final Transport transport = entry.getKey();
+            final List<Address> addrs = entry.getValue();
+            try {
+                // we MUST connect to the transport before attempting to send.
+                if(user != null) {
+                    transport.connect(user, password);
+                } else {
+                    transport.connect();
+                }
+                transport.sendMessage(message, addrs.toArray(new Address[addrs.size()]));
+                // if we have to throw an exception because of another failure, these addresses need to
+                // be in the valid list.  Since we succeeded here, we can add these now.
+                sentAddresses.addAll(addrs);
+            } catch (final SendFailedException e) {
+                // a true send failure.  The exception contains a wealth of information about
+                // the failures, including a potential chain of exceptions explaining what went wrong.  We're
+                // going to send a new one of these, so we need to merge the information.
+
+                // add this to our exception chain
+                if (chainedException == null) {
+                    chainedException = e;
+                }
+                else {
+                    chainedException.setNextException(e);
+                }
+
+                // now extract each of the address categories from
+                Address[] exAddrs = e.getValidSentAddresses();
+                if (exAddrs != null) {
+                    for (int j = 0; j < exAddrs.length; j++) {
+                        sentAddresses.add(exAddrs[j]);
+                    }
+                }
+
+                exAddrs = e.getValidUnsentAddresses();
+                if (exAddrs != null) {
+                    for (int j = 0; j < exAddrs.length; j++) {
+                        unsentAddresses.add(exAddrs[j]);
+                    }
+                }
+
+                exAddrs = e.getInvalidAddresses();
+                if (exAddrs != null) {
+                    for (int j = 0; j < exAddrs.length; j++) {
+                        invalidAddresses.add(exAddrs[j]);
+                    }
+                }
+
+            } catch (final MessagingException e) {
+                // add this to our exception chain
+                if (chainedException == null) {
+                    chainedException = e;
+                }
+                else {
+                    chainedException.setNextException(e);
+                }
+            }
+            finally {
+                transport.close();
+            }
+        }
+
+        // if we have an exception chain then we need to throw a new exception giving the failure
+        // information.
+        if (chainedException != null) {
+            // if we're only sending to a single transport (common), and we received a SendFailedException
+            // as a result, then we have a fully formed exception already.  Rather than wrap this in another
+            // exception, we can just rethrow the one we have.
+            if (msgsByTransport.size() == 1 && chainedException instanceof SendFailedException) {
+                throw chainedException;
+            }
+
+            // create our lists for notification and exception reporting from this point on.
+            final Address[] sent = sentAddresses.toArray(new Address[0]);
+            final Address[] unsent = unsentAddresses.toArray(new Address[0]);
+            final Address[] invalid = invalidAddresses.toArray(new Address[0]);
+
+            throw new SendFailedException("Send failure", chainedException, sent, unsent, invalid);
+        }
+    }
+
+    
+    /**
+     * Send a message.  The message will be sent to all recipient
+     * addresses specified in the message (as returned from the
+     * Message method getAllRecipients).
+     * The send method calls the saveChanges
+     * method on the message before sending it. 
+     *
+     * Use the specified user name and password to authenticate to
+     * the mail server.
+     *
+     * @param   msg the message to send
+     * @param   user    the user name
+     * @param   password this user's password
+     * @exception   SendFailedException if the message could not
+     *          be sent to some or any of the recipients.
+     * @exception   MessagingException
+     * @see     Message#saveChanges
+     * @see             #send(Message)
+     * @see     SendFailedException
+     * @since       JavaMail 1.5
+     */
+    public static void send(final Message msg,
+        final String user, final String password) throws MessagingException {
+        
+        send(msg, msg.getAllRecipients(), user, password);
+    }
+
+    /**
+     * Send the message to the specified addresses, ignoring any
+     * recipients specified in the message itself. The
+     * send method calls the saveChanges
+     * method on the message before sending it. 
+     *
+     * Use the specified user name and password to authenticate to
+     * the mail server.
+     *
+     * @param   msg the message to send
+     * @param   addresses the addresses to which to send the message
+     * @param   user    the user name
+     * @param   password this user's password
+     * @exception   SendFailedException if the message could not
+     *          be sent to some or any of the recipients.
+     * @exception   MessagingException
+     * @see     Message#saveChanges
+     * @see             #send(Message)
+     * @see     SendFailedException
+     * @since       JavaMail 1.5
+     */
+    public static void send(final Message msg, final Address[] addresses,
+        final String user, final String password) throws MessagingException {
+        
+        sendInternal(msg, addresses, user, password);
+    
+    }
+    
+    
+    /**
+     * Constructor taking Session and URLName parameters required for {@link Service#Service(Session, URLName)}.
+     *
+     * @param session the Session this transport is for
+     * @param name    the location this transport is for
+     */
+    public Transport(final Session session, final URLName name) {
+        super(session, name);
+    }
+
+    /**
+     * Send a message to the supplied addresses using this transport; if any of the addresses are
+     * invalid then a {@link SendFailedException} is thrown. Whether the message is actually sent
+     * to any of the addresses is undefined.
+     * <p/>
+     * Unlike the static {@link #send(Message, Address[])} method, {@link Message#saveChanges()} is
+     * not called. A {@link TransportEvent} will be sent to registered listeners once the delivery
+     * attempt has been made.
+     *
+     * @param message   the message to send
+     * @param addresses list of addresses to send it to
+     * @throws SendFailedException if the send failed
+     * @throws MessagingException  if there was a problem sending the message
+     */
+    public abstract void sendMessage(Message message, Address[] addresses) throws MessagingException;
+
+    private final Vector<TransportListener> transportListeners = new Vector<TransportListener>();
+
+    public void addTransportListener(final TransportListener listener) {
+        transportListeners.add(listener);
+    }
+
+    public void removeTransportListener(final TransportListener listener) {
+        transportListeners.remove(listener);
+    }
+
+    protected void notifyTransportListeners(final int type, final Address[] validSent, final Address[] validUnsent, final Address[] invalid, final Message message) {
+        queueEvent(new TransportEvent(this, type, validSent, validUnsent, invalid, message), transportListeners);
+    }
+}                                                                                            

Added: geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/UIDFolder.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/UIDFolder.java?rev=1900504&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/UIDFolder.java (added)
+++ geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/UIDFolder.java Tue May  3 12:22:08 2022
@@ -0,0 +1,144 @@
+/*
+ * 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 jakarta.mail;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface UIDFolder {
+    /**
+     * A special value than can be passed as the <code>end</code> parameter to
+     * {@link Folder#getMessages(int, int)} to indicate the last message in this folder.
+     */
+    public static final long LASTUID = -1;
+
+    /**
+     * The largest value possible for a UID, a 32-bit unsigned integer.
+     * This can be used to fetch all new messages by keeping track of the
+     * last UID that was seen and using:
+     * <blockquote><pre>
+     *
+     * 	Folder f = store.getFolder("whatever");
+     *	UIDFolder uf = (UIDFolder)f;
+     *	Message[] newMsgs =
+     *		uf.getMessagesByUID(lastSeenUID + 1, UIDFolder.MAXUID);
+     *
+     * </pre></blockquote><p>
+     *
+     * @since JavaMail 1.6
+     */
+    public static final long MAXUID = 0xffffffffL;
+
+    /**
+     * Get the UID validity value for this Folder.
+     * 
+     * @return The current UID validity value, as a long. 
+     * @exception MessagingException
+     */
+    public abstract long getUIDValidity() throws MessagingException;
+
+    /**
+     * Retrieve a message using the UID rather than the 
+     * message sequence number.  Returns null if the message
+     * doesn't exist.
+     * 
+     * @param uid    The target UID.
+     * 
+     * @return the Message object.  Returns null if the message does
+     *         not exist.
+     * @exception MessagingException
+     */
+    public abstract Message getMessageByUID(long uid)
+            throws MessagingException;
+
+    /**
+     * Get a series of messages using a UID range.  The 
+     * special value LASTUID can be used to mark the 
+     * last available message.
+     * 
+     * @param start  The start of the UID range.
+     * @param end    The end of the UID range.  The special value
+     *               LASTUID can be used to request all messages up
+     *               to the last UID.
+     * 
+     * @return An array containing all of the messages in the 
+     *         range.
+     * @exception MessagingException
+     */
+    public abstract Message[] getMessagesByUID(long start, long end)
+            throws MessagingException;
+
+    /**
+     * Retrieve a set of messages by explicit UIDs.  If 
+     * any message in the list does not exist, null 
+     * will be returned for the corresponding item.
+     * 
+     * @param ids    An array of UID values to be retrieved.
+     * 
+     * @return An array of Message items the same size as the ids
+     *         argument array.  This array will contain null
+     *         entries for any UIDs that do not exist.
+     * @exception MessagingException
+     */
+    public abstract Message[] getMessagesByUID(long[] ids)
+            throws MessagingException;
+
+    /**
+     * Retrieve the UID for a message from this Folder.
+     * The argument Message MUST belong to this Folder
+     * instance, otherwise a NoSuchElementException will 
+     * be thrown.
+     * 
+     * @param message The target message.
+     * 
+     * @return The UID associated with this message.
+     * @exception MessagingException
+     */
+    public abstract long getUID(Message message) throws MessagingException;
+
+    /**
+     * Returns the predicted UID that will be assigned to the
+     * next message that is appended to this folder.
+     * Messages might be appended to the folder after this value
+     * is retrieved, causing this value to be out of date.
+     * This value might only be updated when a folder is first opened.
+     * Note that messages may have been appended to the folder
+     * while it was open and thus this value may be out of
+     * date. <p>
+     *
+     * If the value is unknown, -1 is returned.  <p>
+     *
+     * @return  the UIDNEXT value, or -1 if unknown
+     * @exception       MessagingException for failures
+     * @since   JavaMail 1.6
+     */
+    public long getUIDNext() throws MessagingException;
+
+    /**
+     * Special profile item used for fetching UID information.
+     */
+    public static class FetchProfileItem extends FetchProfile.Item {
+        public static final FetchProfileItem UID = new FetchProfileItem("UID");
+
+        protected FetchProfileItem(final String name) {
+            super(name);
+        }
+    }
+}