Author: rdonkin
Date: Sun Feb 10 02:40:18 2008
New Revision: 620257

URL: http://svn.apache.org/viewvc?rev=620257&view=rev
Log:
Fetch groups for part fetches

Added:
    
james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/impl/PartContentDescriptorImpl.java
Modified:
    
james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/MessageResult.java
    
james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/impl/FetchGroupImpl.java
    
james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/FetchProcessor.java
    
james/server/trunk/torque-mailboxmanager-function/src/main/java/org/apache/james/mailboxmanager/torque/OrFetchGroup.java

Modified: 
james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/MessageResult.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/MessageResult.java?rev=620257&r1=620256&r2=620257&view=diff
==============================================================================
--- 
james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/MessageResult.java
 (original)
+++ 
james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/MessageResult.java
 Sun Feb 10 02:40:18 2008
@@ -23,6 +23,7 @@
 import java.nio.channels.WritableByteChannel;
 import java.util.Date;
 import java.util.Iterator;
+import java.util.Set;
 
 import javax.mail.Flags;
 import javax.mail.MessagingException;
@@ -101,6 +102,46 @@
          * @see #BODY_CONTENT
          */
         public int content();
+        
+        /**
+         * Gets contents to be fetched for contained parts.
+         * For each part to be contained, 
+         * only one descriptor should be contained.
+         * @return <code>Set</code> of [EMAIL PROTECTED] 
PartContentDescriptor},
+         * or null if there is no part content to be fetched
+         */
+        public Set getPartContentDescriptors();
+        
+        /**
+         * Describes the contents to be fetched for a mail part.
+         * All implementations MUST implement equals.
+         * Two implementations are equal if and only if
+         * their paths are equal.
+         */
+        public interface PartContentDescriptor {
+            /**
+             * Contents to be fetched.
+             * Composed bitwise.
+             * 
+             * @return bitwise descripion
+             * @see #MINIMAL
+             * @see #MIME_MESSAGE
+             * @see #KEY
+             * @see #SIZE
+             * @see #INTERNAL_DATE
+             * @see #FLAGS
+             * @see #HEADERS
+             * @see #FULL_CONTENT
+             * @see #BODY_CONTENT
+             */
+            public int content();
+            
+            /**
+             * Path describing the part to be fetched.
+             * @return path describing the part, not null
+             */
+            public MimePath path();
+        }
     }
     
     /**
@@ -252,6 +293,9 @@
     
     /**
      * Describes a path within a multipart MIME message.
+     * All implementations must implement equals.
+     * Two paths are equal if and only if
+     * each position is identical.
      */
     public interface MimePath {
         

Modified: 
james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/impl/FetchGroupImpl.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/impl/FetchGroupImpl.java?rev=620257&r1=620256&r2=620257&view=diff
==============================================================================
--- 
james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/impl/FetchGroupImpl.java
 (original)
+++ 
james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/impl/FetchGroupImpl.java
 Sun Feb 10 02:40:18 2008
@@ -19,7 +19,12 @@
 
 package org.apache.james.mailboxmanager.impl;
 
+import java.util.Iterator;
+import java.util.Set;
+
 import org.apache.james.mailboxmanager.MessageResult;
+import org.apache.james.mailboxmanager.MessageResult.FetchGroup;
+import org.apache.james.mailboxmanager.MessageResult.MimePath;
 
 /**
  * Specifies a fetch group.
@@ -47,8 +52,7 @@
     
     
     private int content = MessageResult.FetchGroup.MINIMAL;
-    private int[] mimeParts = null;
-    private int[] mimeHeaders = null;
+    private Set partContentDescriptors;
     
     public FetchGroupImpl() {
         super();
@@ -59,34 +63,51 @@
         this.content = content;
     }
     
-    public FetchGroupImpl(int content, int[] mimeParts, int[] mimeHeaders) {
+    public FetchGroupImpl(int content, Set partContentDescriptors) {
         super();
         this.content = content;
-        this.mimeParts = mimeParts;
-        this.mimeHeaders = mimeHeaders;
+        this.partContentDescriptors = partContentDescriptors;
     }
 
     public int content() {
         return content;
     }
     
-    public int[] mimeHeaders() {
-        return mimeHeaders;
-    }
-
-    public int[] mimeBodies() {
-        return mimeParts;
-    }
-    
-    public void setMimeParts(int[] mimeParts) {
-        this.mimeParts = mimeParts;
-    }
-    
-    public void setMimeHeaders(int[] mimeHeaders) {
-        this.mimeHeaders = mimeHeaders;
+    public void or(int content) {
+        this.content = this.content | content;
     }
     
     public String toString() {
         return "Fetch " + content;
+    }
+
+    /**
+     * Gets content descriptors for the parts to be fetched.
+     * @return <code>Set</code> of [EMAIL PROTECTED] 
FetchGroup.PartContentDescriptor}, possibly null
+     */
+    public Set getPartContentDescriptors() {
+        return partContentDescriptors;
+    }
+
+    /**
+     * Adds content for the particular part.
+     * @param path <code>MimePath</code>, not null
+     * @param content bitwise content constant
+     */
+    public void addPartContent(MimePath path, int content) {
+        PartContentDescriptorImpl currentDescriptor = null;
+        for (Iterator it=partContentDescriptors.iterator();it.hasNext();) {
+            PartContentDescriptorImpl descriptor = (PartContentDescriptorImpl) 
it.next();
+            if (path.equals(descriptor.path())) {
+                currentDescriptor = descriptor;
+                break;
+            }
+        }
+        if (currentDescriptor == null) {
+            currentDescriptor = new PartContentDescriptorImpl(path);
+            partContentDescriptors.add(currentDescriptor);
+        }
+        
+        currentDescriptor.or(content);
     }
 }

Added: 
james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/impl/PartContentDescriptorImpl.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/impl/PartContentDescriptorImpl.java?rev=620257&view=auto
==============================================================================
--- 
james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/impl/PartContentDescriptorImpl.java
 (added)
+++ 
james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/impl/PartContentDescriptorImpl.java
 Sun Feb 10 02:40:18 2008
@@ -0,0 +1,77 @@
+/****************************************************************
+ * 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.mailboxmanager.impl;
+
+import org.apache.james.mailboxmanager.MessageResult.MimePath;
+import 
org.apache.james.mailboxmanager.MessageResult.FetchGroup.PartContentDescriptor;
+
+public class PartContentDescriptorImpl implements PartContentDescriptor {
+
+    private int content = 0;
+    private final MimePath path;
+    
+    public PartContentDescriptorImpl(final MimePath path) {
+        super();
+        this.path = path;
+    }
+
+    public PartContentDescriptorImpl(int content, final MimePath path) {
+        super();
+        this.content = content;
+        this.path = path;
+    }
+    
+    public void or(int content) {
+        this.content = this.content | content;
+    }
+    
+    public int content() {
+        return content;
+    }
+
+    public MimePath path() {
+        return path;
+    }
+
+    public int hashCode() {
+        final int PRIME = 31;
+        int result = 1;
+        result = PRIME * result + ((path == null) ? 0 : path.hashCode());
+        return result;
+    }
+
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        final PartContentDescriptor other = (PartContentDescriptor) obj;
+        if (path == null) {
+            if (other.path() != null)
+                return false;
+        } else if (!path.equals(other.path()))
+            return false;
+        return true;
+    }
+
+    
+}

Modified: 
james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/FetchProcessor.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/FetchProcessor.java?rev=620257&r1=620256&r2=620257&view=diff
==============================================================================
--- 
james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/FetchProcessor.java
 (original)
+++ 
james/server/trunk/imap-mailbox-processor-function/src/main/java/org/apache/james/imapserver/processor/imap4rev1/FetchProcessor.java
 Sun Feb 10 02:40:18 2008
@@ -23,6 +23,7 @@
 import java.nio.ByteBuffer;
 import java.nio.channels.WritableByteChannel;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Date;
 import java.util.Iterator;
@@ -60,6 +61,7 @@
 import org.apache.james.mailboxmanager.UnsupportedCriteriaException;
 import org.apache.james.mailboxmanager.MessageResult.Content;
 import org.apache.james.mailboxmanager.MessageResult.FetchGroup;
+import org.apache.james.mailboxmanager.MessageResult.MimePath;
 import org.apache.james.mailboxmanager.impl.FetchGroupImpl;
 import org.apache.james.mailboxmanager.impl.GeneralMessageSetImpl;
 import org.apache.james.mailboxmanager.mailbox.ImapMailbox;
@@ -132,47 +134,43 @@
     }
 
     private FetchGroup getFetchGroup(FetchData fetch) throws ProtocolException 
{
-        int result = FetchGroup.MINIMAL;
+        FetchGroupImpl result = new FetchGroupImpl();
         if (fetch.isFlags() || fetch.isSetSeen()) {
-            result |= FetchGroup.FLAGS;
+            result.or(FetchGroup.FLAGS);
         }
         if (fetch.isInternalDate()) {
-            result |= FetchGroup.INTERNAL_DATE;
+            result.or(FetchGroup.INTERNAL_DATE);
         }
         if (fetch.isSize()) {
-            result |= FetchGroup.SIZE;
+            result.or(FetchGroup.SIZE);
         }
         if (fetch.isEnvelope()) {
-            result |= FetchGroup.HEADERS;
+            result.or(FetchGroup.HEADERS);
         }
         if (fetch.isBody() || fetch.isBodyStructure()) {
             // TODO: structure
-            result |= FetchGroup.MIME_MESSAGE;
+            result.or(FetchGroup.MIME_MESSAGE);
         }
 
-        result |= fetchForBodyElements(fetch.getBodyElements());
-
-        return new FetchGroupImpl(result);
-    }
-
-    private int fetchForBodyElements(final Collection bodyElements) throws 
ProtocolException {
-        int result = 0;
+        Collection bodyElements = fetch.getBodyElements();
         if (bodyElements != null) {
             for (final Iterator it = bodyElements.iterator(); it.hasNext();) {
                 final BodyFetchElement element = (BodyFetchElement) it.next();
                 final int sectionType = element.getSectionType();
+                final int[] path = element.getPath();
+                final boolean isBase = (path == null || path.length == 0);
                 switch(sectionType) {
                     case BodyFetchElement.CONTENT:
-                        result = result | 
MessageResult.FetchGroup.FULL_CONTENT;
+                        addContent(result, path, isBase, 
MessageResult.FetchGroup.FULL_CONTENT);
                         break;
                     case BodyFetchElement.HEADER:
                     case BodyFetchElement.HEADER_NOT_FIELDS:
                     case BodyFetchElement.HEADER_FIELDS:
                     case BodyFetchElement.MIME:
-                        result = result | MessageResult.FetchGroup.HEADERS;
+                        addContent(result, path, isBase, 
MessageResult.FetchGroup.HEADERS);
                         break;
                     case BodyFetchElement.TEXT:
-                        result = result | 
MessageResult.FetchGroup.BODY_CONTENT;
+                        addContent(result, path, isBase, 
MessageResult.FetchGroup.BODY_CONTENT);
                         break;
                 }
                 
@@ -181,6 +179,15 @@
         return result;
     }
 
+    private void addContent(FetchGroupImpl result, final int[] path, final 
boolean isBase, final int content) {
+        if (isBase) {                            
+            result.or(content);
+        } else {
+            MimePath mimePath = new MimePathImpl(path);
+            result.addPartContent(mimePath, content);
+        }
+    }
+
     private static final class FetchResponseBuilder {
         private final Logger logger;
         private int msn;
@@ -577,7 +584,40 @@
         public int[] getPositions() {
             return positions;
         }
-        
+
+        public int hashCode() {
+            final int PRIME = 31;
+            int result = 1;
+            result = PRIME * result + Arrays.hashCode(positions);
+            return result;
+        }
+
+        public boolean equals(Object obj) {
+            if (this == obj)
+                return true;
+            if (obj == null)
+                return false;
+            if (getClass() != obj.getClass())
+                return false;
+            final MimePathImpl other = (MimePathImpl) obj;
+            if (!Arrays.equals(positions, other.positions))
+                return false;
+            return true;
+        }
+        
+        public String toString() {
+            final StringBuffer buffer = new StringBuffer("MIMEPath:");
+            boolean isFirst = false;
+            for (int i = 0; i < positions.length; i++) {
+                if (isFirst) {
+                    isFirst = false;
+                } else {
+                    buffer.append('.');
+                }
+                buffer.append(positions[i]);
+            }
+            return buffer.toString();
+        }
     }
     
     private static final class EnvelopeImpl implements FetchResponse.Envelope {

Modified: 
james/server/trunk/torque-mailboxmanager-function/src/main/java/org/apache/james/mailboxmanager/torque/OrFetchGroup.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/torque-mailboxmanager-function/src/main/java/org/apache/james/mailboxmanager/torque/OrFetchGroup.java?rev=620257&r1=620256&r2=620257&view=diff
==============================================================================
--- 
james/server/trunk/torque-mailboxmanager-function/src/main/java/org/apache/james/mailboxmanager/torque/OrFetchGroup.java
 (original)
+++ 
james/server/trunk/torque-mailboxmanager-function/src/main/java/org/apache/james/mailboxmanager/torque/OrFetchGroup.java
 Sun Feb 10 02:40:18 2008
@@ -19,8 +19,9 @@
 
 package org.apache.james.mailboxmanager.torque;
 
+import java.util.Set;
+
 import org.apache.james.mailboxmanager.MessageResult.FetchGroup;
-import org.apache.james.mailboxmanager.MessageResult.MimePath;
 
 /**
  * Wraps a fetch group and ORs content.
@@ -43,6 +44,10 @@
 
     public String toString() {
         return "Fetch " + or + " OR " + delegate;
+    }
+
+    public Set getPartContentDescriptors() {
+        return delegate.getPartContentDescriptors();
     }
 
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to