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 [2/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
Modified: james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/search/comparator/AbstractHeaderComparator.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/search/comparator/AbstractHeaderComparator.java?rev=1136175&r1=1136174&r2=1136175&view=diff
==============================================================================
--- james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/search/comparator/AbstractHeaderComparator.java
(original)
+++ james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/search/comparator/AbstractHeaderComparator.java
Wed Jun 15 20:24:10 2011
@@ -18,11 +18,14 @@
  ****************************************************************/
 package org.apache.james.mailbox.store.search.comparator;
 
+import java.io.IOException;
 import java.util.Comparator;
 import java.util.List;
 import java.util.Locale;
 
-import org.apache.james.mailbox.store.mail.model.Header;
+import org.apache.james.mailbox.MailboxException;
+import org.apache.james.mailbox.MessageResult.Header;
+import org.apache.james.mailbox.store.ResultUtils;
 import org.apache.james.mailbox.store.mail.model.Message;
 
 
@@ -33,13 +36,22 @@ public abstract class AbstractHeaderComp
     public final static String CC ="cc";
 
     protected String getHeaderValue(String headerName, Message<?> message) {
-        final List<Header> headers = message.getHeaders();
-        for (Header header:headers) {
-            final String name = header.getFieldName();
-            if (headerName.equalsIgnoreCase(name)) {
-                final String value = header.getValue();
-                return value.toUpperCase(Locale.ENGLISH);
+        try {
+            final List<Header> headers = ResultUtils.createHeaders(message);
+            for (Header header : headers) {
+                try {
+                    String name = header.getName();
+                    if (headerName.equalsIgnoreCase(name)) {
+                        final String value = header.getValue();
+                        return value.toUpperCase(Locale.ENGLISH);
+                    }
+                } catch (MailboxException e) {
+                    // skip the header line
+                }
+
             }
+        } catch (IOException e) {
+            // skip the header
         }
         return "";
     }

Modified: james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/streaming/InputStreamContent.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/streaming/InputStreamContent.java?rev=1136175&r1=1136174&r2=1136175&view=diff
==============================================================================
--- james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/streaming/InputStreamContent.java
(original)
+++ james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/streaming/InputStreamContent.java
Wed Jun 15 20:24:10 2011
@@ -27,6 +27,7 @@ import java.nio.channels.WritableByteCha
 
 import org.apache.commons.io.input.BoundedInputStream;
 import org.apache.james.mailbox.Content;
+import org.apache.james.mailbox.store.ResultUtils;
 import org.apache.james.mailbox.store.mail.model.Message;
 
 /**
@@ -69,7 +70,7 @@ public final class InputStreamContent im
         // wrap the streams in a BoundedInputStream to make sure it really match with the
stored size.
         switch (type) {
         case Full:
-            return new BoundedInputStream(m.getFullContent(), size());
+            return new BoundedInputStream(ResultUtils.toInput(m), size());
         default:
             return new BoundedInputStream(m.getBodyContent(), size());
         }
@@ -86,7 +87,7 @@ public final class InputStreamContent im
         try {
             switch (type) {
             case Full:
-                in = m.getFullContent();
+                in = ResultUtils.toInput(m);
                 break;
             default:
                 in = m.getBodyContent();

Modified: james/mailbox/trunk/store/src/test/java/org/apache/james/mailbox/store/MessageBuilder.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/store/src/test/java/org/apache/james/mailbox/store/MessageBuilder.java?rev=1136175&r1=1136174&r2=1136175&view=diff
==============================================================================
--- james/mailbox/trunk/store/src/test/java/org/apache/james/mailbox/store/MessageBuilder.java
(original)
+++ james/mailbox/trunk/store/src/test/java/org/apache/james/mailbox/store/MessageBuilder.java
Wed Jun 15 20:24:10 2011
@@ -18,13 +18,12 @@
  ****************************************************************/
 package org.apache.james.mailbox.store;
 
-import java.util.ArrayList;
 import java.util.Date;
-import java.util.List;
+import java.util.HashMap;
+import java.util.Map;
 
 import javax.mail.Flags;
 
-import org.apache.james.mailbox.store.mail.model.Header;
 import org.apache.james.mailbox.store.mail.model.Message;
 
 public class MessageBuilder {
@@ -35,7 +34,7 @@ public class MessageBuilder {
     public int size = 8867;
     public Flags flags = new Flags();
     public byte[] body = {};
-    public final List<SimpleHeader> headers = new ArrayList<SimpleHeader>();
+    public final Map<String, String> headers = new HashMap<String, String>();
     public int lineNumber = 0;
     
     public Message<Long> build() throws Exception {
@@ -43,10 +42,8 @@ public class MessageBuilder {
         return result;
     }
     
-    public Header header(String field, String value) {
-        SimpleHeader header = new SimpleHeader(field, ++lineNumber, value);
-        headers.add(header);
-        return header;
+    public void header(String field, String value) {
+        headers.put(field, value);
     }
 
     public void setKey(int mailboxId, int uid) {

Modified: james/mailbox/trunk/store/src/test/java/org/apache/james/mailbox/store/SimpleMailboxMembership.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/store/src/test/java/org/apache/james/mailbox/store/SimpleMailboxMembership.java?rev=1136175&r1=1136174&r2=1136175&view=diff
==============================================================================
--- james/mailbox/trunk/store/src/test/java/org/apache/james/mailbox/store/SimpleMailboxMembership.java
(original)
+++ james/mailbox/trunk/store/src/test/java/org/apache/james/mailbox/store/SimpleMailboxMembership.java
Wed Jun 15 20:24:10 2011
@@ -26,11 +26,14 @@ import java.io.OutputStreamWriter;
 import java.io.Writer;
 import java.util.ArrayList;
 import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
 
 import javax.mail.Flags;
 
-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;
 
@@ -49,36 +52,21 @@ public class SimpleMailboxMembership imp
     public boolean seen = false;
 
     public SimpleMailboxMembership(long mailboxId, long uid, long modSeq, Date internalDate,
int size, 
-            Flags flags, byte[] body, final List<SimpleHeader> headers) throws Exception
{
+            Flags flags, byte[] body, final Map<String, String> headers) throws Exception
{
         super();
         this.mailboxId = mailboxId;
         this.uid = uid;
         this.internalDate = internalDate;
         this.size = size;
         this.body = body;
-        final List<SimpleHeader> originalHeaders = headers;
+        final Map<String,String> originalHeaders = headers;
         if (originalHeaders == null) {
-            this.headers = new ArrayList<SimpleHeader>();
+            this.headers = new HashMap<String,String>();
         } else {
-            this.headers = new ArrayList<SimpleHeader>(originalHeaders.size());
-            for (SimpleHeader header:originalHeaders) {
-                this.headers.add(new SimpleHeader(header));
-            }
+            this.headers = originalHeaders;
         }
         
-        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        final Writer writer = new OutputStreamWriter(baos, "us-ascii");
-        for (SimpleHeader header:headers) {
-            writer.write(header.getFieldName());
-            writer.write(": ");
-            writer.write(header.getValue());
-            writer.write(NEW_LINE);
-        }
-        writer.write(NEW_LINE);
-        writer.flush();
-        baos.write(body);
-        baos.flush();
-        fullContent = baos.toByteArray();
+        this.body =  body;
         setFlags(flags);
     }
 
@@ -240,8 +228,7 @@ public class SimpleMailboxMembership imp
     public static final char[] NEW_LINE = { 0x0D, 0x0A };
     
     public byte[] body;
-    public byte[] fullContent;
-    public List<SimpleHeader> headers;
+    public Map<String, String> headers;
     public List<SimpleProperty> properties;
     public String subType = null;
     public String mediaType = null;
@@ -260,20 +247,26 @@ public class SimpleMailboxMembership imp
         return new ByteArrayInputStream(body);
     }
 
-    /**
-     * Gets the full content (including headers) of the document.
-     * @return read only buffer, not null
-     * @throws IOException 
-     */
-    public InputStream getFullContent() throws IOException {
-        return new ByteArrayInputStream(fullContent);
-    }
-    
-    /**
-     * @see org.apache.james.imap.Message.mail.model.Document#getHeaders()
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.mailbox.store.mail.model.Message#getHeaderContent()
      */
-    public List<Header> getHeaders() {
-        return new ArrayList<Header>(headers);
+    public InputStream getHeaderContent() throws IOException {
+        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        final Writer writer = new OutputStreamWriter(baos, "us-ascii");
+
+        Iterator<Entry<String, String>> hIt = headers.entrySet().iterator();
+        while (hIt.hasNext()) {
+            Entry<String, String> header = hIt.next();
+            writer.write(header.getKey());
+            writer.write(": ");
+            writer.write(header.getValue());
+            writer.write(NEW_LINE);
+        }
+        writer.flush();
+        return new ByteArrayInputStream(baos.toByteArray());
+
     }
 
     public long getBodyOctets() {



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