james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r931500 - in /james/server/trunk: pop3server/src/test/java/org/apache/james/pop3server/ spoolmanager/src/main/java/org/apache/james/ spring-deployment/src/main/config/james/META-INF/
Date Wed, 07 Apr 2010 10:54:44 GMT
Author: norman
Date: Wed Apr  7 10:54:44 2010
New Revision: 931500

URL: http://svn.apache.org/viewvc?rev=931500&view=rev
Log:
Don't copy the MimeMessage into memory before append it to the Mailbox. This is possible with
the new api which was introduced in (IMAP-127)

Modified:
    james/server/trunk/pop3server/src/test/java/org/apache/james/pop3server/AsyncPOP3ServerTest.java
    james/server/trunk/spoolmanager/src/main/java/org/apache/james/MailboxManagerPoster.java
    james/server/trunk/spring-deployment/src/main/config/james/META-INF/persistence.xml

Modified: james/server/trunk/pop3server/src/test/java/org/apache/james/pop3server/AsyncPOP3ServerTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server/src/test/java/org/apache/james/pop3server/AsyncPOP3ServerTest.java?rev=931500&r1=931499&r2=931500&view=diff
==============================================================================
--- james/server/trunk/pop3server/src/test/java/org/apache/james/pop3server/AsyncPOP3ServerTest.java
(original)
+++ james/server/trunk/pop3server/src/test/java/org/apache/james/pop3server/AsyncPOP3ServerTest.java
Wed Apr  7 10:54:44 2010
@@ -19,6 +19,7 @@
 
 package org.apache.james.pop3server;
 
+import java.io.ByteArrayInputStream;
 import java.io.Reader;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
@@ -422,9 +423,9 @@ public class AsyncPOP3ServerTest extends
                                  "Subject: test\r\n\r\n"+
                                  "Body Text POP3ServerTest.setupTestMails\r\n").getBytes();
         
-        mailbox.appendMessage(content, new Date(), session, true, new Flags());
+        mailbox.appendMessage(new ByteArrayInputStream(content), new Date(), session, true,
new Flags());
         byte[] content2 = ("EMPTY").getBytes();
-        mailbox.appendMessage(content2, new Date(), session, true, new Flags());
+        mailbox.appendMessage(new ByteArrayInputStream(content2), new Date(), session, true,
new Flags());
     }
 
     /*

Modified: james/server/trunk/spoolmanager/src/main/java/org/apache/james/MailboxManagerPoster.java
URL: http://svn.apache.org/viewvc/james/server/trunk/spoolmanager/src/main/java/org/apache/james/MailboxManagerPoster.java?rev=931500&r1=931499&r2=931500&view=diff
==============================================================================
--- james/server/trunk/spoolmanager/src/main/java/org/apache/james/MailboxManagerPoster.java
(original)
+++ james/server/trunk/spoolmanager/src/main/java/org/apache/james/MailboxManagerPoster.java
Wed Apr  7 10:54:44 2010
@@ -19,9 +19,12 @@
 
 package org.apache.james;
 
+import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.Date;
+import java.util.Enumeration;
 
 import javax.annotation.Resource;
 import javax.mail.MessagingException;
@@ -120,9 +123,8 @@ public class MailboxManagerPoster implem
                                 throw new MessagingException(error);
                             }
 
-                            final ByteArrayOutputStream baos = new ByteArrayOutputStream();
-                            mail.writeTo(baos);
-                            mailbox.appendMessage(baos.toByteArray() , new Date(), session,
true, null);
+
+                            mailbox.appendMessage(new MimeMessageInputStream(mail) , new
Date(), session, true, null);
                         }
                         catch (IOException e)
                         {
@@ -154,4 +156,76 @@ public class MailboxManagerPoster implem
     public void setLog(Log log) {
         this.logger = log;
     }
+
+	/**
+	 * {@link InputStream} which contains the headers and the Body of the wrapped {@link MimeMessage}
+	 *
+	 */
+    private final class MimeMessageInputStream extends InputStream {
+        private InputStream headersInputStream;
+        private InputStream bodyInputStream;
+        private int cStream = 0;
+
+        boolean nextCR = false;
+        boolean nextLF = false;
+
+        @SuppressWarnings("unchecked")
+        public MimeMessageInputStream(MimeMessage message) throws IOException {
+            try {
+                ByteArrayOutputStream headersOut = new ByteArrayOutputStream();
+                Enumeration headers = message.getAllHeaderLines();
+                while (headers.hasMoreElements()) {
+                    headersOut.write(headers.nextElement().toString().getBytes("US-ASCII"));
+                    headersOut.write("\r\n".getBytes());
+                }
+                headersInputStream = new ByteArrayInputStream(headersOut.toByteArray());
+                this.bodyInputStream = message.getInputStream();
+            } catch (MessagingException e) {
+                throw new IOException("Unable to read MimeMessage", e);
+            }
+        }
+
+        @Override
+        public int read() throws IOException {
+            if (nextCR) {
+                nextCR = false;
+                nextLF = true;
+                return '\r';
+            } else if (nextLF) {
+                nextLF = false;
+                return '\n';
+            } else {
+                int i = -1;
+                if (cStream == 0) {
+                    i = headersInputStream.read();
+                } else {
+                    i = bodyInputStream.read();
+                }
+
+                if (i == -1 && cStream == 0) {
+                    cStream++;
+                    nextCR = true;
+                    return read();
+                }
+                return i;
+            }
+
+        }
+
+        /** Closes all streams */
+        public void close() throws IOException {
+            headersInputStream.close();
+            bodyInputStream.close();
+        }
+
+        /** Is there more data to read */
+        public int available() throws IOException {
+            if (cStream == 0) {
+                return headersInputStream.available() + bodyInputStream.available() + 2;
+            } else {
+                return bodyInputStream.available();
+            }
+        }
+
+    }
 }

Modified: james/server/trunk/spring-deployment/src/main/config/james/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/spring-deployment/src/main/config/james/META-INF/persistence.xml?rev=931500&r1=931499&r2=931500&view=diff
==============================================================================
--- james/server/trunk/spring-deployment/src/main/config/james/META-INF/persistence.xml (original)
+++ james/server/trunk/spring-deployment/src/main/config/james/META-INF/persistence.xml Wed
Apr  7 10:54:44 2010
@@ -2,16 +2,18 @@
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     version="1.0">
     <persistence-unit name="James" transaction-type="RESOURCE_LOCAL">
-        <!-- IMAP stuff-->
-	    <class>org.apache.james.imap.jpa.mail.model.JPAHeader</class>
-    	<class>org.apache.james.imap.jpa.mail.model.JPAMailbox</class>
-    	<class>org.apache.james.imap.jpa.mail.model.JPAMailboxMembership</class>
-    	<class>org.apache.james.imap.jpa.mail.model.JPAMessage</class>
-    	<class>org.apache.james.imap.jpa.mail.model.JPAProperty</class>
-    	<class>org.apache.james.imap.jpa.user.model.JPASubscription</class>
+        <!-- Mailbox stuff-->
+        <class>org.apache.james.imap.jpa.mail.model.JPAHeader</class>
+        <class>org.apache.james.imap.jpa.mail.model.JPAMailbox</class>
+        <class>org.apache.james.imap.jpa.mail.model.JPAMailboxMembership</class>
+        <class>org.apache.james.imap.jpa.mail.model.AbstractJPAMessage</class>
+        <class>org.apache.james.imap.jpa.mail.model.JPAMessage</class>
+        <class>org.apache.james.imap.jpa.mail.model.openjpa.JPAStreamingMessage</class>
+        <class>org.apache.james.imap.jpa.mail.model.JPAProperty</class>
+        <class>org.apache.james.imap.jpa.user.model.JPASubscription</class>
         
         <!-- UsersRepository -->
-    	<class>org.apache.james.server.jpa.JPAUser</class>
+        <class>org.apache.james.server.jpa.JPAUser</class>
 
         <properties>
             <!-- workaround for MYSQL till openjpa 1.3 or 2.0.0 was released -->
@@ -21,7 +23,7 @@
             <property name="openjpa.jdbc.DBDictionary" value="blobTypeName=LONGBLOB"/>
             -->
             <!--  create tables on startup -->
-	    	<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/>
+            <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/>
         </properties>
     </persistence-unit>
 </persistence>



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