Author: rdonkin
Date: Tue Jul 29 09:54:20 2008
New Revision: 680766

URL: http://svn.apache.org/viewvc?rev=680766&view=rev
Log:
BODYSTRUCTURE for message/rfc822 types

Modified:
    
james/server/trunk/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/encode/writer/ChannelImapResponseWriter.java
    
james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/AbstractTestFetchBodyStructure.java
    
james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchStructureEmbedded.test
    
james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/ImapResponseComposer.java
    
james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/base/ImapResponseComposerImpl.java
    
james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/imap4rev1/FetchResponseEncoder.java
    
james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/base/ByteImapResponseWriter.java
    
james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/imap4rev1/FetchResponseEncoderEnvelopeTest.java
    
james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/imap4rev1/legacy/MockImapResponseWriter.java
    
james/server/trunk/torque-mailboxmanager-function/src/main/java/org/apache/james/mailboxmanager/torque/MimeDescriptorImpl.java

Modified: 
james/server/trunk/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/encode/writer/ChannelImapResponseWriter.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/encode/writer/ChannelImapResponseWriter.java?rev=680766&r1=680765&r2=680766&view=diff
==============================================================================
--- 
james/server/trunk/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/encode/writer/ChannelImapResponseWriter.java
 (original)
+++ 
james/server/trunk/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/encode/writer/ChannelImapResponseWriter.java
 Tue Jul 29 09:54:20 2008
@@ -195,7 +195,7 @@
         skipNextSpace = true;
     }
     
-    private void space() throws IOException {
+    public void space() throws IOException {
         if (skipNextSpace) {
             skipNextSpace = false;
         } else {

Modified: 
james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/AbstractTestFetchBodyStructure.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/AbstractTestFetchBodyStructure.java?rev=680766&r1=680765&r2=680766&view=diff
==============================================================================
--- 
james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/AbstractTestFetchBodyStructure.java
 (original)
+++ 
james/server/trunk/experimental-seda-imap-function/src/test/java/org/apache/james/test/functional/imap/AbstractTestFetchBodyStructure.java
 Tue Jul 29 09:54:20 2008
@@ -50,4 +50,16 @@
     public void testFetchFetchMultipartBodyStructureITALY() throws Exception {
         scriptTest("FetchMultipartBodyStructure", Locale.ITALY);
     }
+    
+    public void testFetchStructureEmbeddedUS() throws Exception {
+        scriptTest("FetchStructureEmbedded", Locale.US);
+    }
+
+    public void testFetchStructureEmbeddedITALY() throws Exception {
+        scriptTest("FetchStructureEmbedded", Locale.ITALY);
+    }
+
+    public void testFetchStructureEmbeddedKOREA() throws Exception {
+        scriptTest("FetchStructureEmbedded", Locale.KOREA);
+    }
 }

Modified: 
james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchStructureEmbedded.test
URL: 
http://svn.apache.org/viewvc/james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchStructureEmbedded.test?rev=680766&r1=680765&r2=680766&view=diff
==============================================================================
--- 
james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchStructureEmbedded.test
 (original)
+++ 
james/server/trunk/experimental-seda-imap-function/src/test/resources/org/apache/james/test/functional/imap/scripts/FetchStructureEmbedded.test
 Tue Jul 29 09:54:20 2008
@@ -550,7 +550,7 @@
 S: \)
 S: A24 OK FETCH completed\.
 C: A25 FETCH 1:* (BODY BODYSTRUCTURE)
-S: \* 1 FETCH \(BODY \(\("text" "plain" \("charset" "US-ASCII"\) NIL NIL 
"7bit" 10 1\)\("application" "octet-stream" NIL NIL NIL "base64" 
16\)\("message" "rfc822" NIL NIL NIL "7bit" 395 \("Thu, 14 Feb 2008 12:00:00 
\+0000 \(GMT\)" "A Multipart Alternative Email" \(\("Timothy Tayler" NIL 
"timothy" "example\.org"\)\) \(\("Timothy Tayler" NIL "timothy" 
"example\.org"\)\) \(\("Timothy Tayler" NIL "timothy" "example\.org"\)\) 
\(\("Samual Smith" NIL "samual" "example\.org"\)\) NIL NIL NIL NIL\) \(\("text" 
"plain" \("charset" "US-ASCII"\) NIL NIL "7bit" 10 1\)\("application" 
"octet-stream" NIL NIL NIL "7bit" 23\) "alternative"\) 19\)\(\("image" "gif" 
NIL "238478934723847238947892374" "Bogus Image Data" "base64" 17\)\("message" 
"rfc822" NIL NIL NIL "7bit" 579 \("Sat, 16 Feb 2008 12:00:00 \+0000 \(GMT\)" 
"Another Example Email" \(\("Timothy Tayler" NIL "timothy" "example\.org"\)\) 
\(\("Timothy Tayler" NIL "timothy" "example\.org"\)\) \(\("Timothy Tayler" NIL 
"timothy" "example\.org"\
 )\) \(\("John Smith" NIL "john" "example\.org"\)\) NIL NIL NIL NIL\) 
\(\("text" "plain" \("charset" "us-ascii"\) NIL NIL "7bit" 22 1\)\(\("text" 
"plain" \("charset" "us-ascii"\) NIL NIL "7bit" 18 1\)\("text" "plain" 
\("charset" "us-ascii"\) NIL NIL "7bit" 49 3\) "alternative"\) "mixed"\) 30\) 
"mixed"\) "mixed"\) BODYSTRUCTURE \(\("text" "plain" \("charset" "US-ASCII"\) 
NIL NIL "7bit" 10 1 NIL NIL NIL\)\("application" "octet-stream" NIL NIL NIL 
"base64" 16 NIL NIL NIL\)\("message" "rfc822" NIL NIL NIL "7bit" 395 \("Thu, 14 
Feb 2008 12:00:00 \+0000 \(GMT\)" "A Multipart Alternative Email" \(\("Timothy 
Tayler" NIL "timothy" "example\.org"\)\) \(\("Timothy Tayler" NIL "timothy" 
"example\.org"\)\) \(\("Timothy Tayler" NIL "timothy" "example\.org"\)\) 
\(\("Samual Smith" NIL "samual" "example\.org"\)\) NIL NIL NIL NIL\) \(\("text" 
"plain" \("charset" "US-ASCII"\) NIL NIL "7bit" 10 1 NIL NIL 
NIL\)\("application" "octet-stream" NIL NIL NIL "7bit" 23 NIL NIL NIL\) 
"alternative" \("bou
 ndary" "42"\) NIL NIL\) 19 NIL NIL NIL\)\(\("image" "gif" NIL 
"238478934723847238947892374" "Bogus Image Data" "base64" 17 NIL NIL 
NIL\)\("message" "rfc822" NIL NIL NIL "7bit" 579 \("Sat, 16 Feb 2008 12:00:00 
\+0000 \(GMT\)" "Another Example Email" \(\("Timothy Tayler" NIL "timothy" 
"example\.org"\)\) \(\("Timothy Tayler" NIL "timothy" "example\.org"\)\) 
\(\("Timothy Tayler" NIL "timothy" "example\.org"\)\) \(\("John Smith" NIL 
"john" "example\.org"\)\) NIL NIL NIL NIL\) \(\("text" "plain" \("charset" 
"us-ascii"\) NIL NIL "7bit" 22 1 NIL NIL NIL\)\(\("text" "plain" \("charset" 
"us-ascii"\) NIL NIL "7bit" 18 1 NIL NIL NIL\)\("text" "plain" \("charset" 
"us-ascii"\) NIL NIL "7bit" 49 3 NIL NIL NIL\) "alternative" \("boundary" 
"3\.243F6A8885A308D3"\) NIL NIL\) "mixed" \("boundary" "2\.50290787509"\) NIL 
NIL\) 30 NIL NIL NIL\) "mixed" \("boundary" "4\.66920160910299"\) NIL NIL\) 
"mixed" \("boundary" "1729"\) NIL NIL\)\)
+S: \* 1 FETCH \(BODY \(\("TEXT" "PLAIN" \("charset" "us-ascii"\) NIL NIL 
"7BIT" 10 1\)\("APPLICATION" "OCTET-STREAM" NIL NIL NIL "BASE64" 
16\)\("MESSAGE" "RFC822" NIL NIL NIL "7BIT" 395 \("Thu, 14 Feb 2008 12:00:00 
\+0000 \(GMT\)" "A Multipart Alternative Email" \(\("Timothy Tayler" NIL 
"timothy" "example\.org"\)\) \(\("Timothy Tayler" NIL "timothy" 
"example\.org"\)\) \(\("Timothy Tayler" NIL "timothy" "example\.org"\)\) 
\(\("Samual Smith" NIL "samual" "example\.org"\)\) NIL NIL NIL NIL\) \(\("TEXT" 
"PLAIN" \("charset" "us-ascii"\) NIL NIL "7BIT" 10 1\)\("APPLICATION" 
"OCTET-STREAM" NIL NIL NIL "7BIT" 23\) "ALTERNATIVE"\) 19\)\(\("IMAGE" "GIF" 
NIL "238478934723847238947892374" "Bogus Image Data" "BASE64" 17\)\("MESSAGE" 
"RFC822" NIL NIL NIL "7BIT" 579 \("Sat, 16 Feb 2008 12:00:00 \+0000 \(GMT\)" 
"Another Example Email" \(\("Timothy Tayler" NIL "timothy" "example\.org"\)\) 
\(\("Timothy Tayler" NIL "timothy" "example\.org"\)\) \(\("Timothy Tayler" NIL 
"timothy" "example\.org"\
 )\) \(\("John Smith" NIL "john" "example\.org"\)\) NIL NIL NIL NIL\) 
\(\("TEXT" "PLAIN" \("charset" "us-ascii"\) NIL NIL "7BIT" 22 1\)\(\("TEXT" 
"PLAIN" \("charset" "us-ascii"\) NIL NIL "7BIT" 18 1\)\("TEXT" "PLAIN" 
\("charset" "us-ascii"\) NIL NIL "7BIT" 49 3\) "ALTERNATIVE"\) "MIXED"\) 30\) 
"MIXED"\) "MIXED"\) BODYSTRUCTURE \(\("TEXT" "PLAIN" \("charset" "us-ascii"\) 
NIL NIL "7BIT" 10 1 NIL NIL NIL NIL\)\("APPLICATION" "OCTET-STREAM" NIL NIL NIL 
"BASE64" 16 NIL NIL NIL NIL\)\("MESSAGE" "RFC822" NIL NIL NIL "7BIT" 395 
\("Thu, 14 Feb 2008 12:00:00 \+0000 \(GMT\)" "A Multipart Alternative Email" 
\(\("Timothy Tayler" NIL "timothy" "example\.org"\)\) \(\("Timothy Tayler" NIL 
"timothy" "example\.org"\)\) \(\("Timothy Tayler" NIL "timothy" 
"example\.org"\)\) \(\("Samual Smith" NIL "samual" "example\.org"\)\) NIL NIL 
NIL NIL\) \(\("TEXT" "PLAIN" \("charset" "us-ascii"\) NIL NIL "7BIT" 10 1 NIL 
NIL NIL NIL\)\("APPLICATION" "OCTET-STREAM" NIL NIL NIL "7BIT" 23 NIL NIL NIL 
NIL\) "ALT
 ERNATIVE" \("boundary" "42"\) NIL NIL NIL\) 19 NIL NIL NIL NIL\)\(\("IMAGE" 
"GIF" NIL "238478934723847238947892374" "Bogus Image Data" "BASE64" 17 NIL NIL 
NIL NIL\)\("MESSAGE" "RFC822" NIL NIL NIL "7BIT" 579 \("Sat, 16 Feb 2008 
12:00:00 \+0000 \(GMT\)" "Another Example Email" \(\("Timothy Tayler" NIL 
"timothy" "example\.org"\)\) \(\("Timothy Tayler" NIL "timothy" 
"example\.org"\)\) \(\("Timothy Tayler" NIL "timothy" "example\.org"\)\) 
\(\("John Smith" NIL "john" "example\.org"\)\) NIL NIL NIL NIL\) \(\("TEXT" 
"PLAIN" \("charset" "us-ascii"\) NIL NIL "7BIT" 22 1 NIL NIL NIL 
NIL\)\(\("TEXT" "PLAIN" \("charset" "us-ascii"\) NIL NIL "7BIT" 18 1 NIL NIL 
NIL NIL\)\("TEXT" "PLAIN" \("charset" "us-ascii"\) NIL NIL "7BIT" 49 3 NIL NIL 
NIL NIL\) "ALTERNATIVE" \("boundary" "3\.243F6A8885A308D3"\) NIL NIL NIL\) 
"MIXED" \("boundary" "2\.50290787509"\) NIL NIL NIL\) 30 NIL NIL NIL NIL\) 
"MIXED" \("boundary" "4\.66920160910299"\) NIL NIL NIL\) "MIXED" \("boundary" 
"1729"\) NIL NIL NIL\)\)
 S: A25 OK FETCH completed\.
 C: A26 DELETE testmailbox
 S: A26 OK DELETE completed\.

Modified: 
james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/ImapResponseComposer.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/ImapResponseComposer.java?rev=680766&r1=680765&r2=680766&view=diff
==============================================================================
--- 
james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/ImapResponseComposer.java
 (original)
+++ 
james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/ImapResponseComposer.java
 Tue Jul 29 09:54:20 2008
@@ -180,10 +180,11 @@
      * Starts a <code>FETCH ENVELOPE</code> production.
      * @param date envelope date, or null for <code>NIL</code>
      * @param subject envelope subject, or null for <code>NIL</code>
+     * @param prefixWithName whether <code>ENVELOPE</code> should be prefixed
      * @throws IOException
      * @see [EMAIL PROTECTED] #endEnvelope(String, String)} must be called
      */
-    public abstract void startEnvelope(String date, String subject) throws 
IOException;
+    public abstract void startEnvelope(String date, String subject, boolean 
prefixWithName) throws IOException;
     
     /**
      * Starts a list of addresses.

Modified: 
james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/base/ImapResponseComposerImpl.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/base/ImapResponseComposerImpl.java?rev=680766&r1=680765&r2=680766&view=diff
==============================================================================
--- 
james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/base/ImapResponseComposerImpl.java
 (original)
+++ 
james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/base/ImapResponseComposerImpl.java
 Tue Jul 29 09:54:20 2008
@@ -534,8 +534,10 @@
         openParen();
     }
 
-    public void startEnvelope(String date, String subject) throws IOException {
-        message(ENVELOPE);
+    public void startEnvelope(String date, String subject, boolean 
prefixWithName) throws IOException {
+        if (prefixWithName) {
+            message(ENVELOPE);
+        }
         openParen();
         nillableQuote(date);
         nillableQuote(subject);
@@ -575,7 +577,7 @@
     }
 
     public ImapResponseComposer nillableQuotes(String[] quotes) throws 
IOException {
-        if (quotes == null) {
+        if (quotes == null || quotes.length == 0) {
             nil();
         } else {
             openParen();

Modified: 
james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/imap4rev1/FetchResponseEncoder.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/imap4rev1/FetchResponseEncoder.java?rev=680766&r1=680765&r2=680766&view=diff
==============================================================================
--- 
james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/imap4rev1/FetchResponseEncoder.java
 (original)
+++ 
james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/imap4rev1/FetchResponseEncoder.java
 Tue Jul 29 09:54:20 2008
@@ -228,8 +228,8 @@
         final FetchResponse.Structure embeddedStructure = structure.getBody();
         
         encodeBodyFields(composer, structure, mediaType, subType);
-        encodeEnvelope(composer, envelope);
-        encodeStructure(composer, embeddedStructure, includeExtensions, true);
+        encodeEnvelope(composer, envelope, false);
+        encodeStructure(composer, embeddedStructure, includeExtensions, false);
         composer.message(lines);
         
         if (includeExtensions) {
@@ -286,10 +286,11 @@
 
     private void encodeEnvelope(final ImapResponseComposer composer, final 
FetchResponse fetchResponse) throws IOException {
         final FetchResponse.Envelope envelope = fetchResponse.getEnvelope();
-        encodeEnvelope(composer, envelope);
+        encodeEnvelope(composer, envelope, true);
     }
 
-    private void encodeEnvelope(final ImapResponseComposer composer, final 
FetchResponse.Envelope envelope) throws IOException {
+    private void encodeEnvelope(final ImapResponseComposer composer, final 
FetchResponse.Envelope envelope, 
+            boolean prefixWithName) throws IOException {
         if (envelope != null) {
             final String date = envelope.getDate();
             final String subject = envelope.getSubject();
@@ -302,7 +303,7 @@
             final String inReplyTo = envelope.getInReplyTo();
             final String messageId = envelope.getMessageId();
             
-            composer.startEnvelope(date, subject);
+            composer.startEnvelope(date, subject, prefixWithName);
             encodeAddresses(composer, from);
             encodeAddresses(composer, sender);
             encodeAddresses(composer, replyTo);

Modified: 
james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/base/ByteImapResponseWriter.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/base/ByteImapResponseWriter.java?rev=680766&r1=680765&r2=680766&view=diff
==============================================================================
--- 
james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/base/ByteImapResponseWriter.java
 (original)
+++ 
james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/base/ByteImapResponseWriter.java
 Tue Jul 29 09:54:20 2008
@@ -161,7 +161,7 @@
         skipNextSpace = true;
     }
     
-    private void space() {
+    public void space() {
         if (skipNextSpace) {
             skipNextSpace = false;
         } else {

Modified: 
james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/imap4rev1/FetchResponseEncoderEnvelopeTest.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/imap4rev1/FetchResponseEncoderEnvelopeTest.java?rev=680766&r1=680765&r2=680766&view=diff
==============================================================================
--- 
james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/imap4rev1/FetchResponseEncoderEnvelopeTest.java
 (original)
+++ 
james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/imap4rev1/FetchResponseEncoderEnvelopeTest.java
 Tue Jul 29 09:54:20 2008
@@ -129,7 +129,7 @@
     public void testShouldNilAllNullProperties() throws Exception {
         envelopExpects();
         
mockComposer.expects(once()).method("openFetchResponse").with(eq((long)MSN)).id("open");
-        mockComposer.expects(once()).method("startEnvelope").with(NULL, 
NULL).after("open").id("start");
+        mockComposer.expects(once()).method("startEnvelope").with(NULL, NULL, 
eq(true)).after("open").id("start");
         
mockComposer.expects(exactly(6)).method("nil").after("start").id("last");
         mockComposer.expects(once()).method("endEnvelope").with(NULL, 
NULL).after("last").id("end");
         mockComposer.expects(once()).method("closeFetchResponse").after("end");
@@ -141,7 +141,7 @@
         date = "a date";
         envelopExpects();
         
mockComposer.expects(once()).method("openFetchResponse").with(eq((long)MSN)).id("open");
-        mockComposer.expects(once()).method("startEnvelope").with(eq(date), 
NULL).after("open").id("start");
+        mockComposer.expects(once()).method("startEnvelope").with(eq(date), 
NULL, eq(true)).after("open").id("start");
         
mockComposer.expects(exactly(6)).method("nil").after("start").id("last");
         mockComposer.expects(once()).method("endEnvelope").with(NULL, 
NULL).after("last").id("end");
         mockComposer.expects(once()).method("closeFetchResponse").after("end");
@@ -153,7 +153,7 @@
         subject = "some subject";
         envelopExpects();
         
mockComposer.expects(once()).method("openFetchResponse").with(eq((long)MSN)).id("open");
-        mockComposer.expects(once()).method("startEnvelope").with(NULL, 
eq(subject)).after("open").id("start");
+        mockComposer.expects(once()).method("startEnvelope").with(NULL, 
eq(subject), eq(true)).after("open").id("start");
         
mockComposer.expects(exactly(6)).method("nil").after("start").id("last");
         mockComposer.expects(once()).method("endEnvelope").with(NULL, 
NULL).after("last").id("end");
         mockComposer.expects(once()).method("closeFetchResponse").after("end");
@@ -165,7 +165,7 @@
         inReplyTo = "some reply to";
         envelopExpects();
         
mockComposer.expects(once()).method("openFetchResponse").with(eq((long)MSN)).id("open");
-        mockComposer.expects(once()).method("startEnvelope").with(NULL, 
NULL).after("open").id("start");
+        mockComposer.expects(once()).method("startEnvelope").with(NULL, NULL, 
eq(true)).after("open").id("start");
         
mockComposer.expects(exactly(6)).method("nil").after("start").id("last");
         mockComposer.expects(once()).method("endEnvelope").with(eq(inReplyTo), 
NULL).after("last").id("end");
         mockComposer.expects(once()).method("closeFetchResponse").after("end");
@@ -177,7 +177,7 @@
         messageId = "some message id";
         envelopExpects();
         
mockComposer.expects(once()).method("openFetchResponse").with(eq((long)MSN)).id("open");
-        mockComposer.expects(once()).method("startEnvelope").with(NULL, 
NULL).after("open").id("start");
+        mockComposer.expects(once()).method("startEnvelope").with(NULL, NULL, 
eq(true)).after("open").id("start");
         
mockComposer.expects(exactly(6)).method("nil").after("start").id("last");
         mockComposer.expects(once()).method("endEnvelope").with(NULL, 
eq(messageId)).after("last").id("end");
         mockComposer.expects(once()).method("closeFetchResponse").after("end");
@@ -189,7 +189,7 @@
         from = mockOneAddress();
         envelopExpects();
         
mockComposer.expects(once()).method("openFetchResponse").with(eq((long)MSN)).id("open");
-        mockComposer.expects(once()).method("startEnvelope").with(NULL, 
NULL).after("open").id("start");
+        mockComposer.expects(once()).method("startEnvelope").with(NULL, NULL, 
eq(true)).after("open").id("start");
         
mockComposer.expects(once()).method("startAddresses").after("start").id("start-from");
         
mockComposer.expects(once()).method("address").with(eq(ADDRESS_ONE_NAME), 
eq(ADDRESS_ONE_DOMAIN_LIST), eq(ADDRESS_ONE_MAILBOX), 
eq(ADDRESS_ONE_HOST)).after("start-from").id("address-one");
         
mockComposer.expects(once()).method("endAddresses").after("address-one").id("from");
@@ -204,7 +204,7 @@
         from = mockManyAddresses();
         envelopExpects();
         
mockComposer.expects(once()).method("openFetchResponse").with(eq((long)MSN)).id("open");
-        mockComposer.expects(once()).method("startEnvelope").with(NULL, 
NULL).after("open").id("start");
+        mockComposer.expects(once()).method("startEnvelope").with(NULL, NULL, 
eq(true)).after("open").id("start");
         
mockComposer.expects(once()).method("startAddresses").after("start").id("start-from");
         
mockComposer.expects(once()).method("address").with(eq(ADDRESS_ONE_NAME), 
eq(ADDRESS_ONE_DOMAIN_LIST), eq(ADDRESS_ONE_MAILBOX), 
eq(ADDRESS_ONE_HOST)).after("start-from").id("address-one");
         
mockComposer.expects(once()).method("address").with(eq(ADDRESS_TWO_NAME), 
eq(ADDRESS_TWO_DOMAIN_LIST), eq(ADDRESS_TWO_MAILBOX), 
eq(ADDRESS_TWO_HOST)).after("address-one").id("address-two");
@@ -220,7 +220,7 @@
         sender = mockOneAddress();
         envelopExpects();
         
mockComposer.expects(once()).method("openFetchResponse").with(eq((long)MSN)).id("open");
-        mockComposer.expects(once()).method("startEnvelope").with(NULL, 
NULL).after("open").id("start");
+        mockComposer.expects(once()).method("startEnvelope").with(NULL, NULL, 
eq(true)).after("open").id("start");
         
mockComposer.expects(exactly(1)).method("nil").after("start").id("before");
         
mockComposer.expects(once()).method("startAddresses").after("before").id("start-addresses");
         
mockComposer.expects(once()).method("address").with(eq(ADDRESS_ONE_NAME), 
eq(ADDRESS_ONE_DOMAIN_LIST), eq(ADDRESS_ONE_MAILBOX), 
eq(ADDRESS_ONE_HOST)).after("start-addresses").id("address-one");
@@ -236,7 +236,7 @@
         sender = mockManyAddresses();
         envelopExpects();
         
mockComposer.expects(once()).method("openFetchResponse").with(eq((long)MSN)).id("open");
-        mockComposer.expects(once()).method("startEnvelope").with(NULL, 
NULL).after("open").id("start");
+        mockComposer.expects(once()).method("startEnvelope").with(NULL, NULL, 
eq(true)).after("open").id("start");
         
mockComposer.expects(exactly(1)).method("nil").after("start").id("before");
         
mockComposer.expects(once()).method("startAddresses").after("before").id("start-addresses");
         
mockComposer.expects(once()).method("address").with(eq(ADDRESS_ONE_NAME), 
eq(ADDRESS_ONE_DOMAIN_LIST), eq(ADDRESS_ONE_MAILBOX), 
eq(ADDRESS_ONE_HOST)).after("start-addresses").id("address-one");
@@ -254,7 +254,7 @@
         replyTo = mockOneAddress();
         envelopExpects();
         
mockComposer.expects(once()).method("openFetchResponse").with(eq((long)MSN)).id("open");
-        mockComposer.expects(once()).method("startEnvelope").with(NULL, 
NULL).after("open").id("start");
+        mockComposer.expects(once()).method("startEnvelope").with(NULL, NULL, 
eq(true)).after("open").id("start");
         
mockComposer.expects(exactly(2)).method("nil").after("start").id("before");
         
mockComposer.expects(once()).method("startAddresses").after("before").id("start-addresses");
         
mockComposer.expects(once()).method("address").with(eq(ADDRESS_ONE_NAME), 
eq(ADDRESS_ONE_DOMAIN_LIST), eq(ADDRESS_ONE_MAILBOX), 
eq(ADDRESS_ONE_HOST)).after("start-addresses").id("address-one");
@@ -270,7 +270,7 @@
         replyTo = mockManyAddresses();
         envelopExpects();
         
mockComposer.expects(once()).method("openFetchResponse").with(eq((long)MSN)).id("open");
-        mockComposer.expects(once()).method("startEnvelope").with(NULL, 
NULL).after("open").id("start");
+        mockComposer.expects(once()).method("startEnvelope").with(NULL, NULL, 
eq(true)).after("open").id("start");
         
mockComposer.expects(exactly(2)).method("nil").after("start").id("before");
         
mockComposer.expects(once()).method("startAddresses").after("before").id("start-addresses");
         
mockComposer.expects(once()).method("address").with(eq(ADDRESS_ONE_NAME), 
eq(ADDRESS_ONE_DOMAIN_LIST), eq(ADDRESS_ONE_MAILBOX), 
eq(ADDRESS_ONE_HOST)).after("start-addresses").id("address-one");
@@ -287,7 +287,7 @@
         to = mockOneAddress();
         envelopExpects();
         
mockComposer.expects(once()).method("openFetchResponse").with(eq((long)MSN)).id("open");
-        mockComposer.expects(once()).method("startEnvelope").with(NULL, 
NULL).after("open").id("start");
+        mockComposer.expects(once()).method("startEnvelope").with(NULL, NULL, 
eq(true)).after("open").id("start");
         
mockComposer.expects(exactly(3)).method("nil").after("start").id("before");
         
mockComposer.expects(once()).method("startAddresses").after("before").id("start-addresses");
         
mockComposer.expects(once()).method("address").with(eq(ADDRESS_ONE_NAME), 
eq(ADDRESS_ONE_DOMAIN_LIST), eq(ADDRESS_ONE_MAILBOX), 
eq(ADDRESS_ONE_HOST)).after("start-addresses").id("address-one");
@@ -303,7 +303,7 @@
         to = mockManyAddresses();
         envelopExpects();
         
mockComposer.expects(once()).method("openFetchResponse").with(eq((long)MSN)).id("open");
-        mockComposer.expects(once()).method("startEnvelope").with(NULL, 
NULL).after("open").id("start");
+        mockComposer.expects(once()).method("startEnvelope").with(NULL, NULL, 
eq(true)).after("open").id("start");
         
mockComposer.expects(exactly(3)).method("nil").after("start").id("before");
         
mockComposer.expects(once()).method("startAddresses").after("before").id("start-addresses");
         
mockComposer.expects(once()).method("address").with(eq(ADDRESS_ONE_NAME), 
eq(ADDRESS_ONE_DOMAIN_LIST), eq(ADDRESS_ONE_MAILBOX), 
eq(ADDRESS_ONE_HOST)).after("start-addresses").id("address-one");
@@ -321,7 +321,7 @@
         cc = mockOneAddress();
         envelopExpects();
         
mockComposer.expects(once()).method("openFetchResponse").with(eq((long)MSN)).id("open");
-        mockComposer.expects(once()).method("startEnvelope").with(NULL, 
NULL).after("open").id("start");
+        mockComposer.expects(once()).method("startEnvelope").with(NULL, NULL, 
eq(true)).after("open").id("start");
         
mockComposer.expects(exactly(4)).method("nil").after("start").id("before");
         
mockComposer.expects(once()).method("startAddresses").after("before").id("start-addresses");
         
mockComposer.expects(once()).method("address").with(eq(ADDRESS_ONE_NAME), 
eq(ADDRESS_ONE_DOMAIN_LIST), eq(ADDRESS_ONE_MAILBOX), 
eq(ADDRESS_ONE_HOST)).after("start-addresses").id("address-one");
@@ -337,7 +337,7 @@
         cc = mockManyAddresses();
         envelopExpects();
         
mockComposer.expects(once()).method("openFetchResponse").with(eq((long)MSN)).id("open");
-        mockComposer.expects(once()).method("startEnvelope").with(NULL, 
NULL).after("open").id("start");
+        mockComposer.expects(once()).method("startEnvelope").with(NULL, NULL, 
eq(true)).after("open").id("start");
         
mockComposer.expects(exactly(4)).method("nil").after("start").id("before");
         
mockComposer.expects(once()).method("startAddresses").after("before").id("start-addresses");
         
mockComposer.expects(once()).method("address").with(eq(ADDRESS_ONE_NAME), 
eq(ADDRESS_ONE_DOMAIN_LIST), eq(ADDRESS_ONE_MAILBOX), 
eq(ADDRESS_ONE_HOST)).after("start-addresses").id("address-one");
@@ -354,7 +354,7 @@
         bcc = mockOneAddress();
         envelopExpects();
         
mockComposer.expects(once()).method("openFetchResponse").with(eq((long)MSN)).id("open");
-        mockComposer.expects(once()).method("startEnvelope").with(NULL, 
NULL).after("open").id("start");
+        mockComposer.expects(once()).method("startEnvelope").with(NULL, NULL, 
eq(true)).after("open").id("start");
         
mockComposer.expects(exactly(5)).method("nil").after("start").id("before");
         
mockComposer.expects(once()).method("startAddresses").after("before").id("start-addresses");
         
mockComposer.expects(once()).method("address").with(eq(ADDRESS_ONE_NAME), 
eq(ADDRESS_ONE_DOMAIN_LIST), eq(ADDRESS_ONE_MAILBOX), 
eq(ADDRESS_ONE_HOST)).after("start-addresses").id("address-one");
@@ -369,7 +369,7 @@
         bcc = mockManyAddresses();
         envelopExpects();
         
mockComposer.expects(once()).method("openFetchResponse").with(eq((long)MSN)).id("open");
-        mockComposer.expects(once()).method("startEnvelope").with(NULL, 
NULL).after("open").id("start");
+        mockComposer.expects(once()).method("startEnvelope").with(NULL, NULL, 
eq(true)).after("open").id("start");
         
mockComposer.expects(exactly(5)).method("nil").after("start").id("before");
         
mockComposer.expects(once()).method("startAddresses").after("before").id("start-addresses");
         
mockComposer.expects(once()).method("address").with(eq(ADDRESS_ONE_NAME), 
eq(ADDRESS_ONE_DOMAIN_LIST), eq(ADDRESS_ONE_MAILBOX), 
eq(ADDRESS_ONE_HOST)).after("start-addresses").id("address-one");

Modified: 
james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/imap4rev1/legacy/MockImapResponseWriter.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/imap4rev1/legacy/MockImapResponseWriter.java?rev=680766&r1=680765&r2=680766&view=diff
==============================================================================
--- 
james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/imap4rev1/legacy/MockImapResponseWriter.java
 (original)
+++ 
james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/imap4rev1/legacy/MockImapResponseWriter.java
 Tue Jul 29 09:54:20 2008
@@ -420,5 +420,8 @@
 
     public void quoteUpperCaseAscii(String message) throws IOException {
         operations.add(new UpperCaseASCIIOperation(message, true));
+    }
+
+    public void space() {
     }    
 }

Modified: 
james/server/trunk/torque-mailboxmanager-function/src/main/java/org/apache/james/mailboxmanager/torque/MimeDescriptorImpl.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/torque-mailboxmanager-function/src/main/java/org/apache/james/mailboxmanager/torque/MimeDescriptorImpl.java?rev=680766&r1=680765&r2=680766&view=diff
==============================================================================
--- 
james/server/trunk/torque-mailboxmanager-function/src/main/java/org/apache/james/mailboxmanager/torque/MimeDescriptorImpl.java
 (original)
+++ 
james/server/trunk/torque-mailboxmanager-function/src/main/java/org/apache/james/mailboxmanager/torque/MimeDescriptorImpl.java
 Tue Jul 29 09:54:20 2008
@@ -32,30 +32,36 @@
 import org.apache.james.mime4j.MaximalBodyDescriptor;
 import org.apache.james.mime4j.MimeException;
 import org.apache.james.mime4j.MimeTokenStream;
+import org.apache.james.mime4j.RecursionMode;
 
 public class MimeDescriptorImpl implements MessageResult.MimeDescriptor {
     
     public static MimeDescriptorImpl build(final InputStream stream) throws 
IOException {
         final MimeTokenStream parser = 
MimeTokenStream.createMaximalDescriptorStream();
         parser.parse(stream);
+        parser.setRecursionMode(RecursionMode.M_NO_RECURSE);
         return createDescriptor(parser);
     }
 
     private static MimeDescriptorImpl createDescriptor(
             final MimeTokenStream parser) throws IOException, MimeException {
         int next = parser.next();
+        final Collection headers = new ArrayList();
         while (next != MimeTokenStream.T_BODY && next != 
MimeTokenStream.T_END_OF_STREAM
-                && next != MimeTokenStream.T_START_MULTIPART) { 
+                && next != MimeTokenStream.T_START_MULTIPART) {
+            if (next == MimeTokenStream.T_FIELD) {
+                headers.add(new Header(parser.getFieldName(), 
parser.getFieldValue().trim()));
+            }
             next = parser.next();
         }        
         
         final MimeDescriptorImpl mimeDescriptorImpl;
         switch (next) {
             case MimeTokenStream.T_BODY:
-                mimeDescriptorImpl = simplePartDescriptor(parser);
+                mimeDescriptorImpl = simplePartDescriptor(parser, headers);
                 break;
             case MimeTokenStream.T_START_MULTIPART:
-                mimeDescriptorImpl = compositePartDescriptor(parser);
+                mimeDescriptorImpl = compositePartDescriptor(parser, headers);
                 break;
             case MimeTokenStream.T_END_OF_STREAM:
                 throw new MimeException("Premature end of stream");
@@ -66,9 +72,9 @@
     }
 
     private static MimeDescriptorImpl compositePartDescriptor(
-            final MimeTokenStream parser) throws IOException {
+            final MimeTokenStream parser, final Collection headers) throws 
IOException {
         MaximalBodyDescriptor descriptor = (MaximalBodyDescriptor) 
parser.getBodyDescriptor();
-        MimeDescriptorImpl mimeDescriptor = createDescriptor(0, 0, descriptor);
+        MimeDescriptorImpl mimeDescriptor = createDescriptor(0, 0, descriptor, 
null, headers);
         int next = parser.next();
         while (next != MimeTokenStream.T_END_MULTIPART && next != 
MimeTokenStream.T_END_OF_STREAM) {
             if (next == MimeTokenStream.T_START_BODYPART) {
@@ -80,32 +86,40 @@
     }
     
     private static MimeDescriptorImpl simplePartDescriptor(
-            final MimeTokenStream parser) throws IOException {
-        final InputStream body = parser.getInputStream();
-        long bodyOctets = 0;
-        long lines = 0;
-        for (int n=body.read();n>=0;n=body.read())  {
-            if (n == '\r') {
-                lines++;
+            final MimeTokenStream parser, final Collection headers) throws 
IOException {
+        MaximalBodyDescriptor descriptor = (MaximalBodyDescriptor) 
parser.getBodyDescriptor();
+        final MimeDescriptorImpl mimeDescriptorImpl;
+        if ("message".equalsIgnoreCase(descriptor.getMediaType()) && 
"rfc822".equalsIgnoreCase(descriptor.getSubType())) {
+            final CountingInputStream messageStream = new 
CountingInputStream(parser.getDecodedInputStream());
+            MimeDescriptorImpl embeddedMessageDescriptor = 
build(messageStream);
+            final int octetCount = messageStream.getOctetCount();
+            final int lineCount = messageStream.getLineCount();
+            
+            mimeDescriptorImpl = createDescriptor(octetCount, lineCount, 
descriptor, embeddedMessageDescriptor, headers);
+        } else {
+            final InputStream body = parser.getInputStream();
+            long bodyOctets = 0;
+            long lines = 0;
+            for (int n=body.read();n>=0;n=body.read())  {
+                if (n == '\r') {
+                    lines++;
+                }
+                bodyOctets++;
             }
-            bodyOctets++;
+            
+            mimeDescriptorImpl = createDescriptor(bodyOctets, lines, 
descriptor, null, headers);
         }
-        
-        MaximalBodyDescriptor descriptor = (MaximalBodyDescriptor) 
parser.getBodyDescriptor();
-        final MimeDescriptorImpl mimeDescriptorImpl = createDescriptor(
-                bodyOctets, lines, descriptor);
         return mimeDescriptorImpl;
     }
 
     private static MimeDescriptorImpl createDescriptor(long bodyOctets,
-            long lines, MaximalBodyDescriptor descriptor) {
+            long lines, MaximalBodyDescriptor descriptor, MimeDescriptor 
embeddedMessage, final Collection headers) {
         final String contentDescription = descriptor.getContentDescription();
         final String contentId = descriptor.getContentId();
         
         final String subType = descriptor.getSubType();
         final String type = descriptor.getMediaType();
         final String transferEncoding = descriptor.getTransferEncoding();
-        final Collection headers = new ArrayList();
         final Collection contentTypeParameters = new ArrayList();
         final Map valuesByName = descriptor.getContentTypeParameters();
         for (final Iterator it=valuesByName.keySet().iterator(); it.hasNext(); 
) {
@@ -134,7 +148,6 @@
         final List languages = descriptor.getContentLanguage();
         final String disposition = descriptor.getContentDispositionType();
         final Map dispositionParams = 
descriptor.getContentDispositionParameters();
-        final MessageResult.MimeDescriptor embeddedMessage = null;
         final Collection parts = new ArrayList();
         final String location = descriptor.getContentLocation();
         final String md5 = descriptor.getContentMD5Raw();
@@ -253,4 +266,35 @@
         return md5;
     }
 
+    private static final class CountingInputStream extends InputStream {
+
+        private final InputStream in;
+        
+        private int lineCount;
+        private int octetCount;
+        
+        private CountingInputStream(InputStream in) {
+            super();
+            this.in = in;
+        }
+
+        public int read() throws IOException {
+            int next = in.read();
+            if (next >0) {
+                octetCount++;
+                if (next == '\r') {
+                    lineCount++;
+                }
+            }
+            return next;
+        }
+
+        public final int getLineCount() {
+            return lineCount;
+        }
+
+        public final int getOctetCount() {
+            return octetCount;
+        }
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to