/****************************************************************
 * 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.mailbox;

import java.util.List;


/**
 * Listens to <code>Mailbox</code> events.<br>
 * Note that listeners may be removed asynchronously.<br>
 * When {@link #isClosed()} returns true, the listener may be removed from the
 * mailbox by the dispatcher.
 */
public interface MailboxListener {

    /**
     * Informs this listener about the given event.
     * 
     * @param event
     *            not null
     */
    void event(final Event event);

    /**
     * A mailbox event.
     */
    public class Event {
        private final MailboxSession session;
        private final MailboxPath path;

        public Event(final MailboxSession session, final MailboxPath path) {
            this.session = session;
            this.path = path;
        }

        /**
         * Gets the {@link MailboxSession} in which's context the {@link Event}
         * happened
         * 
         * @return session
         */
        public MailboxSession getSession() {
            return session;
        }

        /**
         * Return the path of the Mailbox this event belongs to.
         * 
         * @return path
         */
        public MailboxPath getMailboxPath() {
            return path;
        }
    }

    /**
     * Indicates that mailbox has been deleted.
     */
    public class MailboxDeletion extends Event {

        public MailboxDeletion(final MailboxSession session, MailboxPath path) {
            super(session, path);
        }
    }

    /**
     * Indicates that a mailbox has been Added.
     */
    public class MailboxAdded extends Event {
        public MailboxAdded(final MailboxSession session, MailboxPath path) {
            super(session, path);
        }
    }

    /**
     * Indicates that a mailbox has been renamed.
     */
    public abstract class MailboxRenamed extends Event {
        public MailboxRenamed(final MailboxSession session, MailboxPath path) {
            super(session, path);
        }

        /**
         * Gets the new name for this mailbox.
         * 
         * @return name, not null
         */
        public abstract MailboxPath getNewPath();
    }

    /**
     * A mailbox event related to a message.
     */
    public abstract class MessageEvent extends Event {

        public MessageEvent(MailboxSession session, MailboxPath path) {
            super(session, path);
        }

        /**
         * Gets the message UIDs for the subject of this event.
         * 
         * @return message uids
         */
        public abstract List<Long> getUids();
    }

    public abstract class Expunged extends MessageEvent {

        public Expunged(MailboxSession session, MailboxPath path) {
            super(session, path);
        }
        
        /**
         * Return the flags which were set for the added message
         * 
         * @return flags
         */
        public abstract MessageMetaData getMetaData(long uid);
    }

    /**
     * A mailbox event related to updated flags
     */
    public abstract class FlagsUpdated extends MessageEvent {

        public FlagsUpdated(MailboxSession session, MailboxPath path) {
            super(session, path);
        }

        public abstract List<UpdatedFlags> getUpdatedFlags();
    }

    /**
     * A mailbox event related to added message
     */
    public abstract class Added extends MessageEvent {

        public Added(MailboxSession session, MailboxPath path) {
            super(session, path);
        }
        
        /**
         * Return the flags which were set for the added message
         * 
         * @return flags
         */
        public abstract MessageMetaData getMetaData(long uid);
        
    }

}

@@ -1218,16 +1218,45 @@
 ilbox;%0A%0A
+import java.io.Serializable;%0A
 import j
@@ -1270,16 +1270,16 @@
 l.List;%0A
-
 %0A%0A/**%0A *
@@ -1721,32 +1721,64 @@
  event.%0A     */%0A
+    @SuppressWarnings(%22serial%22)%0A
     public class
@@ -1768,24 +1768,33 @@
 %0A    public 
+abstract 
 class Event 
@@ -1785,32 +1785,56 @@
 act class Event 
+implements Serializable 
 %7B%0A        privat
@@ -2626,32 +2626,126 @@
 xtends Event %7B%0A%0A
+        /**%0A         * %0A         */%0A        private static final long serialVersionUID = 1L;%0A%0A
         public M
@@ -2962,32 +2962,126 @@
 extends Event %7B%0A
+        /**%0A         * %0A         */%0A        private static final long serialVersionUID = 1L;%0A%0A
         public M
@@ -3308,32 +3308,126 @@
 extends Event %7B%0A
+        /**%0A         * %0A         */%0A        private static final long serialVersionUID = 1L;%0A%0A
         public M
@@ -3818,32 +3818,126 @@
 xtends Event %7B%0A%0A
+        /**%0A         * %0A         */%0A        private static final long serialVersionUID = 1L;%0A%0A
         public M
@@ -4273,32 +4273,126 @@
 MessageEvent %7B%0A%0A
+        /**%0A         * %0A         */%0A        private static final long serialVersionUID = 1L;%0A%0A
         public E
@@ -4811,32 +4811,126 @@
 MessageEvent %7B%0A%0A
+        /**%0A         * %0A         */%0A        private static final long serialVersionUID = 1L;%0A%0A
         public F
@@ -5155,32 +5155,32 @@
 message%0A     */%0A
-
     public abstr
@@ -5211,32 +5211,126 @@
 MessageEvent %7B%0A%0A
+        /**%0A         * %0A         */%0A        private static final long serialVersionUID = 1L;%0A%0A
         public A

Make MailboxListener.Event implement Serializable. See MAILBOX-147