james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r931266 - in /james/imap/trunk: api/src/main/java/org/apache/james/imap/api/ api/src/main/java/org/apache/james/imap/api/message/request/ decode/ decode/src/main/java/org/apache/james/imap/decode/ decode/src/main/java/org/apache/james/imap/...
Date Tue, 06 Apr 2010 18:48:15 GMT
Author: norman
Date: Tue Apr  6 18:48:14 2010
New Revision: 931266

URL: http://svn.apache.org/viewvc?rev=931266&view=rev
Log:
Allow to append message without read it into memory first (IMAP-127)

Added:
    james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/base/EolInputStream.java
Modified:
    james/imap/trunk/api/src/main/java/org/apache/james/imap/api/ImapMessage.java
    james/imap/trunk/api/src/main/java/org/apache/james/imap/api/ImapMessageFactory.java
    james/imap/trunk/api/src/main/java/org/apache/james/imap/api/message/request/SearchKey.java
    james/imap/trunk/decode/pom.xml
    james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/DecodingException.java
    james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java
    james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/base/AbstractImapCommandParser.java
    james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/base/FixedLengthInputStream.java
    james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/parser/AppendCommandParser.java
    james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/parser/StatusCommandParser.java
    james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryStoreMailbox.java
    james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/SimpleMailboxMembership.java
    james/imap/trunk/message/src/main/java/org/apache/james/imap/message/request/AbstractImapRequest.java
    james/imap/trunk/message/src/main/java/org/apache/james/imap/message/request/AppendRequest.java
    james/imap/trunk/message/src/main/java/org/apache/james/imap/message/request/BaseImap4Rev1MessageFactory.java
    james/imap/trunk/parent/pom.xml
    james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/AbstractMailboxProcessor.java
    james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/AppendProcessor.java
    james/imap/trunk/seda/src/main/java/org/apache/james/imap/main/ImapRequestHandler.java
    james/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java

Modified: james/imap/trunk/api/src/main/java/org/apache/james/imap/api/ImapMessage.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/api/src/main/java/org/apache/james/imap/api/ImapMessage.java?rev=931266&r1=931265&r2=931266&view=diff
==============================================================================
--- james/imap/trunk/api/src/main/java/org/apache/james/imap/api/ImapMessage.java (original)
+++ james/imap/trunk/api/src/main/java/org/apache/james/imap/api/ImapMessage.java Tue Apr
 6 18:48:14 2010
@@ -28,4 +28,5 @@ package org.apache.james.imap.api;
  * </p>
  */
 public interface ImapMessage {
+  
 }

Modified: james/imap/trunk/api/src/main/java/org/apache/james/imap/api/ImapMessageFactory.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/api/src/main/java/org/apache/james/imap/api/ImapMessageFactory.java?rev=931266&r1=931265&r2=931266&view=diff
==============================================================================
--- james/imap/trunk/api/src/main/java/org/apache/james/imap/api/ImapMessageFactory.java (original)
+++ james/imap/trunk/api/src/main/java/org/apache/james/imap/api/ImapMessageFactory.java Tue
Apr  6 18:48:14 2010
@@ -18,7 +18,6 @@
  ****************************************************************/
 package org.apache.james.imap.api;
 
-import java.io.InputStream;
 import java.util.Date;
 
 import javax.mail.Flags;
@@ -29,6 +28,7 @@ import org.apache.james.imap.api.message
 import org.apache.james.imap.api.message.StatusDataItems;
 import org.apache.james.imap.api.message.request.SearchKey;
 import org.apache.james.imap.api.message.response.StatusResponse;
+import org.apache.james.imap.decode.base.EolInputStream;
 
 /**
  * Creates messages. Implementations may support message pooling but this is not
@@ -54,7 +54,7 @@ public interface ImapMessageFactory {
 
     public ImapMessage createAppendMessage(ImapCommand command,
             String mailboxName, Flags flags, Date datetime,
-            InputStream message, String tag);
+            EolInputStream message, String tag);
 
     public ImapMessage createAuthenticateMessage(final ImapCommand command,
             final String authType, final String tag);

Modified: james/imap/trunk/api/src/main/java/org/apache/james/imap/api/message/request/SearchKey.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/api/src/main/java/org/apache/james/imap/api/message/request/SearchKey.java?rev=931266&r1=931265&r2=931266&view=diff
==============================================================================
--- james/imap/trunk/api/src/main/java/org/apache/james/imap/api/message/request/SearchKey.java
(original)
+++ james/imap/trunk/api/src/main/java/org/apache/james/imap/api/message/request/SearchKey.java
Tue Apr  6 18:48:14 2010
@@ -427,7 +427,9 @@ public final class SearchKey {
         int result = 1;
         result = PRIME * result + ((date == null) ? 0 : date.hashCode());
         result = PRIME * result + ((name == null) ? 0 : name.hashCode());
-        result = PRIME * result + sequence.length;
+        if (sequence != null) {
+            result = PRIME * result + sequence.length;
+        }
         result = PRIME * result + (int) (size ^ (size >>> 32));
         result = PRIME * result + ((keys == null) ? 0 : keys.hashCode());
         result = PRIME * result + type;

Modified: james/imap/trunk/decode/pom.xml
URL: http://svn.apache.org/viewvc/james/imap/trunk/decode/pom.xml?rev=931266&r1=931265&r2=931266&view=diff
==============================================================================
--- james/imap/trunk/decode/pom.xml (original)
+++ james/imap/trunk/decode/pom.xml Tue Apr  6 18:48:14 2010
@@ -59,7 +59,10 @@
       <groupId>commons-lang</groupId>
       <artifactId>commons-lang</artifactId>
     </dependency>
-
+    <dependency>
+      <groupId>commons-io</groupId>
+      <artifactId>commons-io</artifactId>
+    </dependency>
     <dependency>
       <groupId>org.apache.james</groupId>
       <artifactId>apache-james-imap-api</artifactId>

Modified: james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/DecodingException.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/DecodingException.java?rev=931266&r1=931265&r2=931266&view=diff
==============================================================================
--- james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/DecodingException.java
(original)
+++ james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/DecodingException.java
Tue Apr  6 18:48:14 2010
@@ -19,6 +19,8 @@
 
 package org.apache.james.imap.decode;
 
+import java.io.IOException;
+
 import org.apache.james.imap.api.display.HumanReadableText;
 
 /**
@@ -36,7 +38,7 @@ import org.apache.james.imap.api.display
  * <li>{@link HumanReadableText#BAD_IO_ENCODING}</li>
  * </ul>
  */
-public class DecodingException extends Exception {
+public class DecodingException extends IOException {
 
     private static final long serialVersionUID = 8719349386686261422L;
 

Modified: james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java?rev=931266&r1=931265&r2=931266&view=diff
==============================================================================
--- james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java
(original)
+++ james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java
Tue Apr  6 18:48:14 2010
@@ -24,6 +24,7 @@ import java.io.InputStream;
 import java.io.OutputStream;
 
 import org.apache.james.imap.api.display.HumanReadableText;
+import org.apache.james.imap.decode.base.FixedLengthInputStream;
 
 /**
  * Wraps the client input reader with a bunch of convenience methods, allowing
@@ -161,25 +162,12 @@ public class ImapRequestLineReader {
      * @throws DecodingException
      *             If a char can't be read into each array element.
      */
-    public void read(byte[] holder) throws DecodingException {
-        int readTotal = 0;
-        try {
-            while (readTotal < holder.length) {
-                int count = 0;
-                count = input
-                        .read(holder, readTotal, holder.length - readTotal);
-                if (count == -1) {
-                    throw new DecodingException(HumanReadableText.ILLEGAL_ARGUMENTS, "Unexpected
end of stream.");
-                }
-                readTotal += count;
-            }
-            // Unset the next char.
-            nextSeen = false;
-            nextChar = 0;
-        } catch (IOException e) {
-            throw new DecodingException(HumanReadableText.SOCKET_IO_FAILURE, 
-                    "Error reading from stream.", e);
-        }
+    public InputStream read(int size) throws DecodingException {
+
+        // Unset the next char.
+        nextSeen = false;
+        nextChar = 0;
+        return new FixedLengthInputStream(input, size);
 
     }
 

Modified: james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/base/AbstractImapCommandParser.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/base/AbstractImapCommandParser.java?rev=931266&r1=931265&r2=931266&view=diff
==============================================================================
--- james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/base/AbstractImapCommandParser.java
(original)
+++ james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/base/AbstractImapCommandParser.java
Tue Apr  6 18:48:14 2010
@@ -19,6 +19,9 @@
 
 package org.apache.james.imap.decode.base;
 
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
 import java.nio.ByteBuffer;
 import java.nio.CharBuffer;
 import java.nio.charset.CharacterCodingException;
@@ -33,6 +36,7 @@ import java.util.Date;
 
 import javax.mail.Flags;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.commons.logging.Log;
 import org.apache.james.imap.api.ImapMessageFactory;
 import org.apache.james.imap.api.ImapCommand;
@@ -115,6 +119,7 @@ public abstract class AbstractImapComman
 
         } catch (DecodingException e) {
             logger.debug("Cannot parse protocol ", e);
+            e.printStackTrace();
             result = messageFactory.taggedBad(tag, command, e.getKey());
         }
         return result;
@@ -319,13 +324,19 @@ public abstract class AbstractImapComman
         if (charset == null) {
             return consumeLiteral(request, US_ASCII);
         } else {
-            final byte[] bytes = consumeLiteral(request);
+            ByteArrayOutputStream out = new ByteArrayOutputStream();
+            try {
+                IOUtils.copy(consumeLiteral(request),out);
+            } catch (IOException e) {
+                throw new DecodingException(HumanReadableText.BAD_IO_ENCODING, "Bad character
encoding",  e);
+            }
+            final byte[] bytes = out.toByteArray();
             final ByteBuffer buffer = ByteBuffer.wrap(bytes);
             return decode(charset, buffer);
         }
     }
 
-    protected byte[] consumeLiteral(final ImapRequestLineReader request) throws DecodingException
{
+    protected InputStream  consumeLiteral(final ImapRequestLineReader request) throws DecodingException
{
         // The 1st character must be '{'
         consumeChar(request, '{');
 
@@ -358,15 +369,12 @@ public abstract class AbstractImapComman
         }
 
         final int size = Integer.parseInt(digits.toString());
-        final byte[] bytes = new byte[size];
-        request.read(bytes);
-        return bytes;
+        return request.read(size);
     }
 
     private String decode(final Charset charset, final ByteBuffer buffer)
             throws DecodingException {
         try {
-
             final String result = charset.newDecoder().onMalformedInput(
                     CodingErrorAction.REPORT).onUnmappableCharacter(
                     CodingErrorAction.REPORT).decode(buffer).toString();

Added: james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/base/EolInputStream.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/base/EolInputStream.java?rev=931266&view=auto
==============================================================================
--- james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/base/EolInputStream.java
(added)
+++ james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/base/EolInputStream.java
Tue Apr  6 18:48:14 2010
@@ -0,0 +1,80 @@
+/****************************************************************
+ * 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.imap.decode.base;
+
+import java.io.FileInputStream;
+import java.io.FilterInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.james.imap.decode.ImapRequestLineReader;
+
+/**
+ * {@link FileInputStream} which call the eol() method of the {@link ImapRequestLineReader}
when the end 
+ * of the wrapped {@link InputStream} is reached
+ * 
+ *
+ */
+public class EolInputStream extends FilterInputStream{
+
+    private ImapRequestLineReader reader;
+
+    public EolInputStream(ImapRequestLineReader reader, InputStream in) {
+        super(in);
+        this.reader = reader;
+    }
+
+    @Override
+    public int read() throws IOException {
+        int i = in.read();
+        eol(i);
+        return i;
+    }
+
+    @Override
+    public int read(byte[] b, int off, int len) throws IOException {
+        int i = in.read(b, off, len);
+        eol(i);
+        return i;
+    }
+
+    @Override
+    public int read(byte[] b) throws IOException {
+        int i = in.read(b);
+        eol(i);
+        return i;
+    }
+
+    private void eol(int i ) throws IOException{
+        if (i == -1) {
+            reader.eol();
+        }
+    }
+    
+    /**
+     * Consume the whole stream
+     */
+    public void cosume() { 
+        try {
+            while (read() != -1);
+        } catch (IOException e) {
+            // do nothing here
+        }
+    }
+}

Modified: james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/base/FixedLengthInputStream.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/base/FixedLengthInputStream.java?rev=931266&r1=931265&r2=931266&view=diff
==============================================================================
--- james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/base/FixedLengthInputStream.java
(original)
+++ james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/base/FixedLengthInputStream.java
Tue Apr  6 18:48:14 2010
@@ -24,14 +24,13 @@ import java.io.IOException;
 import java.io.InputStream;
 
 /**
- * This class is not yet used in the AppendCommand.
  * 
  * An input stream which reads a fixed number of bytes from the underlying input
  * stream. Once the number of bytes has been read, the FixedLengthInputStream
  * will act as thought the end of stream has been reached, even if more bytes
  * are present in the underlying input stream.
  */
-class FixedLengthInputStream extends FilterInputStream {
+public class FixedLengthInputStream extends FilterInputStream {
     private long pos = 0;
 
     private long length;
@@ -50,22 +49,30 @@ class FixedLengthInputStream extends Fil
     }
 
     public int read(byte b[]) throws IOException {
-        if (pos >= length) {
+
+        if (pos >= length) {   
             return -1;
         }
 
         if (pos + b.length >= length) {
+            int readLimit = (int) length - (int) pos;
             pos = length;
-            return super.read(b, 0, (int) (length - pos));
+
+            return super.read(b, 0, readLimit);
         }
 
         pos += b.length;
+
         return super.read(b);
     }
 
     public int read(byte b[], int off, int len) throws IOException {
-        throw new IOException("Not implemented");
-        // return super.read( b, off, len );
+        byte[] tmpArray = new byte[len]; 
+        int a = in.read(tmpArray);
+        for (int i = 0; i < tmpArray.length; i++) {
+            b[off + i] = tmpArray[i];
+        }
+        return a;
     }
 
     public long skip(long n) throws IOException {
@@ -74,7 +81,7 @@ class FixedLengthInputStream extends Fil
     }
 
     public int available() throws IOException {
-        return super.available();
+        return 0;
     }
 
     public void close() throws IOException {

Modified: james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/parser/AppendCommandParser.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/parser/AppendCommandParser.java?rev=931266&r1=931265&r2=931266&view=diff
==============================================================================
--- james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/parser/AppendCommandParser.java
(original)
+++ james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/parser/AppendCommandParser.java
Tue Apr  6 18:48:14 2010
@@ -18,7 +18,6 @@
  ****************************************************************/
 package org.apache.james.imap.decode.parser;
 
-import java.io.ByteArrayInputStream;
 import java.util.Date;
 
 import javax.mail.Flags;
@@ -31,6 +30,7 @@ import org.apache.james.imap.api.ImapMes
 import org.apache.james.imap.decode.ImapRequestLineReader;
 import org.apache.james.imap.decode.DecodingException;
 import org.apache.james.imap.decode.base.AbstractImapCommandParser;
+import org.apache.james.imap.decode.base.EolInputStream;
 
 class AppendCommandParser extends AbstractImapCommandParser {
 
@@ -79,12 +79,12 @@ class AppendCommandParser extends Abstra
             datetime = new Date();
         }
         request.nextWordChar();
-        final byte[] message = consumeLiteral(request);
-        endLine(request);
+        
+        // Use a EolInputStream so it will call eol when the message was read
+        final EolInputStream message = new EolInputStream(request, consumeLiteral(request));
         final ImapMessageFactory factory = getMessageFactory();
-        //TODO: FIX ME
         final ImapMessage result = factory.createAppendMessage(command,
-                mailboxName, flags, datetime, new ByteArrayInputStream(message), tag);
+                mailboxName, flags, datetime, message, tag);
         return result;
     }
 }

Modified: james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/parser/StatusCommandParser.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/parser/StatusCommandParser.java?rev=931266&r1=931265&r2=931266&view=diff
==============================================================================
--- james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/parser/StatusCommandParser.java
(original)
+++ james/imap/trunk/decode/src/main/java/org/apache/james/imap/decode/parser/StatusCommandParser.java
Tue Apr  6 18:48:14 2010
@@ -43,6 +43,7 @@ class StatusCommandParser extends Abstra
         consumeChar(request, '(');
         CharacterValidator validator = new NoopCharValidator();
         String nextWord = consumeWord(request, validator);
+
         while (!nextWord.endsWith(")")) {
             addItem(nextWord, items);
             nextWord = consumeWord(request, validator);
@@ -57,6 +58,7 @@ class StatusCommandParser extends Abstra
 
     private void addItem(String nextWord, StatusDataItems items)
             throws DecodingException {
+
         if (nextWord.equals(ImapConstants.STATUS_MESSAGES)) {
             items.setMessages(true);
         } else if (nextWord.equals(ImapConstants.STATUS_RECENT)) {
@@ -81,6 +83,7 @@ class StatusCommandParser extends Abstra
         final ImapMessageFactory factory = getMessageFactory();
         final ImapMessage result = factory.createStatusMessage(command,
                 mailboxName, statusDataItems, tag);
+        
         return result;
     }
 }

Modified: james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryStoreMailbox.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryStoreMailbox.java?rev=931266&r1=931265&r2=931266&view=diff
==============================================================================
--- james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryStoreMailbox.java
(original)
+++ james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryStoreMailbox.java
Tue Apr  6 18:48:14 2010
@@ -82,9 +82,10 @@ public class InMemoryStoreMailbox extend
                 out.close();
 
         } catch (Exception e) {
+            e.printStackTrace();
             byteContent = new byte[0];
         }
-        
+        System.out.println("byte=" + new String(byteContent));
         return new SimpleMailboxMembership(internalDate, uid, size, bodyStartOctet, byteContent,
flags, headers, propertyBuilder, mailboxId);
 
 

Modified: james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/SimpleMailboxMembership.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/SimpleMailboxMembership.java?rev=931266&r1=931265&r2=931266&view=diff
==============================================================================
--- james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/SimpleMailboxMembership.java
(original)
+++ james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/SimpleMailboxMembership.java
Tue Apr  6 18:48:14 2010
@@ -76,6 +76,7 @@ public class SimpleMailboxMembership ext
             Flags flags, List<Header> headers, PropertyBuilder propertyBuilder, final
long mailboxId) {
         this.uid = uid;
         this.document = document;
+        
         this.size = size;
         this.bodyStartOctet = bodyStartOctet;
         setFlags(flags);

Modified: james/imap/trunk/message/src/main/java/org/apache/james/imap/message/request/AbstractImapRequest.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/message/src/main/java/org/apache/james/imap/message/request/AbstractImapRequest.java?rev=931266&r1=931265&r2=931266&view=diff
==============================================================================
--- james/imap/trunk/message/src/main/java/org/apache/james/imap/message/request/AbstractImapRequest.java
(original)
+++ james/imap/trunk/message/src/main/java/org/apache/james/imap/message/request/AbstractImapRequest.java
Tue Apr  6 18:48:14 2010
@@ -50,4 +50,5 @@ abstract public class AbstractImapReques
     public final String getTag() {
         return tag;
     }
+    
 }

Modified: james/imap/trunk/message/src/main/java/org/apache/james/imap/message/request/AppendRequest.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/message/src/main/java/org/apache/james/imap/message/request/AppendRequest.java?rev=931266&r1=931265&r2=931266&view=diff
==============================================================================
--- james/imap/trunk/message/src/main/java/org/apache/james/imap/message/request/AppendRequest.java
(original)
+++ james/imap/trunk/message/src/main/java/org/apache/james/imap/message/request/AppendRequest.java
Tue Apr  6 18:48:14 2010
@@ -18,12 +18,12 @@
  ****************************************************************/
 package org.apache.james.imap.message.request;
 
-import java.io.InputStream;
 import java.util.Date;
 
 import javax.mail.Flags;
 
 import org.apache.james.imap.api.ImapCommand;
+import org.apache.james.imap.decode.base.EolInputStream;
 
 public class AppendRequest extends AbstractImapRequest {
     private final String mailboxName;
@@ -32,10 +32,10 @@ public class AppendRequest extends Abstr
 
     private final Date datetime;
 
-    private final InputStream message;
+    private final EolInputStream message;
 
     public AppendRequest(ImapCommand command, String mailboxName, Flags flags,
-            Date datetime, InputStream message, String tag) {
+            Date datetime, EolInputStream message, String tag) {
         super(tag, command);
         this.mailboxName = mailboxName;
         this.flags = flags;
@@ -55,7 +55,9 @@ public class AppendRequest extends Abstr
         return mailboxName;
     }
 
-    public InputStream getMessage() {
+    public EolInputStream getMessage() {
         return message;
     }
+    
+    
 }

Modified: james/imap/trunk/message/src/main/java/org/apache/james/imap/message/request/BaseImap4Rev1MessageFactory.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/message/src/main/java/org/apache/james/imap/message/request/BaseImap4Rev1MessageFactory.java?rev=931266&r1=931265&r2=931266&view=diff
==============================================================================
--- james/imap/trunk/message/src/main/java/org/apache/james/imap/message/request/BaseImap4Rev1MessageFactory.java
(original)
+++ james/imap/trunk/message/src/main/java/org/apache/james/imap/message/request/BaseImap4Rev1MessageFactory.java
Tue Apr  6 18:48:14 2010
@@ -18,7 +18,6 @@
  ****************************************************************/
 package org.apache.james.imap.message.request;
 
-import java.io.InputStream;
 import java.util.Date;
 
 import javax.mail.Flags;
@@ -33,6 +32,7 @@ import org.apache.james.imap.api.message
 import org.apache.james.imap.api.message.request.SearchKey;
 import org.apache.james.imap.api.message.response.StatusResponse;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
+import org.apache.james.imap.decode.base.EolInputStream;
 
 /**
  * Naive, factory creates unpooled instances.
@@ -49,7 +49,7 @@ public class BaseImap4Rev1MessageFactory
 
     public ImapMessage createAppendMessage(ImapCommand command,
             String mailboxName, Flags flags, Date datetime,
-            InputStream message, String tag) {
+            EolInputStream message, String tag) {
         return new AppendRequest(command, mailboxName, flags, datetime,
                 message, tag);
     }

Modified: james/imap/trunk/parent/pom.xml
URL: http://svn.apache.org/viewvc/james/imap/trunk/parent/pom.xml?rev=931266&r1=931265&r2=931266&view=diff
==============================================================================
--- james/imap/trunk/parent/pom.xml (original)
+++ james/imap/trunk/parent/pom.xml Tue Apr  6 18:48:14 2010
@@ -418,7 +418,6 @@
       <dependency>
         <groupId>commons-io</groupId>
         <artifactId>commons-io</artifactId>
-        <scope>test</scope>
         <version>1.4</version>
       </dependency>
       <dependency>

Modified: james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/AbstractMailboxProcessor.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/AbstractMailboxProcessor.java?rev=931266&r1=931265&r2=931266&view=diff
==============================================================================
--- james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/AbstractMailboxProcessor.java
(original)
+++ james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/AbstractMailboxProcessor.java
Tue Apr  6 18:48:14 2010
@@ -289,6 +289,13 @@ abstract public class AbstractMailboxPro
         responder.respond(response);
     }
 
+    protected void taggedBad(final ImapCommand command, final String tag,
+            final ImapProcessor.Responder responder,
+            final HumanReadableText e) {
+        StatusResponse response = factory.taggedBad(tag, command, e);
+
+        responder.respond(response);
+    }
     protected void bye(final ImapProcessor.Responder responder) {
         final StatusResponse response = factory.bye(HumanReadableText.BYE);
         responder.respond(response);

Modified: james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/AppendProcessor.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/AppendProcessor.java?rev=931266&r1=931265&r2=931266&view=diff
==============================================================================
--- james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/AppendProcessor.java
(original)
+++ james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/AppendProcessor.java
Tue Apr  6 18:48:14 2010
@@ -34,11 +34,13 @@ import org.apache.james.imap.api.message
 import org.apache.james.imap.api.process.ImapProcessor;
 import org.apache.james.imap.api.process.ImapSession;
 import org.apache.james.imap.api.process.SelectedMailbox;
+import org.apache.james.imap.decode.base.EolInputStream;
 import org.apache.james.imap.mailbox.Mailbox;
 import org.apache.james.imap.mailbox.MailboxException;
 import org.apache.james.imap.mailbox.MailboxManager;
 import org.apache.james.imap.mailbox.MailboxNotFoundException;
 import org.apache.james.imap.mailbox.MailboxSession;
+import org.apache.james.imap.mailbox.StorageException;
 import org.apache.james.imap.message.request.AppendRequest;
 import org.apache.james.imap.processor.base.ImapSessionUtils;
 
@@ -61,7 +63,7 @@ public class AppendProcessor extends Abs
             String tag, ImapCommand command, Responder responder) {
         final AppendRequest request = (AppendRequest) message;
         final String mailboxName = request.getMailboxName();
-        final InputStream messageIn = request.getMessage();
+        final EolInputStream messageIn = request.getMessage();
         final Date datetime = request.getDatetime();
         final Flags flags = request.getFlags();
         try {
@@ -72,12 +74,18 @@ public class AppendProcessor extends Abs
             appendToMailbox(messageIn, datetime, flags, session, tag,
                     command, mailbox, responder, fullMailboxName);
         } catch (MailboxNotFoundException e) {
+            // consume stream
+            messageIn.cosume();
+            
 //          Indicates that the mailbox does not exist
 //          So TRY CREATE
             tryCreate(session, tag, command, responder, e);
+            
         } catch (MailboxException e) {
+           
 //          Some other issue
             no(command, tag, responder, e, session);
+            
         }
 
     }
@@ -100,9 +108,11 @@ public class AppendProcessor extends Abs
         if (logger.isDebugEnabled()) {
             logger.debug("Cannot open mailbox: ", e);
         }
+        
         no(command, tag, responder,
                 HumanReadableText.FAILURE_NO_SUCH_MAILBOX,
                 StatusResponse.ResponseCode.tryCreate());
+       
     }
 
     private void appendToMailbox(final InputStream message, final Date datetime,
@@ -125,6 +135,8 @@ public class AppendProcessor extends Abs
 //          Indicates that the mailbox does not exist
 //          So TRY CREATE
             tryCreate(session, tag, command, responder, e);
+        } catch (StorageException e) {
+            taggedBad(command, tag, responder, e.getKey());
         } catch (MailboxException e) {
 //          Some other issue
             no(command, tag, responder, e, session);

Modified: james/imap/trunk/seda/src/main/java/org/apache/james/imap/main/ImapRequestHandler.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/seda/src/main/java/org/apache/james/imap/main/ImapRequestHandler.java?rev=931266&r1=931265&r2=931266&view=diff
==============================================================================
--- james/imap/trunk/seda/src/main/java/org/apache/james/imap/main/ImapRequestHandler.java
(original)
+++ james/imap/trunk/seda/src/main/java/org/apache/james/imap/main/ImapRequestHandler.java
Tue Apr  6 18:48:14 2010
@@ -169,6 +169,7 @@ public final class ImapRequestHandler  {
         final ResponseEncoder responseEncoder = new ResponseEncoder(encoder,
                 response, session);
         processor.process(message, responseEncoder, session);
+        
         final boolean result;
         final IOException failure = responseEncoder.getFailure();
         if (failure == null) {

Modified: james/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java?rev=931266&r1=931265&r2=931266&view=diff
==============================================================================
--- james/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java
(original)
+++ james/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java
Tue Apr  6 18:48:14 2010
@@ -20,6 +20,9 @@
 package org.apache.james.mailboxmanager.torque;
 
 import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.sql.SQLException;
@@ -37,6 +40,7 @@ import java.util.TreeMap;
 import java.util.TreeSet;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 
+import javax.imageio.stream.FileImageInputStream;
 import javax.mail.Flags;
 import javax.mail.MessagingException;
 import javax.mail.internet.MimeMessage;
@@ -133,6 +137,7 @@ public class TorqueMailbox implements Ma
             final MailboxRow myMailboxRow = reserveNextUid();
 
             if (myMailboxRow != null) {
+                File file = null;
                 try {
                     
                     // To be thread safe, we first get our own copy and the
@@ -150,7 +155,21 @@ public class TorqueMailbox implements Ma
                     messageRow.setMailboxId(getMailboxRow().getMailboxId());
                     messageRow.setUid(uid);
                     messageRow.setInternalDate(internalDate);
-                    final MimeMessage mimeMessage = new MimeMessage(null, messageIn);
+                    // Create a temporary file and copy the message to it. We will work with
the file as
+                    // source for the InputStream
+                    file = File.createTempFile("imap", ".msg");
+                    FileOutputStream out = new FileOutputStream(file);
+                    
+                    byte[] buf = new byte[1024];
+                    int i = 0;
+                    while ((i = messageIn.read(buf)) != -1) {
+                        out.write(buf, 0, i);
+                    }
+                    out.flush();
+                    out.close();
+                    
+                    final MimeMessage mimeMessage = new MimeMessage(null, new FileInputStream(file));
+
                     if (isRecent) {
                         mimeMessage.setFlag(Flags.Flag.RECENT, true);
                     }
@@ -174,7 +193,12 @@ public class TorqueMailbox implements Ma
                     getUidChangeTracker().found(messageResult.getUid(), messageResult.getFlags());
                     return messageResult.getUid();
                 } catch (Exception e) {
+                    e.printStackTrace();
                     throw new MailboxException(HumanReadableText.FAILURE_MAIL_PARSE, e);
+                } finally {
+                    if (file != null) {
+                        file.delete();
+                    }
                 }
             } else {
                 // mailboxRow==null



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