james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From matth...@apache.org
Subject svn commit: r1724227 - in /james/project/trunk/mailbox: hbase/src/main/java/org/apache/james/mailbox/hbase/mail/ jcr/src/main/java/org/apache/james/mailbox/jcr/mail/model/ jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/ maildir/src/m...
Date Tue, 12 Jan 2016 13:18:56 GMT
Author: matthieu
Date: Tue Jan 12 13:18:56 2016
New Revision: 1724227

URL: http://svn.apache.org/viewvc?rev=1724227&view=rev
Log:
MAILBOX-262 try to make Abstract*Message useless by delegating when needed

Added:
    james/project/trunk/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/model/MaildirMessage.java
      - copied, changed from r1724226, james/project/trunk/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/model/MaildirMailboxMessage.java
    james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/DelegatingMailboxMessage.java
      - copied, changed from r1724226, james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/AbstractMailboxMessage.java
    james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/FlagsBuilder.java
      - copied, changed from r1724226, james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AbstractMailboxMessageTest.java
    james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/MessageUidComparator.java
    james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMessage.java
    james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/DelegatingMailboxMessageTest.java
      - copied, changed from r1724226, james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AbstractMailboxMessageTest.java
Removed:
    james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/AbstractMailboxMessage.java
    james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AbstractMailboxMessageTest.java
Modified:
    james/project/trunk/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/mail/HBaseMailboxMessage.java
    james/project/trunk/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/model/JCRMailboxMessage.java
    james/project/trunk/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/AbstractJPAMailboxMessage.java
    james/project/trunk/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/JPAEncryptedMailboxMessage.java
    james/project/trunk/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/JPAMailboxMessage.java
    james/project/trunk/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/JPAStreamingMailboxMessage.java
    james/project/trunk/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/model/MaildirMailboxMessage.java
    james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMailboxMessage.java
    james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMailboxMessageTest.java

Modified: james/project/trunk/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/mail/HBaseMailboxMessage.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/mail/HBaseMailboxMessage.java?rev=1724227&r1=1724226&r2=1724227&view=diff
==============================================================================
--- james/project/trunk/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/mail/HBaseMailboxMessage.java (original)
+++ james/project/trunk/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/mail/HBaseMailboxMessage.java Tue Jan 12 13:18:56 2016
@@ -25,6 +25,7 @@ import static org.apache.james.mailbox.h
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.SequenceInputStream;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Date;
@@ -36,9 +37,12 @@ import org.apache.hadoop.conf.Configurat
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.hbase.HBaseId;
 import org.apache.james.mailbox.hbase.io.ChunkInputStream;
-import org.apache.james.mailbox.store.mail.model.AbstractMailboxMessage;
+import org.apache.james.mailbox.store.mail.model.DefaultMessageId;
+import org.apache.james.mailbox.store.mail.model.FlagsBuilder;
 import org.apache.james.mailbox.store.mail.model.MailboxMessage;
+import org.apache.james.mailbox.store.mail.model.MessageId;
 import org.apache.james.mailbox.store.mail.model.Property;
+import org.apache.james.mailbox.store.mail.model.impl.MessageUidComparator;
 import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
 
 /**
@@ -46,8 +50,9 @@ import org.apache.james.mailbox.store.ma
  * message content. The message content is retrieved using a ChunkedInputStream
  * directly from HBase.
  */
-public class HBaseMailboxMessage extends AbstractMailboxMessage<HBaseId> {
+public class HBaseMailboxMessage implements MailboxMessage<HBaseId> {
 
+    private static final MessageUidComparator MESSAGE_UID_COMPARATOR = new MessageUidComparator();
     private static final String TOSTRING_SEPARATOR = " ";
     /** Configuration for the HBase cluster */
     private final Configuration conf;
@@ -84,18 +89,12 @@ public class HBaseMailboxMessage extends
     /** Meta data for this message */
     private List<Property> properties;
     private List<String> userFlags;
-
+    
     /**
      * Create a copy of the given message.
      * All properties are cloned except mailbox and UID.
-     * @param mailboxId
-     * @param uid
-     * @param modSeq
-     * @param original
-     * @throws MailboxException
      */
     public HBaseMailboxMessage(Configuration conf, HBaseId mailboxId, long uid, long modSeq, MailboxMessage<?> original) throws MailboxException {
-        super();
         this.conf = conf;
         this.mailboxId = mailboxId;
         this.uid = uid;
@@ -117,15 +116,6 @@ public class HBaseMailboxMessage extends
         this.properties = original.getProperties();
     }
 
-    /**
-     * Create a copy of the given message.
-     * @param mailboxId
-     * @param internalDate
-     * @param flags
-     * @param contentOctets
-     * @param bodyStartOctet
-     * @param propertyBuilder
-     */
     public HBaseMailboxMessage(Configuration conf, HBaseId mailboxId, Date internalDate, Flags flags, long contentOctets, int bodyStartOctet, PropertyBuilder propertyBuilder) {
         super();
         this.conf = conf;
@@ -142,25 +132,22 @@ public class HBaseMailboxMessage extends
         this.properties = propertyBuilder.toProperties();
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.mailbox.store.mail.model.MailboxMessage#getBodyContent()
-     */
     @Override
     public InputStream getBodyContent() throws IOException {
         return new ChunkInputStream(conf, MESSAGES_TABLE, MESSAGE_DATA_BODY_CF, messageRowKey(this));
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.mailbox.store.mail.model.MailboxMessage#getHeaderContent()
-     */
     @Override
     public InputStream getHeaderContent() throws IOException {
         return new ChunkInputStream(conf, MESSAGES_TABLE, MESSAGE_DATA_HEADERS_CF, messageRowKey(this));
     }
 
     @Override
+    public InputStream getFullContent() throws IOException {
+        return new SequenceInputStream(getHeaderContent(), getBodyContent());
+    }
+
+    @Override
     public int hashCode() {
         final int PRIME = 31;
         int result = 1;
@@ -196,19 +183,11 @@ public class HBaseMailboxMessage extends
         return true;
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.mailbox.store.mail.model.MailboxMessage#getModSeq()
-     */
     @Override
     public long getModSeq() {
         return modSeq;
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.mailbox.store.mail.model.MailboxMessage#setModSeq(long)
-     */
     @Override
     public void setModSeq(long modSeq) {
         this.modSeq = modSeq;
@@ -234,6 +213,11 @@ public class HBaseMailboxMessage extends
         return subType;
     }
 
+    @Override
+    public long getBodyOctets() {
+        return getFullContentOctets() - bodyStartOctet;
+    }
+
     /**
      * Gets a read-only list of meta-data properties.
      * For properties with multiple values, this list will contain
@@ -259,87 +243,56 @@ public class HBaseMailboxMessage extends
         this.textualLineCount = textualLineCount;
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.mailbox.store.mail.model.Document#getFullContentOctets()
-     */
     @Override
     public long getFullContentOctets() {
         return contentOctets;
     }
 
     @Override
-    protected int getBodyStartOctet() {
-        return bodyStartOctet;
+    public MessageId getMessageId() {
+        return new DefaultMessageId(getMailboxId(), getUid());
     }
 
-    /**
-     * @see MailboxMessage#getInternalDate()
-     */
     @Override
     public Date getInternalDate() {
         return internalDate;
     }
 
-    /**
-     * @see MailboxMessage#getMailboxId()
-     */
     @Override
     public HBaseId getMailboxId() {
         return mailboxId;
     }
 
-    /**
-     * @see MailboxMessage#getUid()
-     */
     @Override
     public long getUid() {
         return uid;
     }
 
-    /**
-     * @see MailboxMessage#isAnswered()
-     */
     @Override
     public boolean isAnswered() {
         return answered;
     }
 
-    /**
-     * @see MailboxMessage#isDeleted()
-     */
     @Override
     public boolean isDeleted() {
         return deleted;
     }
 
-    /**
-     * @see MailboxMessage#isDraft()
-     */
     @Override
     public boolean isDraft() {
         return draft;
     }
 
-    /**
-     * @see MailboxMessage#isFlagged()
-     */
     @Override
     public boolean isFlagged() {
         return flagged;
     }
 
-    /**
-     * @see MailboxMessage#isRecent()
-     */
     @Override
     public boolean isRecent() {
         return recent;
     }
 
-    /**
-     * @see MailboxMessage#isSeen()
-     */
     @Override
     public boolean isSeen() {
         return seen;
@@ -350,9 +303,6 @@ public class HBaseMailboxMessage extends
         this.uid = uid;
     }
 
-    /**
-     * @see MailboxMessage#setFlags(javax.mail.Flags)
-     */
     @Override
     public final void setFlags(Flags flags) {
         answered = flags.contains(Flags.Flag.ANSWERED);
@@ -366,12 +316,14 @@ public class HBaseMailboxMessage extends
         userFlags.addAll(Arrays.asList(userflags));
     }
 
+    @Override
+    public Flags createFlags() {
+        return FlagsBuilder.createFlags(this, createUserFlags());
+    }
+
     /**
      * This implementation supports user flags
-     *
-     *
      */
-    @Override
     public String[] createUserFlags() {
         String[] flags = new String[userFlags.size()];
         for (int i = 0; i < userFlags.size(); i++) {
@@ -396,4 +348,9 @@ public class HBaseMailboxMessage extends
                 + " )";
         return retValue;
     }
+
+    @Override
+    public int compareTo(MailboxMessage<HBaseId> other) {
+        return MESSAGE_UID_COMPARATOR.compare(this, other);
+    }
 }

Modified: james/project/trunk/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/model/JCRMailboxMessage.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/model/JCRMailboxMessage.java?rev=1724227&r1=1724226&r2=1724227&view=diff
==============================================================================
--- james/project/trunk/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/model/JCRMailboxMessage.java (original)
+++ james/project/trunk/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/model/JCRMailboxMessage.java Tue Jan 12 13:18:56 2016
@@ -41,18 +41,19 @@ import org.apache.james.mailbox.exceptio
 import org.apache.james.mailbox.jcr.JCRId;
 import org.apache.james.mailbox.jcr.JCRImapConstants;
 import org.apache.james.mailbox.jcr.Persistent;
-import org.apache.james.mailbox.store.mail.model.AbstractMailboxMessage;
+import org.apache.james.mailbox.store.mail.model.DefaultMessageId;
+import org.apache.james.mailbox.store.mail.model.FlagsBuilder;
 import org.apache.james.mailbox.store.mail.model.MailboxMessage;
+import org.apache.james.mailbox.store.mail.model.MessageId;
 import org.apache.james.mailbox.store.mail.model.Property;
+import org.apache.james.mailbox.store.mail.model.impl.MessageUidComparator;
 import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
 import org.slf4j.Logger;
 
-/**
- * JCR implementation of {@link MailboxMessage}
- *
- */
-public class JCRMailboxMessage extends AbstractMailboxMessage<JCRId> implements JCRImapConstants, Persistent{
+public class JCRMailboxMessage implements MailboxMessage<JCRId>, JCRImapConstants, Persistent {
 
+    private static final MessageUidComparator MESSAGE_UID_COMPARATOR = new MessageUidComparator();
+    
     private Node node;
     private final Logger logger;
     private SharedInputStream content;
@@ -125,12 +126,8 @@ public class JCRMailboxMessage extends A
         
     }
 
-
     /**
      * Create a copy of the given message
-     * 
-     * @param message
-     * @throws IOException 
      */
     public JCRMailboxMessage(JCRId mailboxUUID, long uid, long modSeq, JCRMailboxMessage message, Logger logger) throws MailboxException {
         this.mailboxUUID = mailboxUUID;
@@ -158,11 +155,8 @@ public class JCRMailboxMessage extends A
             this.properties.add(new JCRProperty(property,  logger));
         }
     }
-    
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.mailbox.store.mail.model.Document#getFullContentOctets()
-     */
+
+    @Override
     public long getFullContentOctets() {
         if (isPersistent()) {
             try {
@@ -176,10 +170,7 @@ public class JCRMailboxMessage extends A
         return size;
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.mailbox.store.mail.model.Document#getMediaType()
-     */
+    @Override
     public String getMediaType() {
         if (isPersistent()) {
             try {
@@ -192,10 +183,7 @@ public class JCRMailboxMessage extends A
         return mediaType;
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.mailbox.store.mail.model.Document#getProperties()
-     */
+    @Override
     public List<Property> getProperties() {
         if (isPersistent()) {
             try {
@@ -212,10 +200,7 @@ public class JCRMailboxMessage extends A
         return new ArrayList<Property>(properties);
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.mailbox.store.mail.model.Document#getSubType()
-     */
+    @Override
     public String getSubType() {
         if (isPersistent()) {
             try {
@@ -228,10 +213,12 @@ public class JCRMailboxMessage extends A
         return subType;
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.mailbox.store.mail.model.Document#getTextualLineCount()
-     */
+    @Override
+    public long getBodyOctets() {
+        return getFullContentOctets() - getBodyStartOctet();
+    }
+
+    @Override
     public Long getTextualLineCount() {
         if (isPersistent()) {
             try {
@@ -247,18 +234,12 @@ public class JCRMailboxMessage extends A
         return textualLineCount;
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.mailbox.jcr.Persistent#getNode()
-     */
+    @Override
     public Node getNode() {
         return node;
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.mailbox.jcr.Persistent#isPersistent()
-     */
+    @Override
     public boolean isPersistent() {
         return node != null;
     }
@@ -273,11 +254,8 @@ public class JCRMailboxMessage extends A
         }
         return null;
     }
-    
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.mailbox.jcr.Persistent#merge(javax.jcr.Node)
-     */
+
+    @Override
     public void merge(Node node) throws RepositoryException, IOException {
 
         // update the flags 
@@ -343,13 +321,7 @@ public class JCRMailboxMessage extends A
 
     }
     
-    @Override
-    protected String[] createUserFlags() {
-        return userFlags;
-    }
-
-    @Override
-    protected int getBodyStartOctet() {
+    private int getBodyStartOctet() {
         if (isPersistent()) {
             try {
                 return (int)node.getProperty(BODY_START_OCTET_PROPERTY).getLong();
@@ -399,14 +371,12 @@ public class JCRMailboxMessage extends A
     }
 
 
+    @Override
+    public MessageId getMessageId() {
+        return new DefaultMessageId(getMailboxId(), getUid());
+    }
 
-    /*
-     * (non-Javadoc)
-     * 
-     * @see
-     * org.apache.james.mailbox.store.mail.model.MailboxMembership#getInternalDate
-     * ()
-     */
+    @Override
     public Date getInternalDate() {
         if (isPersistent()) {
             try {
@@ -423,12 +393,7 @@ public class JCRMailboxMessage extends A
         return internalDate;
     }
 
-    /*
-     * (non-Javadoc)
-     * 
-     * @see
-     * org.apache.james.mailbox.store.mail.model.MailboxMembership#getMailboxId()
-     */
+    @Override
     public JCRId getMailboxId() {
         if (isPersistent()) {
             try {
@@ -442,11 +407,7 @@ public class JCRMailboxMessage extends A
     }
 
 
-    /*
-     * (non-Javadoc)
-     * 
-     * @see org.apache.james.mailbox.store.mail.model.MailboxMembership#getUid()
-     */
+    @Override
     public long getUid() {
         if (isPersistent()) {
             try {
@@ -460,12 +421,7 @@ public class JCRMailboxMessage extends A
         return uid;
     }
 
-    /*
-     * (non-Javadoc)
-     * 
-     * @see
-     * org.apache.james.mailbox.store.mail.model.MailboxMembership#isAnswered()
-     */
+    @Override
     public boolean isAnswered() {
         if (isPersistent()) {
             try {
@@ -482,11 +438,7 @@ public class JCRMailboxMessage extends A
         return answered;
     }
 
-    /*
-     * (non-Javadoc)
-     * 
-     * @see org.apache.james.mailbox.store.mail.model.MailboxMembership#isDeleted()
-     */
+    @Override
     public boolean isDeleted() {
         if (isPersistent()) {
             try {
@@ -503,11 +455,7 @@ public class JCRMailboxMessage extends A
         return deleted;
     }
 
-    /*
-     * (non-Javadoc)
-     * 
-     * @see org.apache.james.mailbox.store.mail.model.MailboxMembership#isDraft()
-     */
+    @Override
     public boolean isDraft() {
         if (isPersistent()) {
             try {
@@ -522,11 +470,7 @@ public class JCRMailboxMessage extends A
         return draft;
     }
 
-    /*
-     * (non-Javadoc)
-     * 
-     * @see org.apache.james.mailbox.store.mail.model.MailboxMembership#isFlagged()
-     */
+    @Override
     public boolean isFlagged() {
         if (isPersistent()) {
             try {
@@ -542,11 +486,7 @@ public class JCRMailboxMessage extends A
         return flagged;
     }
 
-    /*
-     * (non-Javadoc)
-     * 
-     * @see org.apache.james.mailbox.store.mail.model.MailboxMembership#isRecent()
-     */
+    @Override
     public boolean isRecent() {
         if (isPersistent()) {
             try {
@@ -561,11 +501,7 @@ public class JCRMailboxMessage extends A
         return recent;
     }
 
-    /*
-     * (non-Javadoc)
-     * 
-     * @see org.apache.james.mailbox.store.mail.model.MailboxMembership#isSeen()
-     */
+    @Override
     public boolean isSeen() {
         if (isPersistent()) {
             try {
@@ -579,13 +515,7 @@ public class JCRMailboxMessage extends A
         return seen;
     }
 
-    /*
-     * (non-Javadoc)
-     * 
-     * @see
-     * org.apache.james.mailbox.store.mail.model.MailboxMembership#setFlags(javax
-     * .mail.Flags)
-     */
+    @Override
     public void setFlags(Flags flags) {
         if (isPersistent()) {
             try {
@@ -616,12 +546,11 @@ public class JCRMailboxMessage extends A
         }
     }
 
-    /*
-     * (non-Javadoc)
-     * 
-     * @see
-     * org.apache.james.mailbox.store.mail.model.MailboxMembership#unsetRecent()
-     */
+    @Override
+    public Flags createFlags() {
+        return FlagsBuilder.createFlags(this, userFlags);
+    }
+
     public void unsetRecent() {
         if (isPersistent()) {
             try {
@@ -636,7 +565,6 @@ public class JCRMailboxMessage extends A
     }
 
 
-
     public String getId() {
         if (isPersistent()) {
             try {
@@ -692,20 +620,14 @@ public class JCRMailboxMessage extends A
         return content.newStream(0, -1);
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.mailbox.store.mail.model.MailboxMessage#getBodyContent()
-     */
+    @Override
     public InputStream getBodyContent() throws IOException {
         InputStream body = getFullContent();
         IOUtils.skipFully(body,  getBodyStartOctet());
         return body;
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.mailbox.store.mail.model.MailboxMessage#getModSeq()
-     */
+    @Override
     public long getModSeq() {
         if (isPersistent()) {
             try {
@@ -719,10 +641,7 @@ public class JCRMailboxMessage extends A
         return modSeq;
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.mailbox.store.mail.model.MailboxMessage#setModSeq(long)
-     */
+    @Override
     public void setModSeq(long modSeq) {
         if (isPersistent()) {
             try {
@@ -735,10 +654,7 @@ public class JCRMailboxMessage extends A
         }  
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.mailbox.store.mail.model.MailboxMessage#setUid(long)
-     */
+    @Override
     public void setUid(long uid) {
         if (isPersistent()) {
             try {
@@ -751,10 +667,7 @@ public class JCRMailboxMessage extends A
         }          
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.mailbox.store.mail.model.MailboxMessage#getHeaderContent()
-     */
+    @Override
     public InputStream getHeaderContent() throws IOException {
         long limit = getBodyStartOctet();
         if (limit < 0) {
@@ -762,4 +675,9 @@ public class JCRMailboxMessage extends A
         }
         return new BoundedInputStream(getFullContent(), limit);
     }
+
+    @Override
+    public int compareTo(MailboxMessage<JCRId> other) {
+        return MESSAGE_UID_COMPARATOR.compare(this, other);
+    }
 }

Modified: james/project/trunk/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/AbstractJPAMailboxMessage.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/AbstractJPAMailboxMessage.java?rev=1724227&r1=1724226&r2=1724227&view=diff
==============================================================================
--- james/project/trunk/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/AbstractJPAMailboxMessage.java (original)
+++ james/project/trunk/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/AbstractJPAMailboxMessage.java Tue Jan 12 13:18:56 2016
@@ -18,6 +18,9 @@
  ****************************************************************/
 package org.apache.james.mailbox.jpa.mail.model.openjpa;
 
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.SequenceInputStream;
 import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.Date;
@@ -42,16 +45,20 @@ import org.apache.james.mailbox.jpa.JPAI
 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.AbstractMailboxMessage;
+import org.apache.james.mailbox.store.mail.model.DelegatingMailboxMessage;
+import org.apache.james.mailbox.store.mail.model.DefaultMessageId;
+import org.apache.james.mailbox.store.mail.model.FlagsBuilder;
 import org.apache.james.mailbox.store.mail.model.MailboxMessage;
+import org.apache.james.mailbox.store.mail.model.MessageId;
 import org.apache.james.mailbox.store.mail.model.Property;
+import org.apache.james.mailbox.store.mail.model.impl.MessageUidComparator;
 import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
 import org.apache.openjpa.persistence.jdbc.ElementJoinColumn;
 import org.apache.openjpa.persistence.jdbc.ElementJoinColumns;
 import org.apache.openjpa.persistence.jdbc.Index;
 
 /**
- * Abstract base class for JPA based implementations of {@link AbstractMailboxMessage}
+ * Abstract base class for JPA based implementations of {@link DelegatingMailboxMessage}
  */
 @IdClass(AbstractJPAMailboxMessage.MailboxIdUidKey.class)
 @NamedQueries({
@@ -99,10 +106,9 @@ import org.apache.openjpa.persistence.jd
             query="DELETE FROM MailboxMessage message")
 })
 @MappedSuperclass
-public abstract class AbstractJPAMailboxMessage extends AbstractMailboxMessage<JPAId> {
-
-
+public abstract class AbstractJPAMailboxMessage implements MailboxMessage<JPAId> {
 
+    private static final MessageUidComparator MESSAGE_UID_COMPARATOR = new MessageUidComparator();
     private static final String TOSTRING_SEPARATOR = " ";
 
     /** Identifies composite key */
@@ -244,11 +250,7 @@ public abstract class AbstractJPAMailbox
     @ElementJoinColumn(name="MAIL_UID", referencedColumnName="MAIL_UID")})
     private List<JPAUserFlag> userFlags;
     
-    @Deprecated
-    public AbstractJPAMailboxMessage() {}
-
     public AbstractJPAMailboxMessage(JPAMailbox mailbox, Date internalDate, Flags flags, final long contentOctets, final int bodyStartOctet, final PropertyBuilder propertyBuilder) {
-        super();
         this.mailbox = mailbox;
         this.internalDate = internalDate;
         userFlags = new ArrayList<JPAUserFlag>();
@@ -275,7 +277,6 @@ public abstract class AbstractJPAMailbox
      * @param uid new UID
      * @param modSeq new modSeq
      * @param original message to be copied, not null
-     * @throws IOException 
      */
     public AbstractJPAMailboxMessage(JPAMailbox mailbox, long uid, long modSeq, MailboxMessage<?> original) throws MailboxException {
         super();
@@ -394,7 +395,6 @@ public abstract class AbstractJPAMailbox
         return contentOctets;
     }
 
-    @Override
     protected int getBodyStartOctet() {
         return bodyStartOctet;
     }
@@ -519,12 +519,11 @@ public abstract class AbstractJPAMailbox
         return mailbox;
     }
 
-    /**
-     * This implementation supports user flags
-     * 
-     * 
-     */
     @Override
+    public Flags createFlags() {
+        return FlagsBuilder.createFlags(this, createUserFlags());
+    }
+
     protected String[] createUserFlags() {
         String[] flags = new String[userFlags.size()];
         for (int i = 0; i < userFlags.size(); i++) {
@@ -540,6 +539,26 @@ public abstract class AbstractJPAMailbox
         this.mailbox = mailbox;
     }
 
+    @Override
+    public InputStream getFullContent() throws IOException {
+        return new SequenceInputStream(getHeaderContent(), getBodyContent());
+    }
+
+    @Override
+    public long getBodyOctets() {
+        return getFullContentOctets() - getBodyStartOctet();
+    }
+
+    @Override
+    public MessageId getMessageId() {
+        return new DefaultMessageId(getMailboxId(), uid);
+    }
+
+    @Override
+    public int compareTo(MailboxMessage<JPAId> other) {
+        return MESSAGE_UID_COMPARATOR.compare(this, other);
+    }
+
     public String toString() {
         final String retValue = 
             "message("

Modified: james/project/trunk/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/JPAEncryptedMailboxMessage.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/JPAEncryptedMailboxMessage.java?rev=1724227&r1=1724226&r2=1724227&view=diff
==============================================================================
--- james/project/trunk/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/JPAEncryptedMailboxMessage.java (original)
+++ james/project/trunk/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/JPAEncryptedMailboxMessage.java Tue Jan 12 13:18:56 2016
@@ -61,9 +61,6 @@ public class JPAEncryptedMailboxMessage
         @Factory("EncryptDecryptHelper.getDecrypted")
         @Lob private byte[] header;
         
-        @Deprecated
-        public JPAEncryptedMailboxMessage() {}
-
         public JPAEncryptedMailboxMessage(JPAMailbox mailbox, Date internalDate, int size, Flags flags, SharedInputStream content, int bodyStartOctet, final PropertyBuilder propertyBuilder) throws MailboxException {
             super(mailbox, internalDate, flags, size ,bodyStartOctet, propertyBuilder);
             try {
@@ -81,9 +78,6 @@ public class JPAEncryptedMailboxMessage
 
         /**
          * Create a copy of the given message
-         * 
-         * @param message
-         * @throws MailboxException 
          */
         public JPAEncryptedMailboxMessage(JPAMailbox mailbox, long uid, long modSeq, MailboxMessage<?> message) throws MailboxException{
             super(mailbox, uid, modSeq, message);
@@ -96,16 +90,12 @@ public class JPAEncryptedMailboxMessage
         }
 
 
-        /**
-         * @see MailboxMessage#getBodyContent()
-         */
+        @Override
         public InputStream getBodyContent() throws IOException {
             return new ByteArrayInputStream(body);
         }
 
-        /**
-         * @see MailboxMessage#getHeaderContent()
-         */
+        @Override
         public InputStream getHeaderContent() throws IOException {
             return new ByteArrayInputStream(header);
         }

Modified: james/project/trunk/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/JPAMailboxMessage.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/JPAMailboxMessage.java?rev=1724227&r1=1724226&r2=1724227&view=diff
==============================================================================
--- james/project/trunk/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/JPAMailboxMessage.java (original)
+++ james/project/trunk/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/JPAMailboxMessage.java Tue Jan 12 13:18:56 2016
@@ -55,9 +55,6 @@ public class JPAMailboxMessage extends A
     @Column(name = "HEADER_BYTES", length = 10485760, nullable = false)
     @Lob private byte[] header;
     
-    @Deprecated
-    public JPAMailboxMessage() {}
-
     public JPAMailboxMessage(JPAMailbox mailbox, Date internalDate, int size, Flags flags, SharedInputStream content, int bodyStartOctet, final PropertyBuilder propertyBuilder) throws MailboxException {
         super(mailbox, internalDate, flags, size ,bodyStartOctet, propertyBuilder);
         try {
@@ -75,9 +72,6 @@ public class JPAMailboxMessage extends A
 
     /**
      * Create a copy of the given message
-     * 
-     * @param message
-     * @throws MailboxException 
      */
     public JPAMailboxMessage(JPAMailbox mailbox, long uid, long modSeq, MailboxMessage<?> message) throws MailboxException{
         super(mailbox, uid, modSeq, message);
@@ -89,17 +83,12 @@ public class JPAMailboxMessage extends A
         }
     }
 
-
-    /**
-     * @see MailboxMessage#getBodyContent()
-     */
+    @Override
     public InputStream getBodyContent() throws IOException {
         return new ByteArrayInputStream(body);
     }
 
-    /**
-     * @see MailboxMessage#getHeaderContent()
-     */
+    @Override
     public InputStream getHeaderContent() throws IOException {
         return new ByteArrayInputStream(header);
     }

Modified: james/project/trunk/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/JPAStreamingMailboxMessage.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/JPAStreamingMailboxMessage.java?rev=1724227&r1=1724226&r2=1724227&view=diff
==============================================================================
--- james/project/trunk/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/JPAStreamingMailboxMessage.java (original)
+++ james/project/trunk/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/JPAStreamingMailboxMessage.java Tue Jan 12 13:18:56 2016
@@ -61,9 +61,6 @@ public class JPAStreamingMailboxMessage
 
     private SharedInputStream content;
 
-    @Deprecated
-    public JPAStreamingMailboxMessage() {}
-
     public JPAStreamingMailboxMessage(JPAMailbox mailbox, Date internalDate, int size, Flags flags, SharedInputStream content, int bodyStartOctet, final PropertyBuilder propertyBuilder) throws MailboxException {
         super(mailbox, internalDate, flags, size ,bodyStartOctet, propertyBuilder);
         this.content = content;
@@ -79,9 +76,6 @@ public class JPAStreamingMailboxMessage
 
     /**
      * Create a copy of the given message
-     * 
-     * @param message
-     * @throws IOException 
      */
     public JPAStreamingMailboxMessage(JPAMailbox mailbox, long uid, long modSeq, MailboxMessage<?> message) throws MailboxException {
         super(mailbox, uid, modSeq, message);
@@ -94,17 +88,12 @@ public class JPAStreamingMailboxMessage
         }
     }
 
-    
-    /**
-     * @see MailboxMessage#getBodyContent()
-     */
+    @Override
     public InputStream getBodyContent() throws IOException {
         return content.newStream(getBodyStartOctet(), -1);
     }
 
-    /**
-     * @see MailboxMessage#getHeaderContent()
-     */
+    @Override
     public InputStream getHeaderContent() throws IOException {
         int headerEnd = getBodyStartOctet() -2;
         if (headerEnd < 0) {

Modified: james/project/trunk/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/model/MaildirMailboxMessage.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/model/MaildirMailboxMessage.java?rev=1724227&r1=1724226&r2=1724227&view=diff
==============================================================================
--- james/project/trunk/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/model/MaildirMailboxMessage.java (original)
+++ james/project/trunk/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/model/MaildirMailboxMessage.java Tue Jan 12 13:18:56 2016
@@ -19,42 +19,19 @@
 package org.apache.james.mailbox.maildir.mail.model;
 
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
-import java.io.InputStream;
-import java.io.PushbackInputStream;
-import java.util.Date;
-import java.util.List;
 
 import javax.mail.Flags;
-import javax.mail.util.SharedFileInputStream;
 
-import org.apache.commons.io.IOUtils;
 import org.apache.james.mailbox.maildir.MaildirFolder;
 import org.apache.james.mailbox.maildir.MaildirId;
 import org.apache.james.mailbox.maildir.MaildirMessageName;
-import org.apache.james.mailbox.store.mail.model.AbstractMailboxMessage;
+import org.apache.james.mailbox.store.mail.model.DelegatingMailboxMessage;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
-import org.apache.james.mailbox.store.mail.model.MailboxMessage;
-import org.apache.james.mailbox.store.mail.model.Property;
-import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
-import org.apache.james.mailbox.store.streaming.CountingInputStream;
-import org.apache.james.mailbox.store.streaming.LimitingFileInputStream;
-import org.apache.james.mime4j.MimeException;
-import org.apache.james.mime4j.message.DefaultBodyDescriptorBuilder;
-import org.apache.james.mime4j.message.MaximalBodyDescriptor;
-import org.apache.james.mime4j.stream.EntityState;
-import org.apache.james.mime4j.stream.MimeConfig;
-import org.apache.james.mime4j.stream.MimeTokenStream;
-import org.apache.james.mime4j.stream.RecursionMode;
-
-public class MaildirMailboxMessage extends AbstractMailboxMessage<MaildirId> {
-
-	private MaildirMessageName messageName;
-    private int bodyStartOctet;
-    private final PropertyBuilder propertyBuilder = new PropertyBuilder();
-    private boolean parsed;
+
+public class MaildirMailboxMessage extends DelegatingMailboxMessage<MaildirId> {
+
     private boolean answered;
     private boolean deleted;
     private boolean draft;
@@ -67,6 +44,8 @@ public class MaildirMailboxMessage exten
     private long modSeq;
     
     public MaildirMailboxMessage(Mailbox<MaildirId> mailbox, long uid, MaildirMessageName messageName) throws IOException {
+        super(new MaildirMessage(messageName));
+
         this.mailbox = mailbox;
         setUid(uid);
         setModSeq(messageName.getFile().lastModified());
@@ -86,7 +65,6 @@ public class MaildirMailboxMessage exten
             }
         }
         setFlags(flags);
-        this.messageName = messageName;
     }
 
     
@@ -104,11 +82,8 @@ public class MaildirMailboxMessage exten
     public void setUid(long uid) {
         this.uid = uid;
     }
-    /**
-     * @see
-     * MailboxMessage#setFlags(
-     * javax.mail.Flags)
-     */
+
+
     @Override
     public void setFlags(Flags flags) {
         if (flags != null) {
@@ -121,54 +96,31 @@ public class MaildirMailboxMessage exten
         }
     }
     
-    /**
-     * @see
-     * MailboxMessage#isAnswered()
-     */
     @Override
     public boolean isAnswered() {
         return answered;
     }
 
-    /**
-     * @see
-     * MailboxMessage#isDeleted()
-     */
     @Override
     public boolean isDeleted() {
         return deleted;
     }
 
-    /**
-     * @see
-     * MailboxMessage#isDraft()
-     */
     @Override
     public boolean isDraft() {
         return draft;
     }
 
-    /**
-     * @see
-     * MailboxMessage#isFlagged()
-     */
     @Override
     public boolean isFlagged() {
         return flagged;
     }
 
-    /**
-     * @see
-     * MailboxMessage#isRecent()
-     */
     @Override
     public boolean isRecent() {
         return recent;
     }
 
-    /**
-     * @see MailboxMessage#isSeen()
-     */
     @Override
     public boolean isSeen() {
         return seen;
@@ -182,8 +134,17 @@ public class MaildirMailboxMessage exten
     public boolean isNew() {
         return newMessage;
     }
-    
-    
+
+    @Override
+    public long getModSeq() {
+        return modSeq;
+    }
+
+    @Override
+    public void setModSeq(long modSeq) {
+        this.modSeq = modSeq;
+    }
+
     @Override
     public String toString() {
         StringBuilder theString = new StringBuilder("MaildirMailboxMessage ");
@@ -205,259 +166,4 @@ public class MaildirMailboxMessage exten
         return theString.toString();
     }
 
-    /**
-     * @see MailboxMessage#getModSeq()
-     */
-    @Override
-    public long getModSeq() {
-        return modSeq;
-    }
-
-    /**
-     * @see MailboxMessage#setModSeq(long)
-     */
-    @Override
-    public void setModSeq(long modSeq) {
-        this.modSeq = modSeq;
-    }
-    /**
-     * Parse message if needed
-     */
-    private synchronized void parseMessage() {
-        if (parsed)
-            return;
-        SharedFileInputStream tmpMsgIn = null;
-        try {
-            tmpMsgIn = new SharedFileInputStream(messageName.getFile());
-
-            bodyStartOctet = bodyStartOctet(tmpMsgIn);
-
-            // Disable line length... This should be handled by the smtp server
-            // component and not the parser itself
-            // https://issues.apache.org/jira/browse/IMAP-122
-            MimeConfig config = MimeConfig.custom().setMaxLineLen(-1).build();
-            final MimeTokenStream parser = new MimeTokenStream(config, new DefaultBodyDescriptorBuilder());
-            parser.setRecursionMode(RecursionMode.M_NO_RECURSE);
-            parser.parse(tmpMsgIn.newStream(0, -1));
-
-            EntityState next = parser.next();
-            while (next != EntityState.T_BODY && next != EntityState.T_END_OF_STREAM && next != EntityState.T_START_MULTIPART) {
-                next = parser.next();
-            }
-            final MaximalBodyDescriptor descriptor = (MaximalBodyDescriptor) parser.getBodyDescriptor();
-            final String mediaType;
-            final String mediaTypeFromHeader = descriptor.getMediaType();
-            final String subType;
-            if (mediaTypeFromHeader == null) {
-                mediaType = "text";
-                subType = "plain";
-            } else {
-                mediaType = mediaTypeFromHeader;
-                subType = descriptor.getSubType();
-            }
-            propertyBuilder.setMediaType(mediaType);
-            propertyBuilder.setSubType(subType);
-            propertyBuilder.setContentID(descriptor.getContentId());
-            propertyBuilder.setContentDescription(descriptor.getContentDescription());
-            propertyBuilder.setContentLocation(descriptor.getContentLocation());
-            propertyBuilder.setContentMD5(descriptor.getContentMD5Raw());
-            propertyBuilder.setContentTransferEncoding(descriptor.getTransferEncoding());
-            propertyBuilder.setContentLanguage(descriptor.getContentLanguage());
-            propertyBuilder.setContentDispositionType(descriptor.getContentDispositionType());
-            propertyBuilder.setContentDispositionParameters(descriptor.getContentDispositionParameters());
-            propertyBuilder.setContentTypeParameters(descriptor.getContentTypeParameters());
-            // Add missing types
-            final String codeset = descriptor.getCharset();
-            if (codeset == null) {
-                if ("TEXT".equalsIgnoreCase(mediaType)) {
-                    propertyBuilder.setCharset("us-ascii");
-                }
-            } else {
-                propertyBuilder.setCharset(codeset);
-            }
-
-            final String boundary = descriptor.getBoundary();
-            if (boundary != null) {
-                propertyBuilder.setBoundary(boundary);
-            }
-            if ("text".equalsIgnoreCase(mediaType)) {
-                long lines = -1;
-                final CountingInputStream bodyStream = new CountingInputStream(parser.getInputStream());
-                try {
-                    bodyStream.readAll();
-                    lines = bodyStream.getLineCount();
-                } finally {
-                    IOUtils.closeQuietly(bodyStream);
-                }
-
-                next = parser.next();
-                if (next == EntityState.T_EPILOGUE) {
-                    final CountingInputStream epilogueStream = new CountingInputStream(parser.getInputStream());
-                    try {
-                        epilogueStream.readAll();
-                        lines += epilogueStream.getLineCount();
-                    } finally {
-                        IOUtils.closeQuietly(epilogueStream);
-                    }
-                }
-                propertyBuilder.setTextualLineCount(lines);
-            }
-        } catch (IOException e) {
-            // has successfully been parsen when appending, shouldn't give any
-            // problems
-        } catch (MimeException e) {
-            // has successfully been parsen when appending, shouldn't give any
-            // problems
-        } finally {
-            if (tmpMsgIn != null) {
-                try {
-                    tmpMsgIn.close();
-                } catch (IOException e) {
-                    // ignore on close
-                }
-            }
-            parsed = true;
-        }
-    }
-
-    /**
-     * Return the position in the given {@link InputStream} at which the Body of
-     * the MailboxMessage starts
-     * 
-     * @param msgIn
-     * @return bodyStartOctet
-     * @throws IOException
-     */
-    private int bodyStartOctet(InputStream msgIn) throws IOException {
-        // we need to pushback maximal 3 bytes
-        PushbackInputStream in = new PushbackInputStream(msgIn, 3);
-        int localBodyStartOctet = in.available();
-        int i = -1;
-        int count = 0;
-        while ((i = in.read()) != -1 && in.available() > 4) {
-            if (i == 0x0D) {
-                int a = in.read();
-                if (a == 0x0A) {
-                    int b = in.read();
-
-                    if (b == 0x0D) {
-                        int c = in.read();
-
-                        if (c == 0x0A) {
-                            localBodyStartOctet = count + 4;
-                            break;
-                        }
-                        in.unread(c);
-                    }
-                    in.unread(b);
-                }
-                in.unread(a);
-            }
-            count++;
-        }
-        return localBodyStartOctet;
-    }
-
-    /**
-     * @see MailboxMessage#getMediaType()
-     */
-    @Override
-    public String getMediaType() {
-        parseMessage();
-        return propertyBuilder.getMediaType();
-    }
-
-    /**
-     * @see MailboxMessage#getSubType()
-     */
-    @Override
-    public String getSubType() {
-        parseMessage();
-        return propertyBuilder.getSubType();
-    }
-
-    /**
-     * @see MailboxMessage#getFullContentOctets()
-     */
-    @Override
-    public long getFullContentOctets() {
-        Long size = messageName.getSize();
-        if (size != null) {
-            return size;
-        } else {
-            try {
-                return messageName.getFile().length();
-            } catch (FileNotFoundException e) {
-                return -1;
-            }
-        }
-    }
-
-    /**
-     * @see MailboxMessage#getTextualLineCount()
-     */
-    @Override
-    public Long getTextualLineCount() {
-        parseMessage();
-        return propertyBuilder.getTextualLineCount();
-    }
-
-    /**
-     * @see MailboxMessage#getProperties()
-     */
-    @Override
-    public List<Property> getProperties() {
-        parseMessage();
-        return propertyBuilder.toProperties();
-    }
-
-    /**
-     * @see MailboxMessage#getInternalDate()
-     */
-    @Override
-    public Date getInternalDate() {
-        return messageName.getInternalDate();
-    }
-
-    /**
-     * Return the full content of the message via a {@link FileInputStream}
-     */
-    @Override
-    public InputStream getFullContent() throws IOException {
-        return new FileInputStream(messageName.getFile());
-    }
-
-    /**
-     * @see MailboxMessage#getBodyContent()
-     */
-    @Override
-    public InputStream getBodyContent() throws IOException {
-        parseMessage();
-        FileInputStream body = new FileInputStream(messageName.getFile());
-        IOUtils.skipFully(body, bodyStartOctet);
-        return body;
-
-    }
-
-    /**
-     * @see AbstractMailboxMessage#getBodyStartOctet()
-     */
-    @Override
-    protected int getBodyStartOctet() {
-        parseMessage();
-        return bodyStartOctet;
-    }
-
-    @Override
-    public InputStream getHeaderContent() throws IOException {
-        parseMessage();
-        long limit = getBodyStartOctet();
-        if (limit < 0) {
-            limit = 0;
-        }
-        return new LimitingFileInputStream(messageName.getFile(), limit);
-
-    }
-
-
 }

Copied: james/project/trunk/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/model/MaildirMessage.java (from r1724226, james/project/trunk/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/model/MaildirMailboxMessage.java)
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/model/MaildirMessage.java?p2=james/project/trunk/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/model/MaildirMessage.java&p1=james/project/trunk/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/model/MaildirMailboxMessage.java&r1=1724226&r2=1724227&rev=1724227&view=diff
==============================================================================
--- james/project/trunk/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/model/MaildirMailboxMessage.java (original)
+++ james/project/trunk/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/model/MaildirMessage.java Tue Jan 12 13:18:56 2016
@@ -18,25 +18,10 @@
  ****************************************************************/
 package org.apache.james.mailbox.maildir.mail.model;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.PushbackInputStream;
-import java.util.Date;
-import java.util.List;
-
-import javax.mail.Flags;
-import javax.mail.util.SharedFileInputStream;
-
 import org.apache.commons.io.IOUtils;
-import org.apache.james.mailbox.maildir.MaildirFolder;
-import org.apache.james.mailbox.maildir.MaildirId;
 import org.apache.james.mailbox.maildir.MaildirMessageName;
-import org.apache.james.mailbox.store.mail.model.AbstractMailboxMessage;
-import org.apache.james.mailbox.store.mail.model.Mailbox;
-import org.apache.james.mailbox.store.mail.model.MailboxMessage;
+import org.apache.james.mailbox.store.mail.model.Message;
+import org.apache.james.mailbox.store.mail.model.MessageId;
 import org.apache.james.mailbox.store.mail.model.Property;
 import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
 import org.apache.james.mailbox.store.streaming.CountingInputStream;
@@ -49,178 +34,27 @@ import org.apache.james.mime4j.stream.Mi
 import org.apache.james.mime4j.stream.MimeTokenStream;
 import org.apache.james.mime4j.stream.RecursionMode;
 
-public class MaildirMailboxMessage extends AbstractMailboxMessage<MaildirId> {
+import javax.mail.util.SharedFileInputStream;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PushbackInputStream;
+import java.util.Date;
+import java.util.List;
 
-	private MaildirMessageName messageName;
+public class MaildirMessage implements Message {
+
+    private MaildirMessageName messageName;
     private int bodyStartOctet;
     private final PropertyBuilder propertyBuilder = new PropertyBuilder();
     private boolean parsed;
-    private boolean answered;
-    private boolean deleted;
-    private boolean draft;
-    private boolean flagged;
-    private boolean recent;
-    private boolean seen;
-    private Mailbox<MaildirId> mailbox;
-    private long uid;
-    protected boolean newMessage;
-    private long modSeq;
-    
-    public MaildirMailboxMessage(Mailbox<MaildirId> mailbox, long uid, MaildirMessageName messageName) throws IOException {
-        this.mailbox = mailbox;
-        setUid(uid);
-        setModSeq(messageName.getFile().lastModified());
-        Flags flags = messageName.getFlags();
-        
-        // Set the flags for the message and respect if its RECENT
-        // See MAILBOX-84
-        File file = messageName.getFile();
-        if (!file.exists()) {
-            throw new FileNotFoundException("Unable to read file " + file.getAbsolutePath() + " for the message");
-        } else {
-            // if the message resist in the new folder its RECENT
-            if (file.getParentFile().getName().equals(MaildirFolder.NEW)) {
-                if (flags == null)
-                    flags = new Flags();
-                flags.add(Flags.Flag.RECENT);
-            }
-        }
-        setFlags(flags);
-        this.messageName = messageName;
-    }
-
-    
-    @Override
-    public MaildirId getMailboxId() {
-        return mailbox.getMailboxId();
-    }
 
-    @Override
-    public long getUid() {
-        return uid;
-    }
-
-    @Override
-    public void setUid(long uid) {
-        this.uid = uid;
-    }
-    /**
-     * @see
-     * MailboxMessage#setFlags(
-     * javax.mail.Flags)
-     */
-    @Override
-    public void setFlags(Flags flags) {
-        if (flags != null) {
-            answered = flags.contains(Flags.Flag.ANSWERED);
-            deleted = flags.contains(Flags.Flag.DELETED);
-            draft = flags.contains(Flags.Flag.DRAFT);
-            flagged = flags.contains(Flags.Flag.FLAGGED);
-            recent = flags.contains(Flags.Flag.RECENT);
-            seen = flags.contains(Flags.Flag.SEEN);
-        }
-    }
-    
-    /**
-     * @see
-     * MailboxMessage#isAnswered()
-     */
-    @Override
-    public boolean isAnswered() {
-        return answered;
-    }
-
-    /**
-     * @see
-     * MailboxMessage#isDeleted()
-     */
-    @Override
-    public boolean isDeleted() {
-        return deleted;
-    }
-
-    /**
-     * @see
-     * MailboxMessage#isDraft()
-     */
-    @Override
-    public boolean isDraft() {
-        return draft;
-    }
-
-    /**
-     * @see
-     * MailboxMessage#isFlagged()
-     */
-    @Override
-    public boolean isFlagged() {
-        return flagged;
-    }
-
-    /**
-     * @see
-     * MailboxMessage#isRecent()
-     */
-    @Override
-    public boolean isRecent() {
-        return recent;
-    }
-
-    /**
-     * @see MailboxMessage#isSeen()
-     */
-    @Override
-    public boolean isSeen() {
-        return seen;
-    }
-
-    /**
-     * Indicates whether this MaildirMailboxMessage reflects a new message or one that already
-     * exists in the file system.
-     * @return true if it is new, false if it already exists
-     */
-    public boolean isNew() {
-        return newMessage;
-    }
-    
-    
-    @Override
-    public String toString() {
-        StringBuilder theString = new StringBuilder("MaildirMailboxMessage ");
-        theString.append(getUid());
-        theString.append(" {");
-        Flags flags = createFlags();
-        if (flags.contains(Flags.Flag.DRAFT))
-            theString.append(MaildirMessageName.FLAG_DRAFT);
-        if (flags.contains(Flags.Flag.FLAGGED))
-            theString.append(MaildirMessageName.FLAG_FLAGGED);
-        if (flags.contains(Flags.Flag.ANSWERED))
-            theString.append(MaildirMessageName.FLAG_ANSWERD);
-        if (flags.contains(Flags.Flag.SEEN))
-            theString.append(MaildirMessageName.FLAG_SEEN);
-        if (flags.contains(Flags.Flag.DELETED))
-            theString.append(MaildirMessageName.FLAG_DELETED);
-        theString.append("} ");
-        theString.append(getInternalDate());
-        return theString.toString();
-    }
-
-    /**
-     * @see MailboxMessage#getModSeq()
-     */
-    @Override
-    public long getModSeq() {
-        return modSeq;
+    public MaildirMessage(MaildirMessageName messageName) {
+        this.messageName = messageName;
     }
 
     /**
-     * @see MailboxMessage#setModSeq(long)
-     */
-    @Override
-    public void setModSeq(long modSeq) {
-        this.modSeq = modSeq;
-    }
-    /**
      * Parse message if needed
      */
     private synchronized void parseMessage() {
@@ -320,19 +154,16 @@ public class MaildirMailboxMessage exten
         }
     }
 
+
     /**
      * Return the position in the given {@link InputStream} at which the Body of
      * the MailboxMessage starts
-     * 
-     * @param msgIn
-     * @return bodyStartOctet
-     * @throws IOException
      */
     private int bodyStartOctet(InputStream msgIn) throws IOException {
         // we need to pushback maximal 3 bytes
         PushbackInputStream in = new PushbackInputStream(msgIn, 3);
         int localBodyStartOctet = in.available();
-        int i = -1;
+        int i;
         int count = 0;
         while ((i = in.read()) != -1 && in.available() > 4) {
             if (i == 0x0D) {
@@ -358,27 +189,23 @@ public class MaildirMailboxMessage exten
         return localBodyStartOctet;
     }
 
-    /**
-     * @see MailboxMessage#getMediaType()
-     */
     @Override
     public String getMediaType() {
         parseMessage();
         return propertyBuilder.getMediaType();
     }
 
-    /**
-     * @see MailboxMessage#getSubType()
-     */
     @Override
     public String getSubType() {
         parseMessage();
         return propertyBuilder.getSubType();
     }
 
-    /**
-     * @see MailboxMessage#getFullContentOctets()
-     */
+    @Override
+    public long getBodyOctets() {
+        return getFullContentOctets() - getBodyStartOctet();
+    }
+
     @Override
     public long getFullContentOctets() {
         Long size = messageName.getSize();
@@ -393,27 +220,23 @@ public class MaildirMailboxMessage exten
         }
     }
 
-    /**
-     * @see MailboxMessage#getTextualLineCount()
-     */
     @Override
     public Long getTextualLineCount() {
         parseMessage();
         return propertyBuilder.getTextualLineCount();
     }
 
-    /**
-     * @see MailboxMessage#getProperties()
-     */
     @Override
     public List<Property> getProperties() {
         parseMessage();
         return propertyBuilder.toProperties();
     }
 
-    /**
-     * @see MailboxMessage#getInternalDate()
-     */
+    @Override
+    public MessageId getMessageId() {
+        return null;
+    }
+
     @Override
     public Date getInternalDate() {
         return messageName.getInternalDate();
@@ -427,9 +250,6 @@ public class MaildirMailboxMessage exten
         return new FileInputStream(messageName.getFile());
     }
 
-    /**
-     * @see MailboxMessage#getBodyContent()
-     */
     @Override
     public InputStream getBodyContent() throws IOException {
         parseMessage();
@@ -439,11 +259,7 @@ public class MaildirMailboxMessage exten
 
     }
 
-    /**
-     * @see AbstractMailboxMessage#getBodyStartOctet()
-     */
-    @Override
-    protected int getBodyStartOctet() {
+    private int getBodyStartOctet() {
         parseMessage();
         return bodyStartOctet;
     }
@@ -456,8 +272,6 @@ public class MaildirMailboxMessage exten
             limit = 0;
         }
         return new LimitingFileInputStream(messageName.getFile(), limit);
-
     }
 
-
 }

Copied: james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/DelegatingMailboxMessage.java (from r1724226, james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/AbstractMailboxMessage.java)
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/DelegatingMailboxMessage.java?p2=james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/DelegatingMailboxMessage.java&p1=james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/AbstractMailboxMessage.java&r1=1724226&r2=1724227&rev=1724227&view=diff
==============================================================================
--- james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/AbstractMailboxMessage.java (original)
+++ james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/DelegatingMailboxMessage.java Tue Jan 12 13:18:56 2016
@@ -20,62 +20,33 @@ package org.apache.james.mailbox.store.m
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.SequenceInputStream;
+import java.util.Date;
+import java.util.List;
 
 import javax.mail.Flags;
 
+import org.apache.james.mailbox.store.mail.model.impl.MessageUidComparator;
 
+public abstract class DelegatingMailboxMessage<Id extends MailboxId> implements MailboxMessage<Id> {
 
-/**
- * Abstract base class for {@link MailboxMessage}
- *
- */
-public abstract class AbstractMailboxMessage<Id extends MailboxId> implements MailboxMessage<Id> {
+    private static final MessageUidComparator MESSAGE_UID_COMPARATOR = new MessageUidComparator();
     
+    private final Message message;
 
-    /**
-     * @see java.lang.Comparable#compareTo(java.lang.Object)
-     */
+    protected DelegatingMailboxMessage(Message message) {
+        this.message = message;
+    }
+
+    @Override
     public int compareTo(MailboxMessage<Id> other) {
-        return (int) (getUid() - other.getUid());
+        return MESSAGE_UID_COMPARATOR.compare(this, other);
     }
-    
-    
 
-    /**
-     * @see MailboxMessage#createFlags()
-     */
+    @Override
     public final Flags createFlags() {
-        final Flags flags = new Flags();
-
-        if (isAnswered()) {
-            flags.add(Flags.Flag.ANSWERED);
-        }
-        if (isDeleted()) {
-            flags.add(Flags.Flag.DELETED);
-        }
-        if (isDraft()) {
-            flags.add(Flags.Flag.DRAFT);
-        }
-        if (isFlagged()) {
-            flags.add(Flags.Flag.FLAGGED);
-        }
-        if (isRecent()) {
-            flags.add(Flags.Flag.RECENT);
-        }
-        if (isSeen()) {
-            flags.add(Flags.Flag.SEEN);
-        }
-        String[] userFlags = createUserFlags();
-        if (userFlags != null && userFlags.length > 0) {
-            for (int i = 0; i < userFlags.length; i++) {
-                flags.add(userFlags[i]);
-            }
-        }
-        return flags;
+        return FlagsBuilder.createFlags(this, createUserFlags());
     }
-    
-    
+
     /**
      * Return all stored user flags or null if none are stored. By default this return null as no user flags are stored
      * permanent. This method SHOULD get overridden, If the implementation supports to store user flags.
@@ -85,37 +56,55 @@ public abstract class AbstractMailboxMes
     protected String[] createUserFlags() {
         return null;
     }
-    
-    
-    /**
-     * The number of octets contained in the body of this part.
-     * 
-     * @return number of octets
-     */
+
+    @Override
     public long getBodyOctets() {
-        return getFullContentOctets() - getBodyStartOctet();
+        return message.getBodyOctets();
+    }
+
+    @Override
+    public long getFullContentOctets() {
+        return message.getFullContentOctets();
     }
-    
-    /**
-     * Return the start octet of the body
-     * 
-     * @return startOctet
-     */
-    protected abstract int getBodyStartOctet();
 
+    @Override
+    public Long getTextualLineCount() {
+        return message.getTextualLineCount();
+    }
 
+    @Override
+    public InputStream getHeaderContent() throws IOException {
+        return message.getHeaderContent();
+    }
 
-    
-    /**
-     * This implementation just concat {@link #getHeaderContent()} and {@link #getBodyContent()}.
-     * 
-     * Implementation should override this if they can provide a more performant solution
-     * 
-     * @return content
-     * @throws exception
-     */
+    @Override
     public InputStream getFullContent() throws IOException {
-        return new SequenceInputStream(getHeaderContent(), getBodyContent());
+        return message.getFullContent();
+    }
+
+    @Override
+    public List<Property> getProperties() {
+        return message.getProperties();
+    }
+
+    @Override
+    public Date getInternalDate() {
+        return message.getInternalDate();
+    }
+
+    @Override
+    public InputStream getBodyContent() throws IOException {
+        return message.getBodyContent();
+    }
+
+    @Override
+    public String getMediaType() {
+        return message.getMediaType();
+    }
+
+    @Override
+    public String getSubType() {
+        return message.getSubType();
     }
 
     @Override
@@ -123,4 +112,7 @@ public abstract class AbstractMailboxMes
         return new DefaultMessageId(getMailboxId(), getUid());
     }
 
+    public Message getMessage() {
+        return message;
+    }
 }

Copied: james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/FlagsBuilder.java (from r1724226, james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AbstractMailboxMessageTest.java)
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/FlagsBuilder.java?p2=james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/FlagsBuilder.java&p1=james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AbstractMailboxMessageTest.java&r1=1724226&r2=1724227&rev=1724227&view=diff
==============================================================================
--- james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AbstractMailboxMessageTest.java (original)
+++ james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/FlagsBuilder.java Tue Jan 12 13:18:56 2016
@@ -16,43 +16,40 @@
  * specific language governing permissions and limitations      *
  * under the License.                                           *
  ****************************************************************/
-
 package org.apache.james.mailbox.store.mail.model;
 
-import static org.junit.Assert.*;
+import javax.mail.Flags;
 
-import org.apache.james.mailbox.store.MessageBuilder;
-import org.apache.james.mailbox.store.TestId;
-import org.junit.Test;
-
-public class AbstractMailboxMessageTest {
-    
-    @Test
-    public void testShouldReturnPositiveWhenFirstGreaterThanSecond()
-            throws Exception {
-        MailboxMessage<TestId> one = buildMessage(100);
-        MailboxMessage<TestId> two = buildMessage(99);
-        assertTrue( one.compareTo(two) > 0);
-    }
+public class FlagsBuilder {
 
-    private MailboxMessage<TestId> buildMessage(int uid) throws Exception {
-        MessageBuilder builder = new MessageBuilder();
-        builder.uid = uid;
-        return builder.build();
-    }
+    public static Flags createFlags(MailboxMessage<?> mailboxMessage, String[] userFlags) {
+        final Flags flags = new Flags();
 
-    @Test
-    public void testShouldReturnNegativeWhenFirstLessThanSecond()
-            throws Exception {
-        MailboxMessage<TestId> one = buildMessage(98);
-        MailboxMessage<TestId> two = buildMessage(99);
-        assertTrue( one.compareTo(two) < 0);
+        if (mailboxMessage.isAnswered()) {
+            flags.add(Flags.Flag.ANSWERED);
+        }
+        if (mailboxMessage.isDeleted()) {
+            flags.add(Flags.Flag.DELETED);
+        }
+        if (mailboxMessage.isDraft()) {
+            flags.add(Flags.Flag.DRAFT);
+        }
+        if (mailboxMessage.isFlagged()) {
+            flags.add(Flags.Flag.FLAGGED);
+        }
+        if (mailboxMessage.isRecent()) {
+            flags.add(Flags.Flag.RECENT);
+        }
+        if (mailboxMessage.isSeen()) {
+            flags.add(Flags.Flag.SEEN);
+        }
+        if (userFlags != null && userFlags.length > 0) {
+            for (int i = 0; i < userFlags.length; i++) {
+                flags.add(userFlags[i]);
+            }
+        }
+        return flags;
     }
 
-    @Test
-    public void testShouldReturnZeroWhenFirstEqualsSecond() throws Exception {
-        MailboxMessage<TestId> one = buildMessage(90);
-        MailboxMessage<TestId> two = buildMessage(90);
-        assertEquals(0, one.compareTo(two));
-    }
+
 }

Added: james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/MessageUidComparator.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/MessageUidComparator.java?rev=1724227&view=auto
==============================================================================
--- james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/MessageUidComparator.java (added)
+++ james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/MessageUidComparator.java Tue Jan 12 13:18:56 2016
@@ -0,0 +1,31 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.mailbox.store.mail.model.impl;
+
+import org.apache.james.mailbox.store.mail.model.MailboxMessage;
+
+import java.util.Comparator;
+
+public class MessageUidComparator implements Comparator<MailboxMessage<?>> {
+
+    @Override
+    public int compare(MailboxMessage<?> m1, MailboxMessage<?> m2) {
+        return Long.valueOf(m1.getUid()).compareTo(m2.getUid());
+    }
+}

Modified: james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMailboxMessage.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMailboxMessage.java?rev=1724227&r1=1724226&r2=1724227&view=diff
==============================================================================
--- james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMailboxMessage.java (original)
+++ james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMailboxMessage.java Tue Jan 12 13:18:56 2016
@@ -20,9 +20,7 @@
 package org.apache.james.mailbox.store.mail.model.impl;
 
 import java.io.IOException;
-import java.io.InputStream;
 import java.util.Date;
-import java.util.List;
 
 import javax.mail.Flags;
 import javax.mail.internet.SharedInputStream;
@@ -30,15 +28,14 @@ import javax.mail.util.SharedByteArrayIn
 
 import org.apache.commons.io.IOUtils;
 import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.store.mail.model.AbstractMailboxMessage;
+import org.apache.james.mailbox.store.mail.model.DelegatingMailboxMessage;
 import org.apache.james.mailbox.store.mail.model.MailboxId;
 import org.apache.james.mailbox.store.mail.model.MailboxMessage;
-import org.apache.james.mailbox.store.mail.model.Property;
 
+import com.google.common.base.Objects;
 import com.google.common.primitives.Ints;
 
-
-public class SimpleMailboxMessage<Id extends MailboxId> extends AbstractMailboxMessage<Id> {
+public class SimpleMailboxMessage<Id extends MailboxId> extends DelegatingMailboxMessage<Id> {
 
     public static <Id extends MailboxId> SimpleMailboxMessage<Id> copy(Id mailboxId, MailboxMessage<Id> original) throws MailboxException {
         Date internalDate = original.getInternalDate();
@@ -60,7 +57,6 @@ public class SimpleMailboxMessage<Id ext
 
     private long uid;
     private final Id mailboxId;
-    private long size;
     private boolean answered;
     private boolean deleted;
     private boolean draft;
@@ -68,29 +64,21 @@ public class SimpleMailboxMessage<Id ext
     private boolean recent;
     private boolean seen;
     private String[] userFlags;
-    private Date internalDate;
-    private final String subType;
-    private List<Property> properties;
-    private final String mediaType;
-    private Long lineCount;
-    private int bodyStartOctet;
     private long modSeq;
-    private SharedInputStream content;
 
     public SimpleMailboxMessage(Date internalDate, long size, int bodyStartOctet,
                                 SharedInputStream content, Flags flags,
                                 PropertyBuilder propertyBuilder, final Id mailboxId) {
-        this.content = content;
+        super(new SimpleMessage(
+            content, size, internalDate, propertyBuilder.getSubType(),
+            propertyBuilder.getMediaType(),
+            bodyStartOctet,
+            propertyBuilder.getTextualLineCount(),
+            propertyBuilder.toProperties()
+            ));
 
-        this.size = size;
-        this.bodyStartOctet = bodyStartOctet;
         setFlags(flags);
-        lineCount = propertyBuilder.getTextualLineCount();
-        this.internalDate = internalDate;
         this.mailboxId = mailboxId;
-        this.properties = propertyBuilder.toProperties();
-        this.mediaType = propertyBuilder.getMediaType();
-        this.subType = propertyBuilder.getSubType();
         this.userFlags = flags.getUserFlags();
     }
 
@@ -99,10 +87,6 @@ public class SimpleMailboxMessage<Id ext
         return userFlags.clone();
     }
 
-    public Date getInternalDate() {
-        return internalDate;
-    }
-
     public Id getMailboxId() {
         return mailboxId;
     }
@@ -135,6 +119,18 @@ public class SimpleMailboxMessage<Id ext
         return seen;
     }
 
+    public long getModSeq() {
+        return modSeq;
+    }
+
+    public void setModSeq(long modSeq) {
+        this.modSeq = modSeq;
+    }
+
+    public void setUid(long uid) {
+        this.uid = uid;
+    }
+
     public synchronized void setFlags(Flags flags) {
         answered = flags.contains(Flags.Flag.ANSWERED);
         deleted = flags.contains(Flags.Flag.DELETED);
@@ -145,30 +141,6 @@ public class SimpleMailboxMessage<Id ext
         userFlags = flags.getUserFlags();
     }
 
-    public InputStream getBodyContent() throws IOException {
-        return content.newStream(getBodyStartOctet(), -1);
-    }
-
-    public long getFullContentOctets() {
-        return size;
-    }
-
-    public String getMediaType() {
-        return mediaType;
-    }
-
-    public List<Property> getProperties() {
-        return properties;
-    }
-
-    public String getSubType() {
-        return subType;
-    }
-
-    public Long getTextualLineCount() {
-        return lineCount;
-    }
-
     @Override
     public int hashCode() {
         final int PRIME = 31;
@@ -192,60 +164,18 @@ public class SimpleMailboxMessage<Id ext
         return true;
     }
 
-    /**
-     * Representation suitable for logging and debugging.
-     * 
-     * @return a <code>String</code> representation of this object.
-     */
     public String toString() {
-        return super.toString() + "[" + "uid = " + this.uid + " "
-                + "mailboxId = " + this.mailboxId + " " + "size = " + this.size
-                + " " + "answered = " + this.answered + " " + "deleted = "
-                + this.deleted + " " + "draft = " + this.draft + " "
-                + "flagged = " + this.flagged + " " + "recent = " + this.recent
-                + " " + "seen = " + this.seen + " " + "internalDate = "
-                + this.internalDate + " " + "subType = " + this.subType + " "
-                + "mediaType = " + this.mediaType + " " + " ]";
-    }
-
-    @Override
-    protected int getBodyStartOctet() {
-        return bodyStartOctet;
-    }
-
-    /**
-     * @see MailboxMessage#getModSeq()
-     */
-    public long getModSeq() {
-        return modSeq;
-    }
-
-    /**
-     * @see MailboxMessage#setModSeq(long)
-     */
-    public void setModSeq(long modSeq) {
-        this.modSeq = modSeq;
-    }
-
-    /**
-     * @see MailboxMessage#setUid(long)
-     */
-    public void setUid(long uid) {
-        this.uid = uid;
-    }
-
-    @Override
-    public InputStream getHeaderContent() throws IOException {
-        long headerEnd = getBodyStartOctet();
-        if (headerEnd < 0) {
-            headerEnd = 0;
-        }
-        return content.newStream(0, headerEnd);
-    }
-
-    @Override
-    public InputStream getFullContent() throws IOException {
-        return content.newStream(0, -1);
+        return Objects.toStringHelper(this)
+            .add("uid", this.uid)
+            .add("mailboxId", this.mailboxId)
+            .add("answered", this.answered)
+            .add("deleted", this.deleted)
+            .add("draft", this.draft)
+            .add("flagged", this.flagged)
+            .add("recent", this.recent)
+            .add("seen", this.seen)
+            .add("message", this.getMessage())
+            .toString();
     }
 
 }

Added: james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMessage.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMessage.java?rev=1724227&view=auto
==============================================================================
--- james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMessage.java (added)
+++ james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMessage.java Tue Jan 12 13:18:56 2016
@@ -0,0 +1,111 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.mailbox.store.mail.model.impl;
+
+import org.apache.james.mailbox.store.mail.model.Message;
+import org.apache.james.mailbox.store.mail.model.MessageId;
+import org.apache.james.mailbox.store.mail.model.Property;
+
+import javax.mail.internet.SharedInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Date;
+import java.util.List;
+
+public class SimpleMessage implements Message {
+
+    private final String subType;
+    private final String mediaType;
+    private final SharedInputStream content;
+    private final int bodyStartOctet;
+    private final Date internalDate;
+    private final long size;
+    private final Long textualLineCount;
+    private final List<Property> properties;
+
+    public SimpleMessage(SharedInputStream content, long size, Date internalDate, String subType, String mediaType, int bodyStartOctet, Long textualLineCount, List<Property> properties) {
+        this.subType = subType;
+        this.mediaType = mediaType;
+        this.content = content;
+        this.bodyStartOctet = bodyStartOctet;
+        this.internalDate = internalDate;
+        this.size = size;
+        this.textualLineCount = textualLineCount;
+        this.properties = properties;
+    }
+
+    @Override
+    public MessageId getMessageId() {
+        return null;
+    }
+
+    @Override
+    public Date getInternalDate() {
+        return internalDate;
+    }
+
+    @Override
+    public InputStream getBodyContent() throws IOException {
+        return content.newStream(bodyStartOctet, -1);
+    }
+
+    @Override
+    public String getMediaType() {
+        return mediaType;
+    }
+
+    @Override
+    public String getSubType() {
+        return subType;
+    }
+
+    @Override
+    public long getBodyOctets() {
+        return getFullContentOctets() - bodyStartOctet;
+    }
+
+    @Override
+    public long getFullContentOctets() {
+        return size;
+    }
+
+    @Override
+    public Long getTextualLineCount() {
+        return textualLineCount;
+    }
+
+    @Override
+    public InputStream getHeaderContent() throws IOException {
+        long headerEnd = bodyStartOctet;
+        if (headerEnd < 0) {
+            headerEnd = 0;
+        }
+        return content.newStream(0, headerEnd);
+    }
+
+    @Override
+    public InputStream getFullContent() throws IOException {
+        return content.newStream(0, -1);
+    }
+
+    @Override
+    public List<Property> getProperties() {
+        return properties;
+    }
+}

Copied: james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/DelegatingMailboxMessageTest.java (from r1724226, james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AbstractMailboxMessageTest.java)
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/DelegatingMailboxMessageTest.java?p2=james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/DelegatingMailboxMessageTest.java&p1=james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AbstractMailboxMessageTest.java&r1=1724226&r2=1724227&rev=1724227&view=diff
==============================================================================
--- james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AbstractMailboxMessageTest.java (original)
+++ james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/DelegatingMailboxMessageTest.java Tue Jan 12 13:18:56 2016
@@ -25,7 +25,7 @@ import org.apache.james.mailbox.store.Me
 import org.apache.james.mailbox.store.TestId;
 import org.junit.Test;
 
-public class AbstractMailboxMessageTest {
+public class DelegatingMailboxMessageTest {
     
     @Test
     public void testShouldReturnPositiveWhenFirstGreaterThanSecond()

Modified: james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMailboxMessageTest.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMailboxMessageTest.java?rev=1724227&r1=1724226&r2=1724227&view=diff
==============================================================================
--- james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMailboxMessageTest.java (original)
+++ james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMailboxMessageTest.java Tue Jan 12 13:18:56 2016
@@ -34,6 +34,7 @@ import org.apache.commons.io.IOUtils;
 import org.apache.james.mailbox.FlagsBuilder;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.store.TestId;
+import org.assertj.core.internal.FieldByFieldComparator;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -93,7 +94,8 @@ public class SimpleMailboxMessageTest {
     public void copyShouldReturnFieldByFieldEqualsObject() throws MailboxException {
         SimpleMailboxMessage<TestId> original = buildMessage("my content");
         SimpleMailboxMessage<TestId> copy = SimpleMailboxMessage.copy(TestId.of(1337), original);
-        assertThat((Object)copy).isEqualToIgnoringGivenFields(original, "mailboxId").isNotSameAs(original);
+        assertThat((Object)copy).isEqualToIgnoringGivenFields(original, "message", "mailboxId").isNotSameAs(original);
+        assertThat(copy.getMessage()).usingComparator(new FieldByFieldComparator()).isEqualTo(original.getMessage());
     }
 
     private static SimpleMailboxMessage<TestId> buildMessage(String content) {



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