james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r1102882 - in /james/mailbox/trunk: api/src/main/java/org/apache/james/mailbox/ api/src/main/java/org/apache/james/mailbox/util/ store/src/main/java/org/apache/james/mailbox/store/
Date Fri, 13 May 2011 20:03:41 GMT
Author: norman
Date: Fri May 13 20:03:41 2011
New Revision: 1102882

URL: http://svn.apache.org/viewvc?rev=1102882&view=rev
Log:
Add some metadata to the Added event which will later be used for support quotas. See MAILBOX-64

Added:
    james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/SimpleMessageMetaData.java
Modified:
    james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
    james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/util/MailboxEventDispatcher.java
    james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java

Modified: james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/MailboxListener.java?rev=1102882&r1=1102881&r2=1102882&view=diff
==============================================================================
--- james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/MailboxListener.java (original)
+++ james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/MailboxListener.java Fri
May 13 20:03:41 2011
@@ -19,8 +19,8 @@
 
 package org.apache.james.mailbox;
 
+import java.util.Date;
 import java.util.List;
-import java.util.Map;
 
 import javax.mail.Flags;
 
@@ -171,7 +171,14 @@ public interface MailboxListener {
          * 
          * @return flags
          */
-        public abstract Map<Long, Flags> getFlags();
+        public abstract MessageMetaData getMetaData(long uid);
+        
+        public interface MessageMetaData {
+            public long getUid();
+            public Flags getFlags();
+            public long getSize();
+            public Date getInternalDate();
+        }
     }
 
 }

Modified: james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/util/MailboxEventDispatcher.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/util/MailboxEventDispatcher.java?rev=1102882&r1=1102881&r2=1102882&view=diff
==============================================================================
--- james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/util/MailboxEventDispatcher.java
(original)
+++ james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/util/MailboxEventDispatcher.java
Fri May 13 20:03:41 2011
@@ -27,9 +27,8 @@ import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.CopyOnWriteArraySet;
 
-import javax.mail.Flags;
-
 import org.apache.james.mailbox.MailboxListener;
+import org.apache.james.mailbox.MailboxListener.Added.MessageMetaData;
 import org.apache.james.mailbox.MailboxPath;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.UpdatedFlags;
@@ -74,7 +73,7 @@ public class MailboxEventDispatcher impl
      * @param sessionId
      * @param path
      */
-    public void added(MailboxSession session, Map<Long, Flags> uids, MailboxPath path)
{
+    public void added(MailboxSession session, Map<Long, MessageMetaData> uids, MailboxPath
path) {
         pruneClosed();
         final AddedImpl added = new AddedImpl(session, path, uids);
         event(added);
@@ -152,12 +151,10 @@ public class MailboxEventDispatcher impl
 
     private final static class AddedImpl extends MailboxListener.Added {
 
-        private final List<Long> uids;
-        private Map<Long, Flags> added;
+        private Map<Long, MessageMetaData> added;
 
-        public AddedImpl(final MailboxSession session, final MailboxPath path, final Map<Long,
Flags> added) {
+        public AddedImpl(final MailboxSession session, final MailboxPath path, final Map<Long,
MessageMetaData> added) {
             super(session, path);
-            this.uids = new ArrayList<Long>(added.keySet());
             this.added = added;
         }
 
@@ -166,16 +163,18 @@ public class MailboxEventDispatcher impl
          * @see org.apache.james.mailbox.MailboxListener.MessageEvent#getUids()
          */
         public List<Long> getUids() {
-            return uids;
+            return new ArrayList<Long>(added.keySet());
         }
 
         /*
          * (non-Javadoc)
-         * @see org.apache.james.mailbox.MailboxListener.Added#getFlags()
+         * @see org.apache.james.mailbox.MailboxListener.Added#getMetaData(long)
          */
-        public Map<Long, Flags> getFlags() {
-            return added;
+        public MessageMetaData getMetaData(long uid) {
+            return added.get(uid);
         }
+
+
     }
 
     private final static class ExpungedImpl extends MailboxListener.Expunged {

Added: james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/SimpleMessageMetaData.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/SimpleMessageMetaData.java?rev=1102882&view=auto
==============================================================================
--- james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/SimpleMessageMetaData.java
(added)
+++ james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/SimpleMessageMetaData.java
Fri May 13 20:03:41 2011
@@ -0,0 +1,73 @@
+/****************************************************************
+ * 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.store;
+
+import java.util.Date;
+
+import javax.mail.Flags;
+
+import org.apache.james.mailbox.MailboxListener.Added.MessageMetaData;
+
+public class SimpleMessageMetaData implements MessageMetaData{
+    private long uid;
+    private Flags flags;
+    private long size;
+    private Date internalDate;
+
+    public SimpleMessageMetaData(long uid, Flags flags, long size, Date internalDate) {
+        this.uid = uid;
+        this.flags = flags;
+        this.size = size;
+        this.internalDate = internalDate;
+    }
+    
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.mailbox.MailboxListener.Added.MessageMetaData#getFlags()
+     */
+    public Flags getFlags() {
+        return flags;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.mailbox.MailboxListener.Added.MessageMetaData#getSize()
+     */
+    public long getSize() {
+        return size;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.mailbox.MailboxListener.Added.MessageMetaData#getInternalDate()
+     */
+    public Date getInternalDate() {
+        return internalDate;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.mailbox.MailboxListener.Added.MessageMetaData#getUid()
+     */
+    public long getUid() {
+        return uid;
+    }
+
+}

Modified: james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java?rev=1102882&r1=1102881&r2=1102882&view=diff
==============================================================================
--- james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
(original)
+++ james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
Fri May 13 20:03:41 2011
@@ -40,6 +40,7 @@ import javax.mail.util.SharedFileInputSt
 
 import org.apache.james.mailbox.MailboxException;
 import org.apache.james.mailbox.MailboxListener;
+import org.apache.james.mailbox.MailboxListener.Added.MessageMetaData;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageRange;
 import org.apache.james.mailbox.MessageResult;
@@ -288,8 +289,8 @@ public abstract class StoreMessageManage
             final Message<Id> message = createMessage(nextUid, internalDate, size,
bodyStartOctet, tmpMsgIn.newStream(0, -1), flags, headers, propertyBuilder);
             long uid = appendMessageToStore(message, mailboxSession);
                        
-            Map<Long, Flags> uids = new HashMap<Long, Flags>();
-            uids.put(uid, flags);
+            Map<Long, MessageMetaData> uids = new HashMap<Long, MessageMetaData>();
+            uids.put(uid, new SimpleMessageMetaData(uid, flags, size, internalDate));
             dispatcher.added(mailboxSession, uids, new StoreMailboxPath<Id>(getMailboxEntity()));
             return uid;
         } catch (IOException e) {
@@ -511,7 +512,7 @@ public abstract class StoreMessageManage
      */
     public List<MessageRange> copyTo(MessageRange set, StoreMessageManager<Id>
toMailbox, MailboxSession session) throws MailboxException {
         try {
-            Map<Long, Flags> copiedUids = copy(set, toMailbox, session);
+            Map<Long, MessageMetaData> copiedUids = copy(set, toMailbox, session);
             dispatcher.added(session, copiedUids, new StoreMailboxPath<Id>(toMailbox.getMailboxEntity()));
 
             return MessageRange.toRanges(new ArrayList<Long>(copiedUids.keySet()));
@@ -728,19 +729,20 @@ public abstract class StoreMessageManage
      * (non-Javadoc)
      * @see org.apache.james.mailbox.store.AbstractStoreMessageManager#copy(org.apache.james.mailbox.MessageRange,
org.apache.james.mailbox.store.AbstractStoreMessageManager, org.apache.james.mailbox.MailboxSession)
      */
-    private Map<Long, Flags> copy(MessageRange set, final StoreMessageManager<Id>
to, final MailboxSession session) throws MailboxException {
+    private Map<Long, MessageMetaData> copy(MessageRange set, final StoreMessageManager<Id>
to, final MailboxSession session) throws MailboxException {
         try {
             MessageMapper<Id> messageMapper = mapperFactory.getMessageMapper(session);
 
-            final Map<Long, Flags> copiedMessages = new HashMap<Long, Flags>();
+            final Map<Long, MessageMetaData> copiedMessages = new HashMap<Long,
MessageMetaData>();
             messageMapper.findInMailbox(getMailboxEntity(), set, new MailboxMembershipCallback<Id>()
{
 
                 public void onMailboxMembers(List<Message<Id>> originalRows)
throws MailboxException {
                     Iterator<Long> ids = to.copy(originalRows, session);
                     int i = 0; 
                     while (ids.hasNext()) {
-                        
-                        copiedMessages.put(ids.next(), originalRows.get(i).createFlags());
+                        Message<Id> m = originalRows.get(i);
+                        long uid = ids.next();
+                        copiedMessages.put(uid, new SimpleMessageMetaData(uid, m.createFlags(),
m.getFullContentOctets(), m.getInternalDate()));
                         i++;
                     }
                 }



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message