You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ba...@apache.org on 2006/10/10 10:35:02 UTC

svn commit: r454662 [13/15] - in /james/server/sandbox/imap-integration: ./ src/java/org/apache/james/imapserver/ src/java/org/apache/james/imapserver/commands/ src/java/org/apache/james/imapserver/debug/ src/java/org/apache/james/imapserver/store/ src...

Modified: james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/wrapper/UidToMsnBidiMap.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/wrapper/UidToMsnBidiMap.java?view=diff&rev=454662&r1=454661&r2=454662
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/wrapper/UidToMsnBidiMap.java (original)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/wrapper/UidToMsnBidiMap.java Tue Oct 10 01:34:56 2006
@@ -9,102 +9,102 @@
 
 public class UidToMsnBidiMap {
 
-	protected SortedMap msnToUid;
+    protected SortedMap msnToUid;
 
-	protected SortedMap uidToMsn;
+    protected SortedMap uidToMsn;
 
-	protected long highestUid = 0;
-	
-	protected int highestMsn = 0;
-
-	public UidToMsnBidiMap() {
-		msnToUid = new TreeMap();
-		uidToMsn = new TreeMap();
-	}
-
-	public synchronized long getUid(int msn) {
-		if (msn == -1) {
-			return -1;
-		}
-		Long uid = (Long) msnToUid.get(new Integer(msn));
-		if (uid != null) {
-			return uid.longValue();
-		} else {
-			if (msn > 0) {
-				return highestUid;
-			} else {
-				return 0;
-			}
-		}
-	}
-
-	public synchronized int getMsn(long uid) {
-		Integer msn = (Integer) uidToMsn.get(new Long(uid));
-		if (msn != null) {
-			return msn.intValue();
-		} else {
-			return -1;
-		}
-
-	}
-
-	protected synchronized void add(int msn, long uid) {
-		if (uid > highestUid) {
-			highestUid = uid;
-		}
-		msnToUid.put(new Integer(msn), new Long(uid));
-		uidToMsn.put(new Long(uid), new Integer(msn));
-	}
-
-	
-	
-	public synchronized void expunge(long uid) {
-		int msn=getMsn(uid);
-		remove(msn,uid);
-		List renumberMsns=new ArrayList(msnToUid.tailMap(new Integer(msn+1)).keySet());
-		for (Iterator iter = renumberMsns.iterator(); iter.hasNext();) {
-			int aMsn = ((Integer) iter.next()).intValue();
-			long aUid= getUid(aMsn);
-			remove(aMsn,aUid);
-			add(aMsn-1,aUid);
-		}
-		highestMsn--;
-		assertValidity();
-	}
-	
-	protected void remove(int msn,long uid) {
-		uidToMsn.remove(new Long(uid));
-		msnToUid.remove(new Integer(msn));
-	}
-	
+    protected long highestUid = 0;
+    
+    protected int highestMsn = 0;
+
+    public UidToMsnBidiMap() {
+        msnToUid = new TreeMap();
+        uidToMsn = new TreeMap();
+    }
+
+    public synchronized long getUid(int msn) {
+        if (msn == -1) {
+            return -1;
+        }
+        Long uid = (Long) msnToUid.get(new Integer(msn));
+        if (uid != null) {
+            return uid.longValue();
+        } else {
+            if (msn > 0) {
+                return highestUid;
+            } else {
+                return 0;
+            }
+        }
+    }
+
+    public synchronized int getMsn(long uid) {
+        Integer msn = (Integer) uidToMsn.get(new Long(uid));
+        if (msn != null) {
+            return msn.intValue();
+        } else {
+            return -1;
+        }
+
+    }
+
+    protected synchronized void add(int msn, long uid) {
+        if (uid > highestUid) {
+            highestUid = uid;
+        }
+        msnToUid.put(new Integer(msn), new Long(uid));
+        uidToMsn.put(new Long(uid), new Integer(msn));
+    }
+
+    
+    
+    public synchronized void expunge(long uid) {
+        int msn=getMsn(uid);
+        remove(msn,uid);
+        List renumberMsns=new ArrayList(msnToUid.tailMap(new Integer(msn+1)).keySet());
+        for (Iterator iter = renumberMsns.iterator(); iter.hasNext();) {
+            int aMsn = ((Integer) iter.next()).intValue();
+            long aUid= getUid(aMsn);
+            remove(aMsn,aUid);
+            add(aMsn-1,aUid);
+        }
+        highestMsn--;
+        assertValidity();
+    }
+    
+    protected void remove(int msn,long uid) {
+        uidToMsn.remove(new Long(uid));
+        msnToUid.remove(new Integer(msn));
+    }
+    
     synchronized void assertValidity() {
-    	Integer[] msns=(Integer[])msnToUid.keySet().toArray(new Integer[0]);
-    	for (int i = 0; i < msns.length; i++) {
-			if (msns[i].intValue()!=(i+1)) {
-				throw new AssertionError("Msn at position "+(i+1)+" was "+msns[i].intValue());
-			}
-		}
-    	if (msns[msns.length-1].intValue()!=highestMsn) {
-    		throw new AssertionError("highestMsn "+highestMsn+" msns[msns.length-1] "+msns[msns.length-1]);
-    	}
-		if (!msnToUid.keySet().equals(new TreeSet(uidToMsn.values()))) {
-			System.out.println(msnToUid.keySet());
-			System.out.println(uidToMsn.values());
-			throw new AssertionError("msnToUid.keySet() does not equal uidToMsn.values()");
-		}
-		if (!uidToMsn.keySet().equals(new TreeSet(msnToUid.values()))) {
-			System.out.println(uidToMsn.keySet());
-			System.out.println(msnToUid.values());
-			throw new AssertionError("uidToMsn.keySet() does not equal msnToUid.values()");
-		}
-
-	}
-
-	public synchronized void add(long uid) {
-		if (!uidToMsn.containsKey(new Long(uid))) {
-			highestMsn++;
-			add(highestMsn, uid);
-		}
-	}
+        Integer[] msns=(Integer[])msnToUid.keySet().toArray(new Integer[0]);
+        for (int i = 0; i < msns.length; i++) {
+            if (msns[i].intValue()!=(i+1)) {
+                throw new AssertionError("Msn at position "+(i+1)+" was "+msns[i].intValue());
+            }
+        }
+        if (msns[msns.length-1].intValue()!=highestMsn) {
+            throw new AssertionError("highestMsn "+highestMsn+" msns[msns.length-1] "+msns[msns.length-1]);
+        }
+        if (!msnToUid.keySet().equals(new TreeSet(uidToMsn.values()))) {
+            System.out.println(msnToUid.keySet());
+            System.out.println(uidToMsn.values());
+            throw new AssertionError("msnToUid.keySet() does not equal uidToMsn.values()");
+        }
+        if (!uidToMsn.keySet().equals(new TreeSet(msnToUid.values()))) {
+            System.out.println(uidToMsn.keySet());
+            System.out.println(msnToUid.values());
+            throw new AssertionError("uidToMsn.keySet() does not equal msnToUid.values()");
+        }
+
+    }
+
+    public synchronized void add(long uid) {
+        if (!uidToMsn.containsKey(new Long(uid))) {
+            highestMsn++;
+            add(highestMsn, uid);
+        }
+    }
 
 }

Propchange: james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/wrapper/UidToMsnBidiMap.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/server/sandbox/imap-integration/src/java/org/apache/james/util/Assert.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/util/Assert.java?view=diff&rev=454662&r1=454661&r2=454662
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/util/Assert.java (original)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/util/Assert.java Tue Oct 10 01:34:56 2006
@@ -1,61 +1,61 @@
-/****************************************************************
- * 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.util;
-
-
-/**
- * A set of debugging utilities.
- */
-public final class Assert
-{
-    public static final boolean ON = true;
-
-    // Can't instantiate.
-    private Assert()
-    {
-    };
-
-    /**
-     * Checks the supplied boolean expression, throwing an AssertionException if false;
-     */
-    public static void isTrue( boolean expression )
-    {
-        if ( !expression ) {
-            throw new RuntimeException( "Assertion Failed." );
-        }
-    }
-
-    /**
-     * Fails with an assertion exception.
-     */
-    public static void fail()
-    {
-        throw new RuntimeException( "Assertion error - should not reach here." );
-    }
-
-    /**
-     * Fails, indicating not-yet-implemented features.
-     */
-    public static void notImplemented()
-    {
-        throw new RuntimeException( "Not implemented" );
-    }
-
-}
+/****************************************************************
+ * 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.util;
+
+
+/**
+ * A set of debugging utilities.
+ */
+public final class Assert
+{
+    public static final boolean ON = true;
+
+    // Can't instantiate.
+    private Assert()
+    {
+    };
+
+    /**
+     * Checks the supplied boolean expression, throwing an AssertionException if false;
+     */
+    public static void isTrue( boolean expression )
+    {
+        if ( !expression ) {
+            throw new RuntimeException( "Assertion Failed." );
+        }
+    }
+
+    /**
+     * Fails with an assertion exception.
+     */
+    public static void fail()
+    {
+        throw new RuntimeException( "Assertion error - should not reach here." );
+    }
+
+    /**
+     * Fails, indicating not-yet-implemented features.
+     */
+    public static void notImplemented()
+    {
+        throw new RuntimeException( "Not implemented" );
+    }
+
+}

Propchange: james/server/sandbox/imap-integration/src/java/org/apache/james/util/Assert.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/TestConstants.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/TestConstants.java?view=diff&rev=454662&r1=454661&r2=454662
==============================================================================
--- james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/TestConstants.java (original)
+++ james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/TestConstants.java Tue Oct 10 01:34:56 2006
@@ -2,15 +2,15 @@
 
 public interface TestConstants
 {
-	final static String USER_NAME="tuser";
+    final static String USER_NAME="tuser";
     final static String USER_MAILBOX_ROOT=ImapConstants.USER_NAMESPACE+"."+USER_NAME;
-	final static String USER_PASSWORD="abc";
-	final static String USER_REALNAME="Test User";
-	
-	final static String HOST_NAME="localhost";
-	final static String HOST_ADDRESS="127.0.0.1";
-	final static int HOST_PORT=10143;
-	
+    final static String USER_PASSWORD="abc";
+    final static String USER_REALNAME="Test User";
+    
+    final static String HOST_NAME="localhost";
+    final static String HOST_ADDRESS="127.0.0.1";
+    final static int HOST_PORT=10143;
+    
 
-	
+    
 }

Propchange: james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/TestConstants.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/AbstractCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/AbstractCommand.java?view=diff&rev=454662&r1=454661&r2=454662
==============================================================================
--- james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/AbstractCommand.java (original)
+++ james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/AbstractCommand.java Tue Oct 10 01:34:56 2006
@@ -8,20 +8,20 @@
 
 public abstract class AbstractCommand implements Command {
 
-	protected List responseList = new LinkedList();
-	protected String statusResponse = null;
-	protected String command = null; 
+    protected List responseList = new LinkedList();
+    protected String statusResponse = null;
+    protected String command = null; 
 
-	public List getExpectedResponseList() throws MessagingException, IOException {
-		return responseList ;
-	}
+    public List getExpectedResponseList() throws MessagingException, IOException {
+        return responseList ;
+    }
 
-	public String getExpectedStatusResponse() {
-		return statusResponse;
-	}
+    public String getExpectedStatusResponse() {
+        return statusResponse;
+    }
 
-	public String getCommand() {
-		return command;
-	}
+    public String getCommand() {
+        return command;
+    }
 
 }

Propchange: james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/AbstractCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/Command.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/Command.java?view=diff&rev=454662&r1=454661&r2=454662
==============================================================================
--- james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/Command.java (original)
+++ james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/Command.java Tue Oct 10 01:34:56 2006
@@ -7,18 +7,18 @@
 
 public interface Command {
 
-	public List getExpectedResponseList() throws MessagingException, IOException;
+    public List getExpectedResponseList() throws MessagingException, IOException;
 
-	/**
-	 * Untagged, without leading space or trailing newline.<br>
-	 * e.g. : "OK LOGIN completed."
-	 */
-	public String getExpectedStatusResponse();
+    /**
+     * Untagged, without leading space or trailing newline.<br>
+     * e.g. : "OK LOGIN completed."
+     */
+    public String getExpectedStatusResponse();
 
-	/**
-	 * Untagged, without leading space with trailing newline. <br>
-	 *  e.g. : "LOGIN user password\n"
-	 */
-	public String getCommand();
+    /**
+     * Untagged, without leading space with trailing newline. <br>
+     *  e.g. : "LOGIN user password\n"
+     */
+    public String getCommand();
 
 }

Propchange: james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/Command.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/CopyClientCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/CopyClientCommand.java?view=diff&rev=454662&r1=454661&r2=454662
==============================================================================
--- james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/CopyClientCommand.java (original)
+++ james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/CopyClientCommand.java Tue Oct 10 01:34:56 2006
@@ -1,14 +1,14 @@
 package org.apache.james.imapserver.client;
 
 public class CopyClientCommand extends AbstractCommand {
-	
-	public CopyClientCommand(MessageSet set,String destination) {
-		command = "";
-		if (set.isUid())  { 
-			command ="UID ";
-		}
-		command += "COPY "+set + " \""+destination+"\"";
-		statusResponse="OK COPY completed.";
-	}
+    
+    public CopyClientCommand(MessageSet set,String destination) {
+        command = "";
+        if (set.isUid())  { 
+            command ="UID ";
+        }
+        command += "COPY "+set + " \""+destination+"\"";
+        statusResponse="OK COPY completed.";
+    }
 
 }

Propchange: james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/CopyClientCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/CreateClientCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/CreateClientCommand.java?view=diff&rev=454662&r1=454661&r2=454662
==============================================================================
--- james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/CreateClientCommand.java (original)
+++ james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/CreateClientCommand.java Tue Oct 10 01:34:56 2006
@@ -2,8 +2,8 @@
 
 public class CreateClientCommand extends AbstractCommand {
 
-	public CreateClientCommand(String folder) {
-		command = "CREATE \""+folder+"\"";
-		statusResponse="OK CREATE completed.";
-	}
+    public CreateClientCommand(String folder) {
+        command = "CREATE \""+folder+"\"";
+        statusResponse="OK CREATE completed.";
+    }
 }

Propchange: james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/CreateClientCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/DeleteClientCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/DeleteClientCommand.java?view=diff&rev=454662&r1=454661&r2=454662
==============================================================================
--- james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/DeleteClientCommand.java (original)
+++ james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/DeleteClientCommand.java Tue Oct 10 01:34:56 2006
@@ -2,8 +2,8 @@
 
 public class DeleteClientCommand extends AbstractCommand {
 
-	public DeleteClientCommand(String folder) {
-		command = "DELETE \""+folder+"\"";
-		statusResponse="OK DELETE completed.";
-	}
+    public DeleteClientCommand(String folder) {
+        command = "DELETE \""+folder+"\"";
+        statusResponse="OK DELETE completed.";
+    }
 }

Propchange: james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/DeleteClientCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/FetchCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/FetchCommand.java?view=diff&rev=454662&r1=454661&r2=454662
==============================================================================
--- james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/FetchCommand.java (original)
+++ james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/FetchCommand.java Tue Oct 10 01:34:56 2006
@@ -15,211 +15,211 @@
 
 public class FetchCommand extends AbstractCommand {
 
-	final long from;
+    final long from;
 
-	final long to;
+    final long to;
 
-	boolean uid;
+    boolean uid;
 
-	private MimeMessage[] msgs;
+    private MimeMessage[] msgs;
 
-	private long[] uids;
-
-	private boolean fetchFlags;
-
-	private boolean fetchRfc822Size;
-	
-	private FetchBody body;
-
-	public FetchCommand(MimeMessage[] msgs, long from, long to) {
-		statusResponse = "OK FETCH completed.";
-		this.msgs = msgs;
-		this.from = from;
-		this.to = to;
-	}
-	
-	public void setUids(long[] uids) {
-		this.uids=uids;
-		this.uid=true;
-	}
-
-	public String getCommand() {
-		String command = "";
-		if (uid) {
-			command += "UID ";
-		}
-		command += "fetch " + from + ":";
-		if (to > 0) {
-			command += to;
-		} else {
-			command += "*";
-		}
-		command += " (";
-		String items="";
-		// FLAGS
-		if (fetchFlags) {
-			items += " FLAGS";	
-		}
-		// RFC822.SIZE
-		if (fetchRfc822Size) {
-			items += " RFC822.SIZE";
-		}
-		// BODY
-		if (body!=null) {
-			items += " "+body.getCommand();
-		}
-		
-		
-		if (items.length()>0) {
-			items=items.substring(1);
-		}
-
-		command += items+")\n";
-		return command;
-	}
-
-	private List getSelectedMessageNumbers() {
-		List selectedNumbers = new ArrayList();
-		
-		
-		if (uid) {
-			final long to;
-			if (this.to>0) {
-				to=this.to;
-			} else {
-				to=Long.MAX_VALUE;
-			}
-			for (int i=0; i< msgs.length; i++) {
-				if (uids[i]>=from && uids[i]<=to)  {
-					selectedNumbers.add(new Integer((int)i+1));
-				}
-			}
-
-		} else {
-			final long from;
-			if (this.from > 0) {
-				from = this.from;
-			} else {
-				from = 1;
-			}
-
-			final long to;
-			if (this.to > 0) {
-				if (this.to > msgs.length) {
-					to = msgs.length;
-				} else {
-					to = this.to;
-				}
-			} else {
-				to = msgs.length;
-			}
-
-			for (long i = from; i <= to; i++) {
-				selectedNumbers.add(new Integer((int)i));
-			}
-		}
-		
-		return selectedNumbers;
-	}
-	public String getResultForMessageNumber(int no) throws MessagingException, IOException {
-		final MimeMessage mm = msgs[no-1];
-		String result = "";
-		
-		// FLAGS
-		if (fetchFlags) {
-			result +=" FLAGS ("+flagsToString(mm.getFlags())+")";
-		}
-		
-		// UID
-		if (uid) {
-			final long uid=uids[no-1];
-			result += " UID "+uid;
-		}
-		
-		// RFC822.SIZE
-		if (fetchRfc822Size) {
-			final int size=mm.getSize();
-			result += " RFC822.SIZE "+size;
-		}
+    private long[] uids;
+
+    private boolean fetchFlags;
+
+    private boolean fetchRfc822Size;
+    
+    private FetchBody body;
+
+    public FetchCommand(MimeMessage[] msgs, long from, long to) {
+        statusResponse = "OK FETCH completed.";
+        this.msgs = msgs;
+        this.from = from;
+        this.to = to;
+    }
+    
+    public void setUids(long[] uids) {
+        this.uids=uids;
+        this.uid=true;
+    }
+
+    public String getCommand() {
+        String command = "";
+        if (uid) {
+            command += "UID ";
+        }
+        command += "fetch " + from + ":";
+        if (to > 0) {
+            command += to;
+        } else {
+            command += "*";
+        }
+        command += " (";
+        String items="";
+        // FLAGS
+        if (fetchFlags) {
+            items += " FLAGS";  
+        }
+        // RFC822.SIZE
+        if (fetchRfc822Size) {
+            items += " RFC822.SIZE";
+        }
+        // BODY
+        if (body!=null) {
+            items += " "+body.getCommand();
+        }
+        
+        
+        if (items.length()>0) {
+            items=items.substring(1);
+        }
+
+        command += items+")\n";
+        return command;
+    }
+
+    private List getSelectedMessageNumbers() {
+        List selectedNumbers = new ArrayList();
+        
+        
+        if (uid) {
+            final long to;
+            if (this.to>0) {
+                to=this.to;
+            } else {
+                to=Long.MAX_VALUE;
+            }
+            for (int i=0; i< msgs.length; i++) {
+                if (uids[i]>=from && uids[i]<=to)  {
+                    selectedNumbers.add(new Integer((int)i+1));
+                }
+            }
+
+        } else {
+            final long from;
+            if (this.from > 0) {
+                from = this.from;
+            } else {
+                from = 1;
+            }
+
+            final long to;
+            if (this.to > 0) {
+                if (this.to > msgs.length) {
+                    to = msgs.length;
+                } else {
+                    to = this.to;
+                }
+            } else {
+                to = msgs.length;
+            }
+
+            for (long i = from; i <= to; i++) {
+                selectedNumbers.add(new Integer((int)i));
+            }
+        }
+        
+        return selectedNumbers;
+    }
+    public String getResultForMessageNumber(int no) throws MessagingException, IOException {
+        final MimeMessage mm = msgs[no-1];
+        String result = "";
+        
+        // FLAGS
+        if (fetchFlags) {
+            result +=" FLAGS ("+flagsToString(mm.getFlags())+")";
+        }
+        
+        // UID
+        if (uid) {
+            final long uid=uids[no-1];
+            result += " UID "+uid;
+        }
+        
+        // RFC822.SIZE
+        if (fetchRfc822Size) {
+            final int size=mm.getSize();
+            result += " RFC822.SIZE "+size;
+        }
 
         // BODY
-		if (body!=null) {
-			result += " "+body.getResult(mm);
-		}
-		
-		if (result.length()>0) {
-    		 // without leading space
-			result=result.substring(1);
-		}
-		return result;
-	}
-	
-	public List getExpectedResponseList() throws MessagingException, IOException {
-		List responseList = new LinkedList();
-
-		List selectedNumbers = getSelectedMessageNumbers();
-		
-		for (Iterator it = selectedNumbers.iterator(); it.hasNext();) {
-			final int no=((Integer)it.next()).intValue();
-			String line = "* " + no + " FETCH (";
-			line += getResultForMessageNumber(no);
-			line += ")";
-			responseList.add(line);
-		}
-		return responseList;
-
-	}
-
-	public static String flagToString(Flag flag) {
-		if (flag.equals(Flag.ANSWERED)) {
-			return "\\Answered";
-		}
+        if (body!=null) {
+            result += " "+body.getResult(mm);
+        }
+        
+        if (result.length()>0) {
+             // without leading space
+            result=result.substring(1);
+        }
+        return result;
+    }
+    
+    public List getExpectedResponseList() throws MessagingException, IOException {
+        List responseList = new LinkedList();
+
+        List selectedNumbers = getSelectedMessageNumbers();
+        
+        for (Iterator it = selectedNumbers.iterator(); it.hasNext();) {
+            final int no=((Integer)it.next()).intValue();
+            String line = "* " + no + " FETCH (";
+            line += getResultForMessageNumber(no);
+            line += ")";
+            responseList.add(line);
+        }
+        return responseList;
+
+    }
+
+    public static String flagToString(Flag flag) {
+        if (flag.equals(Flag.ANSWERED)) {
+            return "\\Answered";
+        }
         if (flag.equals(Flag.DELETED)) {
             return "\\Deleted";
         }
         if (flag.equals(Flag.DRAFT)) {
             return "\\Draft";
         }
-		if (flag.equals(Flag.FLAGGED)) {
-			return "\\Flagged";
-		}
-		if (flag.equals(Flag.RECENT)) {
-			return "\\Recent";
-		}
-		if (flag.equals(Flag.SEEN)) {
-			return "\\Seen";
-		}
-		throw new IllegalArgumentException("unknown Flag: "+flag);
-
-	}
-	
-	public static  String flagsToString(Flags flags) {
-		String result="";
-		Flag[] f=flags.getSystemFlags();
-		for (int i = 0; i < f.length; i++) {
-			result +=" "+flagToString(f[i]);
-		}
-		if (result.length()>0) {
-     		 // without leading space
-			result=result.substring(1);
-		}
-		return result;
-	}
-
-	public void setFetchFlags(boolean fetchFlags) {
-		this.fetchFlags=fetchFlags;
-		
-	}
-
-	public void setFetchRfc822Size(boolean fetchRfc822Size) {
-		this.fetchRfc822Size=fetchRfc822Size;
-		
-	}
-	
-
-	public void setFetchBody(FetchBody body) {
-		this.body=body;
-		
-	}
+        if (flag.equals(Flag.FLAGGED)) {
+            return "\\Flagged";
+        }
+        if (flag.equals(Flag.RECENT)) {
+            return "\\Recent";
+        }
+        if (flag.equals(Flag.SEEN)) {
+            return "\\Seen";
+        }
+        throw new IllegalArgumentException("unknown Flag: "+flag);
+
+    }
+    
+    public static  String flagsToString(Flags flags) {
+        String result="";
+        Flag[] f=flags.getSystemFlags();
+        for (int i = 0; i < f.length; i++) {
+            result +=" "+flagToString(f[i]);
+        }
+        if (result.length()>0) {
+             // without leading space
+            result=result.substring(1);
+        }
+        return result;
+    }
+
+    public void setFetchFlags(boolean fetchFlags) {
+        this.fetchFlags=fetchFlags;
+        
+    }
+
+    public void setFetchRfc822Size(boolean fetchRfc822Size) {
+        this.fetchRfc822Size=fetchRfc822Size;
+        
+    }
+    
+
+    public void setFetchBody(FetchBody body) {
+        this.body=body;
+        
+    }
 
 }

Propchange: james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/FetchCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/LoginCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/LoginCommand.java?view=diff&rev=454662&r1=454661&r2=454662
==============================================================================
--- james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/LoginCommand.java (original)
+++ james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/LoginCommand.java Tue Oct 10 01:34:56 2006
@@ -3,11 +3,11 @@
 
 public class LoginCommand extends AbstractCommand {
 
-	
-	public LoginCommand(String userName, String password) {
-		command="LOGIN "+userName+" "+password+"\n";
-		statusResponse="OK LOGIN completed.";
-	}
+    
+    public LoginCommand(String userName, String password) {
+        command="LOGIN "+userName+" "+password+"\n";
+        statusResponse="OK LOGIN completed.";
+    }
 
 
 

Propchange: james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/LoginCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/LogoutClientCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/LogoutClientCommand.java?view=diff&rev=454662&r1=454661&r2=454662
==============================================================================
--- james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/LogoutClientCommand.java (original)
+++ james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/LogoutClientCommand.java Tue Oct 10 01:34:56 2006
@@ -2,10 +2,10 @@
 
 public class LogoutClientCommand extends AbstractCommand {
 
-	public LogoutClientCommand() {
-		command="LOGOUT\n";
-		statusResponse="OK LOGOUT completed.";
-		responseList.add("* BYE IMAP4rev1 Server logging out");
-	}
-	
+    public LogoutClientCommand() {
+        command="LOGOUT\n";
+        statusResponse="OK LOGOUT completed.";
+        responseList.add("* BYE IMAP4rev1 Server logging out");
+    }
+    
 }

Propchange: james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/LogoutClientCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/MessageSet.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/MessageSet.java?view=diff&rev=454662&r1=454661&r2=454662
==============================================================================
--- james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/MessageSet.java (original)
+++ james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/MessageSet.java Tue Oct 10 01:34:56 2006
@@ -7,43 +7,43 @@
 import javax.mail.internet.MimeMessage;
 
 public class MessageSet {
-	
-	private final long from;
-	private final long to;
+    
+    private final long from;
+    private final long to;
     private boolean useUid=false;
-	private long[] uids;
-	private MimeMessage[] msgs;
-	private ArrayList selectedMessageNumbers;
+    private long[] uids;
+    private MimeMessage[] msgs;
+    private ArrayList selectedMessageNumbers;
 
-	public MessageSet(MimeMessage[] msgs,long[] uids,long from,long to) {
-		this(msgs,from,to);
-		this.uids=uids;
+    public MessageSet(MimeMessage[] msgs,long[] uids,long from,long to) {
+        this(msgs,from,to);
+        this.uids=uids;
         this.useUid=true;
-	}
-	public MessageSet(MimeMessage[] msgs,long[] uids,long number) {
-		this(msgs,number);
-		this.uids=uids;
+    }
+    public MessageSet(MimeMessage[] msgs,long[] uids,long number) {
+        this(msgs,number);
+        this.uids=uids;
         this.useUid=true;
-	}
-	
-	public MessageSet(MimeMessage[] msgs,long from,long to) {
-		this(from,to);
-		this.msgs=msgs;
-	}
-	public MessageSet(MimeMessage[] msgs,long number) {
-		this(number);
-		this.msgs=msgs;
-	}
-	public MessageSet(long from,long to) {
-		this.from=from;
-		this.to=to;
-	}
-	public MessageSet(long number) {
-		this.from=-1;
-		this.to=number;
-	}
-	
-	public MessageSet(MimeMessage[] msgs, long from, long to, int[] numbers, long[] uids, boolean useUid) {
+    }
+    
+    public MessageSet(MimeMessage[] msgs,long from,long to) {
+        this(from,to);
+        this.msgs=msgs;
+    }
+    public MessageSet(MimeMessage[] msgs,long number) {
+        this(number);
+        this.msgs=msgs;
+    }
+    public MessageSet(long from,long to) {
+        this.from=from;
+        this.to=to;
+    }
+    public MessageSet(long number) {
+        this.from=-1;
+        this.to=number;
+    }
+    
+    public MessageSet(MimeMessage[] msgs, long from, long to, int[] numbers, long[] uids, boolean useUid) {
         if (useUid) {
             from=uids[(int)from-1];
             to=uids[(int)to-1];
@@ -60,75 +60,75 @@
 
     }
     public String toString() {
-		String result="";
-		if (from>0)  {
-			result += from +":";
-		}
-		if (to>0) {
-			result += to;
-		} else {
-			result += "*";
-		}
-		return result;
-	}
-	
-	public boolean isUid() {
-		return useUid;
-	}
-	
-	public List getSelectedMessageNumbers() {
-		if (selectedMessageNumbers==null) {
-			selectedMessageNumbers=new ArrayList();
-			if (isUid()) {
-				final long from;
-				if (this.from>0) {
-					from=this.from;
-				} else {
-					from=this.to;
-				}
-				final long to;
-				if (this.to>0) {
-					to=this.to;
-				} else {
-					to=Long.MAX_VALUE;
-				}
-				for (int i=0; i< msgs.length; i++) {
-					if (uids[i]>=from && uids[i]<=to)  {
-						selectedMessageNumbers.add(new Integer((int)i+1));
-					}
-				}
+        String result="";
+        if (from>0)  {
+            result += from +":";
+        }
+        if (to>0) {
+            result += to;
+        } else {
+            result += "*";
+        }
+        return result;
+    }
+    
+    public boolean isUid() {
+        return useUid;
+    }
+    
+    public List getSelectedMessageNumbers() {
+        if (selectedMessageNumbers==null) {
+            selectedMessageNumbers=new ArrayList();
+            if (isUid()) {
+                final long from;
+                if (this.from>0) {
+                    from=this.from;
+                } else {
+                    from=this.to;
+                }
+                final long to;
+                if (this.to>0) {
+                    to=this.to;
+                } else {
+                    to=Long.MAX_VALUE;
+                }
+                for (int i=0; i< msgs.length; i++) {
+                    if (uids[i]>=from && uids[i]<=to)  {
+                        selectedMessageNumbers.add(new Integer((int)i+1));
+                    }
+                }
 
-			} else {
-				final long from;
-				if (this.from > 0) {
-					from = this.from;
-				} else {
-					from = this.to;
-				}
+            } else {
+                final long from;
+                if (this.from > 0) {
+                    from = this.from;
+                } else {
+                    from = this.to;
+                }
 
-				final long to;
-				if (this.to > 0) {
-					if (this.to > msgs.length) {
-						to = msgs.length;
-					} else {
-						to = this.to;
-					}
-				} else {
-					to = msgs.length;
-				}
+                final long to;
+                if (this.to > 0) {
+                    if (this.to > msgs.length) {
+                        to = msgs.length;
+                    } else {
+                        to = this.to;
+                    }
+                } else {
+                    to = msgs.length;
+                }
 
-				for (long i = from; i <= to; i++) {
-					selectedMessageNumbers.add(new Integer((int)i));
-				}
-			}
-		}
-		return selectedMessageNumbers;
-	}
-	public MimeMessage getMessage(int no) {
-		return msgs[no-1];
-	}
-	public long getUid(int no) {
-		return uids[no-1];
-	}
+                for (long i = from; i <= to; i++) {
+                    selectedMessageNumbers.add(new Integer((int)i));
+                }
+            }
+        }
+        return selectedMessageNumbers;
+    }
+    public MimeMessage getMessage(int no) {
+        return msgs[no-1];
+    }
+    public long getUid(int no) {
+        return uids[no-1];
+    }
 
 }

Propchange: james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/MessageSet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/RenameClientCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/RenameClientCommand.java?view=diff&rev=454662&r1=454661&r2=454662
==============================================================================
--- james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/RenameClientCommand.java (original)
+++ james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/RenameClientCommand.java Tue Oct 10 01:34:56 2006
@@ -1,9 +1,9 @@
 package org.apache.james.imapserver.client;
 
 public class RenameClientCommand extends AbstractCommand {
-	
-	public RenameClientCommand(String folder,String destination) {
-		command = "RENAME \""+folder+"\" \""+destination+"\"";
-		statusResponse="OK RENAME completed.";
-	}
+    
+    public RenameClientCommand(String folder,String destination) {
+        command = "RENAME \""+folder+"\" \""+destination+"\"";
+        statusResponse="OK RENAME completed.";
+    }
 }

Propchange: james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/RenameClientCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/SelectCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/SelectCommand.java?view=diff&rev=454662&r1=454661&r2=454662
==============================================================================
--- james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/SelectCommand.java (original)
+++ james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/SelectCommand.java Tue Oct 10 01:34:56 2006
@@ -8,24 +8,24 @@
 import org.apache.james.imapserver.util.UnsolicitedResponseGenerator;
 
 public class SelectCommand extends AbstractCommand {
-	
-	int recentCount =0;
+    
+    int recentCount =0;
 
-	public SelectCommand(String folder,MimeMessage[] msgs,long uidv) throws MessagingException {
-		
-		command="SELECT \""+folder+"\"";
+    public SelectCommand(String folder,MimeMessage[] msgs,long uidv) throws MessagingException {
+        
+        command="SELECT \""+folder+"\"";
 
-		UnsolicitedResponseGenerator rg=new UnsolicitedResponseGenerator();
-		rg.addByMessages(msgs);
-		recentCount = rg.getRecent();
-		rg.addUidValidity(uidv);
-		responseList=new ArrayList(rg.getResponseSet());
-		statusResponse="OK [READ-WRITE] SELECT completed.";
-		
-	}
+        UnsolicitedResponseGenerator rg=new UnsolicitedResponseGenerator();
+        rg.addByMessages(msgs);
+        recentCount = rg.getRecent();
+        rg.addUidValidity(uidv);
+        responseList=new ArrayList(rg.getResponseSet());
+        statusResponse="OK [READ-WRITE] SELECT completed.";
+        
+    }
 
-	public int getRecentCount() {
-		return recentCount;
-	}
+    public int getRecentCount() {
+        return recentCount;
+    }
 
 }

Propchange: james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/SelectCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/StoreClientCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/StoreClientCommand.java?view=diff&rev=454662&r1=454661&r2=454662
==============================================================================
--- james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/StoreClientCommand.java (original)
+++ james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/StoreClientCommand.java Tue Oct 10 01:34:56 2006
@@ -10,71 +10,71 @@
 
 public class StoreClientCommand extends AbstractCommand {
 
-	public static final int MODE_SET = 0;
+    public static final int MODE_SET = 0;
 
-	public static final int MODE_ADD = 1;
+    public static final int MODE_ADD = 1;
 
-	public static final int MODE_REMOVE = 2;
+    public static final int MODE_REMOVE = 2;
 
-	private final int mode;
+    private final int mode;
 
-	private final boolean silent;
-
-	private final Flags flags;
-
-	private MessageSet set;
-
-	public StoreClientCommand(int mode, boolean silent, Flags flags,
-			MessageSet set) {
-		this.mode = mode;
-		this.silent = silent;
-		this.flags = flags;
-		this.set = set;
-		this.statusResponse = "OK STORE completed.";
-	}
-
-	public String getCommand() {
-		command = "";
-		if (set.isUid()) {
-			command = "UID ";
-		}
-		command += "STORE ";
-		command += set + " ";
-
-		if (mode == MODE_ADD) {
-			command += "+";
-		} else if (mode == MODE_REMOVE) {
-			command += "-";
-		}
-		command += "FLAGS";
-		if (silent) {
-			command += ".SILENT";
-		}
-		command += " (";
-		command += FetchCommand.flagsToString(flags);
-		command += ")";
-
-		return command;
-
-	}
-
-	public List getExpectedResponseList() throws MessagingException {
-		List responseList = new LinkedList();
-		if (!silent) {
-			List selectedNumbers = set.getSelectedMessageNumbers();
-			for (Iterator it = selectedNumbers.iterator(); it.hasNext();) {
-				final int no = ((Integer) it.next()).intValue();
-				final MimeMessage mm = set.getMessage(no);
-				String line = "* " + no + " FETCH (";
-				line += "FLAGS (" + FetchCommand.flagsToString(mm.getFlags())
-						+ ")";
-				if (set.isUid()) {
-					line += " UID " + set.getUid(no);
-				}
-				line += ")";
-				responseList.add(line);
-			}
-		}
-		return responseList;
-	}
+    private final boolean silent;
+
+    private final Flags flags;
+
+    private MessageSet set;
+
+    public StoreClientCommand(int mode, boolean silent, Flags flags,
+            MessageSet set) {
+        this.mode = mode;
+        this.silent = silent;
+        this.flags = flags;
+        this.set = set;
+        this.statusResponse = "OK STORE completed.";
+    }
+
+    public String getCommand() {
+        command = "";
+        if (set.isUid()) {
+            command = "UID ";
+        }
+        command += "STORE ";
+        command += set + " ";
+
+        if (mode == MODE_ADD) {
+            command += "+";
+        } else if (mode == MODE_REMOVE) {
+            command += "-";
+        }
+        command += "FLAGS";
+        if (silent) {
+            command += ".SILENT";
+        }
+        command += " (";
+        command += FetchCommand.flagsToString(flags);
+        command += ")";
+
+        return command;
+
+    }
+
+    public List getExpectedResponseList() throws MessagingException {
+        List responseList = new LinkedList();
+        if (!silent) {
+            List selectedNumbers = set.getSelectedMessageNumbers();
+            for (Iterator it = selectedNumbers.iterator(); it.hasNext();) {
+                final int no = ((Integer) it.next()).intValue();
+                final MimeMessage mm = set.getMessage(no);
+                String line = "* " + no + " FETCH (";
+                line += "FLAGS (" + FetchCommand.flagsToString(mm.getFlags())
+                        + ")";
+                if (set.isUid()) {
+                    line += " UID " + set.getUid(no);
+                }
+                line += ")";
+                responseList.add(line);
+            }
+        }
+        return responseList;
+    }
 }

Propchange: james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/StoreClientCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/fetch/FetchBody.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/fetch/FetchBody.java?view=diff&rev=454662&r1=454661&r2=454662
==============================================================================
--- james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/fetch/FetchBody.java (original)
+++ james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/fetch/FetchBody.java Tue Oct 10 01:34:56 2006
@@ -9,53 +9,53 @@
 
 public class FetchBody {
 
-	final boolean peek;
+    final boolean peek;
 
-	private FetchHeader fetchHeader;
+    private FetchHeader fetchHeader;
 
-	public FetchBody(boolean peek) {
-		this.peek = peek;
-	}
-
-	public String getCommand() {
-		String result= "";
-		if (peek) {
-			result += "BODY.PEEK[";
-		} else {
-			result += "BODY[";
-		}
-		if (fetchHeader!=null) {
-			result += fetchHeader.getCommand();
-		}
-		result += "]";
-		return result;
-	}
-
-	public String getResult(MimeMessage m) throws IOException,
-			MessagingException {
-		// TODO decide whether it should be BODY.PEEK when peek!
-		String result = "BODY[";
-		final String data;
-		if (fetchHeader != null) {
-			result += fetchHeader.getCommand();
-			data = fetchHeader.getData(m);
-		} else {
-			data = getData(m);
-		}
-		result += "] {" + data.length() + "}\r\n" + data;
-		// TODO Shouldn't we append another CRLF?
-		return result;
-	}
-
-	private String getData(MimeMessage m) throws IOException,
-			MessagingException {
-		String data = MessageGenerator.messageContentToString(m);
-		return data;
-	}
+    public FetchBody(boolean peek) {
+        this.peek = peek;
+    }
+
+    public String getCommand() {
+        String result= "";
+        if (peek) {
+            result += "BODY.PEEK[";
+        } else {
+            result += "BODY[";
+        }
+        if (fetchHeader!=null) {
+            result += fetchHeader.getCommand();
+        }
+        result += "]";
+        return result;
+    }
+
+    public String getResult(MimeMessage m) throws IOException,
+            MessagingException {
+        // TODO decide whether it should be BODY.PEEK when peek!
+        String result = "BODY[";
+        final String data;
+        if (fetchHeader != null) {
+            result += fetchHeader.getCommand();
+            data = fetchHeader.getData(m);
+        } else {
+            data = getData(m);
+        }
+        result += "] {" + data.length() + "}\r\n" + data;
+        // TODO Shouldn't we append another CRLF?
+        return result;
+    }
+
+    private String getData(MimeMessage m) throws IOException,
+            MessagingException {
+        String data = MessageGenerator.messageContentToString(m);
+        return data;
+    }
 
-	public void setFetchHeader(FetchHeader fetchHeader) {
-		this.fetchHeader = fetchHeader;
+    public void setFetchHeader(FetchHeader fetchHeader) {
+        this.fetchHeader = fetchHeader;
 
-	}
+    }
 
 }

Propchange: james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/fetch/FetchBody.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/fetch/FetchHeader.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/fetch/FetchHeader.java?view=diff&rev=454662&r1=454661&r2=454662
==============================================================================
--- james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/fetch/FetchHeader.java (original)
+++ james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/fetch/FetchHeader.java Tue Oct 10 01:34:56 2006
@@ -7,47 +7,47 @@
 
 public class FetchHeader {
 
-	private String[] fields;
+    private String[] fields;
 
-	public String getCommand() {
-		if (fields == null) {
-			return "HEADER";
-		} else {
-			return "HEADER.FIELDS ("+getFormattedFieldList()+")";
-		}
-	}
+    public String getCommand() {
+        if (fields == null) {
+            return "HEADER";
+        } else {
+            return "HEADER.FIELDS ("+getFormattedFieldList()+")";
+        }
+    }
 
-	private String getFormattedFieldList() {
-		String result ="";
-		for (int i = 0; i < fields.length; i++) {
-			result +=" "+fields[i];
-			
-		}
-		if (result.length()>0) {
-			result=result.substring(1);
-		}
-		return result;
-	}
+    private String getFormattedFieldList() {
+        String result ="";
+        for (int i = 0; i < fields.length; i++) {
+            result +=" "+fields[i];
+            
+        }
+        if (result.length()>0) {
+            result=result.substring(1);
+        }
+        return result;
+    }
 
-	public String getData(MimeMessage m) throws MessagingException {
-		String result = "";
-		final Enumeration e;
-		if (fields==null) {
-		e= m.getAllHeaderLines();
-		} else {
-			e = m.getMatchingHeaderLines(fields);
-		}
-		while (e.hasMoreElements()) {
-			String line = (String) e.nextElement();
-			result += line + "\r\n";
-		}
-		result += "\r\n"; // TODO Should this be counted for size?
-		return result;
-	}
+    public String getData(MimeMessage m) throws MessagingException {
+        String result = "";
+        final Enumeration e;
+        if (fields==null) {
+        e= m.getAllHeaderLines();
+        } else {
+            e = m.getMatchingHeaderLines(fields);
+        }
+        while (e.hasMoreElements()) {
+            String line = (String) e.nextElement();
+            result += line + "\r\n";
+        }
+        result += "\r\n"; // TODO Should this be counted for size?
+        return result;
+    }
 
-	public void setFields(String[] fields) {
-		this.fields = fields;
+    public void setFields(String[] fields) {
+        this.fields = fields;
 
-	}
+    }
 
 }

Propchange: james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/client/fetch/FetchHeader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/handler/commands/AbstractCommandTest.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/handler/commands/AbstractCommandTest.java?view=diff&rev=454662&r1=454661&r2=454662
==============================================================================
--- james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/handler/commands/AbstractCommandTest.java (original)
+++ james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/handler/commands/AbstractCommandTest.java Tue Oct 10 01:34:56 2006
@@ -14,27 +14,27 @@
 public abstract class AbstractCommandTest extends MockObjectTestCase
 {
 
-	ImapRequestHandler handler;
-	Mock mockSession;
-	Mock mockUsersRepository;
-	Mock mockUser;
+    ImapRequestHandler handler;
+    Mock mockSession;
+    Mock mockUsersRepository;
+    Mock mockUser;
 
-	public void setUp() {
-		handler=new ImapRequestHandler();
-		mockSession = mock ( ImapSession.class);
-		mockUsersRepository = mock ( UsersRepository.class );
-		mockUser = mock (User.class );
-	}
-	
-	public String handleRequest(String s) throws ProtocolException {
-		ByteArrayInputStream is=new ByteArrayInputStream(s.getBytes());
-		ByteArrayOutputStream os=new ByteArrayOutputStream();
-		System.out.println("IN :"+s);
-		handler.handleRequest(is,os,(ImapSession) mockSession.proxy());
-		String out=os.toString();
-		System.out.println("OUT:"+out);
-		return out;
-	}
-	
+    public void setUp() {
+        handler=new ImapRequestHandler();
+        mockSession = mock ( ImapSession.class);
+        mockUsersRepository = mock ( UsersRepository.class );
+        mockUser = mock (User.class );
+    }
+    
+    public String handleRequest(String s) throws ProtocolException {
+        ByteArrayInputStream is=new ByteArrayInputStream(s.getBytes());
+        ByteArrayOutputStream os=new ByteArrayOutputStream();
+        System.out.println("IN :"+s);
+        handler.handleRequest(is,os,(ImapSession) mockSession.proxy());
+        String out=os.toString();
+        System.out.println("OUT:"+out);
+        return out;
+    }
+    
 
 }

Propchange: james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/handler/commands/AbstractCommandTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/handler/commands/LoginTest.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/handler/commands/LoginTest.java?view=diff&rev=454662&r1=454661&r2=454662
==============================================================================
--- james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/handler/commands/LoginTest.java (original)
+++ james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/handler/commands/LoginTest.java Tue Oct 10 01:34:56 2006
@@ -8,46 +8,46 @@
 public class LoginTest extends AbstractCommandTest
 {
 
-	public void testValidUserStateNonAuth() throws ProtocolException {
-		mockSession.expects(atLeastOnce()).method("getState").will(returnValue(ImapSessionState.NON_AUTHENTICATED));
-		mockSession.expects(atLeastOnce()).method("getUsers").will(returnValue(mockUsersRepository.proxy()));
-		
-		mockUsersRepository.expects(once()).method("test").with( eq("joachim2"),eq("abc")).will(returnValue(true));
-		mockUsersRepository.expects(once()).method("getUserByName").with( eq("joachim2")).will(returnValue(mockUser.proxy()));
-		
-		mockSession.expects(once()).method("setAuthenticated").with( same(mockUser.proxy()));
-
-		String response = handleRequest("1 LOGIN joachim2 abc\n");
-
-		assertEquals("1 OK LOGIN completed.\r\n",response);
-	}
-	public void testInvalidUserStateNonAuth() throws ProtocolException {
-		mockSession.expects(atLeastOnce()).method("getState").will(returnValue(ImapSessionState.NON_AUTHENTICATED));
-		mockSession.expects(atLeastOnce()).method("getUsers").will(returnValue(mockUsersRepository.proxy()));
-		
-		mockUsersRepository.expects(once()).method("test").with( eq("joachim2"),eq("abc")).will(returnValue(false));
-
-		String response = handleRequest("1 LOGIN joachim2 abc\n");
-
-		assertEquals("1 NO LOGIN failed. Invalid login/password\r\n",response);
-	}
-	public void testValidUserStateAuth() throws ProtocolException {
-		mockSession.expects(atLeastOnce()).method("getState").will(returnValue(ImapSessionState.AUTHENTICATED));
-
-		String response = handleRequest("1 LOGIN joachim2 abc\n");
-		assertEquals("1 NO LOGIN failed. Command not valid in this state\r\n",response);
-	}
-
-	public void testValidUserStateLogout() throws ProtocolException {
-		mockSession.expects(atLeastOnce()).method("getState").will(returnValue(ImapSessionState.LOGOUT));
-
-		String response = handleRequest("1 LOGIN joachim2 abc\n");
-		assertEquals("1 NO LOGIN failed. Command not valid in this state\r\n",response);
-	}
-	public void testValidUserStateSelected() throws ProtocolException {
-		mockSession.expects(atLeastOnce()).method("getState").will(returnValue(ImapSessionState.SELECTED));
-
-		String response = handleRequest("1 LOGIN joachim2 abc\n");
-		assertEquals("1 NO LOGIN failed. Command not valid in this state\r\n",response);
-	}
+    public void testValidUserStateNonAuth() throws ProtocolException {
+        mockSession.expects(atLeastOnce()).method("getState").will(returnValue(ImapSessionState.NON_AUTHENTICATED));
+        mockSession.expects(atLeastOnce()).method("getUsers").will(returnValue(mockUsersRepository.proxy()));
+        
+        mockUsersRepository.expects(once()).method("test").with( eq("joachim2"),eq("abc")).will(returnValue(true));
+        mockUsersRepository.expects(once()).method("getUserByName").with( eq("joachim2")).will(returnValue(mockUser.proxy()));
+        
+        mockSession.expects(once()).method("setAuthenticated").with( same(mockUser.proxy()));
+
+        String response = handleRequest("1 LOGIN joachim2 abc\n");
+
+        assertEquals("1 OK LOGIN completed.\r\n",response);
+    }
+    public void testInvalidUserStateNonAuth() throws ProtocolException {
+        mockSession.expects(atLeastOnce()).method("getState").will(returnValue(ImapSessionState.NON_AUTHENTICATED));
+        mockSession.expects(atLeastOnce()).method("getUsers").will(returnValue(mockUsersRepository.proxy()));
+        
+        mockUsersRepository.expects(once()).method("test").with( eq("joachim2"),eq("abc")).will(returnValue(false));
+
+        String response = handleRequest("1 LOGIN joachim2 abc\n");
+
+        assertEquals("1 NO LOGIN failed. Invalid login/password\r\n",response);
+    }
+    public void testValidUserStateAuth() throws ProtocolException {
+        mockSession.expects(atLeastOnce()).method("getState").will(returnValue(ImapSessionState.AUTHENTICATED));
+
+        String response = handleRequest("1 LOGIN joachim2 abc\n");
+        assertEquals("1 NO LOGIN failed. Command not valid in this state\r\n",response);
+    }
+
+    public void testValidUserStateLogout() throws ProtocolException {
+        mockSession.expects(atLeastOnce()).method("getState").will(returnValue(ImapSessionState.LOGOUT));
+
+        String response = handleRequest("1 LOGIN joachim2 abc\n");
+        assertEquals("1 NO LOGIN failed. Command not valid in this state\r\n",response);
+    }
+    public void testValidUserStateSelected() throws ProtocolException {
+        mockSession.expects(atLeastOnce()).method("getState").will(returnValue(ImapSessionState.SELECTED));
+
+        String response = handleRequest("1 LOGIN joachim2 abc\n");
+        assertEquals("1 NO LOGIN failed. Command not valid in this state\r\n",response);
+    }
 }

Propchange: james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/handler/commands/LoginTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/handler/session/AbstractSessionTest.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/handler/session/AbstractSessionTest.java?view=diff&rev=454662&r1=454661&r2=454662
==============================================================================
--- james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/handler/session/AbstractSessionTest.java (original)
+++ james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/handler/session/AbstractSessionTest.java Tue Oct 10 01:34:56 2006
@@ -40,75 +40,75 @@
 import org.jmock.MockObjectTestCase;
 
 public abstract class AbstractSessionTest extends MockObjectTestCase implements TestConstants {
-	
-	GeneralManager mailboxManager;
-	
-	private ImapRequestHandler handler;
-	private ImapSession session;
-	
-	int counter=0;
-	
-	public AbstractSessionTest() {
-	}
-	
-	public void setUp() throws MailboxException, MessagingException, IOException, MailboxManagerException
-	{
+    
+    GeneralManager mailboxManager;
+    
+    private ImapRequestHandler handler;
+    private ImapSession session;
+    
+    int counter=0;
+    
+    public AbstractSessionTest() {
+    }
+    
+    public void setUp() throws MailboxException, MessagingException, IOException, MailboxManagerException
+    {
         
-		MockImapHandlerConfigurationData theConfigData = new MockImapHandlerConfigurationData();
+        MockImapHandlerConfigurationData theConfigData = new MockImapHandlerConfigurationData();
         theConfigData.getMailboxManagerProvider().deleteEverything();
-		session = new ImapSessionImpl(theConfigData.getMailboxManagerProvider(),
-				theConfigData.getUsersRepository(), new MockImapHandler(),
-				HOST_NAME, HOST_ADDRESS);
-		handler = new ImapRequestHandler();
+        session = new ImapSessionImpl(theConfigData.getMailboxManagerProvider(),
+                theConfigData.getUsersRepository(), new MockImapHandler(),
+                HOST_NAME, HOST_ADDRESS);
+        handler = new ImapRequestHandler();
         mailboxManager=theConfigData.getMailboxManagerProvider().getGeneralManagerInstance(new MockUser());
 
-	}
-	
-	void createFolders(String[] folders) throws MailboxManagerException {
-		for (int i=0; i<folders.length; i++) {
-			mailboxManager.createMailbox(folders[i]);
-		}
-	}
-	
-	public void appendMessagesClosed(String folder,MimeMessage[] msgs) throws MailboxManagerException, MessagingException {
+    }
+    
+    void createFolders(String[] folders) throws MailboxManagerException {
+        for (int i=0; i<folders.length; i++) {
+            mailboxManager.createMailbox(folders[i]);
+        }
+    }
+    
+    public void appendMessagesClosed(String folder,MimeMessage[] msgs) throws MailboxManagerException, MessagingException {
         GeneralMailboxSession mailbox=getImapMailboxSession(folder);
         for (int i = 0; i < msgs.length; i++) {
             msgs[i].setFlags(new Flags(Flags.Flag.RECENT), true);
             mailbox.appendMessage(msgs[i],new Date(),MessageResult.NOTHING);
             
         }
-		mailbox.close();
-	}
+        mailbox.close();
+    }
 
-	public long[] addUIDMessagesOpen(String folder,MimeMessage[] msgs) throws MailboxManagerException, MessagingException {
-		GeneralMailboxSession mailbox=getImapMailboxSession(folder);
+    public long[] addUIDMessagesOpen(String folder,MimeMessage[] msgs) throws MailboxManagerException, MessagingException {
+        GeneralMailboxSession mailbox=getImapMailboxSession(folder);
         long[] uids=new long[msgs.length];
         for (int i = 0; i < msgs.length; i++) {
             msgs[i].setFlags(new Flags(Flags.Flag.RECENT), false);
             uids[i]=mailbox.appendMessage(msgs[i],new Date(),MessageResult.UID).getUid();
         }
         mailbox.close();
-		return uids;
-	}
-	public long getUidValidity(String folder) throws MailboxManagerException {
+        return uids;
+    }
+    public long getUidValidity(String folder) throws MailboxManagerException {
         ImapMailboxSession mailbox=getImapMailboxSession(folder);
         long uidv=mailbox.getUidValidity();
         mailbox.close();
-		return uidv;
-	}
-	
-	public MimeMessage[] getMessages(String folder) throws MailboxManagerException {
-		GeneralMailboxSession mailbox=getImapMailboxSession(folder);
+        return uidv;
+    }
+    
+    public MimeMessage[] getMessages(String folder) throws MailboxManagerException {
+        GeneralMailboxSession mailbox=getImapMailboxSession(folder);
         MessageResult[] messageResults=mailbox.getMessages(GeneralMessageSetImpl.all(),MessageResult.MIME_MESSAGE);
-		MimeMessage[] mms=new MimeMessage[messageResults.length];
-		for (int i = 0; i < messageResults.length; i++) {
-			mms[i]=messageResults[i].getMimeMessage();
-		}
-        mailbox.close();
-		return mms;
-	}
-	
-	public long[] getUids(String folder) throws MailboxManagerException {
+        MimeMessage[] mms=new MimeMessage[messageResults.length];
+        for (int i = 0; i < messageResults.length; i++) {
+            mms[i]=messageResults[i].getMimeMessage();
+        }
+        mailbox.close();
+        return mms;
+    }
+    
+    public long[] getUids(String folder) throws MailboxManagerException {
         GeneralMailboxSession mailbox=getImapMailboxSession(folder);
         MessageResult[] messageResults=mailbox.getMessages(GeneralMessageSetImpl.all(),MessageResult.UID);
 
@@ -118,36 +118,36 @@
         }
         mailbox.close();
         return uids;
-	}
-	
-	public boolean folderExists(String folder) throws MailboxManagerException {
-		return mailboxManager.existsMailbox(folder);
-	}
-	
-	public String[] getFolderNames() throws MailboxManagerException {
+    }
+    
+    public boolean folderExists(String folder) throws MailboxManagerException {
+        return mailboxManager.existsMailbox(folder);
+    }
+    
+    public String[] getFolderNames() throws MailboxManagerException {
         ListResult[] listResults=mailboxManager.list("","*",false);
-		String[] names=new String[listResults.length];
-		for (int i = 0; i < listResults.length; i++) {
-			names[i]=listResults[i].getName();
-		}
-		return names;
-	}
-	
-	public void verifyFolderList(String[] expected,String[] found) {
-		Set expectedSet=new HashSet(Arrays.asList(expected));
-		Set foundSet=new HashSet(Arrays.asList(found));
-		Set missing=new HashSet(expectedSet);
-		missing.removeAll(foundSet);
-		Set notExpected=new HashSet(foundSet);
-		notExpected.removeAll(expectedSet);
-		assertEquals("Missing folders :"+missing,0,missing.size());
-		assertEquals("Not expected folders :"+notExpected,0,notExpected.size());
-	}
-	
-	public boolean isOpen(String folder)  throws MessagingException {
+        String[] names=new String[listResults.length];
+        for (int i = 0; i < listResults.length; i++) {
+            names[i]=listResults[i].getName();
+        }
+        return names;
+    }
+    
+    public void verifyFolderList(String[] expected,String[] found) {
+        Set expectedSet=new HashSet(Arrays.asList(expected));
+        Set foundSet=new HashSet(Arrays.asList(found));
+        Set missing=new HashSet(expectedSet);
+        missing.removeAll(foundSet);
+        Set notExpected=new HashSet(foundSet);
+        notExpected.removeAll(expectedSet);
+        assertEquals("Missing folders :"+missing,0,missing.size());
+        assertEquals("Not expected folders :"+notExpected,0,notExpected.size());
+    }
+    
+    public boolean isOpen(String folder)  throws MessagingException {
         // TODO implement this
-		return false;
-	}
+        return false;
+    }
     public void useFolder(String folder) {
         
     }
@@ -155,101 +155,101 @@
         
     }
     
-	public void deleteAll(String folder) throws MailboxManagerException {
-		ImapMailboxSession mailbox=getImapMailboxSession(folder);
+    public void deleteAll(String folder) throws MailboxManagerException {
+        ImapMailboxSession mailbox=getImapMailboxSession(folder);
         mailbox.setFlags(new Flags(Flag.DELETED),true,false,GeneralMessageSetImpl.all(),null);
         mailbox.expunge(GeneralMessageSetImpl.all(),MessageResult.NOTHING);
         mailbox.close();
-	}
-	public BufferedReader handleRequestReader(String s) throws ProtocolException
-	{
-		return new BufferedReader(new StringReader(handleRequest(s)));
-	}
+    }
+    public BufferedReader handleRequestReader(String s) throws ProtocolException
+    {
+        return new BufferedReader(new StringReader(handleRequest(s)));
+    }
 
-	public String handleRequest(String s) throws ProtocolException
-	{
-		ByteArrayInputStream is = new ByteArrayInputStream(s.getBytes());
-		ByteArrayOutputStream os = new ByteArrayOutputStream();
-		System.out.println("IN :" + s);
-		handler.handleRequest(is, os, session);
-		String out = os.toString();
-		System.out.println("OUT:" + out);
-		return out;
-		
-	}
-	protected void verify(final String command, final Set requiredResponseSet, final String requiredStatusResponse) throws ProtocolException, IOException, MessagingException {
-		Command c=new Command() {
-			public List getExpectedResponseList() throws MessagingException, IOException {
-				return new LinkedList(requiredResponseSet);
-			}
-			public String getExpectedStatusResponse() {
-				return requiredStatusResponse;
-			}
-			public String getCommand() {
-				return command;
-			}
-	    };
-		verifyCommand(c);
-	}
-	
-	protected void verifyCommand(Command command) throws ProtocolException, IOException, MessagingException {
-		
-		BufferedReader br=handleRequestReader((++counter)+" "+command.getCommand()+"\n");
-		Set	requiredResponseSet=new HashSet(command.getExpectedResponseList());
-		List rec=new ArrayList();
-		String line;
-		while ((line=br.readLine())!=null) {
-			 rec.add(line);
-		}
-		assertFalse("nothing received",rec.isEmpty());
-		String statusResponse=(String)rec.get(rec.size()-1);
-		rec.remove(rec.size()-1);
-		Set responseSet=new HashSet(rec);
-		responseSet.removeAll(requiredResponseSet);
-		requiredResponseSet.removeAll(new HashSet(rec));
-		if (responseSet.size()>0) {
-			System.out.println("Not awaitet responses: "+responseSet);
-		}
-		if (requiredResponseSet.size()>0) {
-			System.out.println("Missed responses: "+requiredResponseSet);
-		}
-		assertEquals("Missed responses: "+requiredResponseSet,0,requiredResponseSet.size());
-		assertEquals("Not awaitet responses: "+responseSet,0,responseSet.size());
-		assertEquals("Status respons differs",counter+" "+command.getExpectedStatusResponse(),statusResponse);
-	}
-	
-	protected void  verifyCommandOrdered(Command command)  throws ProtocolException, IOException, MessagingException
-	{
-		BufferedReader br=handleRequestReader((++counter)+" "+command.getCommand()+"\n");
-		
-		int c=0;
-		for (Iterator it = command.getExpectedResponseList().iterator(); it.hasNext();) {
-			c++;
-			String expectedResponse = (String) it.next();
-//			System.out.println("Expected: "+expectedResponse);
-			String[] expectedLines=expectedResponse.split("\r\n");
-			for (int i = 0; i < expectedLines.length; i++) {
-				String readLine=br.readLine();
-				assertNotNull("Unexpected end of response (response "+c+" line "+i+")",readLine);
-				assertEquals("Unexpected response line (response "+c+" line "+i+")",expectedLines[i],readLine);				
-			}
-		}
-		
-		String statusResponse=(String)br.readLine();;
-		assertEquals("Status response differs",counter+" "+command.getExpectedStatusResponse(),statusResponse);
-		String notExpected=br.readLine();
-		assertNull("did expect eof",notExpected);
-	}
+    public String handleRequest(String s) throws ProtocolException
+    {
+        ByteArrayInputStream is = new ByteArrayInputStream(s.getBytes());
+        ByteArrayOutputStream os = new ByteArrayOutputStream();
+        System.out.println("IN :" + s);
+        handler.handleRequest(is, os, session);
+        String out = os.toString();
+        System.out.println("OUT:" + out);
+        return out;
+        
+    }
+    protected void verify(final String command, final Set requiredResponseSet, final String requiredStatusResponse) throws ProtocolException, IOException, MessagingException {
+        Command c=new Command() {
+            public List getExpectedResponseList() throws MessagingException, IOException {
+                return new LinkedList(requiredResponseSet);
+            }
+            public String getExpectedStatusResponse() {
+                return requiredStatusResponse;
+            }
+            public String getCommand() {
+                return command;
+            }
+        };
+        verifyCommand(c);
+    }
+    
+    protected void verifyCommand(Command command) throws ProtocolException, IOException, MessagingException {
+        
+        BufferedReader br=handleRequestReader((++counter)+" "+command.getCommand()+"\n");
+        Set requiredResponseSet=new HashSet(command.getExpectedResponseList());
+        List rec=new ArrayList();
+        String line;
+        while ((line=br.readLine())!=null) {
+             rec.add(line);
+        }
+        assertFalse("nothing received",rec.isEmpty());
+        String statusResponse=(String)rec.get(rec.size()-1);
+        rec.remove(rec.size()-1);
+        Set responseSet=new HashSet(rec);
+        responseSet.removeAll(requiredResponseSet);
+        requiredResponseSet.removeAll(new HashSet(rec));
+        if (responseSet.size()>0) {
+            System.out.println("Not awaitet responses: "+responseSet);
+        }
+        if (requiredResponseSet.size()>0) {
+            System.out.println("Missed responses: "+requiredResponseSet);
+        }
+        assertEquals("Missed responses: "+requiredResponseSet,0,requiredResponseSet.size());
+        assertEquals("Not awaitet responses: "+responseSet,0,responseSet.size());
+        assertEquals("Status respons differs",counter+" "+command.getExpectedStatusResponse(),statusResponse);
+    }
+    
+    protected void  verifyCommandOrdered(Command command)  throws ProtocolException, IOException, MessagingException
+    {
+        BufferedReader br=handleRequestReader((++counter)+" "+command.getCommand()+"\n");
+        
+        int c=0;
+        for (Iterator it = command.getExpectedResponseList().iterator(); it.hasNext();) {
+            c++;
+            String expectedResponse = (String) it.next();
+//          System.out.println("Expected: "+expectedResponse);
+            String[] expectedLines=expectedResponse.split("\r\n");
+            for (int i = 0; i < expectedLines.length; i++) {
+                String readLine=br.readLine();
+                assertNotNull("Unexpected end of response (response "+c+" line "+i+")",readLine);
+                assertEquals("Unexpected response line (response "+c+" line "+i+")",expectedLines[i],readLine);             
+            }
+        }
+        
+        String statusResponse=(String)br.readLine();;
+        assertEquals("Status response differs",counter+" "+command.getExpectedStatusResponse(),statusResponse);
+        String notExpected=br.readLine();
+        assertNull("did expect eof",notExpected);
+    }
     
     public void setFlags(String mailboxName,long fromUid,long toUid,Flags flags, boolean value, boolean replace) throws MailboxManagerException {
-    	ImapMailboxSession mailbox=getImapMailboxSession(mailboxName);
+        ImapMailboxSession mailbox=getImapMailboxSession(mailboxName);
         mailbox.setFlags(flags, value, replace, GeneralMessageSetImpl.uidRange(fromUid, toUid), null);
         mailbox.close();
     }
     private ImapMailboxSession getImapMailboxSession(String mailboxName) throws MailboxManagerException {
-    	int[] neededSets = new int[] {GeneralMessageSet.TYPE_UID};
-    	int neededResults= MessageResult.UID + MessageResult.MIME_MESSAGE + MessageResult.FLAGS;
-    	ImapMailboxSession mailboxSession= (ImapMailboxSession) mailboxManager.getMailboxSession(mailboxName, ImapMailboxSession.class, neededSets, neededResults);
-    	return mailboxSession;
+        int[] neededSets = new int[] {GeneralMessageSet.TYPE_UID};
+        int neededResults= MessageResult.UID + MessageResult.MIME_MESSAGE + MessageResult.FLAGS;
+        ImapMailboxSession mailboxSession= (ImapMailboxSession) mailboxManager.getMailboxSession(mailboxName, ImapMailboxSession.class, neededSets, neededResults);
+        return mailboxSession;
     }
 }

Propchange: james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/handler/session/AbstractSessionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/handler/session/BodyFetchSessionTest.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/handler/session/BodyFetchSessionTest.java?view=diff&rev=454662&r1=454661&r2=454662
==============================================================================
--- james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/handler/session/BodyFetchSessionTest.java (original)
+++ james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/handler/session/BodyFetchSessionTest.java Tue Oct 10 01:34:56 2006
@@ -24,84 +24,84 @@
  */
 
 public class BodyFetchSessionTest extends AbstractSessionTest {
-	
-	String[] onlyInbox = {USER_MAILBOX_ROOT+".INBOX"};
-	MimeMessage[] msgs= null;
-	long[] uids = null;
-	
-	public void setUp() throws MailboxException, MessagingException, IOException, MailboxManagerException {
-		super.setUp();
-		msgs=MessageGenerator.generateSimplesMessages(4);
-		createFolders(onlyInbox);
-		// increase the uid
-		appendMessagesClosed(USER_MAILBOX_ROOT+".INBOX",msgs);
-		deleteAll(USER_MAILBOX_ROOT+".INBOX");
-		uids=addUIDMessagesOpen(USER_MAILBOX_ROOT+".INBOX",msgs);
-	}
-	
-	
-	public void testFetchCompleteAndSize() throws ProtocolException, IOException, MessagingException, MailboxManagerException {
-		verifyCommand(new LoginCommand(USER_NAME,USER_PASSWORD));
-		verifyCommand(new SelectCommand("INBOX", msgs, getUidValidity(USER_MAILBOX_ROOT+".INBOX")));
-		msgs=getMessages(USER_MAILBOX_ROOT+".INBOX");
-		FetchCommand fc=new FetchCommand(msgs,1,-1);
-		fc.setFetchRfc822Size(true);
-		fc.setFetchBody(new FetchBody(true));
-		// TODO test \Seen get's not set because of peek and vice versa
-		verifyCommandOrdered(fc);
-	}
-	public void testFetchCompleteHeader() throws ProtocolException, IOException, MessagingException, MailboxManagerException {
-		verifyCommand(new LoginCommand(USER_NAME,USER_PASSWORD));
-		verifyCommand(new SelectCommand("INBOX", msgs, getUidValidity(USER_MAILBOX_ROOT+".INBOX")));
-		msgs=getMessages(USER_MAILBOX_ROOT+".INBOX");
-		FetchCommand fc=new FetchCommand(msgs,1,-1);
-		fc.setFetchRfc822Size(true);
-		FetchBody fetchBody=new FetchBody(true);
-		fetchBody.setFetchHeader(new FetchHeader());
-		fc.setFetchBody(fetchBody);
-		verifyCommandOrdered(fc);
-	}
-	public void testFetchSomeExistingHeader() throws ProtocolException, IOException, MessagingException, MailboxManagerException {
-		verifyCommand(new LoginCommand(USER_NAME,USER_PASSWORD));
-		verifyCommand(new SelectCommand("INBOX", msgs, getUidValidity(USER_MAILBOX_ROOT+".INBOX")));
-		msgs=getMessages(USER_MAILBOX_ROOT+".INBOX");
-		FetchCommand fc=new FetchCommand(msgs,1,-1);
-		fc.setFetchRfc822Size(true);
-		FetchHeader fetchHeader=new FetchHeader();
-		fetchHeader.setFields(new String[] {"Date","From","To"});
-		FetchBody fetchBody=new FetchBody(true);
-		fetchBody.setFetchHeader(fetchHeader);
-		fc.setFetchBody(fetchBody);
-		verifyCommandOrdered(fc);
-	}
-	public void testFetchSomeNonExistingHeader() throws ProtocolException, IOException, MessagingException, MailboxManagerException {
-		verifyCommand(new LoginCommand(USER_NAME,USER_PASSWORD));
-		verifyCommand(new SelectCommand("INBOX", msgs, getUidValidity(USER_MAILBOX_ROOT+".INBOX")));
-		msgs=getMessages(USER_MAILBOX_ROOT+".INBOX");
-		FetchCommand fc=new FetchCommand(msgs,1,-1);
-		fc.setFetchRfc822Size(true);
-		FetchHeader fetchHeader=new FetchHeader();
-		fetchHeader.setFields(new String[] {"Blob","Test","Oh"});
-		FetchBody fetchBody=new FetchBody(true);
-		fetchBody.setFetchHeader(fetchHeader);
-		fc.setFetchBody(fetchBody);
-		verifyCommandOrdered(fc);
-	}
-	public void testFetchSomeNoneAndExistingHeader() throws ProtocolException, IOException, MessagingException, MailboxManagerException {
-		verifyCommand(new LoginCommand(USER_NAME,USER_PASSWORD));
-		verifyCommand(new SelectCommand("INBOX", msgs, getUidValidity(USER_MAILBOX_ROOT+".INBOX")));
-		msgs=getMessages(USER_MAILBOX_ROOT+".INBOX");
-		FetchCommand fc=new FetchCommand(msgs,1,-1);
-		fc.setFetchRfc822Size(true);
-		FetchHeader fetchHeader=new FetchHeader();
-		fetchHeader.setFields(new String[] {"To","Message-ID","Blob","Test","Oh"});
-		FetchBody fetchBody=new FetchBody(true);
-		fetchBody.setFetchHeader(fetchHeader);
-		fc.setFetchBody(fetchBody);
-		verifyCommandOrdered(fc);
-	}
+    
+    String[] onlyInbox = {USER_MAILBOX_ROOT+".INBOX"};
+    MimeMessage[] msgs= null;
+    long[] uids = null;
+    
+    public void setUp() throws MailboxException, MessagingException, IOException, MailboxManagerException {
+        super.setUp();
+        msgs=MessageGenerator.generateSimplesMessages(4);
+        createFolders(onlyInbox);
+        // increase the uid
+        appendMessagesClosed(USER_MAILBOX_ROOT+".INBOX",msgs);
+        deleteAll(USER_MAILBOX_ROOT+".INBOX");
+        uids=addUIDMessagesOpen(USER_MAILBOX_ROOT+".INBOX",msgs);
+    }
+    
+    
+    public void testFetchCompleteAndSize() throws ProtocolException, IOException, MessagingException, MailboxManagerException {
+        verifyCommand(new LoginCommand(USER_NAME,USER_PASSWORD));
+        verifyCommand(new SelectCommand("INBOX", msgs, getUidValidity(USER_MAILBOX_ROOT+".INBOX")));
+        msgs=getMessages(USER_MAILBOX_ROOT+".INBOX");
+        FetchCommand fc=new FetchCommand(msgs,1,-1);
+        fc.setFetchRfc822Size(true);
+        fc.setFetchBody(new FetchBody(true));
+        // TODO test \Seen get's not set because of peek and vice versa
+        verifyCommandOrdered(fc);
+    }
+    public void testFetchCompleteHeader() throws ProtocolException, IOException, MessagingException, MailboxManagerException {
+        verifyCommand(new LoginCommand(USER_NAME,USER_PASSWORD));
+        verifyCommand(new SelectCommand("INBOX", msgs, getUidValidity(USER_MAILBOX_ROOT+".INBOX")));
+        msgs=getMessages(USER_MAILBOX_ROOT+".INBOX");
+        FetchCommand fc=new FetchCommand(msgs,1,-1);
+        fc.setFetchRfc822Size(true);
+        FetchBody fetchBody=new FetchBody(true);
+        fetchBody.setFetchHeader(new FetchHeader());
+        fc.setFetchBody(fetchBody);
+        verifyCommandOrdered(fc);
+    }
+    public void testFetchSomeExistingHeader() throws ProtocolException, IOException, MessagingException, MailboxManagerException {
+        verifyCommand(new LoginCommand(USER_NAME,USER_PASSWORD));
+        verifyCommand(new SelectCommand("INBOX", msgs, getUidValidity(USER_MAILBOX_ROOT+".INBOX")));
+        msgs=getMessages(USER_MAILBOX_ROOT+".INBOX");
+        FetchCommand fc=new FetchCommand(msgs,1,-1);
+        fc.setFetchRfc822Size(true);
+        FetchHeader fetchHeader=new FetchHeader();
+        fetchHeader.setFields(new String[] {"Date","From","To"});
+        FetchBody fetchBody=new FetchBody(true);
+        fetchBody.setFetchHeader(fetchHeader);
+        fc.setFetchBody(fetchBody);
+        verifyCommandOrdered(fc);
+    }
+    public void testFetchSomeNonExistingHeader() throws ProtocolException, IOException, MessagingException, MailboxManagerException {
+        verifyCommand(new LoginCommand(USER_NAME,USER_PASSWORD));
+        verifyCommand(new SelectCommand("INBOX", msgs, getUidValidity(USER_MAILBOX_ROOT+".INBOX")));
+        msgs=getMessages(USER_MAILBOX_ROOT+".INBOX");
+        FetchCommand fc=new FetchCommand(msgs,1,-1);
+        fc.setFetchRfc822Size(true);
+        FetchHeader fetchHeader=new FetchHeader();
+        fetchHeader.setFields(new String[] {"Blob","Test","Oh"});
+        FetchBody fetchBody=new FetchBody(true);
+        fetchBody.setFetchHeader(fetchHeader);
+        fc.setFetchBody(fetchBody);
+        verifyCommandOrdered(fc);
+    }
+    public void testFetchSomeNoneAndExistingHeader() throws ProtocolException, IOException, MessagingException, MailboxManagerException {
+        verifyCommand(new LoginCommand(USER_NAME,USER_PASSWORD));
+        verifyCommand(new SelectCommand("INBOX", msgs, getUidValidity(USER_MAILBOX_ROOT+".INBOX")));
+        msgs=getMessages(USER_MAILBOX_ROOT+".INBOX");
+        FetchCommand fc=new FetchCommand(msgs,1,-1);
+        fc.setFetchRfc822Size(true);
+        FetchHeader fetchHeader=new FetchHeader();
+        fetchHeader.setFields(new String[] {"To","Message-ID","Blob","Test","Oh"});
+        FetchBody fetchBody=new FetchBody(true);
+        fetchBody.setFetchHeader(fetchHeader);
+        fc.setFetchBody(fetchBody);
+        verifyCommandOrdered(fc);
+    }
 
-	
-		
+    
+        
 
 }

Propchange: james/server/sandbox/imap-integration/src/test/org/apache/james/imapserver/handler/session/BodyFetchSessionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org