darrell 2002/11/27 04:26:46
Modified: proposals/imap2/java/org/apache/james/imapserver
ImapRequestLineReader.java
proposals/imap2/java/org/apache/james/imapserver/commands
CommandParser.java CommandTemplate.java
ImapCommandFactory.java SubscribeCommand.java
UnsubscribeCommand.java
proposals/imap2/java/org/apache/james/imapserver/store
ImapMailbox.java InMemoryStore.java
MessageFlags.java
proposals/imap2/test/org/apache/james/imapserver
TestAuthenticated.java
proposals/imap2/test/org/apache/james/test
FileProtocolSessionBuilder.java
ProtocolSession.java
Added: proposals/imap2/java/org/apache/james/imapserver/commands
AppendCommand.java
proposals/imap2/java/org/apache/james/imapserver/store
ImapMessage.java
proposals/imap2/test/org/apache/james/imapserver Append.test
ImapMailboxTest.java
Log:
Imap proposal:
* implemented APPEND
Revision Changes Path
1.3 +2 -3
jakarta-james/proposals/imap2/java/org/apache/james/imapserver/ImapRequestLineReader.java
Index: ImapRequestLineReader.java
===================================================================
RCS file:
/home/cvs/jakarta-james/proposals/imap2/java/org/apache/james/imapserver/ImapRequestLineReader.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ImapRequestLineReader.java 26 Nov 2002 14:53:47 -0000 1.2
+++ ImapRequestLineReader.java 27 Nov 2002 12:26:45 -0000 1.3
@@ -18,6 +18,7 @@
/**
* Wraps the client input reader with a bunch of convenience methods, allowing
lookahead=1
* on the underlying character stream.
+ * TODO need to look at encoding, and whether we should be wrapping an InputStream
instead.
*
* @author Darrell DeBoer <[EMAIL PROTECTED]>
*
@@ -80,8 +81,6 @@
if ( next == -1 ) {
throw new ProtocolException( "Unexpected end of stream." );
}
- else {
- }
nextSeen = true;
nextChar = ( char ) next;
1.3 +3 -1
jakarta-james/proposals/imap2/java/org/apache/james/imapserver/commands/CommandParser.java
Index: CommandParser.java
===================================================================
RCS file:
/home/cvs/jakarta-james/proposals/imap2/java/org/apache/james/imapserver/commands/CommandParser.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- CommandParser.java 26 Nov 2002 14:53:48 -0000 1.2
+++ CommandParser.java 27 Nov 2002 12:26:46 -0000 1.3
@@ -184,6 +184,8 @@
/**
* Reads an argument of type "literal" from the request, in the format:
* "{" charCount "}" CRLF *CHAR8
+ * Note before calling, the request should be positioned so that nextChar
+ * is '{'. Leading whitespace is not skipped in this method.
*/
protected String consumeLiteral( ImapRequestLineReader request )
throws ProtocolException
1.3 +12 -1
jakarta-james/proposals/imap2/java/org/apache/james/imapserver/commands/CommandTemplate.java
Index: CommandTemplate.java
===================================================================
RCS file:
/home/cvs/jakarta-james/proposals/imap2/java/org/apache/james/imapserver/commands/CommandTemplate.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- CommandTemplate.java 25 Nov 2002 01:11:44 -0000 1.2
+++ CommandTemplate.java 27 Nov 2002 12:26:46 -0000 1.3
@@ -124,6 +124,17 @@
return session.getHost().getMailbox( session.getUser(), mailboxName,
mustExist );
}
+ protected ImapMailbox getMailbox( String mailboxName,
+ ImapSession session )
+ {
+ try {
+ return session.getHost().getMailbox( session.getUser(), mailboxName,
false );
+ }
+ catch ( MailboxException e ) {
+ throw new RuntimeException( "Unexpected error in CommandTemplate.java"
);
+ }
+ }
+
public CommandParser getParser()
{
return parser;
1.4 +2 -2
jakarta-james/proposals/imap2/java/org/apache/james/imapserver/commands/ImapCommandFactory.java
Index: ImapCommandFactory.java
===================================================================
RCS file:
/home/cvs/jakarta-james/proposals/imap2/java/org/apache/james/imapserver/commands/ImapCommandFactory.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ImapCommandFactory.java 27 Nov 2002 03:24:20 -0000 1.3
+++ ImapCommandFactory.java 27 Nov 2002 12:26:46 -0000 1.4
@@ -54,7 +54,7 @@
_imapCommands.put( ListCommand.NAME, ListCommand.class );
_imapCommands.put( LsubCommand.NAME, LsubCommand.class );
_imapCommands.put( StatusCommand.NAME, StatusCommand.class );
-// _imapCommands.put( "APPEND", AppendCommand.class );
+ _imapCommands.put( AppendCommand.NAME, AppendCommand.class );
// // RFC2342 NAMESPACE
// _imapCommands.put( "NAMESPACE", NamespaceCommand.class );
1.2 +1 -30
jakarta-james/proposals/imap2/java/org/apache/james/imapserver/commands/SubscribeCommand.java
Index: SubscribeCommand.java
===================================================================
RCS file:
/home/cvs/jakarta-james/proposals/imap2/java/org/apache/james/imapserver/commands/SubscribeCommand.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SubscribeCommand.java 27 Nov 2002 03:24:20 -0000 1.1
+++ SubscribeCommand.java 27 Nov 2002 12:26:46 -0000 1.2
@@ -52,32 +52,3 @@
return ARGS;
}
}
-
-/*
-6.1.2. NOOP Command
-
- Arguments: none
-
- Responses: no specific responses for this command (but see below)
-
- Result: OK - noop completed
- BAD - command unknown or arguments invalid
-
- The NOOP command always succeeds. It does nothing.
-
- Since any command can return a status update as untagged data, the
- NOOP command can be used as a periodic poll for new messages or
- message status updates during a period of inactivity. The NOOP
- command can also be used to reset any inactivity autologout timer
- on the server.
-
- Example: C: a002 NOOP
- S: a002 OK NOOP completed
- . . .
- C: a047 NOOP
- S: * 22 EXPUNGE
- S: * 23 EXISTS
- S: * 3 RECENT
- S: * 14 FETCH (FLAGS (\Seen \Deleted))
- S: a047 OK NOOP completed
-*/
1.2 +3 -32
jakarta-james/proposals/imap2/java/org/apache/james/imapserver/commands/UnsubscribeCommand.java
Index: UnsubscribeCommand.java
===================================================================
RCS file:
/home/cvs/jakarta-james/proposals/imap2/java/org/apache/james/imapserver/commands/UnsubscribeCommand.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- UnsubscribeCommand.java 27 Nov 2002 03:24:20 -0000 1.1
+++ UnsubscribeCommand.java 27 Nov 2002 12:26:46 -0000 1.2
@@ -29,12 +29,12 @@
/** @see CommandTemplate#doProcess */
protected void doProcess( ImapRequestLineReader request,
ImapResponse response,
- ImapSession session )
+ ImapSession session )
throws ProtocolException, MailboxException
{
String mailboxName = parser.mailbox( request );
parser.endLine( request );
-
+
session.getHost().unsubscribe( session.getUser(), mailboxName );
session.unsolicitedResponses( response );
response.commandComplete( this );
@@ -52,32 +52,3 @@
return ARGS;
}
}
-
-/*
-6.1.2. NOOP Command
-
- Arguments: none
-
- Responses: no specific responses for this command (but see below)
-
- Result: OK - noop completed
- BAD - command unknown or arguments invalid
-
- The NOOP command always succeeds. It does nothing.
-
- Since any command can return a status update as untagged data, the
- NOOP command can be used as a periodic poll for new messages or
- message status updates during a period of inactivity. The NOOP
- command can also be used to reset any inactivity autologout timer
- on the server.
-
- Example: C: a002 NOOP
- S: a002 OK NOOP completed
- . . .
- C: a047 NOOP
- S: * 22 EXPUNGE
- S: * 23 EXISTS
- S: * 3 RECENT
- S: * 14 FETCH (FLAGS (\Seen \Deleted))
- S: a047 OK NOOP completed
-*/
1.1
jakarta-james/proposals/imap2/java/org/apache/james/imapserver/commands/AppendCommand.java
Index: AppendCommand.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
package org.apache.james.imapserver.commands;
import org.apache.james.core.MimeMessageSource;
import org.apache.james.core.MimeMessageWrapper;
import org.apache.james.imapserver.ImapRequestLineReader;
import org.apache.james.imapserver.ImapResponse;
import org.apache.james.imapserver.ImapSession;
import org.apache.james.imapserver.ProtocolException;
import org.apache.james.imapserver.store.ImapMailbox;
import org.apache.james.imapserver.store.MailboxException;
import org.apache.james.imapserver.store.MessageFlags;
import javax.mail.internet.MimeMessage;
import java.io.ByteArrayInputStream;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
/**
* Handles processeing for the APPEND imap command.
*
* @author Darrell DeBoer <[EMAIL PROTECTED]>
*
* @version $Revision: 1.1 $
*/
class AppendCommand extends CommandTemplate
{
public static final String NAME = "APPEND";
public static final String ARGS = "<mailbox> [<flag_list>] [<date_time>]
literal";
private AppendCommandParser parser = new AppendCommandParser();
/** @see CommandTemplate#doProcess */
protected void doProcess( ImapRequestLineReader request,
ImapResponse response,
ImapSession session )
throws ProtocolException, MailboxException
{
String mailboxName = parser.mailbox( request );
MessageFlags flags = parser.optionalAppendFlags( request );
if ( flags == null ) {
flags = new MessageFlags();
}
Date datetime = parser.optionalDateTime( request );
if ( datetime == null ) {
datetime = new Date();
}
MimeMessage message = parser.mimeMessage( request );
parser.endLine( request );
ImapMailbox mailbox = getMailbox( mailboxName, session );
if ( mailbox == null ) {
session.unsolicitedResponses( response );
response.commandFailed( this, "TRYCREATE", "No such mailbox.");
return;
}
mailbox.createMessage( message, flags, datetime );
session.unsolicitedResponses( response );
response.commandComplete( this );
}
/** @see ImapCommand#getName */
public String getName()
{
return NAME;
}
/** @see CommandTemplate#getArgSyntax */
public String getArgSyntax()
{
return ARGS;
}
private class AppendCommandParser extends CommandParser
{
/**
* If the next character in the request is a '(', tries to read
* a "flag_list" argument from the request. If not, returns a
* MessageFlags with no flags set.
*/
public MessageFlags optionalAppendFlags( ImapRequestLineReader request )
throws ProtocolException
{
char next = request.nextWordChar();
if ( next == '(' ) {
return flagList( request );
}
else {
return null;
}
}
/**
* If the next character in the request is a '"', tries to read
* a DateTime argument. If not, returns null.
*/
public Date optionalDateTime( ImapRequestLineReader request )
throws ProtocolException
{
char next = request.nextWordChar();
if ( next == '"' ) {
return dateTime( request );
}
else {
return null;
}
}
/**
* Reads a MimeMessage encoded as a string literal from the request.
* TODO shouldn't need to read as a string and write out bytes
* use FixedLengthInputStream instead. Hopefully it can then be dynamic.
* @param request The Imap APPEND request
* @return A MimeMessage read off the request.
*/
public MimeMessage mimeMessage( ImapRequestLineReader request )
throws ProtocolException
{
request.nextWordChar();
String mailString = consumeLiteral( request );
MimeMessageSource source;
try {
byte[] messageBytes = mailString.getBytes( "US-ASCII" );
source = new MimeMessageByteArraySource( "Mail" +
System.currentTimeMillis(),
messageBytes);
}
catch ( Exception e ) {
throw new ProtocolException( "UnexpectedException: " +
e.getMessage() );
}
return new MimeMessageWrapper( source );
}
}
class MimeMessageByteArraySource extends MimeMessageSource
{
private String sourceId;
private byte[] byteArray;
public MimeMessageByteArraySource( String sourceId, byte[] byteArray )
{
this.sourceId = sourceId;
this.byteArray = byteArray;
}
public String getSourceId()
{
return sourceId;
}
public InputStream getInputStream() throws IOException
{
return new ByteArrayInputStream( byteArray );
}
}
/**
* This class is not yet used in the AppendCommand.
*
* An input stream which reads a fixed number of bytes from the underlying
* input stream. Once the number of bytes has been read, the
FixedLengthInputStream
* will act as thought the end of stream has been reached, even if more bytes are
* present in the underlying input stream.
*/
class FixedLengthInputStream extends FilterInputStream
{
private long pos = 0;
private long length;
public FixedLengthInputStream( InputStream in, long length )
{
super( in );
this.length = length;
}
public int read() throws IOException
{
if ( pos >= length ) {
return -1;
}
pos++;
return super.read();
}
public int read( byte b[] ) throws IOException
{
if ( pos >= length ) {
return -1;
}
if ( pos + b.length >= length ) {
pos = length;
return super.read( b, 0, (int) (length - pos) );
}
pos += b.length;
return super.read( b );
}
public int read( byte b[], int off, int len ) throws IOException
{
throw new IOException("Not implemented");
// return super.read( b, off, len );
}
public long skip( long n ) throws IOException
{
throw new IOException( "Not implemented" );
// return super.skip( n );
}
public int available() throws IOException
{
return super.available();
}
public void close() throws IOException
{
// Don't do anything to the underlying stream.
}
public synchronized void mark( int readlimit )
{
// Don't do anything.
}
public synchronized void reset() throws IOException
{
throw new IOException( "mark not supported" );
}
public boolean markSupported()
{
return false;
}
}
}
/*
6.3.11. APPEND Command
Arguments: mailbox name
OPTIONAL flag parenthesized list
OPTIONAL date/time string
message literal
Responses: no specific responses for this command
Result: OK - append completed
NO - append error: can't append to that mailbox, error
in flags or date/time or message text
BAD - command unknown or arguments invalid
The APPEND command appends the literal argument as a new message
to the end of the specified destination mailbox. This argument
SHOULD be in the format of an [RFC-822] message. 8-bit characters
are permitted in the message. A server implementation that is
unable to preserve 8-bit data properly MUST be able to reversibly
convert 8-bit APPEND data to 7-bit using a [MIME-IMB] content
transfer encoding.
Note: There MAY be exceptions, e.g. draft messages, in which
required [RFC-822] header lines are omitted in the message literal
argument to APPEND. The full implications of doing so MUST be
understood and carefully weighed.
If a flag parenthesized list is specified, the flags SHOULD be set in
the resulting message; otherwise, the flag list of the resulting
message is set empty by default.
If a date_time is specified, the internal date SHOULD be set in the
resulting message; otherwise, the internal date of the resulting
message is set to the current date and time by default.
If the append is unsuccessful for any reason, the mailbox MUST be
restored to its state before the APPEND attempt; no partial appending
is permitted.
If the destination mailbox does not exist, a server MUST return an
error, and MUST NOT automatically create the mailbox. Unless it is
certain that the destination mailbox can not be created, the server
MUST send the response code "[TRYCREATE]" as the prefix of the text
of the tagged NO response. This gives a hint to the client that it
can attempt a CREATE command and retry the APPEND if the CREATE is
successful.
If the mailbox is currently selected, the normal new mail actions
SHOULD occur. Specifically, the server SHOULD notify the client
immediately via an untagged EXISTS response. If the server does not
do so, the client MAY issue a NOOP command (or failing that, a CHECK
command) after one or more APPEND commands.
Example: C: A003 APPEND saved-messages (\Seen) {310}
C: Date: Mon, 7 Feb 1994 21:52:25 -0800 (PST)
C: From: Fred Foobar <[EMAIL PROTECTED]>
C: Subject: afternoon meeting
C: To: [EMAIL PROTECTED]
C: Message-Id: <[EMAIL PROTECTED]>
C: MIME-Version: 1.0
C: Content-Type: TEXT/PLAIN; CHARSET=US-ASCII
C:
C: Hello Joe, do you think we can meet at 3:30 tomorrow?
C:
S: A003 OK APPEND completed
Note: the APPEND command is not used for message delivery, because
it does not provide a mechanism to transfer [SMTP] envelope
information.
*/
1.3 +21 -5
jakarta-james/proposals/imap2/java/org/apache/james/imapserver/store/ImapMailbox.java
Index: ImapMailbox.java
===================================================================
RCS file:
/home/cvs/jakarta-james/proposals/imap2/java/org/apache/james/imapserver/store/ImapMailbox.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ImapMailbox.java 25 Nov 2002 01:11:44 -0000 1.2
+++ ImapMailbox.java 27 Nov 2002 12:26:46 -0000 1.3
@@ -8,6 +8,11 @@
package org.apache.james.imapserver.store;
import org.apache.james.services.MailRepository;
+import org.apache.james.core.MailImpl;
+
+import javax.mail.internet.MimeMessage;
+import java.util.Date;
+import java.util.Collection;
/**
* Represents a mailbox within an {@link
org.apache.james.imapserver.store.ImapStore}.
@@ -20,7 +25,7 @@
*
* @version $Revision$
*/
-public interface ImapMailbox extends MailRepository
+public interface ImapMailbox
{
String getName();
@@ -32,7 +37,7 @@
int getRecentCount();
- int getUidValidity();
+ long getUidValidity();
int getFirstUnseen();
@@ -40,8 +45,19 @@
boolean isSelectable();
- int getUidNext();
+ long getUidNext();
int getUnseenCount();
-
+
+ ImapMessage createMessage( MimeMessage message, MessageFlags flags, Date
internalDate );
+
+ void storeMessage( ImapMessage message );
+
+ void store( MailImpl mail) throws Exception;
+
+ ImapMessage getMessage( long uid );
+
+ Collection getMessages();
+
+
}
1.3 +39 -24
jakarta-james/proposals/imap2/java/org/apache/james/imapserver/store/InMemoryStore.java
Index: InMemoryStore.java
===================================================================
RCS file:
/home/cvs/jakarta-james/proposals/imap2/java/org/apache/james/imapserver/store/InMemoryStore.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- InMemoryStore.java 25 Nov 2002 01:11:44 -0000 1.2
+++ InMemoryStore.java 27 Nov 2002 12:26:46 -0000 1.3
@@ -11,11 +11,15 @@
import org.apache.james.imapserver.store.ImapStore;
import org.apache.james.imapserver.ImapConstants;
+import javax.mail.internet.MimeMessage;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.StringTokenizer;
+import java.util.Date;
+import java.util.Map;
+import java.util.HashMap;
/**
* A simple in-memory implementation of {@link ImapStore}, used for testing
@@ -184,11 +188,17 @@
protected String name;
private boolean isSelectable = false;
- public HierarchicalMailbox( HierarchicalMailbox parent, String name )
+ private Map mailMessages = new HashMap();
+ private long nextUid = 1;
+ private long uidValidity;
+
+ public HierarchicalMailbox( HierarchicalMailbox parent,
+ String name )
{
this.name = name;
this.children = new ArrayList();
this.parent = parent;
+ this.uidValidity = System.currentTimeMillis();
}
public Collection getChildren()
@@ -235,7 +245,7 @@
public int getMessageCount()
{
- return 0;
+ return mailMessages.size();
}
public int getRecentCount()
@@ -243,14 +253,14 @@
return 0;
}
- public int getUidValidity()
+ public long getUidValidity()
{
- return 0;
+ return uidValidity;
}
- public int getUidNext()
+ public long getUidNext()
{
- return 0;
+ return nextUid;
}
public int getUnseenCount()
@@ -278,38 +288,43 @@
isSelectable = selectable;
}
- // TODO implement these methods.
- public void store( MailImpl mc )
+ public ImapMessage createMessage( MimeMessage message,
+ MessageFlags flags,
+ Date internalDate )
{
- }
+ long uid = nextUid;
+ nextUid++;
- public Iterator list()
- {
- return null;
- }
+ ImapMessage imapMessage = new ImapMessage( message, flags,
+ internalDate, uid );
- public MailImpl retrieve( String key )
- {
- return null;
+ mailMessages.put( new Long( uid ), imapMessage );
+ return imapMessage;
}
- public void remove( MailImpl mail )
+ public void storeMessage( ImapMessage message )
{
+ Long key = new Long( message.getUid() );
+ mailMessages.put( key, message );
}
- public void remove( String key )
+ public void store( MailImpl mail )
+ throws Exception
{
+ MimeMessage message = mail.getMessage();
+ Date internalDate = new Date();
+ MessageFlags flags = new MessageFlags();
+ createMessage( message, flags, internalDate );
}
- public boolean lock( String key )
+ public ImapMessage getMessage( long uid )
{
- return false;
+ return (ImapMessage)mailMessages.get( new Long(uid ) );
}
- public boolean unlock( String key )
+ public Collection getMessages()
{
- return false;
+ return Collections.unmodifiableCollection( mailMessages.values() );
}
}
-
}
1.2 +1 -0
jakarta-james/proposals/imap2/java/org/apache/james/imapserver/store/MessageFlags.java
Index: MessageFlags.java
===================================================================
RCS file:
/home/cvs/jakarta-james/proposals/imap2/java/org/apache/james/imapserver/store/MessageFlags.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- MessageFlags.java 22 Nov 2002 02:09:52 -0000 1.1
+++ MessageFlags.java 27 Nov 2002 12:26:46 -0000 1.2
@@ -11,6 +11,7 @@
/**
* The set of flags associated with a message.
* TODO - should store SEEN flag on a peruser basis (not required, but nice)
+ * TODO - why not use javax.mail.Flags instead of having our own.
*
* <p>Reference: RFC 2060 - para 2.3
* @author <a href="mailto:[EMAIL PROTECTED]">Charles Benett</a>
1.1
jakarta-james/proposals/imap2/java/org/apache/james/imapserver/store/ImapMessage.java
Index: ImapMessage.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
package org.apache.james.imapserver.store;
import javax.mail.internet.MimeMessage;
import java.util.Date;
/**
* A mail message with all of the extra stuff that IMAP requires.
* This is just a placeholder object, while I work out what's really required. A
common
* way of handling *all* messages needs to be available for James (maybe MailImpl?)
* @author Darrell DeBoer <[EMAIL PROTECTED]>
*
* @version $Revision: 1.1 $
*/
public class ImapMessage
{
private MimeMessage mimeMessage;
private MessageFlags flags;
private Date internalDate;
private long uid;
ImapMessage( MimeMessage mimeMessage, MessageFlags flags,
Date internalDate, long uid )
{
this.mimeMessage = mimeMessage;
this.flags = flags;
this.internalDate = internalDate;
this.uid = uid;
}
public MimeMessage getMimeMessage() {
return mimeMessage;
}
public MessageFlags getFlags() {
return flags;
}
public Date getInternalDate() {
return internalDate;
}
public long getUid() {
return uid;
}
}
1.6 +2 -0
jakarta-james/proposals/imap2/test/org/apache/james/imapserver/TestAuthenticated.java
Index: TestAuthenticated.java
===================================================================
RCS file:
/home/cvs/jakarta-james/proposals/imap2/test/org/apache/james/imapserver/TestAuthenticated.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- TestAuthenticated.java 27 Nov 2002 03:24:20 -0000 1.5
+++ TestAuthenticated.java 27 Nov 2002 12:26:46 -0000 1.6
@@ -64,6 +64,8 @@
suite.addTest( new TestAuthenticated( "Subscribe" ) );
suite.addTest( new TestAuthenticated( "Subscribe2" ) );
+ suite.addTest( new TestAuthenticated( "Append" ) );
+
// Run delete last, because many of the tests depend on created mailboxes.
suite.addTest( new TestAuthenticated( "Delete" ) );
1.1
jakarta-james/proposals/imap2/test/org/apache/james/imapserver/Append.test
Index: Append.test
===================================================================
C: A003 APPEND INBOX {309}
C: Date: Mon, 7 Feb 1994 21:52:25 -0800 (PST)
C: From: Fred Foobar <[EMAIL PROTECTED]>
C: Subject: afternoon meeting
C: To: [EMAIL PROTECTED]
C: Message-Id: <[EMAIL PROTECTED]>
C: MIME-Version: 1.0
C: Content-Type: TEXT/PLAIN; CHARSET=US-ASCII
C:
C: Hello Joe, do you think we can meet at 3:30 tomorrow?
C:
S: A003 OK APPEND completed
1.1
jakarta-james/proposals/imap2/test/org/apache/james/imapserver/ImapMailboxTest.java
Index: ImapMailboxTest.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
package org.apache.james.imapserver;
import org.apache.james.imapserver.store.ImapStore;
import org.apache.james.imapserver.store.InMemoryStore;
import org.apache.james.imapserver.store.ImapMailbox;
import org.apache.james.imapserver.store.MailboxException;
import org.apache.james.imapserver.store.MessageFlags;
import org.apache.james.imapserver.store.ImapMessage;
import org.apache.james.core.MimeMessageSource;
import org.apache.james.core.MimeMessageWrapper;
import org.apache.james.core.MailImpl;
import junit.framework.TestCase;
import javax.mail.internet.MimeMessage;
import javax.mail.Address;
import java.util.Date;
import java.io.InputStream;
import java.io.IOException;
import java.io.ByteArrayInputStream;
import java.net.InetAddress;
/**
*
* @author Darrell DeBoer <[EMAIL PROTECTED]>
*
* @version $Revision: 1.1 $
*/
public class ImapMailboxTest extends TestCase
implements ImapConstants
{
public ImapMailboxTest( String s )
{
super( s );
}
public void testAppend() throws Exception
{
ImapMailbox mailbox = getMailbox();
MessageFlags flags = new MessageFlags();
flags.setFlagged( true );
Date datetime = new Date();
String message =
"Date: Mon, 7 Feb 1994 21:52:25 -0800 (PST)\r\n" +
"From: Fred Foobar <[EMAIL PROTECTED]>\r\n" +
"Subject: afternoon meeting\r\n" +
"To: [EMAIL PROTECTED]\r\n" +
"Message-Id: <[EMAIL PROTECTED]>\r\n" +
"MIME-Version: 1.0\r\n" +
"Content-Type: TEXT/PLAIN; CHARSET=US-ASCII\r\n" +
"\r\n" +
"Hello Joe, do you think we can meet at 3:30 tomorrow?\r\n" +
"\r\n";
long uid = appendMessage( message, flags, datetime, mailbox );
ImapMessage imapMessage = mailbox.getMessage( uid );
assertEquals( 1, mailbox.getMessageCount() );
assertTrue( imapMessage.getFlags().isFlagged() );
assertTrue( ! imapMessage.getFlags().isAnswered() );
MimeMessage mime = imapMessage.getMimeMessage();
assertEquals( "TEXT/PLAIN; CHARSET=US-ASCII", mime.getContentType() );
assertEquals( "afternoon meeting", mime.getSubject() );
assertEquals( "Fred Foobar <[EMAIL PROTECTED]>",
mime.getFrom()[0].toString() );
}
private long appendMessage( String messageContent, MessageFlags flags,
Date datetime, ImapMailbox mailbox )
{
MimeMessageSource source =
new MimeMessageByteArraySource( "messageContent:" +
System.currentTimeMillis(),
messageContent.getBytes());
MimeMessage message = new MimeMessageWrapper( source );
ImapMessage imapMessage = mailbox.createMessage( message, flags, datetime );
return imapMessage.getUid();
}
private ImapMailbox getMailbox() throws MailboxException
{
ImapStore store = new InMemoryStore();
ImapMailbox root = store.getMailbox( ImapConstants.USER_NAMESPACE );
ImapMailbox test = store.createMailbox( root, "test", true );
return test;
}
class MimeMessageByteArraySource extends MimeMessageSource
{
private String sourceId;
private byte[] byteArray;
public MimeMessageByteArraySource( String sourceId, byte[] byteArray )
{
this.sourceId = sourceId;
this.byteArray = byteArray;
}
public String getSourceId()
{
return sourceId;
}
public InputStream getInputStream() throws IOException
{
return new ByteArrayInputStream( byteArray );
}
}
}
1.3 +11 -5
jakarta-james/proposals/imap2/test/org/apache/james/test/FileProtocolSessionBuilder.java
Index: FileProtocolSessionBuilder.java
===================================================================
RCS file:
/home/cvs/jakarta-james/proposals/imap2/test/org/apache/james/test/FileProtocolSessionBuilder.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- FileProtocolSessionBuilder.java 27 Nov 2002 01:59:22 -0000 1.2
+++ FileProtocolSessionBuilder.java 27 Nov 2002 12:26:46 -0000 1.3
@@ -22,8 +22,8 @@
*/
public class FileProtocolSessionBuilder
{
- private static final String CLIENT_TAG = "C: ";
- private static final String SERVER_TAG = "S: ";
+ private static final String CLIENT_TAG = "C:";
+ private static final String SERVER_TAG = "S:";
private static final String OPEN_UNORDERED_BLOCK_TAG = "SUB {";
private static final String CLOSE_UNORDERED_BLOCK_TAG = "}";
private static final String COMMENT_TAG = "#";
@@ -77,11 +77,17 @@
while ( ( next = reader.readLine() ) != null ) {
String location = fileName + ":" + lineNumber;
if ( next.startsWith( CLIENT_TAG ) ) {
- String clientMsg = next.substring( 3 );
+ String clientMsg = "";
+ if ( next.length() > 3 ) {
+ clientMsg = next.substring( 3 );
+ }
session.CL( clientMsg );
}
else if ( next.startsWith( SERVER_TAG ) ) {
- String serverMsg = next.substring( 3 );
+ String serverMsg = "";
+ if ( serverMsg.length() > 3 ) {
+ serverMsg = next.substring( 3 );
+ }
session.SL( serverMsg, location );
}
else if ( next.startsWith( OPEN_UNORDERED_BLOCK_TAG ) ) {
1.3 +4 -2
jakarta-james/proposals/imap2/test/org/apache/james/test/ProtocolSession.java
Index: ProtocolSession.java
===================================================================
RCS file:
/home/cvs/jakarta-james/proposals/imap2/test/org/apache/james/test/ProtocolSession.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ProtocolSession.java 27 Nov 2002 01:59:22 -0000 1.2
+++ ProtocolSession.java 27 Nov 2002 12:26:46 -0000 1.3
@@ -134,7 +134,9 @@
*/
public void testProtocol( PrintWriter out, BufferedReader in )
{
- out.println( message );
+ out.print( message );
+ out.write( '\r' );
+ out.write( '\n' );
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>