james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r1136175 [1/2] - in /james/mailbox/trunk: jcr/src/main/java/org/apache/james/mailbox/jcr/ jcr/src/main/java/org/apache/james/mailbox/jcr/mail/model/ jcr/src/main/resources/org/apache/james/mailbox/jcr/ jpa/src/main/java/org/apache/james/mai...
Date Wed, 15 Jun 2011 20:24:11 GMT
Author: norman
Date: Wed Jun 15 20:24:10 2011
New Revision: 1136175

URL: http://svn.apache.org/viewvc?rev=1136175&view=rev
Log:
Remove the Header model class and just return an InputStream which holds the header. See MAILBOX-90

Removed:
    james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/model/JCRHeader.java
    james/mailbox/trunk/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/JPAHeader.java
    james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/model/MaildirHeader.java
    james/mailbox/trunk/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/model/SimpleHeader.java
    james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/mail/model/AbstractComparableHeader.java
    james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/mail/model/Header.java
    james/mailbox/trunk/store/src/test/java/org/apache/james/mailbox/store/SimpleHeader.java
Modified:
    james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMessageManager.java
    james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/model/JCRMessage.java
    james/mailbox/trunk/jcr/src/main/resources/org/apache/james/mailbox/jcr/imap.cnd
    james/mailbox/trunk/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAMessageManager.java
    james/mailbox/trunk/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/AbstractJPAMessage.java
    james/mailbox/trunk/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/JPAMessage.java
    james/mailbox/trunk/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/JPAStreamingMessage.java
    james/mailbox/trunk/jpa/src/main/java/org/apache/james/mailbox/jpa/openjpa/OpenJPAMessageManager.java
    james/mailbox/trunk/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAMailboxManagerTest.java
    james/mailbox/trunk/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAStressTest.java
    james/mailbox/trunk/jpa/src/test/java/org/apache/james/mailbox/jpa/JPASubscriptionManagerTest.java
    james/mailbox/trunk/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java
    james/mailbox/trunk/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndexTest.java
    james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirFolder.java
    james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirMessageManager.java
    james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMessageMapper.java
    james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/model/LazyLoadingMaildirMessage.java
    james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/model/MaildirMessage.java
    james/mailbox/trunk/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryStoreMessageManager.java
    james/mailbox/trunk/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/model/SimpleMailboxMembership.java
    james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/ResultHeader.java
    james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/ResultUtils.java
    james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
    james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/mail/model/Message.java
    james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java
    james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/search/comparator/AbstractHeaderComparator.java
    james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/streaming/InputStreamContent.java
    james/mailbox/trunk/store/src/test/java/org/apache/james/mailbox/store/MessageBuilder.java
    james/mailbox/trunk/store/src/test/java/org/apache/james/mailbox/store/SimpleMailboxMembership.java

Modified: james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMessageManager.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMessageManager.java?rev=1136175&r1=1136174&r2=1136175&view=diff
==============================================================================
--- james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMessageManager.java (original)
+++ james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMessageManager.java Wed Jun 15 20:24:10 2011
@@ -19,21 +19,17 @@
 package org.apache.james.mailbox.jcr;
 
 import java.io.InputStream;
-import java.util.ArrayList;
 import java.util.Date;
-import java.util.List;
 
 import javax.mail.Flags;
 
 import org.apache.james.mailbox.MailboxException;
 import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.jcr.mail.model.JCRHeader;
 import org.apache.james.mailbox.jcr.mail.model.JCRMailbox;
 import org.apache.james.mailbox.jcr.mail.model.JCRMessage;
 import org.apache.james.mailbox.store.MailboxEventDispatcher;
 import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
 import org.apache.james.mailbox.store.StoreMessageManager;
-import org.apache.james.mailbox.store.mail.model.Header;
 import org.apache.james.mailbox.store.mail.model.Message;
 import org.apache.james.mailbox.store.mail.model.PropertyBuilder;
 import org.apache.james.mailbox.store.search.MessageSearchIndex;
@@ -53,19 +49,12 @@ public class JCRMessageManager extends S
         this.log = log;
     }
 
-    @Override
-    protected Header createHeader(int lineNumber, String name, String value) {
-        return new JCRHeader(lineNumber, name, value, log);
-    }
 
     @Override
-    protected Message<String> createMessage(Date internalDate, int size, int bodyStartOctet, InputStream document, Flags flags, List<Header> headers, PropertyBuilder propertyBuilder) throws MailboxException{
-        final List<JCRHeader> jcrHeaders = new ArrayList<JCRHeader>(headers.size());
-        for (Header header: headers) {
-            jcrHeaders.add((JCRHeader) header);
-        }
+    protected Message<String> createMessage(Date internalDate, int size, int bodyStartOctet, InputStream header, InputStream body, Flags flags, PropertyBuilder propertyBuilder) throws MailboxException{
+      
         final Message<String> message = new JCRMessage(getMailboxEntity().getMailboxId(), internalDate, 
-                size, flags, document, bodyStartOctet, jcrHeaders, propertyBuilder, log);
+                size, flags, header, body, bodyStartOctet, propertyBuilder, log);
         return message;
     }
 

Modified: james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/model/JCRMessage.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/model/JCRMessage.java?rev=1136175&r1=1136174&r2=1136175&view=diff
==============================================================================
--- james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/model/JCRMessage.java (original)
+++ james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/model/JCRMessage.java Wed Jun 15 20:24:10 2011
@@ -33,13 +33,14 @@ import javax.jcr.RepositoryException;
 import javax.mail.Flags;
 
 import org.apache.commons.io.IOUtils;
+import org.apache.commons.io.input.BoundedInputStream;
 import org.apache.jackrabbit.JcrConstants;
 import org.apache.jackrabbit.commons.JcrUtils;
 import org.apache.james.mailbox.MailboxException;
 import org.apache.james.mailbox.jcr.JCRImapConstants;
 import org.apache.james.mailbox.jcr.Persistent;
+import org.apache.james.mailbox.store.ResultUtils;
 import org.apache.james.mailbox.store.mail.model.AbstractMessage;
-import org.apache.james.mailbox.store.mail.model.Header;
 import org.apache.james.mailbox.store.mail.model.Message;
 import org.apache.james.mailbox.store.mail.model.Property;
 import org.apache.james.mailbox.store.mail.model.PropertyBuilder;
@@ -55,7 +56,6 @@ public class JCRMessage extends Abstract
     private Node node;
     private final Logger logger;
     private InputStream content;
-    private List<JCRHeader> headers;
     private String mediaType;
     private Long textualLineCount;
     private String subType;
@@ -103,19 +103,17 @@ public class JCRMessage extends Abstract
         this.node = node;
     }
     
-    public JCRMessage(String mailboxUUID, Date internalDate, int size, Flags flags, InputStream content,
-            int bodyStartOctet, final List<JCRHeader> headers,
-            final PropertyBuilder propertyBuilder, Logger logger) {
+    public JCRMessage(String mailboxUUID, Date internalDate, int size, Flags flags, InputStream header, InputStream body,
+            int bodyStartOctet,  final PropertyBuilder propertyBuilder, Logger logger) {
         super();
         this.mailboxUUID = mailboxUUID;
         this.internalDate = internalDate;
         this.size = size;
         this.logger = logger;
         setFlags(flags);
-        this.content = content;
+        this.content = ResultUtils.toInput(header, body);
        
         this.bodyStartOctet = bodyStartOctet;
-        this.headers = new ArrayList<JCRHeader>(headers);
         this.textualLineCount = propertyBuilder.getTextualLineCount();
         this.mediaType = propertyBuilder.getMediaType();
         this.subType = propertyBuilder.getSubType();
@@ -144,19 +142,13 @@ public class JCRMessage extends Abstract
         this.modSeq = modSeq;
         this.logger = logger;
         try {
-            this.content = new ByteArrayInputStream(IOUtils.toByteArray(message.getFullContent()));
+            this.content = new ByteArrayInputStream(IOUtils.toByteArray(ResultUtils.toInput(message)));
         } catch (IOException e) {
             throw new MailboxException("Unable to parse message",e);
         }
        
         this.bodyStartOctet = (int) (message.getFullContentOctets() - message.getBodyOctets());
-        this.headers = new ArrayList<JCRHeader>();
-
-        List<Header> originalHeaders = message.getHeaders();
-        for (int i = 0; i < originalHeaders.size(); i++) {
-            headers.add(new JCRHeader(originalHeaders.get(i),logger));
-        }
-
+        
         PropertyBuilder pBuilder = new PropertyBuilder(message.getProperties());
         this.textualLineCount = message.getTextualLineCount();
         this.mediaType = message.getMediaType();
@@ -188,26 +180,6 @@ public class JCRMessage extends Abstract
 
     /*
      * (non-Javadoc)
-     * @see org.apache.james.mailbox.store.mail.model.Document#getHeaders()
-     */
-    public List<Header> getHeaders() {
-        if (isPersistent()) {
-            try {
-                List<Header> headers = new ArrayList<Header>();
-                NodeIterator nodeIt = node.getNodes("messageHeader");
-                while (nodeIt.hasNext()) {
-                    headers.add(new JCRHeader(nodeIt.nextNode(), logger));
-                }
-                return headers;
-            } catch (RepositoryException e) {
-                logger.error("Unable to retrieve nodes messageHeader", e);
-            }
-        }
-        return new ArrayList<Header>(headers);
-    }
-
-    /*
-     * (non-Javadoc)
      * @see org.apache.james.mailbox.store.mail.model.Document#getMediaType()
      */
     public String getMediaType() {
@@ -348,26 +320,6 @@ public class JCRMessage extends Abstract
             node.setProperty(SUBTYPE_PROPERTY, getSubType());
             node.setProperty(BODY_START_OCTET_PROPERTY, getBodyStartOctet());
 
-            // copy the headers and store them in memory as pure pojos
-            List<Header> currentHeaders = getHeaders();
-            List<Header> newHeaders = new ArrayList<Header>();
-            for (int i = 0; i < currentHeaders.size(); i++) {
-                newHeaders.add(new JCRHeader(currentHeaders.get(i), logger));
-            }
-
-            NodeIterator iterator = node.getNodes("messageHeader");
-            // remove old headers
-            while (iterator.hasNext()) {
-                iterator.nextNode().remove();
-            }
-
-            // add headers to the message again
-            for (int i = 0; i < newHeaders.size(); i++) {
-                JCRHeader header = (JCRHeader) newHeaders.get(i);
-                Node headerNode = node.addNode("messageHeader", "nt:unstructured");
-                headerNode.addMixin(HEADER_NODE_TYPE);
-                header.merge(headerNode);
-            }
 
             List<Property> currentProperties = getProperties();
             List<Property> newProperites = new ArrayList<Property>();
@@ -376,7 +328,7 @@ public class JCRMessage extends Abstract
                 newProperites.add(new JCRProperty(prop, i, logger));
             }
             // remove old properties, we will add a bunch of new ones
-            iterator = node.getNodes("messageProperty");
+            NodeIterator iterator = node.getNodes("messageProperty");
             while (iterator.hasNext()) {
                 iterator.nextNode().remove();
             }
@@ -727,11 +679,8 @@ public class JCRMessage extends Abstract
         return retValue;
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.mailbox.store.mail.model.Message#getFullContent()
-     */
-    public InputStream getFullContent() throws IOException {
+
+    protected InputStream getFullContent() throws IOException {
         if (isPersistent()) {
             try {
                 //TODO: Maybe we should cache this somehow...
@@ -800,4 +749,12 @@ public class JCRMessage extends Abstract
             this.uid = uid;
         }          
     }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.mailbox.store.mail.model.Message#getHeaderContent()
+     */
+    public InputStream getHeaderContent() throws IOException {
+        return new BoundedInputStream(getFullContent(), getBodyStartOctet() - 2);
+    }
 }

Modified: james/mailbox/trunk/jcr/src/main/resources/org/apache/james/mailbox/jcr/imap.cnd
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/jcr/src/main/resources/org/apache/james/mailbox/jcr/imap.cnd?rev=1136175&r1=1136174&r2=1136175&view=diff
==============================================================================
--- james/mailbox/trunk/jcr/src/main/resources/org/apache/james/mailbox/jcr/imap.cnd (original)
+++ james/mailbox/trunk/jcr/src/main/resources/org/apache/james/mailbox/jcr/imap.cnd Wed Jun 15 20:24:10 2011
@@ -23,13 +23,6 @@
     - jamesMailbox:subscriptionMailboxes (STRING) multiple
     + * (nt:unstructured) multiple
     
-
-[jamesMailbox:messageHeader] > mix:created, mix:lockable
-    mixin
-    - jamesMailbox:headerFieldName (STRING) mandatory
-    - jamesMailbox:headerValue(STRING) mandatory
-    - jamesMailbox:headerLineNumber (LONG) mandatory
-
 [jamesMailbox:messageProperty] > mix:created
     mixin
     - jamesMailbox:propertyNamespace (STRING) mandatory
@@ -54,7 +47,6 @@
     - jamesMailbox:messageBodyStartOctet (LONG) mandatory
     - jamesMailbox:messageTextualLineCount (LONG)
     - jamesMailbox:messageSubType (String) mandatory
-    + messageHeader (nt:unstructured)  multiple
     + messageProperty (nt:unstructured) multiple
 
 [jamesMailbox:mailbox] >  mix:referenceable, mix:lockable, mix:created
@@ -66,5 +58,4 @@
     - jamesMailbox:mailboxUser (STRING) 
     - jamesMailbox:mailboxLastKnownUid (LONG) 
     - jamesMailbox:mailboxHighestKnownModSeq (LONG) 
-
     + * (nt:unstructured) multiple

Modified: james/mailbox/trunk/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAMessageManager.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAMessageManager.java?rev=1136175&r1=1136174&r2=1136175&view=diff
==============================================================================
--- james/mailbox/trunk/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAMessageManager.java (original)
+++ james/mailbox/trunk/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAMessageManager.java Wed Jun 15 20:24:10 2011
@@ -19,21 +19,17 @@
 package org.apache.james.mailbox.jpa;
 
 import java.io.InputStream;
-import java.util.ArrayList;
 import java.util.Date;
-import java.util.List;
 
 import javax.mail.Flags;
 
 import org.apache.james.mailbox.MailboxException;
 import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.jpa.mail.model.JPAHeader;
 import org.apache.james.mailbox.jpa.mail.model.JPAMailbox;
 import org.apache.james.mailbox.jpa.mail.model.openjpa.JPAMessage;
 import org.apache.james.mailbox.store.MailboxEventDispatcher;
 import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
 import org.apache.james.mailbox.store.StoreMessageManager;
-import org.apache.james.mailbox.store.mail.model.Header;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.mail.model.Message;
 import org.apache.james.mailbox.store.mail.model.PropertyBuilder;
@@ -49,21 +45,13 @@ public class JPAMessageManager extends S
     }
     
     @Override
-    protected Message<Long> createMessage(Date internalDate, final int size, int bodyStartOctet, final InputStream document, 
-            final Flags flags, final List<Header> headers, PropertyBuilder propertyBuilder) throws MailboxException{
-        final List<JPAHeader> jpaHeaders = new ArrayList<JPAHeader>(headers.size());
-        for (Header header: headers) {
-            jpaHeaders.add((JPAHeader) header);
-        }
-        final Message<Long> message = new JPAMessage((JPAMailbox) getMailboxEntity(), internalDate, size, flags, document, bodyStartOctet, jpaHeaders, propertyBuilder);
+    protected Message<Long> createMessage(Date internalDate, final int size, int bodyStartOctet, final InputStream header, final InputStream body, 
+            final Flags flags, PropertyBuilder propertyBuilder) throws MailboxException{
+       
+        final Message<Long> message = new JPAMessage((JPAMailbox) getMailboxEntity(), internalDate, size, flags, header, body,  bodyStartOctet,  propertyBuilder);
         return message;
     }
-    
-    @Override
-    protected Header createHeader(int lineNumber, String name, String value) {
-        final Header header = new JPAHeader(lineNumber, name, value);
-        return header;
-    }
+
 
     /**
      * Support user flags

Modified: james/mailbox/trunk/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/AbstractJPAMessage.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/AbstractJPAMessage.java?rev=1136175&r1=1136174&r2=1136175&view=diff
==============================================================================
--- james/mailbox/trunk/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/AbstractJPAMessage.java (original)
+++ james/mailbox/trunk/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/AbstractJPAMessage.java Wed Jun 15 20:24:10 2011
@@ -38,12 +38,10 @@ import javax.persistence.OneToMany;
 import javax.persistence.OrderBy;
 
 import org.apache.james.mailbox.MailboxException;
-import org.apache.james.mailbox.jpa.mail.model.JPAHeader;
 import org.apache.james.mailbox.jpa.mail.model.JPAMailbox;
 import org.apache.james.mailbox.jpa.mail.model.JPAProperty;
 import org.apache.james.mailbox.jpa.mail.model.JPAUserFlag;
 import org.apache.james.mailbox.store.mail.model.AbstractMessage;
-import org.apache.james.mailbox.store.mail.model.Header;
 import org.apache.james.mailbox.store.mail.model.Message;
 import org.apache.james.mailbox.store.mail.model.Property;
 import org.apache.james.mailbox.store.mail.model.PropertyBuilder;
@@ -231,12 +229,6 @@ public abstract class AbstractJPAMessage
     @Column(name = "MAIL_TEXTUAL_LINE_COUNT", nullable = true)
     private Long textualLineCount;
     
-    /** Headers for this message */
-    @OneToMany(cascade = CascadeType.ALL, fetch=FetchType.LAZY)
-    @OrderBy("lineNumber")
-    @ElementJoinColumns({@ElementJoinColumn(name="MAILBOX_ID", referencedColumnName="MAILBOX_ID"),
-    @ElementJoinColumn(name="MAIL_UID", referencedColumnName="MAIL_UID")})
-    private List<JPAHeader> headers;
 
     /** Meta data for this message */
     @OneToMany(cascade = CascadeType.ALL, fetch=FetchType.LAZY)
@@ -254,7 +246,7 @@ public abstract class AbstractJPAMessage
     @Deprecated
     public AbstractJPAMessage() {}
 
-    public AbstractJPAMessage(JPAMailbox mailbox, Date internalDate, Flags flags, final long contentOctets, final int bodyStartOctet, final List<JPAHeader> headers, final PropertyBuilder propertyBuilder) {
+    public AbstractJPAMessage(JPAMailbox mailbox, Date internalDate, Flags flags, final long contentOctets, final int bodyStartOctet, final PropertyBuilder propertyBuilder) {
         super();
         this.mailbox = mailbox;
         this.internalDate = internalDate;
@@ -263,7 +255,6 @@ public abstract class AbstractJPAMessage
         setFlags(flags);        
         this.contentOctets = contentOctets;
         this.bodyStartOctet = bodyStartOctet;
-        this.headers = new ArrayList<JPAHeader>(headers);
         this.textualLineCount = propertyBuilder.getTextualLineCount();
         this.mediaType = propertyBuilder.getMediaType();
         this.subType = propertyBuilder.getSubType();
@@ -298,12 +289,8 @@ public abstract class AbstractJPAMessage
 
         this.contentOctets = original.getFullContentOctets();
         this.bodyStartOctet = (int) (original.getFullContentOctets() - original.getBodyOctets());
-        this.headers = new ArrayList<JPAHeader>();
         this.internalDate = original.getInternalDate();
-        List<Header> originalHeaders = original.getHeaders();
-        for (int i = 0; i < originalHeaders.size(); i++) {
-            headers.add(new JPAHeader(originalHeaders.get(i)));
-        }
+
 
         PropertyBuilder pBuilder = new PropertyBuilder(original.getProperties());
         this.textualLineCount = original.getTextualLineCount();
@@ -317,14 +304,6 @@ public abstract class AbstractJPAMessage
         }
     }
 
-
-    /**
-     * @see org.apache.james.mailbox.store.mail.model.Message#getHeaders()
-     */
-    public List<Header> getHeaders() {
-        return new ArrayList<Header>(headers);
-    }
-
     @Override
     public int hashCode() {
         final int PRIME = 31;

Modified: james/mailbox/trunk/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/JPAMessage.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/JPAMessage.java?rev=1136175&r1=1136174&r2=1136175&view=diff
==============================================================================
--- james/mailbox/trunk/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/JPAMessage.java (original)
+++ james/mailbox/trunk/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/JPAMessage.java Wed Jun 15 20:24:10 2011
@@ -22,7 +22,6 @@ import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Date;
-import java.util.List;
 
 import javax.mail.Flags;
 import javax.persistence.Basic;
@@ -34,7 +33,6 @@ import javax.persistence.Table;
 
 import org.apache.commons.io.IOUtils;
 import org.apache.james.mailbox.MailboxException;
-import org.apache.james.mailbox.jpa.mail.model.JPAHeader;
 import org.apache.james.mailbox.jpa.mail.model.JPAMailbox;
 import org.apache.james.mailbox.store.mail.model.Message;
 import org.apache.james.mailbox.store.mail.model.PropertyBuilder;
@@ -47,16 +45,25 @@ public class JPAMessage extends Abstract
     /** We use a max length to represent 1gb data. Thats prolly overkill, but who knows */
     @Basic(optional = false, fetch = FetchType.LAZY)
     @Column(name = "MAIL_BYTES", length = 1048576000, nullable = false)
-    @Lob private byte[] content;
+    @Lob private byte[] body;
 
+
+    /** The value for the header field. Lazy loaded */
+    /** We use a max length to represent 1gb data. Thats prolly overkill, but who knows */
+    @Basic(optional = false, fetch = FetchType.LAZY)
+    @Column(name = "HEADER_BYTES", length = 10485760, nullable = false)
+    @Lob private byte[] header;
+    
     @Deprecated
     public JPAMessage() {}
 
-    public JPAMessage(JPAMailbox mailbox,Date internalDate, int size, Flags flags, 
-            InputStream content, int bodyStartOctet, final List<JPAHeader> headers, final PropertyBuilder propertyBuilder) throws MailboxException {
-        super(mailbox, internalDate, flags, size ,bodyStartOctet,headers,propertyBuilder);
+    public JPAMessage(JPAMailbox mailbox,Date internalDate, int size, Flags flags, InputStream header,
+            InputStream body, int bodyStartOctet, final PropertyBuilder propertyBuilder) throws MailboxException {
+        super(mailbox, internalDate, flags, size ,bodyStartOctet, propertyBuilder);
         try {
-            this.content = IOUtils.toByteArray(content);
+            this.body = IOUtils.toByteArray(body);
+            this.header = IOUtils.toByteArray(header);
+
         } catch (IOException e) {
             throw new MailboxException("Unable to parse message",e);
         }
@@ -71,26 +78,28 @@ public class JPAMessage extends Abstract
     public JPAMessage(JPAMailbox mailbox, long uid, long modSeq, Message<?> message) throws MailboxException{
         super(mailbox, uid, modSeq, message);
         try {
-            this.content = IOUtils.toByteArray(message.getFullContent());
+            this.body = IOUtils.toByteArray(message.getBodyContent());
+            this.header = IOUtils.toByteArray(message.getHeaderContent());
         } catch (IOException e) {
             throw new MailboxException("Unable to parse message",e);
         }
     }
 
+
     /*
      * (non-Javadoc)
-     * @see org.apache.james.mailbox.store.mail.model.Message#getFullContent()
+     * @see org.apache.james.mailbox.store.mail.model.Message#getBodyContent()
      */
-    public InputStream getFullContent() throws IOException {
-        return new ByteArrayInputStream(content);
+    public InputStream getBodyContent() throws IOException {
+        return new ByteArrayInputStream(body);
     }
 
     /*
      * (non-Javadoc)
-     * @see org.apache.james.mailbox.store.mail.model.Message#getBodyContent()
+     * @see org.apache.james.mailbox.store.mail.model.Message#getHeaderContent()
      */
-    public InputStream getBodyContent() throws IOException {
-        return new ByteArrayInputStream(content, getBodyStartOctet(), (int)getFullContentOctets());
+    public InputStream getHeaderContent() throws IOException {
+        return new ByteArrayInputStream(header);
     }
 
 }

Modified: james/mailbox/trunk/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/JPAStreamingMessage.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/JPAStreamingMessage.java?rev=1136175&r1=1136174&r2=1136175&view=diff
==============================================================================
--- james/mailbox/trunk/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/JPAStreamingMessage.java (original)
+++ james/mailbox/trunk/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/JPAStreamingMessage.java Wed Jun 15 20:24:10 2011
@@ -21,9 +21,7 @@ package org.apache.james.mailbox.jpa.mai
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
-
 import java.util.Date;
-import java.util.List;
 
 import javax.mail.Flags;
 import javax.persistence.Column;
@@ -33,11 +31,9 @@ import javax.persistence.Table;
 
 import org.apache.commons.io.IOUtils;
 import org.apache.james.mailbox.MailboxException;
-import org.apache.james.mailbox.jpa.mail.model.JPAHeader;
 import org.apache.james.mailbox.jpa.mail.model.JPAMailbox;
 import org.apache.james.mailbox.store.mail.model.Message;
 import org.apache.james.mailbox.store.mail.model.PropertyBuilder;
-import org.apache.james.mailbox.store.streaming.LazySkippingInputStream;
 import org.apache.openjpa.persistence.Persistent;
 
 /**
@@ -54,17 +50,22 @@ import org.apache.openjpa.persistence.Pe
 @Table(name="JAMES_MAIL")
 public class JPAStreamingMessage extends AbstractJPAMessage {
 
-	@Persistent(optional=false, fetch=FetchType.LAZY)
-	@Column(name = "MAIL_BYTES", length=1048576000, nullable = false)
-	private InputStream content;
-	 
+    @Persistent(optional = false, fetch = FetchType.LAZY)
+    @Column(name = "MAIL_BYTES", length = 1048576000, nullable = false)
+    private InputStream body;
+
+    @Persistent(optional = false, fetch = FetchType.LAZY)
+    @Column(name = "HEADER_BYTES", length = 10485760, nullable = false)
+    private InputStream header;
+
     @Deprecated
     public JPAStreamingMessage() {}
 
-    public JPAStreamingMessage(JPAMailbox mailbox, Date internalDate, int size, Flags flags, 
-            InputStream content, int bodyStartOctet, final List<JPAHeader> headers, final PropertyBuilder propertyBuilder) throws MailboxException {
-        super(mailbox, internalDate, flags, size ,bodyStartOctet,headers,propertyBuilder);
-        this.content = content;
+    public JPAStreamingMessage(JPAMailbox mailbox, Date internalDate, int size, Flags flags, InputStream header, 
+            InputStream body, int bodyStartOctet,final PropertyBuilder propertyBuilder) throws MailboxException {
+        super(mailbox, internalDate, flags, size ,bodyStartOctet, propertyBuilder);
+        this.header = header;
+        this.body = body;
     }
 
     /**
@@ -76,18 +77,28 @@ public class JPAStreamingMessage extends
     public JPAStreamingMessage(JPAMailbox mailbox, long uid, long modSeq, Message<?> message) throws MailboxException {
         super(mailbox, uid, modSeq, message);
         try {
-            this.content = new ByteArrayInputStream(IOUtils.toByteArray(message.getFullContent()));
+            this.header = new ByteArrayInputStream(IOUtils.toByteArray(message.getHeaderContent()));
+            this.body = new ByteArrayInputStream(IOUtils.toByteArray(message.getBodyContent()));
         } catch (IOException e) {
             throw new MailboxException("Unable to parse message",e);
         }
     }
 
-    public InputStream getFullContent() throws IOException {
-        return content;
-    }
     
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.mailbox.store.mail.model.Message#getBodyContent()
+     */
     public InputStream getBodyContent() throws IOException {
-        return new LazySkippingInputStream(content, getBodyStartOctet());
+        return body;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.mailbox.store.mail.model.Message#getHeaderContent()
+     */
+    public InputStream getHeaderContent() throws IOException {
+        return header;
     }
 
 }

Modified: james/mailbox/trunk/jpa/src/main/java/org/apache/james/mailbox/jpa/openjpa/OpenJPAMessageManager.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/jpa/src/main/java/org/apache/james/mailbox/jpa/openjpa/OpenJPAMessageManager.java?rev=1136175&r1=1136174&r2=1136175&view=diff
==============================================================================
--- james/mailbox/trunk/jpa/src/main/java/org/apache/james/mailbox/jpa/openjpa/OpenJPAMessageManager.java (original)
+++ james/mailbox/trunk/jpa/src/main/java/org/apache/james/mailbox/jpa/openjpa/OpenJPAMessageManager.java Wed Jun 15 20:24:10 2011
@@ -20,20 +20,16 @@
 package org.apache.james.mailbox.jpa.openjpa;
 
 import java.io.InputStream;
-import java.util.ArrayList;
 import java.util.Date;
-import java.util.List;
 
 import javax.mail.Flags;
 
 import org.apache.james.mailbox.MailboxException;
 import org.apache.james.mailbox.jpa.JPAMessageManager;
-import org.apache.james.mailbox.jpa.mail.model.JPAHeader;
 import org.apache.james.mailbox.jpa.mail.model.JPAMailbox;
 import org.apache.james.mailbox.jpa.mail.model.openjpa.JPAStreamingMessage;
 import org.apache.james.mailbox.store.MailboxEventDispatcher;
 import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
-import org.apache.james.mailbox.store.mail.model.Header;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.mail.model.Message;
 import org.apache.james.mailbox.store.mail.model.PropertyBuilder;
@@ -58,16 +54,14 @@ public class OpenJPAMessageManager exten
     }
 
     @Override
-    protected Message<Long> createMessage(Date internalDate, int size, int bodyStartOctet, InputStream document, Flags flags, List<Header> headers, PropertyBuilder propertyBuilder) throws MailboxException {
+    protected Message<Long> createMessage(Date internalDate, int size, int bodyStartOctet, InputStream header, InputStream body, Flags flags, PropertyBuilder propertyBuilder) throws MailboxException {
         if (useStreaming) {
-            final List<JPAHeader> jpaHeaders = new ArrayList<JPAHeader>(headers.size());
-            for (Header header: headers) {
-                jpaHeaders.add((JPAHeader) header);
-            }
-            return new JPAStreamingMessage((JPAMailbox) getMailboxEntity(), internalDate, size, flags, document, bodyStartOctet, jpaHeaders, propertyBuilder);
+            return new JPAStreamingMessage((JPAMailbox) getMailboxEntity(), internalDate, size, flags, header, body, bodyStartOctet,  propertyBuilder);
         } else {
-            return super.createMessage(internalDate, size, bodyStartOctet, document, flags, headers, propertyBuilder);
+            return super.createMessage(internalDate, size, bodyStartOctet, header, body, flags,  propertyBuilder);
         }
     }
 
+    
+
 }

Modified: james/mailbox/trunk/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAMailboxManagerTest.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAMailboxManagerTest.java?rev=1136175&r1=1136174&r2=1136175&view=diff
==============================================================================
--- james/mailbox/trunk/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAMailboxManagerTest.java (original)
+++ james/mailbox/trunk/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAMailboxManagerTest.java Wed Jun 15 20:24:10 2011
@@ -26,7 +26,6 @@ import org.apache.james.mailbox.BadCrede
 import org.apache.james.mailbox.MailboxException;
 import org.apache.james.mailbox.MailboxManagerTest;
 import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.jpa.mail.model.JPAHeader;
 import org.apache.james.mailbox.jpa.mail.model.JPAMailbox;
 import org.apache.james.mailbox.jpa.mail.model.JPAProperty;
 import org.apache.james.mailbox.jpa.mail.model.JPAUserFlag;
@@ -86,7 +85,6 @@ public class JPAMailboxManagerTest exten
         properties.put("openjpa.ConnectionFactoryProperties", "PrettyPrint=true, PrettyPrintLineLength=72");
         properties.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)");
         properties.put("openjpa.MetaDataFactory", "jpa(Types=" +
-                JPAHeader.class.getName() + ";" +
                 JPAMailbox.class.getName() + ";" +
                 AbstractJPAMessage.class.getName() + ";" +
                 JPAMessage.class.getName() + ";" +

Modified: james/mailbox/trunk/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAStressTest.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAStressTest.java?rev=1136175&r1=1136174&r2=1136175&view=diff
==============================================================================
--- james/mailbox/trunk/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAStressTest.java (original)
+++ james/mailbox/trunk/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAStressTest.java Wed Jun 15 20:24:10 2011
@@ -27,7 +27,6 @@ import org.apache.james.mailbox.Abstract
 import org.apache.james.mailbox.MailboxException;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.jpa.mail.model.JPAHeader;
 import org.apache.james.mailbox.jpa.mail.model.JPAMailbox;
 import org.apache.james.mailbox.jpa.mail.model.JPAProperty;
 import org.apache.james.mailbox.jpa.mail.model.JPAUserFlag;
@@ -61,7 +60,6 @@ public class JPAStressTest extends Abstr
         properties.put("openjpa.ConnectionFactoryProperties", "PrettyPrint=true, PrettyPrintLineLength=72");
         properties.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)");
         properties.put("openjpa.MetaDataFactory", "jpa(Types=" +
-                JPAHeader.class.getName() + ";" +
                 JPAMailbox.class.getName() + ";" +
                 AbstractJPAMessage.class.getName() + ";" +
                 JPAMessage.class.getName() + ";" +

Modified: james/mailbox/trunk/jpa/src/test/java/org/apache/james/mailbox/jpa/JPASubscriptionManagerTest.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/jpa/src/test/java/org/apache/james/mailbox/jpa/JPASubscriptionManagerTest.java?rev=1136175&r1=1136174&r2=1136175&view=diff
==============================================================================
--- james/mailbox/trunk/jpa/src/test/java/org/apache/james/mailbox/jpa/JPASubscriptionManagerTest.java (original)
+++ james/mailbox/trunk/jpa/src/test/java/org/apache/james/mailbox/jpa/JPASubscriptionManagerTest.java Wed Jun 15 20:24:10 2011
@@ -22,7 +22,6 @@ import java.util.HashMap;
 
 import org.apache.james.mailbox.AbstractSubscriptionManagerTest;
 import org.apache.james.mailbox.SubscriptionManager;
-import org.apache.james.mailbox.jpa.mail.model.JPAHeader;
 import org.apache.james.mailbox.jpa.mail.model.JPAMailbox;
 import org.apache.james.mailbox.jpa.mail.model.JPAProperty;
 import org.apache.james.mailbox.jpa.mail.model.JPAUserFlag;
@@ -48,7 +47,6 @@ public class JPASubscriptionManagerTest 
         properties.put("openjpa.ConnectionFactoryProperties", "PrettyPrint=true, PrettyPrintLineLength=72");
         properties.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)");
         properties.put("openjpa.MetaDataFactory", "jpa(Types=" +
-                JPAHeader.class.getName() + ";" +
                 JPAMailbox.class.getName() + ";" +
                 AbstractJPAMessage.class.getName() + ";" +
                 JPAMessage.class.getName() + ";" +

Modified: james/mailbox/trunk/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java?rev=1136175&r1=1136174&r2=1136175&view=diff
==============================================================================
--- james/mailbox/trunk/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java (original)
+++ james/mailbox/trunk/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java Wed Jun 15 20:24:10 2011
@@ -55,6 +55,7 @@ import org.apache.james.mailbox.SearchQu
 import org.apache.james.mailbox.SearchQuery.NumericRange;
 import org.apache.james.mailbox.SearchQuery.UidCriterion;
 import org.apache.james.mailbox.UnsupportedSearchException;
+import org.apache.james.mailbox.store.ResultUtils;
 import org.apache.james.mailbox.store.mail.MessageMapperFactory;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.mail.model.Message;
@@ -636,7 +637,7 @@ public class LuceneMessageSearchIndex<Id
        
         try {
             // parse the message to index headers and body
-            parser.parse(membership.getFullContent());
+            parser.parse(ResultUtils.toInput(membership));
         } catch (MimeException e) {
             // This should never happen as it was parsed before too without problems.            
             throw new MailboxException("Unable to index content of message", e);

Modified: james/mailbox/trunk/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndexTest.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndexTest.java?rev=1136175&r1=1136174&r2=1136175&view=diff
==============================================================================
--- james/mailbox/trunk/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndexTest.java (original)
+++ james/mailbox/trunk/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndexTest.java Wed Jun 15 20:24:10 2011
@@ -23,12 +23,12 @@ import static org.junit.Assert.assertFal
 import static org.junit.Assert.assertTrue;
 
 import java.nio.charset.Charset;
-import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.Iterator;
-import java.util.List;
 import java.util.Locale;
+import java.util.Map;
 
 import javax.mail.Flags;
 import javax.mail.Flags.Flag;
@@ -36,9 +36,7 @@ import javax.mail.Flags.Flag;
 import org.apache.james.mailbox.SearchQuery;
 import org.apache.james.mailbox.SearchQuery.AddressType;
 import org.apache.james.mailbox.SearchQuery.DateResolution;
-import org.apache.james.mailbox.lucene.search.LuceneMessageSearchIndex;
 import org.apache.james.mailbox.store.MessageBuilder;
-import org.apache.james.mailbox.store.SimpleHeader;
 import org.apache.james.mailbox.store.SimpleMailboxMembership;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.mail.model.Message;
@@ -77,15 +75,15 @@ public class LuceneMessageSearchIndexTes
     public void setUp() throws Exception {
         index = new LuceneMessageSearchIndex<Long>(null, new RAMDirectory(), true, useLenient());
         index.setEnableSuffixMatch(true);
-        List<org.apache.james.mailbox.store.SimpleHeader> headersSubject = new ArrayList<org.apache.james.mailbox.store.SimpleHeader>();
-        headersSubject.add(new SimpleHeader("Subject", 1, "test"));
+        Map<String, String> headersSubject = new HashMap<String, String>();
+        headersSubject.put("Subject", "test");
        
-        List<org.apache.james.mailbox.store.SimpleHeader> headersTest = new ArrayList<org.apache.james.mailbox.store.SimpleHeader>();
-        headersSubject.add(new SimpleHeader("Test", 1, "test"));
+        Map<String, String> headersTest = new HashMap<String, String>();
+        headersSubject.put("Test", "test");
         
-        List<org.apache.james.mailbox.store.SimpleHeader> headersTestSubject = new ArrayList<org.apache.james.mailbox.store.SimpleHeader>();
-        headersTestSubject.add(new SimpleHeader("Test", 1, "test"));
-        headersTestSubject.add(new SimpleHeader("Subject", 2, "test2"));
+        Map<String, String> headersTestSubject =  new HashMap<String, String>();
+        headersTestSubject.put("Test", "test");
+        headersTestSubject.put("Subject", "test2");
 
 
         

Modified: james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirFolder.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirFolder.java?rev=1136175&r1=1136174&r2=1136175&view=diff
==============================================================================
--- james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirFolder.java (original)
+++ james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirFolder.java Wed Jun 15 20:24:10 2011
@@ -43,16 +43,9 @@ import org.apache.james.mailbox.MailboxP
 import org.apache.james.mailbox.MailboxPathLocker;
 import org.apache.james.mailbox.MailboxPathLocker.LockAwareExecution;
 import org.apache.james.mailbox.MailboxSession;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 public class MaildirFolder {
 
-    /**
-     * The logger.
-     */
-    private Logger log = LoggerFactory.getLogger(MaildirFolder.class.getName());
-
     public static final String VALIDITY_FILE = "james-uidvalidity";
     public static final String UIDLIST_FILE = "james-uidlist";
     public static final String CUR = "cur";
@@ -95,27 +88,7 @@ public class MaildirFolder {
     public File getRootFile() {
         return rootFolder;
     }
-    
-    /**
-     * Locks the uidList file and if it has retrieved the lock, returns it.
-     * Make sure to call unlockUidList() in a finally block afterwards.
-     * @return The locked uidList
-     */
-    /*
-    public File lockUidList() {
-        FileLock.lock(uidFile);
-        return uidFile;
-    }
-    */
-    
-    /**
-     * Unlocks the uidList file if it has been locked before.
-     */
-    /*
-    public void unlockUidList() {
-        FileLock.unlock(uidFile);
-    }
-    */
+
     /**
      * Tests whether the directory belonging to this {@link MaildirFolder} exists 
      * @return true if the directory belonging to this {@link MaildirFolder} exists ; false otherwise 

Modified: james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirMessageManager.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirMessageManager.java?rev=1136175&r1=1136174&r2=1136175&view=diff
==============================================================================
--- james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirMessageManager.java (original)
+++ james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirMessageManager.java Wed Jun 15 20:24:10 2011
@@ -19,19 +19,15 @@
 package org.apache.james.mailbox.maildir;
 
 import java.io.InputStream;
-import java.util.ArrayList;
 import java.util.Date;
-import java.util.List;
 
 import javax.mail.Flags;
 
 import org.apache.james.mailbox.MailboxException;
-import org.apache.james.mailbox.maildir.mail.model.MaildirHeader;
 import org.apache.james.mailbox.maildir.mail.model.MaildirMessage;
 import org.apache.james.mailbox.store.MailboxEventDispatcher;
 import org.apache.james.mailbox.store.StoreMessageManager;
 import org.apache.james.mailbox.store.mail.MessageMapperFactory;
-import org.apache.james.mailbox.store.mail.model.Header;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.mail.model.Message;
 import org.apache.james.mailbox.store.mail.model.PropertyBuilder;
@@ -44,22 +40,13 @@ public class MaildirMessageManager exten
         super(mapperFactory, index, dispatcher, mailboxEntiy);
     }
 
-    @Override
-    protected Header createHeader(int lineNumber, String name, String value) {
-        return new MaildirHeader(lineNumber, name, value);
-    }
-
+    
     @Override
     protected Message<Integer> createMessage(Date internalDate,
-            int size, int bodyStartOctet, InputStream documentIn, Flags flags,
-            List<Header> headers, PropertyBuilder propertyBuilder)
+            int size, int bodyStartOctet, InputStream header, InputStream body, Flags flags, PropertyBuilder propertyBuilder)
             throws MailboxException {
-        final List<MaildirHeader> maildirHeaders = new ArrayList<MaildirHeader>(headers.size());
-        for (Header header: headers) {
-            maildirHeaders.add((MaildirHeader) header);
-        }
         final Message<Integer> message = new MaildirMessage(getMailboxEntity(), internalDate, 
-                size, flags, documentIn, bodyStartOctet, maildirHeaders, propertyBuilder);
+                size, flags, header, body, bodyStartOctet, propertyBuilder);
         return message;
     }
 

Modified: james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMessageMapper.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMessageMapper.java?rev=1136175&r1=1136174&r2=1136175&view=diff
==============================================================================
--- james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMessageMapper.java (original)
+++ james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMessageMapper.java Wed Jun 15 20:24:10 2011
@@ -47,6 +47,7 @@ import org.apache.james.mailbox.maildir.
 import org.apache.james.mailbox.maildir.mail.model.AbstractMaildirMessage;
 import org.apache.james.mailbox.maildir.mail.model.LazyLoadingMaildirMessage;
 import org.apache.james.mailbox.maildir.mail.model.MaildirMessage;
+import org.apache.james.mailbox.store.ResultUtils;
 import org.apache.james.mailbox.store.mail.AbstractMessageMapper;
 import org.apache.james.mailbox.store.mail.SimpleMessageMetaData;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
@@ -386,7 +387,7 @@ public class MaildirMessageMapper extend
         try {
             messageFile.createNewFile();
             fos = new FileOutputStream(messageFile);
-            input = message.getFullContent();
+            input = ResultUtils.toInput(message);
             byte[] b = new byte[BUF_SIZE];
             int len = 0;
             while ((len = input.read(b)) != -1)

Modified: james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/model/LazyLoadingMaildirMessage.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/model/LazyLoadingMaildirMessage.java?rev=1136175&r1=1136174&r2=1136175&view=diff
==============================================================================
--- james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/model/LazyLoadingMaildirMessage.java (original)
+++ james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/model/LazyLoadingMaildirMessage.java Wed Jun 15 20:24:10 2011
@@ -24,7 +24,6 @@ import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.PushbackInputStream;
-import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 
@@ -32,9 +31,9 @@ import javax.mail.Flags;
 import javax.mail.util.SharedFileInputStream;
 
 import org.apache.commons.io.IOUtils;
+import org.apache.commons.io.input.BoundedInputStream;
 import org.apache.james.mailbox.maildir.MaildirFolder;
 import org.apache.james.mailbox.maildir.MaildirMessageName;
-import org.apache.james.mailbox.store.mail.model.Header;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.mail.model.Property;
 import org.apache.james.mailbox.store.mail.model.PropertyBuilder;
@@ -51,7 +50,6 @@ public class LazyLoadingMaildirMessage e
     private MaildirMessageName messageName;
     private int bodyStartOctet;
     private final PropertyBuilder propertyBuilder = new PropertyBuilder();
-    private final List<Header> headers = new ArrayList<Header>();
 
     private boolean parsed;
 
@@ -99,19 +97,8 @@ public class LazyLoadingMaildirMessage e
             parser.setRecursionMode(MimeTokenStream.M_NO_RECURSE);
             parser.parse(tmpMsgIn.newStream(0, -1));
 
-            int lineNumber = 0;
             int next = parser.next();
             while (next != MimeTokenStream.T_BODY && next != MimeTokenStream.T_END_OF_STREAM && next != MimeTokenStream.T_START_MULTIPART) {
-                if (next == MimeTokenStream.T_FIELD) {
-                    String fieldValue = parser.getField().getBody();
-                    if (fieldValue.endsWith("\r\f")) {
-                        fieldValue = fieldValue.substring(0, fieldValue.length() - 2);
-                    }
-                    if (fieldValue.startsWith(" ")) {
-                        fieldValue = fieldValue.substring(1);
-                    }
-                    headers.add(new MaildirHeader(lineNumber, parser.getField().getName(), fieldValue));
-                }
                 next = parser.next();
             }
             final MaximalBodyDescriptor descriptor = (MaximalBodyDescriptor) parser.getBodyDescriptor();
@@ -265,16 +252,6 @@ public class LazyLoadingMaildirMessage e
 
     /*
      * (non-Javadoc)
-     * @see org.apache.james.mailbox.store.mail.model.Message#getHeaders()
-     */
-    public List<Header> getHeaders() {
-        parseMessage();
-
-        return headers;
-    }
-
-    /*
-     * (non-Javadoc)
      * @see org.apache.james.mailbox.store.mail.model.Message#getProperties()
      */
     public List<Property> getProperties() {
@@ -290,11 +267,7 @@ public class LazyLoadingMaildirMessage e
         return messageName.getInternalDate();
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.mailbox.store.mail.model.Message#getFullContent()
-     */
-    public InputStream getFullContent() throws IOException {
+    private InputStream getFullContent() throws IOException {
         return new FileInputStream(messageName.getFile());
     }
 
@@ -317,5 +290,13 @@ public class LazyLoadingMaildirMessage e
         return bodyStartOctet;
     }
 
+    @Override
+    public InputStream getHeaderContent() throws IOException {
+        parseMessage();
+            
+        return new BoundedInputStream(getFullContent(), bodyStartOctet - 2);
+
+    }
+
 
 }

Modified: james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/model/MaildirMessage.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/model/MaildirMessage.java?rev=1136175&r1=1136174&r2=1136175&view=diff
==============================================================================
--- james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/model/MaildirMessage.java (original)
+++ james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/model/MaildirMessage.java Wed Jun 15 20:24:10 2011
@@ -28,8 +28,9 @@ import java.util.List;
 import javax.mail.Flags;
 
 import org.apache.commons.io.IOUtils;
+import org.apache.commons.io.input.BoundedInputStream;
 import org.apache.james.mailbox.MailboxException;
-import org.apache.james.mailbox.store.mail.model.Header;
+import org.apache.james.mailbox.store.ResultUtils;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.mail.model.Property;
 import org.apache.james.mailbox.store.mail.model.PropertyBuilder;
@@ -40,7 +41,6 @@ public class MaildirMessage extends Abst
     // Document
     private int bodyStartOctet;
     private InputStream rawFullContent;
-    private List<MaildirHeader> headers;
     private String mediaType;
     private List<MaildirProperty> properties;
     private String subType;
@@ -64,13 +64,11 @@ public class MaildirMessage extends Abst
      * @param propertyBuilder
      */
     public MaildirMessage(Mailbox<Integer> mailbox, Date internalDate,
-            int size, Flags flags, InputStream documentIn, int bodyStartOctet,
-            List<MaildirHeader> maildirHeaders, PropertyBuilder propertyBuilder) {
+            int size, Flags flags, InputStream header, InputStream body, int bodyStartOctet, PropertyBuilder propertyBuilder) {
         super(mailbox);
         // Document
-        this.rawFullContent = documentIn;
+        this.rawFullContent = ResultUtils.toInput(header, body);
         this.bodyStartOctet = bodyStartOctet;
-        this.headers = new ArrayList<MaildirHeader>(maildirHeaders);
         this.textualLineCount = propertyBuilder.getTextualLineCount();
         this.mediaType = propertyBuilder.getMediaType();
         this.subType = propertyBuilder.getSubType();
@@ -109,19 +107,13 @@ public class MaildirMessage extends Abst
         this.seen = message.isSeen();
         
         try {
-            this.rawFullContent = new ByteArrayInputStream(IOUtils.toByteArray(message.getFullContent()));
+            this.rawFullContent = new ByteArrayInputStream(IOUtils.toByteArray(ResultUtils.toInput(message)));
         } catch (IOException e) {
             throw new MailboxException("Parsing of message failed",e);
         }
        
         this.bodyStartOctet = (int) (message.getFullContentOctets() - message.getBodyOctets());
-        this.headers = new ArrayList<MaildirHeader>();
-        
-        List<Header> originalHeaders = message.getHeaders();
-        for (int i = 0; i < originalHeaders.size(); i++) {
-            headers.add(new MaildirHeader(originalHeaders.get(i)));
-        }
-
+      
         PropertyBuilder pBuilder = new PropertyBuilder(message.getProperties());
         this.textualLineCount = message.getTextualLineCount();
         this.mediaType = message.getMediaType();
@@ -149,12 +141,13 @@ public class MaildirMessage extends Abst
         return size;
     }
 
-    /* 
+
+    /*
      * (non-Javadoc)
-     * @see org.apache.james.mailbox.store.mail.model.Document#getHeaders()
+     * @see org.apache.james.mailbox.store.mail.model.Message#getHeaderContent()
      */
-    public List<Header> getHeaders() {
-        return new ArrayList<Header>(headers);
+    public InputStream  getHeaderContent() {
+        return new BoundedInputStream(rawFullContent, bodyStartOctet - 2);
     }
 
     /* 
@@ -245,14 +238,6 @@ public class MaildirMessage extends Abst
 
     /*
      * (non-Javadoc)
-     * @see org.apache.james.mailbox.store.mail.model.Message#getFullContent()
-     */
-    public InputStream getFullContent() throws IOException {
-        return rawFullContent;
-    }
-
-    /*
-     * (non-Javadoc)
      * @see org.apache.james.mailbox.store.mail.model.Message#getBodyContent()
      */
     public InputStream getBodyContent() throws IOException {

Modified: james/mailbox/trunk/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryStoreMessageManager.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryStoreMessageManager.java?rev=1136175&r1=1136174&r2=1136175&view=diff
==============================================================================
--- james/mailbox/trunk/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryStoreMessageManager.java (original)
+++ james/mailbox/trunk/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryStoreMessageManager.java Wed Jun 15 20:24:10 2011
@@ -19,21 +19,19 @@
 
 package org.apache.james.mailbox.inmemory;
 
-import java.io.ByteArrayOutputStream;
+import java.io.IOException;
 import java.io.InputStream;
 import java.util.Date;
-import java.util.List;
 
 import javax.mail.Flags;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.james.mailbox.MailboxException;
 import org.apache.james.mailbox.inmemory.mail.model.InMemoryMailbox;
-import org.apache.james.mailbox.inmemory.mail.model.SimpleHeader;
 import org.apache.james.mailbox.inmemory.mail.model.SimpleMailboxMembership;
 import org.apache.james.mailbox.store.MailboxEventDispatcher;
 import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
 import org.apache.james.mailbox.store.StoreMessageManager;
-import org.apache.james.mailbox.store.mail.model.Header;
 import org.apache.james.mailbox.store.mail.model.Message;
 import org.apache.james.mailbox.store.mail.model.PropertyBuilder;
 import org.apache.james.mailbox.store.search.MessageSearchIndex;
@@ -43,33 +41,16 @@ public class InMemoryStoreMessageManager
     public InMemoryStoreMessageManager(MailboxSessionMapperFactory<Long> mapperFactory, MessageSearchIndex<Long> index, MailboxEventDispatcher<Long> dispatcher, InMemoryMailbox mailbox) throws MailboxException {
         super(mapperFactory, index, dispatcher,mailbox);
     }
-    
-    @Override
-    protected Header createHeader(int lineNumber, String name, String value) {
-        return new SimpleHeader(name, lineNumber, value);
-    }
 
     @Override
     protected Message<Long> createMessage(Date internalDate, int size, int bodyStartOctet, 
-            InputStream  document, Flags flags, List<Header> headers, PropertyBuilder propertyBuilder) throws MailboxException {
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        byte[] byteContent;
+            InputStream header, InputStream  body, Flags flags,  PropertyBuilder propertyBuilder) throws MailboxException {
+
         try {
-            byte[] buf = new byte[1024];
-            int i = 0;
-            while ((i = document.read(buf)) != -1) {
-                out.write(buf, 0, i);
-            }
-            byteContent = out.toByteArray();
-            if (out != null)
-                out.close();
-
-        } catch (Exception e) {
-            e.printStackTrace();
-            byteContent = new byte[0];
+            return new SimpleMailboxMembership(internalDate, size, bodyStartOctet,  IOUtils.toByteArray(header), IOUtils.toByteArray(body), flags, propertyBuilder, ((InMemoryMailbox) getMailboxEntity()).getMailboxId());
+        } catch (IOException e) {
+            throw new MailboxException("Unable to create message", e);
         }
-        InMemoryMailbox mailbox = (InMemoryMailbox) getMailboxEntity();
-        return new SimpleMailboxMembership(internalDate, size, bodyStartOctet, byteContent, flags, headers, propertyBuilder, mailbox.getMailboxId());
     }
     
 }

Modified: james/mailbox/trunk/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/model/SimpleMailboxMembership.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/model/SimpleMailboxMembership.java?rev=1136175&r1=1136174&r2=1136175&view=diff
==============================================================================
--- james/mailbox/trunk/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/model/SimpleMailboxMembership.java (original)
+++ james/mailbox/trunk/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/model/SimpleMailboxMembership.java Wed Jun 15 20:24:10 2011
@@ -28,7 +28,6 @@ import java.util.List;
 import javax.mail.Flags;
 
 import org.apache.james.mailbox.store.mail.model.AbstractMessage;
-import org.apache.james.mailbox.store.mail.model.Header;
 import org.apache.james.mailbox.store.mail.model.Property;
 import org.apache.james.mailbox.store.mail.model.PropertyBuilder;
 
@@ -47,9 +46,9 @@ public class SimpleMailboxMembership ext
     private final String subType;
     private List<Property> properties;
     private final String mediaType;
-    private List<Header> headers;
+    private byte[] header;
     private Long lineCount;
-    private byte[] document;
+    private byte[] body;
     private int bodyStartOctet;
     private long modSeq;
     public SimpleMailboxMembership(long mailboxId, long uid, long modSeq, final SimpleMailboxMembership original) {
@@ -69,21 +68,21 @@ public class SimpleMailboxMembership ext
         this.subType  = original.subType;
         this.mediaType = original.mediaType;
         this.properties = original.properties;
-        this.headers = original.headers;
+        this.header = original.header;
         this.lineCount = original.lineCount;
-        this.document = original.document;
+        this.body = original.body;
         this.bodyStartOctet = original.bodyStartOctet;
     }
     
-    public SimpleMailboxMembership(Date internalDate, int size, int bodyStartOctet, byte[] document, 
-            Flags flags, List<Header> headers, PropertyBuilder propertyBuilder, final long mailboxId) {
-        this.document = document;
+    public SimpleMailboxMembership(Date internalDate, int size, int bodyStartOctet, byte[] header,  byte[] body, 
+            Flags flags, PropertyBuilder propertyBuilder, final long mailboxId) {
+        this.body = body;
         
         this.size = size;
         this.bodyStartOctet = bodyStartOctet;
         setFlags(flags);
         lineCount = propertyBuilder.getTextualLineCount();
-        this.headers = headers;
+        this.header = header;
         this.internalDate = internalDate;
         this.mailboxId = mailboxId;
         this.properties = propertyBuilder.toProperties();
@@ -146,20 +145,14 @@ public class SimpleMailboxMembership ext
     }
 
     public InputStream getBodyContent() throws IOException {
-        return new ByteArrayInputStream(document,bodyStartOctet, (int) getFullContentOctets());      
+        return new ByteArrayInputStream(body);     
     }
 
-    public InputStream getFullContent() throws IOException {
-        return new ByteArrayInputStream(document);
-    }
 
     public long getFullContentOctets() {
-        return document.length;
+        return size;
     }
 
-    public List<Header> getHeaders() {
-        return headers;
-    }
 
     public String getMediaType() {
         return mediaType;
@@ -251,4 +244,9 @@ public class SimpleMailboxMembership ext
     public void setUid(long uid) {
         this.uid = uid;
     }
+
+    @Override
+    public InputStream getHeaderContent() throws IOException {
+        return new ByteArrayInputStream(header);
+    }
 }

Modified: james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/ResultHeader.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/ResultHeader.java?rev=1136175&r1=1136174&r2=1136175&view=diff
==============================================================================
--- james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/ResultHeader.java (original)
+++ james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/ResultHeader.java Wed Jun 15 20:24:10 2011
@@ -33,7 +33,6 @@ import java.nio.channels.WritableByteCha
 import org.apache.james.mailbox.InputStreamContent;
 import org.apache.james.mailbox.MailboxException;
 import org.apache.james.mailbox.MessageResult;
-import org.apache.james.mailbox.store.mail.model.Header;
 
 public final class ResultHeader implements MessageResult.Header, InputStreamContent {
     private final String name;
@@ -42,9 +41,6 @@ public final class ResultHeader implemen
 
     private final long size;
 
-    public ResultHeader(final Header header) {
-        this(header.getFieldName(), header.getValue());
-    }
 
     public ResultHeader(String name, String value) {
         this.name = name;

Modified: james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/ResultUtils.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/ResultUtils.java?rev=1136175&r1=1136174&r2=1136175&view=diff
==============================================================================
--- james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/ResultUtils.java (original)
+++ james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/ResultUtils.java Wed Jun 15 20:24:10 2011
@@ -19,11 +19,13 @@
 
 package org.apache.james.mailbox.store;
 
-import java.io.FilterInputStream;
+import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.SequenceInputStream;
 import java.nio.charset.Charset;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
@@ -34,13 +36,13 @@ import org.apache.james.mailbox.MessageR
 import org.apache.james.mailbox.MessageResult.FetchGroup;
 import org.apache.james.mailbox.MessageResult.MimePath;
 import org.apache.james.mailbox.MimeDescriptor;
-import org.apache.james.mailbox.store.mail.model.Header;
 import org.apache.james.mailbox.store.mail.model.Message;
 import org.apache.james.mailbox.store.streaming.InputStreamContent;
 import org.apache.james.mailbox.store.streaming.InputStreamContent.Type;
 import org.apache.james.mailbox.store.streaming.PartContentBuilder;
 import org.apache.james.mailbox.util.MessageResultImpl;
 import org.apache.james.mime4j.MimeException;
+import org.apache.james.mime4j.parser.Field;
 
 /**
  *
@@ -53,23 +55,18 @@ public class ResultUtils {
 
     static final Charset US_ASCII = Charset.forName("US-ASCII");
 
-    public static List<MessageResult.Header> createHeaders(final Message<?> document) {
-        final List<Header> headers = getSortedHeaders(document);
-
-        final List<MessageResult.Header> results = new ArrayList<MessageResult.Header>(headers.size());
-        for (Header header: headers) {
-            final ResultHeader resultHeader = new ResultHeader(header);
+    public static List<MessageResult.Header> createHeaders(final Message<?> document) throws IOException {
+        org.apache.james.mime4j.message.Header header = new org.apache.james.mime4j.message.Header(document.getHeaderContent());
+        
+        final List<MessageResult.Header> results = new ArrayList<MessageResult.Header>();
+        List<Field> fields = header.getFields();
+        for (Field field: fields) {
+            final ResultHeader resultHeader = new ResultHeader(field.getName(), field.getBody());
             results.add(resultHeader);
         }
         return results;
     }
 
-    private static List<Header> getSortedHeaders(final Message<?> document) {
-        final List<Header> headers = new ArrayList<Header>(document.getHeaders());
-        Collections.sort(headers);
-        return headers;
-    }
-
     /**
      * Return the {@link Content} which holds only the Body for the given {@link MailboxMembership}
      * 
@@ -95,6 +92,20 @@ public class ResultUtils {
     }
 
     /**
+     * Return an {@link InputStream} which holds the full content of the message
+     * @param message
+     * @return
+     * @throws IOException
+     */
+    public static InputStream toInput(final Message<?> message) throws IOException{
+        return toInput(message.getHeaderContent(), message.getBodyContent());
+    }
+    
+    public static InputStream toInput(final InputStream header, final InputStream body) {
+        return new SequenceInputStream(Collections.enumeration(Arrays.asList(header, new ByteArrayInputStream(BYTES_NEW_LINE), body)));
+    }
+    
+    /**
      * Return the {@link MessageResult} for the given {@link MailboxMembership} and {@link FetchGroup}
      * 
      * @param message
@@ -164,7 +175,7 @@ public class ResultUtils {
     }
 
     private static void addHeaders(final Message<?> message,
-            MessageResultImpl messageResult) {
+            MessageResultImpl messageResult) throws IOException {
         final List<MessageResult.Header> headers = createHeaders(message);
         messageResult.setHeaders(headers);
     }
@@ -223,85 +234,6 @@ public class ResultUtils {
     }
    
 
-    /**
-     * Return an {@link InputStream} which holds the content of the given {@link org.apache.james.mailbox.store.mail.model.Message}
-     * 
-     * @param document
-     * @return stream
-     * @throws IOException 
-     */
-    public static InputStream toInput(final Message<?> document) throws IOException {
-        final List<Header> headers = getSortedHeaders(document);
-        final StringBuffer headersToString = new StringBuffer(headers.size() * 50);
-        for (Header header: headers) {
-            headersToString.append(header.getFieldName());
-            headersToString.append(": ");
-            headersToString.append(header.getValue());
-            headersToString.append("\r\n");
-        }
-        headersToString.append("\r\n");
-        final InputStream bodyContent = document.getBodyContent();
-        final MessageInputStream stream = new MessageInputStream(headersToString, bodyContent);
-        return stream;
-    }
-
-
-    private static final class MessageInputStream extends FilterInputStream {
-        private final StringBuffer headers;
-        private int headerPosition = 0;
-
-        public MessageInputStream(final StringBuffer headers,
-                final InputStream bodyContent) throws IOException{
-            super(bodyContent);
-            
-            this.headers = headers;
-        }
-
-        public int read() throws IOException {
-            final int result;
-            if (headerPosition < headers.length()) {
-                result = headers.charAt(headerPosition++);
-            } else  { 
-                result = super.read();
-            }
-            return result;
-        }
-
-        @Override
-        public int read(byte[] b, int off, int len) throws IOException {
-            if (headerPosition < headers.length()) {
-                int headersLeft = headers.length() - headerPosition;
-                if (len > headersLeft) {
-                    int i;
-                    for (i = 0; i < headersLeft; i++) {
-                        int a =  read();
-                        if (a == -1) {
-                            return i;
-                        } 
-                        b[off +i] = (byte) a;
-                    }
-                    int bytesLeft = len - headersLeft;
-                    return i + super.read(b, off +i, bytesLeft);
-                } else {
-
-                    for (int i = 0 ; i < len; i++) {
-                        int a =  read();
-                        if (a == -1) {
-                            return -1;
-                        } 
-                        b[off +i] = (byte) a;
-                    }
-                    return len;
-                }
-            }
-            return super.read(b, off, len);
-        }
-
-        @Override
-        public int read(byte[] b) throws IOException {
-            return read(b, 0, b.length);
-        }
-    }
   
     private static final int[] path(MimePath mimePath) {
         final int[] result;

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=1136175&r1=1136174&r2=1136175&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 Wed Jun 15 20:24:10 2011
@@ -19,6 +19,7 @@
 
 package org.apache.james.mailbox.store;
 
+import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
@@ -49,7 +50,6 @@ import org.apache.james.mailbox.UpdatedF
 import org.apache.james.mailbox.MessageResult.FetchGroup;
 import org.apache.james.mailbox.store.mail.MessageMapper;
 import org.apache.james.mailbox.store.mail.MessageMapperFactory;
-import org.apache.james.mailbox.store.mail.model.Header;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.mail.model.Message;
 import org.apache.james.mailbox.store.mail.model.PropertyBuilder;
@@ -61,6 +61,7 @@ import org.apache.james.mailbox.store.tr
 import org.apache.james.mailbox.store.transaction.Mapper.MailboxMembershipCallback;
 import org.apache.james.mime4j.MimeException;
 import org.apache.james.mime4j.descriptor.MaximalBodyDescriptor;
+import org.apache.james.mime4j.message.Header;
 import org.apache.james.mime4j.parser.MimeEntityConfig;
 import org.apache.james.mime4j.parser.MimeTokenStream;
 
@@ -197,25 +198,14 @@ public abstract class StoreMessageManage
            
             parser.setRecursionMode(MimeTokenStream.M_NO_RECURSE);
             parser.parse(bIn);
-            final List<Header> headers = new ArrayList<Header>();
+            final Header header = new Header();
             
-            int lineNumber = 0;
             int next = parser.next();
             while (next != MimeTokenStream.T_BODY
                     && next != MimeTokenStream.T_END_OF_STREAM
                     && next != MimeTokenStream.T_START_MULTIPART) {
                 if (next == MimeTokenStream.T_FIELD) {
-                    String fieldValue = parser.getField().getBody();
-                    if (fieldValue.endsWith("\r\f")) {
-                        fieldValue = fieldValue.substring(0,fieldValue.length() - 2);
-                    }
-                    if (fieldValue.startsWith(" ")) {
-                        fieldValue = fieldValue.substring(1);
-                    }
-                    final Header header 
-                        = createHeader(++lineNumber, parser.getField().getName(), 
-                            fieldValue);
-                    headers.add(header);
+                    header.addField(parser.getField());
                 }
                 next = parser.next();
             }
@@ -294,10 +284,14 @@ public abstract class StoreMessageManage
                 // via the TeeInputStream
             }
             int bodyStartOctet = (int) bIn.getBodyStartOffset();
+            if (bodyStartOctet == -1) {
+                bodyStartOctet = 0;
+            }
             contentIn = new FileInputStream(file);
+            contentIn.skip(bodyStartOctet);
             final int size = (int) file.length();
 
-            final Message<Id> message = createMessage(internalDate, size, bodyStartOctet, contentIn, flags, headers, propertyBuilder);
+            final Message<Id> message = createMessage(internalDate, size, bodyStartOctet, new ByteArrayInputStream(header.toString().getBytes("US-ASCII")), contentIn, flags, propertyBuilder);
             MessageMetaData data = appendMessageToStore(message, mailboxSession);
                        
             Map<Long, MessageMetaData> uids = new HashMap<Long, MessageMetaData>();
@@ -331,25 +325,15 @@ public abstract class StoreMessageManage
      * @param internalDate
      * @param size
      * @param bodyStartOctet
-     * @param documentIn
+     * @param headersContent
+     * @param bodyContent
      * @param flags
-     * @param headers
-     * @param propertyBuilder
      * @return membership
      * @throws MailboxException 
      */
     protected abstract Message<Id> createMessage(Date internalDate, final int size, int bodyStartOctet, 
-            final InputStream documentIn, final Flags flags, final List<Header> headers, PropertyBuilder propertyBuilder) throws MailboxException;
+            final InputStream headersContent, final InputStream bodyContent, final Flags flags, final PropertyBuilder propertyBuilder) throws MailboxException;
     
-    /**
-     * Create a new {@link Header} for the given data
-     * 
-     * @param lineNumber
-     * @param name
-     * @param value
-     * @return header
-     */
-    protected abstract Header createHeader(int lineNumber, String name, String value);
     
     public void addListener(MailboxListener listener) throws MailboxException {
         dispatcher.addMailboxListener(listener);

Modified: james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/mail/model/Message.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/mail/model/Message.java?rev=1136175&r1=1136174&r2=1136175&view=diff
==============================================================================
--- james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/mail/model/Message.java (original)
+++ james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/mail/model/Message.java Wed Jun 15 20:24:10 2011
@@ -73,8 +73,6 @@ public interface Message<Id> extends Com
      */
     public abstract long getModSeq();
 
-    
-
     /**
      * Return if it was marked as answered
      * 
@@ -132,16 +130,7 @@ public interface Message<Id> extends Com
      * @return new instance, not null
      */
     public abstract Flags createFlags();
-
-    /**
-     * Gets the full content (including headers) of the document. 
-     * 
-     * Be aware that this method need to return a new fresh {@link InputStream}
-     * on every call, which basicly means it need to start at position 0
-     * 
-     * @return fullContent, not null
-     */
-    public abstract InputStream getFullContent() throws IOException;
+    
     
     /**
      * Gets the body content of the document. Headers are excluded.
@@ -188,11 +177,15 @@ public interface Message<Id> extends Com
     public Long getTextualLineCount();
     
     /**
-     * Gets a read-only list of headers.
+     * Gets the header as {@link InputStream}. This MUST exclude the CRLF terminator
+     * 
+     * Be aware that this method need to return a new fresh {@link InputStream}
+     * on every call
      * 
-     * @return unmodifiable list of headers, not null
+     * @return header
+     * @throws IOException 
      */
-    public abstract List<Header> getHeaders();
+    public abstract InputStream getHeaderContent() throws IOException;
     
     /**
      * Gets a read-only list of meta-data properties.

Modified: james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java?rev=1136175&r1=1136174&r2=1136175&view=diff
==============================================================================
--- james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java (original)
+++ james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java Wed Jun 15 20:24:10 2011
@@ -37,13 +37,13 @@ import java.util.TreeSet;
 import javax.mail.Flags;
 
 import org.apache.james.mailbox.MailboxException;
+import org.apache.james.mailbox.MessageResult.Header;
 import org.apache.james.mailbox.SearchQuery;
 import org.apache.james.mailbox.SearchQuery.AddressType;
 import org.apache.james.mailbox.SearchQuery.DateResolution;
 import org.apache.james.mailbox.UnsupportedSearchException;
 import org.apache.james.mailbox.SearchQuery.NumericRange;
 import org.apache.james.mailbox.store.ResultUtils;
-import org.apache.james.mailbox.store.mail.model.Header;
 import org.apache.james.mailbox.store.mail.model.Message;
 import org.apache.james.mailbox.store.search.comparator.CombinedComparator;
 import org.apache.james.mime4j.MimeException;
@@ -138,7 +138,11 @@ public class MessageSearches implements 
         } else if (criterion instanceof SearchQuery.SizeCriterion) {
             result = matches((SearchQuery.SizeCriterion) criterion, message);
         } else if (criterion instanceof SearchQuery.HeaderCriterion) {
-            result = matches((SearchQuery.HeaderCriterion) criterion, message, log);
+            try {
+                result = matches((SearchQuery.HeaderCriterion) criterion, message, log);
+            } catch (IOException e) {
+                throw new MailboxException("Unable to search header", e);
+            }
         } else if (criterion instanceof SearchQuery.UidCriterion) {
             result = matches((SearchQuery.UidCriterion) criterion, message);
         } else if (criterion instanceof SearchQuery.FlagCriterion) {
@@ -313,7 +317,7 @@ public class MessageSearches implements 
         return result;
     }
 
-    private static boolean matches(SearchQuery.HeaderCriterion criterion, Message<?> message, Logger log) throws UnsupportedSearchException {
+    private static boolean matches(SearchQuery.HeaderCriterion criterion, Message<?> message, Logger log) throws MailboxException, IOException {
         final SearchQuery.HeaderOperator operator = criterion.getOperator();
         final String headerName = criterion.getHeaderName();
         final boolean result;
@@ -338,13 +342,15 @@ public class MessageSearches implements 
      * @param headerName
      * @param message
      * @return containsAddress
+     * @throws MailboxException 
+     * @throws IOException 
      */
     private static boolean matchesAddress(final SearchQuery.AddressOperator operator,
-            final String headerName, final Message<?> message, Logger log) {
+            final String headerName, final Message<?> message, Logger log) throws MailboxException, IOException {
         final String text = operator.getAddress().toUpperCase(Locale.ENGLISH);
-        final List<Header> headers = message.getHeaders();
+        final List<Header> headers = ResultUtils.createHeaders(message);
         for (Header header:headers) {
-            final String name = header.getFieldName();
+            final String name = header.getName();
             if (headerName.equalsIgnoreCase(name)) {
                 final String value = header.getValue();
                 try {
@@ -375,11 +381,12 @@ public class MessageSearches implements 
         return false;
     }
     
-    private static boolean exists(String headerName, Message<?> message) {
+    private static boolean exists(String headerName, Message<?> message) throws MailboxException, IOException {
         boolean result = false;
-        final List<Header> headers = message.getHeaders();
+        final List<Header> headers = ResultUtils.createHeaders(message);
+
         for (Header header:headers) {
-            final String name = header.getFieldName();
+            final String name = header.getName();
             if (headerName.equalsIgnoreCase(name)) {
                 result = true;
                 break;
@@ -389,12 +396,12 @@ public class MessageSearches implements 
     }
 
     private static boolean matches(final SearchQuery.ContainsOperator operator,
-            final String headerName, final Message<?> message) {
+            final String headerName, final Message<?> message) throws MailboxException, IOException {
         final String text = operator.getValue().toUpperCase();
         boolean result = false;
-        final List<Header> headers = message.getHeaders();
+        final List<Header> headers = ResultUtils.createHeaders(message);
         for (Header header:headers) {
-            final String name = header.getFieldName();
+            final String name = header.getName();
             if (headerName.equalsIgnoreCase(name)) {
                 final String value = header.getValue();
                 if (value != null) {
@@ -408,19 +415,19 @@ public class MessageSearches implements 
         return result;
     }
 
-    private static boolean matches(final SearchQuery.DateOperator operator,
-            final String headerName, final Message<?> message) throws UnsupportedSearchException {
-       
+    private static boolean matches(final SearchQuery.DateOperator operator, final String headerName, final Message<?> message) throws MailboxException {
+
         final Date date = operator.getDate();
         final DateResolution res = operator.getDateResultion();
-        final String value = headerValue(headerName, message);
-        if (value == null) {
-            return false;
-        } else {
-            try {
-                final Date isoFieldValue = toISODate(value);
-                final SearchQuery.DateComparator type = operator.getType();
-                switch (type) {
+        try {
+            final String value = headerValue(headerName, message);
+            if (value == null) {
+                return false;
+            } else {
+                try {
+                    final Date isoFieldValue = toISODate(value);
+                    final SearchQuery.DateComparator type = operator.getType();
+                    switch (type) {
                     case AFTER:
                         return after(isoFieldValue, date, res);
                     case BEFORE:
@@ -429,18 +436,21 @@ public class MessageSearches implements 
                         return on(isoFieldValue, date, res);
                     default:
                         throw new UnsupportedSearchException();
+                    }
+                } catch (ParseException e) {
+                    return false;
                 }
-            } catch (ParseException e) {
-                return false;
             }
+        } catch (IOException e) {
+            return false;
         }
     }
 
-    private static String headerValue(final String headerName, final Message<?> message) {
-        final List<Header> headers = message.getHeaders();
+    private static String headerValue(final String headerName, final Message<?> message) throws MailboxException, IOException {
+        final List<Header> headers = ResultUtils.createHeaders(message);
         String value = null;
         for (Header header:headers) {
-            final String name = header.getFieldName();
+            final String name = header.getName();
             if (headerName.equalsIgnoreCase(name)) {
                 value = header.getValue();
                 break;



---------------------------------------------------------------------
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