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 [2/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/imapserver/ImapRequestLineReader.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/ImapRequestLineReader.java?view=diff&rev=454662&r1=454661&r2=454662
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/ImapRequestLineReader.java (original)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/ImapRequestLineReader.java Tue Oct 10 01:34:56 2006
@@ -1,204 +1,204 @@
-/****************************************************************
- * 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.imapserver;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-/**
- * 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 <da...@apache.org>
- *
- * @version $Revision: 109034 $
- */
-public class ImapRequestLineReader
-{
- private InputStream input;
- private OutputStream output;
-
- private boolean nextSeen = false;
- private char nextChar; // unknown
-
- ImapRequestLineReader( InputStream input, OutputStream output )
- {
- this.input = input;
- this.output = output;
- }
-
- /**
- * Reads the next regular, non-space character in the current line. Spaces are skipped
- * over, but end-of-line characters will cause a {@link ProtocolException} to be thrown.
- * This method will continue to return
- * the same character until the {@link #consume()} method is called.
- * @return The next non-space character.
- * @throws ProtocolException If the end-of-line or end-of-stream is reached.
- */
- public char nextWordChar() throws ProtocolException
- {
- char next = nextChar();
- while ( next == ' ' ) {
- consume();
- next = nextChar();
- }
-
- if ( next == '\r' || next == '\n' ) {
- throw new ProtocolException( "Missing argument." );
- }
-
- return next;
- }
-
- /**
- * Reads the next character in the current line. This method will continue to return
- * the same character until the {@link #consume()} method is called.
- * @return The next character.
- * @throws ProtocolException If the end-of-stream is reached.
- */
- public char nextChar() throws ProtocolException
- {
- if ( ! nextSeen ) {
- int next = -1;
-
- try {
- next = input.read();
- }
- catch ( IOException e ) {
- throw new ProtocolException( "Error reading from stream." );
- }
- if ( next == -1 ) {
- throw new ProtocolException( "Unexpected end of stream." );
- }
-
- nextSeen = true;
- nextChar = ( char ) next;
-// System.out.println( "Read '" + nextChar + "'" );
- }
- return nextChar;
- }
-
- /**
- * Moves the request line reader to end of the line, checking that no non-space
- * character are found.
- * @throws ProtocolException If more non-space tokens are found in this line,
- * or the end-of-file is reached.
- */
- public void eol() throws ProtocolException
- {
- char next = nextChar();
-
- // Ignore trailing spaces.
- while ( next == ' ' ) {
- consume();
- next = nextChar();
- }
-
- // handle DOS and unix end-of-lines
- if ( next == '\r' ) {
- consume();
- next = nextChar();
- }
-
- // Check if we found extra characters.
- if ( next != '\n' ) {
- // TODO debug log here and other exceptions
- throw new ProtocolException( "Expected end-of-line, found more characters.");
- }
- }
-
- /**
- * Consumes the current character in the reader, so that subsequent calls to the request will
- * provide a new character. This method does *not* read the new character, or check if
- * such a character exists. If no current character has been seen, the method moves to
- * the next character, consumes it, and moves on to the subsequent one.
- * @throws ProtocolException if a the current character can't be obtained (eg we're at
- * end-of-file).
- */
- public char consume() throws ProtocolException
- {
- char current = nextChar();
- nextSeen = false;
- nextChar = 0;
- return current;
- }
-
-
- /**
- * Reads and consumes a number of characters from the underlying reader,
- * filling the char array provided.
- * @param holder A char array which will be filled with chars read from the underlying reader.
- * @throws ProtocolException If a char can't be read into each array element.
- */
- public void read( byte[] holder ) throws ProtocolException
- {
- int readTotal = 0;
- try
- {
- while ( readTotal < holder.length )
- {
- int count = 0;
- count = input.read( holder, readTotal, holder.length - readTotal );
- if ( count == -1 ) {
- throw new ProtocolException( "Unexpectd end of stream." );
- }
- readTotal += count;
- }
- // Unset the next char.
- nextSeen = false;
- nextChar = 0;
- }
- catch ( IOException e ) {
- throw new ProtocolException( "Error reading from stream." );
- }
-
- }
-
- /**
- * Sends a server command continuation request '+' back to the client,
- * requesting more data to be sent.
- */
- public void commandContinuationRequest()
- throws ProtocolException
- {
- try {
- output.write( '+' );
- output.write( '\r' );
- output.write( '\n' );
- output.flush();
- }
- catch ( IOException e ) {
- throw new ProtocolException("Unexpected exception in sending command continuation request.");
- }
- }
-
- public void consumeLine()
- throws ProtocolException
- {
- char next = nextChar();
- while ( next != '\n' ) {
- consume();
- next = nextChar();
- }
- consume();
- }
-}
+/****************************************************************
+ * 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.imapserver;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+/**
+ * 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 <da...@apache.org>
+ *
+ * @version $Revision: 109034 $
+ */
+public class ImapRequestLineReader
+{
+ private InputStream input;
+ private OutputStream output;
+
+ private boolean nextSeen = false;
+ private char nextChar; // unknown
+
+ ImapRequestLineReader( InputStream input, OutputStream output )
+ {
+ this.input = input;
+ this.output = output;
+ }
+
+ /**
+ * Reads the next regular, non-space character in the current line. Spaces are skipped
+ * over, but end-of-line characters will cause a {@link ProtocolException} to be thrown.
+ * This method will continue to return
+ * the same character until the {@link #consume()} method is called.
+ * @return The next non-space character.
+ * @throws ProtocolException If the end-of-line or end-of-stream is reached.
+ */
+ public char nextWordChar() throws ProtocolException
+ {
+ char next = nextChar();
+ while ( next == ' ' ) {
+ consume();
+ next = nextChar();
+ }
+
+ if ( next == '\r' || next == '\n' ) {
+ throw new ProtocolException( "Missing argument." );
+ }
+
+ return next;
+ }
+
+ /**
+ * Reads the next character in the current line. This method will continue to return
+ * the same character until the {@link #consume()} method is called.
+ * @return The next character.
+ * @throws ProtocolException If the end-of-stream is reached.
+ */
+ public char nextChar() throws ProtocolException
+ {
+ if ( ! nextSeen ) {
+ int next = -1;
+
+ try {
+ next = input.read();
+ }
+ catch ( IOException e ) {
+ throw new ProtocolException( "Error reading from stream." );
+ }
+ if ( next == -1 ) {
+ throw new ProtocolException( "Unexpected end of stream." );
+ }
+
+ nextSeen = true;
+ nextChar = ( char ) next;
+// System.out.println( "Read '" + nextChar + "'" );
+ }
+ return nextChar;
+ }
+
+ /**
+ * Moves the request line reader to end of the line, checking that no non-space
+ * character are found.
+ * @throws ProtocolException If more non-space tokens are found in this line,
+ * or the end-of-file is reached.
+ */
+ public void eol() throws ProtocolException
+ {
+ char next = nextChar();
+
+ // Ignore trailing spaces.
+ while ( next == ' ' ) {
+ consume();
+ next = nextChar();
+ }
+
+ // handle DOS and unix end-of-lines
+ if ( next == '\r' ) {
+ consume();
+ next = nextChar();
+ }
+
+ // Check if we found extra characters.
+ if ( next != '\n' ) {
+ // TODO debug log here and other exceptions
+ throw new ProtocolException( "Expected end-of-line, found more characters.");
+ }
+ }
+
+ /**
+ * Consumes the current character in the reader, so that subsequent calls to the request will
+ * provide a new character. This method does *not* read the new character, or check if
+ * such a character exists. If no current character has been seen, the method moves to
+ * the next character, consumes it, and moves on to the subsequent one.
+ * @throws ProtocolException if a the current character can't be obtained (eg we're at
+ * end-of-file).
+ */
+ public char consume() throws ProtocolException
+ {
+ char current = nextChar();
+ nextSeen = false;
+ nextChar = 0;
+ return current;
+ }
+
+
+ /**
+ * Reads and consumes a number of characters from the underlying reader,
+ * filling the char array provided.
+ * @param holder A char array which will be filled with chars read from the underlying reader.
+ * @throws ProtocolException If a char can't be read into each array element.
+ */
+ public void read( byte[] holder ) throws ProtocolException
+ {
+ int readTotal = 0;
+ try
+ {
+ while ( readTotal < holder.length )
+ {
+ int count = 0;
+ count = input.read( holder, readTotal, holder.length - readTotal );
+ if ( count == -1 ) {
+ throw new ProtocolException( "Unexpectd end of stream." );
+ }
+ readTotal += count;
+ }
+ // Unset the next char.
+ nextSeen = false;
+ nextChar = 0;
+ }
+ catch ( IOException e ) {
+ throw new ProtocolException( "Error reading from stream." );
+ }
+
+ }
+
+ /**
+ * Sends a server command continuation request '+' back to the client,
+ * requesting more data to be sent.
+ */
+ public void commandContinuationRequest()
+ throws ProtocolException
+ {
+ try {
+ output.write( '+' );
+ output.write( '\r' );
+ output.write( '\n' );
+ output.flush();
+ }
+ catch ( IOException e ) {
+ throw new ProtocolException("Unexpected exception in sending command continuation request.");
+ }
+ }
+
+ public void consumeLine()
+ throws ProtocolException
+ {
+ char next = nextChar();
+ while ( next != '\n' ) {
+ consume();
+ next = nextChar();
+ }
+ consume();
+ }
+}
Propchange: james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/ImapRequestLineReader.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/ImapResponse.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/ImapResponse.java?view=diff&rev=454662&r1=454661&r2=454662
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/ImapResponse.java (original)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/ImapResponse.java Tue Oct 10 01:34:56 2006
@@ -1,291 +1,291 @@
-/****************************************************************
- * 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.imapserver;
-
-import java.io.OutputStream;
-import java.io.PrintWriter;
-
-import javax.mail.Flags;
-
-import org.apache.james.imapserver.commands.ImapCommand;
-import org.apache.james.imapserver.store.MessageFlags;
-import org.apache.james.util.InternetPrintWriter;
-
-/**
- * Class providing methods to send response messages from the server
- * to the client.
- */
-public class ImapResponse implements ImapConstants
-{
- private PrintWriter writer;
- private String tag = UNTAGGED;
-
- public ImapResponse( OutputStream output )
- {
- this.writer = new InternetPrintWriter( output, true );
- }
-
- public void setTag( String tag )
- {
- this.tag = tag;
- }
-
- /**
- * Writes a standard tagged OK response on completion of a command.
- * Response is writen as:
- * <pre> a01 OK COMMAND_NAME completed.</pre>
- *
- * @param command The ImapCommand which was completed.
- */
- public void commandComplete( ImapCommand command )
- {
- commandComplete( command, null );
- }
-
- /**
- * Writes a standard tagged OK response on completion of a command,
- * with a response code (eg READ-WRITE)
- * Response is writen as:
- * <pre> a01 OK [responseCode] COMMAND_NAME completed.</pre>
- *
- * @param command The ImapCommand which was completed.
- * @param responseCode A string response code to send to the client.
- */
- public void commandComplete( ImapCommand command, String responseCode )
- {
- tag();
- message( OK );
- responseCode( responseCode );
- commandName( command );
- message( "completed." );
- end();
- }
-
- /**
- * Writes a standard NO response on command failure, together with a
- * descriptive message.
- * Response is writen as:
- * <pre> a01 NO COMMAND_NAME failed. <reason></pre>
- *
- * @param command The ImapCommand which failed.
- * @param reason A message describing why the command failed.
- */
- public void commandFailed( ImapCommand command, String reason )
- {
- commandFailed( command, null, reason );
- }
-
- /**
- * Writes a standard NO response on command failure, together with a
- * descriptive message.
- * Response is writen as:
- * <pre> a01 NO [responseCode] COMMAND_NAME failed. <reason></pre>
- *
- * @param command The ImapCommand which failed.
- * @param responseCode The Imap response code to send.
- * @param reason A message describing why the command failed.
- */
- public void commandFailed( ImapCommand command,
- String responseCode,
- String reason )
- {
- tag();
- message( NO );
- responseCode( responseCode );
- commandName( command );
- message( "failed." );
- message( reason );
- end();
- }
-
- /**
- * Writes a standard BAD response on command error, together with a
- * descriptive message.
- * Response is writen as:
- * <pre> a01 BAD <message></pre>
- *
- * @param message The descriptive error message.
- */
- public void commandError( String message )
- {
- tag();
- message( BAD );
- message( message );
- end();
- }
-
- /**
- * Writes a standard untagged BAD response, together with a descriptive message.
- */
- public void badResponse( String message )
- {
- untagged();
- message( BAD );
- message( message );
- end();
- }
-
- /**
- * Writes an untagged OK response, with the supplied response code,
- * and an optional message.
- * @param responseCode The response code, included in [].
- * @param message The message to follow the []
- */
- public void okResponse( String responseCode, String message )
- {
- untagged();
- message( OK );
- responseCode( responseCode );
- message( message );
- end();
- }
-
- public void flagsResponse( Flags flags )
- {
- untagged();
- message( "FLAGS" );
- message( MessageFlags.format(flags) );
- end();
- }
-
- public void existsResponse( int count )
- {
- untagged();
- message( count );
- message( "EXISTS" );
- end();
- }
-
- public void recentResponse( int count )
- {
- untagged();
- message( count );
- message( "RECENT" );
- end();
- }
-
- public void expungeResponse( int msn )
- {
- untagged();
- message( msn );
- message( "EXPUNGE" );
- end();
- }
-
- public void fetchResponse( int msn, String msgData )
- {
- untagged();
- message( msn );
- message( "FETCH" );
- message( "(" + msgData + ")" );
- end();
- }
-
- public void commandResponse( ImapCommand command, String message )
- {
- untagged();
- commandName( command );
- message( message );
- end();
- }
-
- /**
- * Writes the message provided to the client, prepended with the
- * request tag.
- *
- * @param message The message to write to the client.
- */
- public void taggedResponse( String message )
- {
- tag();
- message( message );
- end();
- }
-
- /**
- * Writes the message provided to the client, prepended with the
- * untagged marker "*".
- *
- * @param message The message to write to the client.
- */
- public void untaggedResponse( String message )
- {
- untagged();
- message( message );
- end();
- }
-
- public void byeResponse( String message ) {
- untaggedResponse(BYE + SP + message);
- }
-
- private void untagged()
- {
- writer.print( UNTAGGED );
- }
-
- private void tag()
- {
- writer.print( tag );
- }
-
- private void commandName( ImapCommand command )
- {
- String name = command.getName();
- writer.print( SP );
- writer.print( name );
- }
-
- private void message( String message )
- {
- if ( message != null ) {
- writer.print( SP );
- writer.print( message );
- }
- }
-
- private void message( int number )
- {
- writer.print( SP );
- writer.print( number );
- }
-
- private void responseCode( String responseCode )
- {
- if ( responseCode != null ) {
- writer.print( " [" );
- writer.print( responseCode );
- writer.print( "]" );
- }
- }
-
- private void end()
- {
- writer.println();
- writer.flush();
- }
-
- public void permanentFlagsResponse(Flags flags) {
- untagged();
- message(OK);
- responseCode("PERMANENTFLAGS " + MessageFlags.format(flags));
- end();
- }
-}
+/****************************************************************
+ * 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.imapserver;
+
+import java.io.OutputStream;
+import java.io.PrintWriter;
+
+import javax.mail.Flags;
+
+import org.apache.james.imapserver.commands.ImapCommand;
+import org.apache.james.imapserver.store.MessageFlags;
+import org.apache.james.util.InternetPrintWriter;
+
+/**
+ * Class providing methods to send response messages from the server
+ * to the client.
+ */
+public class ImapResponse implements ImapConstants
+{
+ private PrintWriter writer;
+ private String tag = UNTAGGED;
+
+ public ImapResponse( OutputStream output )
+ {
+ this.writer = new InternetPrintWriter( output, true );
+ }
+
+ public void setTag( String tag )
+ {
+ this.tag = tag;
+ }
+
+ /**
+ * Writes a standard tagged OK response on completion of a command.
+ * Response is writen as:
+ * <pre> a01 OK COMMAND_NAME completed.</pre>
+ *
+ * @param command The ImapCommand which was completed.
+ */
+ public void commandComplete( ImapCommand command )
+ {
+ commandComplete( command, null );
+ }
+
+ /**
+ * Writes a standard tagged OK response on completion of a command,
+ * with a response code (eg READ-WRITE)
+ * Response is writen as:
+ * <pre> a01 OK [responseCode] COMMAND_NAME completed.</pre>
+ *
+ * @param command The ImapCommand which was completed.
+ * @param responseCode A string response code to send to the client.
+ */
+ public void commandComplete( ImapCommand command, String responseCode )
+ {
+ tag();
+ message( OK );
+ responseCode( responseCode );
+ commandName( command );
+ message( "completed." );
+ end();
+ }
+
+ /**
+ * Writes a standard NO response on command failure, together with a
+ * descriptive message.
+ * Response is writen as:
+ * <pre> a01 NO COMMAND_NAME failed. <reason></pre>
+ *
+ * @param command The ImapCommand which failed.
+ * @param reason A message describing why the command failed.
+ */
+ public void commandFailed( ImapCommand command, String reason )
+ {
+ commandFailed( command, null, reason );
+ }
+
+ /**
+ * Writes a standard NO response on command failure, together with a
+ * descriptive message.
+ * Response is writen as:
+ * <pre> a01 NO [responseCode] COMMAND_NAME failed. <reason></pre>
+ *
+ * @param command The ImapCommand which failed.
+ * @param responseCode The Imap response code to send.
+ * @param reason A message describing why the command failed.
+ */
+ public void commandFailed( ImapCommand command,
+ String responseCode,
+ String reason )
+ {
+ tag();
+ message( NO );
+ responseCode( responseCode );
+ commandName( command );
+ message( "failed." );
+ message( reason );
+ end();
+ }
+
+ /**
+ * Writes a standard BAD response on command error, together with a
+ * descriptive message.
+ * Response is writen as:
+ * <pre> a01 BAD <message></pre>
+ *
+ * @param message The descriptive error message.
+ */
+ public void commandError( String message )
+ {
+ tag();
+ message( BAD );
+ message( message );
+ end();
+ }
+
+ /**
+ * Writes a standard untagged BAD response, together with a descriptive message.
+ */
+ public void badResponse( String message )
+ {
+ untagged();
+ message( BAD );
+ message( message );
+ end();
+ }
+
+ /**
+ * Writes an untagged OK response, with the supplied response code,
+ * and an optional message.
+ * @param responseCode The response code, included in [].
+ * @param message The message to follow the []
+ */
+ public void okResponse( String responseCode, String message )
+ {
+ untagged();
+ message( OK );
+ responseCode( responseCode );
+ message( message );
+ end();
+ }
+
+ public void flagsResponse( Flags flags )
+ {
+ untagged();
+ message( "FLAGS" );
+ message( MessageFlags.format(flags) );
+ end();
+ }
+
+ public void existsResponse( int count )
+ {
+ untagged();
+ message( count );
+ message( "EXISTS" );
+ end();
+ }
+
+ public void recentResponse( int count )
+ {
+ untagged();
+ message( count );
+ message( "RECENT" );
+ end();
+ }
+
+ public void expungeResponse( int msn )
+ {
+ untagged();
+ message( msn );
+ message( "EXPUNGE" );
+ end();
+ }
+
+ public void fetchResponse( int msn, String msgData )
+ {
+ untagged();
+ message( msn );
+ message( "FETCH" );
+ message( "(" + msgData + ")" );
+ end();
+ }
+
+ public void commandResponse( ImapCommand command, String message )
+ {
+ untagged();
+ commandName( command );
+ message( message );
+ end();
+ }
+
+ /**
+ * Writes the message provided to the client, prepended with the
+ * request tag.
+ *
+ * @param message The message to write to the client.
+ */
+ public void taggedResponse( String message )
+ {
+ tag();
+ message( message );
+ end();
+ }
+
+ /**
+ * Writes the message provided to the client, prepended with the
+ * untagged marker "*".
+ *
+ * @param message The message to write to the client.
+ */
+ public void untaggedResponse( String message )
+ {
+ untagged();
+ message( message );
+ end();
+ }
+
+ public void byeResponse( String message ) {
+ untaggedResponse(BYE + SP + message);
+ }
+
+ private void untagged()
+ {
+ writer.print( UNTAGGED );
+ }
+
+ private void tag()
+ {
+ writer.print( tag );
+ }
+
+ private void commandName( ImapCommand command )
+ {
+ String name = command.getName();
+ writer.print( SP );
+ writer.print( name );
+ }
+
+ private void message( String message )
+ {
+ if ( message != null ) {
+ writer.print( SP );
+ writer.print( message );
+ }
+ }
+
+ private void message( int number )
+ {
+ writer.print( SP );
+ writer.print( number );
+ }
+
+ private void responseCode( String responseCode )
+ {
+ if ( responseCode != null ) {
+ writer.print( " [" );
+ writer.print( responseCode );
+ writer.print( "]" );
+ }
+ }
+
+ private void end()
+ {
+ writer.println();
+ writer.flush();
+ }
+
+ public void permanentFlagsResponse(Flags flags) {
+ untagged();
+ message(OK);
+ responseCode("PERMANENTFLAGS " + MessageFlags.format(flags));
+ end();
+ }
+}
Propchange: james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/ImapResponse.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/ImapServer.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/ImapServer.java?view=diff&rev=454662&r1=454661&r2=454662
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/ImapServer.java (original)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/ImapServer.java Tue Oct 10 01:34:56 2006
@@ -1,261 +1,261 @@
-/****************************************************************
- * 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.imapserver;
-
-import org.apache.avalon.cornerstone.services.connection.ConnectionHandler;
-import org.apache.avalon.excalibur.pool.ObjectFactory;
-import org.apache.avalon.excalibur.pool.Pool;
-import org.apache.avalon.excalibur.pool.Poolable;
-import org.apache.avalon.framework.activity.Initializable;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.james.core.AbstractJamesService;
-import org.apache.james.mailboxmanager.manager.MailboxManagerProvider;
-import org.apache.james.services.UsersRepository;
-import org.apache.james.util.watchdog.Watchdog;
-import org.apache.james.util.watchdog.WatchdogFactory;
-
-/**
- * TODO: this is a quick cut-and-paste hack from POP3Server. Should probably be
- * rewritten from scratch, together with ImapHandler.
- * TODO: Using a custom, not AbstractJamesHandler, handler together with AbstractJamesServices is not a good idea
- *
- * <p>Accepts IMAP connections on a server socket and dispatches them to IMAPHandlers.</p>
- *
- * <p>Also responsible for loading and parsing IMAP specific configuration.</p>
- *
- * @version 1.0.0, 24/04/1999
- * @author Federico Barbieri <sc...@pop.systemy.it>
- * @author <a href="mailto:danny@apache.org">Danny Angus</a>
- * @author Peter M. Goldstein <fa...@alum.mit.edu>
- * @author Darrell DeBoer <da...@apache.org>
- */
-public class ImapServer extends AbstractJamesService
-{
-
- /**
- * The user repository for this server - used to authenticate users.
- */
- private UsersRepository users;
-
-
- /**
- * The number of bytes to read before resetting
- * the connection timeout timer. Defaults to
- * 20 KB.
- */
- private int lengthReset = 20 * 1024;
-
- /**
- * The factory used to generate Watchdog objects
- */
- private WatchdogFactory theWatchdogFactory;
-
- /**
- * The configuration data to be passed to the handler
- */
- private IMAPHandlerConfigurationDataImpl theConfigData
- = new IMAPHandlerConfigurationDataImpl();
-
- public MailboxManagerProvider mailboxManagerProvider;
-
- public void service( ServiceManager serviceManager ) throws ServiceException
- {
- super.service( serviceManager );
- UsersRepository usersRepository = ( UsersRepository ) serviceManager.
- lookup( "org.apache.james.services.UsersRepository" );
- setUserRepository(usersRepository);
- MailboxManagerProvider mailboxManagerProvider =(MailboxManagerProvider) serviceManager.lookup("org.apache.james.mailboxmanager.manager.MailboxManagerProvider");
- getLogger().debug("MailboxManagerMailRepository uses service "+mailboxManagerProvider);
- setMailboxManagerProvider(mailboxManagerProvider);
- }
-
- void setUserRepository(UsersRepository repository) {
- this.users=repository;
- }
-
- void setMailboxManagerProvider(MailboxManagerProvider mailboxManagerProvider) {
- this.mailboxManagerProvider=mailboxManagerProvider;
- }
-
- /**
- * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
- */
- public void configure( final Configuration configuration ) throws ConfigurationException
- {
- super.configure( configuration );
- if ( isEnabled() ) {
- Configuration handlerConfiguration = configuration.getChild( "handler" );
- lengthReset = handlerConfiguration.getChild( "lengthReset" ).getValueAsInteger( lengthReset );
- getLogger().info( "The idle timeout will be reset every " + lengthReset + " bytes." );
- boolean streamdump=handlerConfiguration.getChild("streamdump").getAttributeAsBoolean("enabled", false);
- theConfigData.setStreamDump(streamdump);
- String streamdumpDir=handlerConfiguration.getChild("streamdump").getAttribute("directory", null);
- theConfigData.setStreamDumpDir(streamdumpDir);
- }
- }
-
- /**
- * @see Initializable#initialize()
- */
- public void initialize() throws Exception
- {
-
- super.initialize();
- if ( !isEnabled() ) {
- return;
- }
-
- theWatchdogFactory = getWatchdogFactory();
- }
-
- /**
- * @see AbstractJamesService#getDefaultPort()
- */
- protected int getDefaultPort()
- {
- return 143;
- }
-
- /**
- * @see AbstractJamesService#getServiceType()
- */
- public String getServiceType()
- {
- return "IMAP Service";
- }
-
- /**
- * @see org.apache.avalon.cornerstone.services.connection.AbstractHandlerFactory#newHandler()
- */
- protected ConnectionHandler newHandler()
- throws Exception
- {
- ImapHandler theHandler = (ImapHandler) theHandlerPool.get();
-
- Watchdog theWatchdog = theWatchdogFactory.getWatchdog( theHandler.getWatchdogTarget() );
-
- theHandler.setConfigurationData( theConfigData );
-
- theHandler.setWatchdog( theWatchdog );
- return theHandler;
- }
-
- /**
- * @see org.apache.avalon.cornerstone.services.connection.ConnectionHandlerFactory#releaseConnectionHandler(ConnectionHandler)
- */
- public void releaseConnectionHandler( ConnectionHandler connectionHandler )
- {
- if ( !( connectionHandler instanceof ImapHandler ) ) {
- throw new IllegalArgumentException( "Attempted to return non-ImapHandler to pool." );
- }
- theHandlerPool.put( ( Poolable ) connectionHandler );
- }
-
- /**
- * The factory for producing handlers.
- */
- /**
- * @see ObjectFactory#newInstance()
- */
- public Object newInstance() throws Exception
- {
- return new ImapHandler();
- }
-
- /**
- * @see ObjectFactory#getCreatedClass()
- */
- public Class getCreatedClass()
- {
- return ImapHandler.class;
- }
-
- /**
- * @see ObjectFactory#decommission(Object)
- */
- public void decommission( Object object ) throws Exception
- {
- return;
- }
-
- /**
- * A class to provide POP3 handler configuration to the handlers
- */
- private class IMAPHandlerConfigurationDataImpl
- implements ImapHandlerConfigurationData
- {
-
- private String streamdumpDir = null;
- private boolean streamdump = false;
- /**
- * @see ImapHandlerConfigurationData#getHelloName()
- */
- public String getHelloName()
- {
- return ImapServer.this.helloName;
- }
-
- public void setStreamDumpDir(String streamdumpDir) {
- this.streamdumpDir=streamdumpDir;
- }
-
- public void setStreamDump(boolean streamdump) {
- this.streamdump=streamdump;
-
- }
-
- /**
- * @see ImapHandlerConfigurationData#getResetLength()
- */
- public int getResetLength()
- {
- return ImapServer.this.lengthReset;
- }
-
- /**
- * @see ImapHandlerConfigurationData#getUsersRepository()
- */
- public UsersRepository getUsersRepository()
- {
- return ImapServer.this.users;
- }
-
- public MailboxManagerProvider getMailboxManagerProvider() {
- return ImapServer.this.mailboxManagerProvider;
- }
-
- public boolean doStreamdump() {
- return streamdump;
- }
-
- public String getStreamdumpDir() {
- return streamdumpDir;
- }
-
- }
-
- protected Object getConfigurationData() {
- return theConfigData;
- }
-
-}
+/****************************************************************
+ * 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.imapserver;
+
+import org.apache.avalon.cornerstone.services.connection.ConnectionHandler;
+import org.apache.avalon.excalibur.pool.ObjectFactory;
+import org.apache.avalon.excalibur.pool.Pool;
+import org.apache.avalon.excalibur.pool.Poolable;
+import org.apache.avalon.framework.activity.Initializable;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.james.core.AbstractJamesService;
+import org.apache.james.mailboxmanager.manager.MailboxManagerProvider;
+import org.apache.james.services.UsersRepository;
+import org.apache.james.util.watchdog.Watchdog;
+import org.apache.james.util.watchdog.WatchdogFactory;
+
+/**
+ * TODO: this is a quick cut-and-paste hack from POP3Server. Should probably be
+ * rewritten from scratch, together with ImapHandler.
+ * TODO: Using a custom, not AbstractJamesHandler, handler together with AbstractJamesServices is not a good idea
+ *
+ * <p>Accepts IMAP connections on a server socket and dispatches them to IMAPHandlers.</p>
+ *
+ * <p>Also responsible for loading and parsing IMAP specific configuration.</p>
+ *
+ * @version 1.0.0, 24/04/1999
+ * @author Federico Barbieri <sc...@pop.systemy.it>
+ * @author <a href="mailto:danny@apache.org">Danny Angus</a>
+ * @author Peter M. Goldstein <fa...@alum.mit.edu>
+ * @author Darrell DeBoer <da...@apache.org>
+ */
+public class ImapServer extends AbstractJamesService
+{
+
+ /**
+ * The user repository for this server - used to authenticate users.
+ */
+ private UsersRepository users;
+
+
+ /**
+ * The number of bytes to read before resetting
+ * the connection timeout timer. Defaults to
+ * 20 KB.
+ */
+ private int lengthReset = 20 * 1024;
+
+ /**
+ * The factory used to generate Watchdog objects
+ */
+ private WatchdogFactory theWatchdogFactory;
+
+ /**
+ * The configuration data to be passed to the handler
+ */
+ private IMAPHandlerConfigurationDataImpl theConfigData
+ = new IMAPHandlerConfigurationDataImpl();
+
+ public MailboxManagerProvider mailboxManagerProvider;
+
+ public void service( ServiceManager serviceManager ) throws ServiceException
+ {
+ super.service( serviceManager );
+ UsersRepository usersRepository = ( UsersRepository ) serviceManager.
+ lookup( "org.apache.james.services.UsersRepository" );
+ setUserRepository(usersRepository);
+ MailboxManagerProvider mailboxManagerProvider =(MailboxManagerProvider) serviceManager.lookup("org.apache.james.mailboxmanager.manager.MailboxManagerProvider");
+ getLogger().debug("MailboxManagerMailRepository uses service "+mailboxManagerProvider);
+ setMailboxManagerProvider(mailboxManagerProvider);
+ }
+
+ void setUserRepository(UsersRepository repository) {
+ this.users=repository;
+ }
+
+ void setMailboxManagerProvider(MailboxManagerProvider mailboxManagerProvider) {
+ this.mailboxManagerProvider=mailboxManagerProvider;
+ }
+
+ /**
+ * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
+ */
+ public void configure( final Configuration configuration ) throws ConfigurationException
+ {
+ super.configure( configuration );
+ if ( isEnabled() ) {
+ Configuration handlerConfiguration = configuration.getChild( "handler" );
+ lengthReset = handlerConfiguration.getChild( "lengthReset" ).getValueAsInteger( lengthReset );
+ getLogger().info( "The idle timeout will be reset every " + lengthReset + " bytes." );
+ boolean streamdump=handlerConfiguration.getChild("streamdump").getAttributeAsBoolean("enabled", false);
+ theConfigData.setStreamDump(streamdump);
+ String streamdumpDir=handlerConfiguration.getChild("streamdump").getAttribute("directory", null);
+ theConfigData.setStreamDumpDir(streamdumpDir);
+ }
+ }
+
+ /**
+ * @see Initializable#initialize()
+ */
+ public void initialize() throws Exception
+ {
+
+ super.initialize();
+ if ( !isEnabled() ) {
+ return;
+ }
+
+ theWatchdogFactory = getWatchdogFactory();
+ }
+
+ /**
+ * @see AbstractJamesService#getDefaultPort()
+ */
+ protected int getDefaultPort()
+ {
+ return 143;
+ }
+
+ /**
+ * @see AbstractJamesService#getServiceType()
+ */
+ public String getServiceType()
+ {
+ return "IMAP Service";
+ }
+
+ /**
+ * @see org.apache.avalon.cornerstone.services.connection.AbstractHandlerFactory#newHandler()
+ */
+ protected ConnectionHandler newHandler()
+ throws Exception
+ {
+ ImapHandler theHandler = (ImapHandler) theHandlerPool.get();
+
+ Watchdog theWatchdog = theWatchdogFactory.getWatchdog( theHandler.getWatchdogTarget() );
+
+ theHandler.setConfigurationData( theConfigData );
+
+ theHandler.setWatchdog( theWatchdog );
+ return theHandler;
+ }
+
+ /**
+ * @see org.apache.avalon.cornerstone.services.connection.ConnectionHandlerFactory#releaseConnectionHandler(ConnectionHandler)
+ */
+ public void releaseConnectionHandler( ConnectionHandler connectionHandler )
+ {
+ if ( !( connectionHandler instanceof ImapHandler ) ) {
+ throw new IllegalArgumentException( "Attempted to return non-ImapHandler to pool." );
+ }
+ theHandlerPool.put( ( Poolable ) connectionHandler );
+ }
+
+ /**
+ * The factory for producing handlers.
+ */
+ /**
+ * @see ObjectFactory#newInstance()
+ */
+ public Object newInstance() throws Exception
+ {
+ return new ImapHandler();
+ }
+
+ /**
+ * @see ObjectFactory#getCreatedClass()
+ */
+ public Class getCreatedClass()
+ {
+ return ImapHandler.class;
+ }
+
+ /**
+ * @see ObjectFactory#decommission(Object)
+ */
+ public void decommission( Object object ) throws Exception
+ {
+ return;
+ }
+
+ /**
+ * A class to provide POP3 handler configuration to the handlers
+ */
+ private class IMAPHandlerConfigurationDataImpl
+ implements ImapHandlerConfigurationData
+ {
+
+ private String streamdumpDir = null;
+ private boolean streamdump = false;
+ /**
+ * @see ImapHandlerConfigurationData#getHelloName()
+ */
+ public String getHelloName()
+ {
+ return ImapServer.this.helloName;
+ }
+
+ public void setStreamDumpDir(String streamdumpDir) {
+ this.streamdumpDir=streamdumpDir;
+ }
+
+ public void setStreamDump(boolean streamdump) {
+ this.streamdump=streamdump;
+
+ }
+
+ /**
+ * @see ImapHandlerConfigurationData#getResetLength()
+ */
+ public int getResetLength()
+ {
+ return ImapServer.this.lengthReset;
+ }
+
+ /**
+ * @see ImapHandlerConfigurationData#getUsersRepository()
+ */
+ public UsersRepository getUsersRepository()
+ {
+ return ImapServer.this.users;
+ }
+
+ public MailboxManagerProvider getMailboxManagerProvider() {
+ return ImapServer.this.mailboxManagerProvider;
+ }
+
+ public boolean doStreamdump() {
+ return streamdump;
+ }
+
+ public String getStreamdumpDir() {
+ return streamdumpDir;
+ }
+
+ }
+
+ protected Object getConfigurationData() {
+ return theConfigData;
+ }
+
+}
Propchange: james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/ImapServer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/ImapServer.xinfo
------------------------------------------------------------------------------
svn:eol-style = native
Modified: james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/ImapSession.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/ImapSession.java?view=diff&rev=454662&r1=454661&r2=454662
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/ImapSession.java (original)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/ImapSession.java Tue Oct 10 01:34:56 2006
@@ -1,127 +1,127 @@
-/****************************************************************
- * 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.imapserver;
-
-import org.apache.james.imapserver.store.MailboxException;
-import org.apache.james.mailboxmanager.MailboxManagerException;
-import org.apache.james.mailboxmanager.mailbox.ImapMailboxSession;
-import org.apache.james.mailboxmanager.manager.GeneralManager;
-import org.apache.james.services.User;
-import org.apache.james.services.UsersRepository;
-
-
-/**
- * Encapsulates all state held for an ongoing Imap session,
- * which commences when a client first establishes a connection to the Imap
- * server, and continues until that connection is closed.
- *
- * @author Darrell DeBoer <da...@apache.org>
- *
- * @version $Revision: 109034 $
- */
-public interface ImapSession
-{
- /**
- * Sends any unsolicited responses to the client, such as EXISTS and FLAGS
- * responses when the selected mailbox is modified by another user.
- * @param response The response to write to
- */
- void unsolicitedResponses( ImapResponse response, boolean useUid ) throws MailboxException;
-
- /**
- * Closes the connection for this session.
- */
- void closeConnection();
-
- void closeConnection(String byeMessage);
-
-
- /**
- * Provides the UsersRepository for this session, to allow session
- * to validate logins.
- *
- * @return The UsersRepository for this session.
- */
- UsersRepository getUsers();
-
- /**
- * @return The hostname of the connected client.
- */
- String getClientHostname();
-
- /**
- * @return The IP address of the connected client.
- */
- String getClientIP();
-
- /**
- * @return Returns the current state of this session.
- */
- ImapSessionState getState();
-
- /**
- * Moves the session into {@link ImapSessionState#AUTHENTICATED} state with
- * the supplied user.
- * @param user The user who is authenticated for this session.
- */
- void setAuthenticated( User user );
-
- /**
- * Provides the authenticated user for this session, or <code>null</code> if this
- * session is not in {@link ImapSessionState#AUTHENTICATED} or
- * {@link ImapSessionState#SELECTED} state.
- * @return The user authenticated for this session
- */
- User getUser();
-
- /**
- * Moves this session into {@link ImapSessionState#SELECTED} state and sets the
- * supplied mailbox to be the currently selected mailbox.
- * @param mailbox The selected mailbox.
- * @param readOnly If <code>true</code>, the selection is set to be read only.
- * @throws MailboxManagerException
- */
- void setSelected( ImapMailboxSession mailbox, boolean readOnly ) throws MailboxManagerException;
-
- /**
- * Moves the session out of {@link ImapSessionState#SELECTED} state and back into
- * {@link ImapSessionState#AUTHENTICATED} state. The selected mailbox is cleared.
- */
- void deselect();
-
- /**
- * Provides the selected mailbox for this session, or <code>null</code> if this
- * session is not in {@link ImapSessionState#SELECTED} state.
- * @return the currently selected mailbox.
- */
- SelectedMailboxSession getSelected();
-
- void unsolicitedResponses( ImapResponse request, boolean omitExpunged, boolean useUid) throws MailboxException;
-
- /**
- * closes the Mailbox if needed
- */
- void closeMailbox();
-
- GeneralManager getMailboxManager() throws MailboxManagerException;
-
- String buildFullName(String mailboxName) throws MailboxManagerException;
-
-}
+/****************************************************************
+ * 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.imapserver;
+
+import org.apache.james.imapserver.store.MailboxException;
+import org.apache.james.mailboxmanager.MailboxManagerException;
+import org.apache.james.mailboxmanager.mailbox.ImapMailboxSession;
+import org.apache.james.mailboxmanager.manager.GeneralManager;
+import org.apache.james.services.User;
+import org.apache.james.services.UsersRepository;
+
+
+/**
+ * Encapsulates all state held for an ongoing Imap session,
+ * which commences when a client first establishes a connection to the Imap
+ * server, and continues until that connection is closed.
+ *
+ * @author Darrell DeBoer <da...@apache.org>
+ *
+ * @version $Revision: 109034 $
+ */
+public interface ImapSession
+{
+ /**
+ * Sends any unsolicited responses to the client, such as EXISTS and FLAGS
+ * responses when the selected mailbox is modified by another user.
+ * @param response The response to write to
+ */
+ void unsolicitedResponses( ImapResponse response, boolean useUid ) throws MailboxException;
+
+ /**
+ * Closes the connection for this session.
+ */
+ void closeConnection();
+
+ void closeConnection(String byeMessage);
+
+
+ /**
+ * Provides the UsersRepository for this session, to allow session
+ * to validate logins.
+ *
+ * @return The UsersRepository for this session.
+ */
+ UsersRepository getUsers();
+
+ /**
+ * @return The hostname of the connected client.
+ */
+ String getClientHostname();
+
+ /**
+ * @return The IP address of the connected client.
+ */
+ String getClientIP();
+
+ /**
+ * @return Returns the current state of this session.
+ */
+ ImapSessionState getState();
+
+ /**
+ * Moves the session into {@link ImapSessionState#AUTHENTICATED} state with
+ * the supplied user.
+ * @param user The user who is authenticated for this session.
+ */
+ void setAuthenticated( User user );
+
+ /**
+ * Provides the authenticated user for this session, or <code>null</code> if this
+ * session is not in {@link ImapSessionState#AUTHENTICATED} or
+ * {@link ImapSessionState#SELECTED} state.
+ * @return The user authenticated for this session
+ */
+ User getUser();
+
+ /**
+ * Moves this session into {@link ImapSessionState#SELECTED} state and sets the
+ * supplied mailbox to be the currently selected mailbox.
+ * @param mailbox The selected mailbox.
+ * @param readOnly If <code>true</code>, the selection is set to be read only.
+ * @throws MailboxManagerException
+ */
+ void setSelected( ImapMailboxSession mailbox, boolean readOnly ) throws MailboxManagerException;
+
+ /**
+ * Moves the session out of {@link ImapSessionState#SELECTED} state and back into
+ * {@link ImapSessionState#AUTHENTICATED} state. The selected mailbox is cleared.
+ */
+ void deselect();
+
+ /**
+ * Provides the selected mailbox for this session, or <code>null</code> if this
+ * session is not in {@link ImapSessionState#SELECTED} state.
+ * @return the currently selected mailbox.
+ */
+ SelectedMailboxSession getSelected();
+
+ void unsolicitedResponses( ImapResponse request, boolean omitExpunged, boolean useUid) throws MailboxException;
+
+ /**
+ * closes the Mailbox if needed
+ */
+ void closeMailbox();
+
+ GeneralManager getMailboxManager() throws MailboxManagerException;
+
+ String buildFullName(String mailboxName) throws MailboxManagerException;
+
+}
Propchange: james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/ImapSession.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/ImapSessionImpl.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/ImapSessionImpl.java?view=diff&rev=454662&r1=454661&r2=454662
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/ImapSessionImpl.java (original)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/ImapSessionImpl.java Tue Oct 10 01:34:56 2006
@@ -1,222 +1,222 @@
-/****************************************************************
- * 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.imapserver;
-
-
-import javax.mail.Flags;
-
-import org.apache.james.imapserver.store.MailboxException;
-import org.apache.james.imapserver.store.MessageFlags;
-import org.apache.james.mailboxmanager.MailboxManagerException;
-import org.apache.james.mailboxmanager.MessageResult;
-import org.apache.james.mailboxmanager.mailbox.ImapMailboxSession;
-import org.apache.james.mailboxmanager.manager.GeneralManager;
-import org.apache.james.mailboxmanager.manager.MailboxManagerProvider;
-import org.apache.james.services.User;
-import org.apache.james.services.UsersRepository;
-
-/**
- *
- * @author Darrell DeBoer <da...@apache.org>
- *
- * @version $Revision: 109034 $
- */
-public final class ImapSessionImpl implements ImapSession, ImapConstants
-{
- private ImapSessionState state = ImapSessionState.NON_AUTHENTICATED;
- private User user = null;
- private SelectedMailboxSession selectedMailbox = null;
-
- private String clientHostName;
- private String clientAddress;
-
- // TODO these shouldn't be in here - they can be provided directly to command components.
- private ImapHandlerInterface handler;
- private MailboxManagerProvider mailboxManagerProvider;
- private UsersRepository users;
-
- private GeneralManager mailboxManager = null;
- private User mailboxManagerUser = null;
-
- public ImapSessionImpl( MailboxManagerProvider mailboxManagerProvider,
- UsersRepository users,
- ImapHandlerInterface handler,
- String clientHostName,
- String clientAddress )
- {
- this.mailboxManagerProvider = mailboxManagerProvider;
- this.users = users;
- this.handler = handler;
- this.clientHostName = clientHostName;
- this.clientAddress = clientAddress;
- }
-
-
-
- private MailboxManagerProvider getMailboxManagerProvider()
- {
- return mailboxManagerProvider;
- }
-
- public void unsolicitedResponses( ImapResponse request, boolean useUid ) throws MailboxException {
- unsolicitedResponses(request, false, useUid);
- }
-
- public void unsolicitedResponses(ImapResponse response, boolean omitExpunged, boolean useUid)
- throws MailboxException {
- SelectedMailboxSession selected = getSelected();
- try {
- if (selected != null) {
- // New message response
- if (selected.isSizeChanged()) {
- response.existsResponse(selected.getMailbox()
- .getMessageCount());
- response.recentResponse(selected.getMailbox()
- .getRecentCount(true));
- selected.setSizeChanged(false);
- }
-
- // Message updates
- MessageResult[] flagUpdates = selected.getMailbox().getFlagEvents(true);
- for (int i = 0; i < flagUpdates.length; i++) {
- MessageResult mr = flagUpdates[i];
- int msn = mr.getMsn();
- Flags updatedFlags = mr.getFlags();
- StringBuffer out = new StringBuffer("FLAGS ");
- out.append(MessageFlags.format(updatedFlags));
- if (useUid) {
- out.append(" UID ");
- out.append(mr.getUid());
- }
- response.fetchResponse(msn, out.toString());
- }
-
- // Expunged messages
- if (!omitExpunged) {
- MessageResult[] expunged = selected.getMailbox().getExpungedEvents(
- true);
- for (int i = 0; i < expunged.length; i++) {
- MessageResult mr = expunged[i];
- response.expungeResponse(mr.getMsn());
- }
- }
- }
- } catch (MailboxManagerException e) {
- throw new MailboxException(e);
- }
- }
-
- public void closeConnection(String byeMessage) {
- closeMailbox();
- handler.forceConnectionClose(byeMessage);
- }
-
- public void closeConnection()
- {
- closeMailbox();
- handler.resetHandler();
- }
-
- public UsersRepository getUsers()
- {
- return users;
- }
-
- public String getClientHostname()
- {
- return clientHostName;
- }
-
- public String getClientIP()
- {
- return clientAddress;
- }
-
- public void setAuthenticated( User user )
- {
- this.state = ImapSessionState.AUTHENTICATED;
- this.user = user;
- }
-
- public User getUser()
- {
- return this.user;
- }
-
- public void deselect()
- {
- this.state = ImapSessionState.AUTHENTICATED;
- closeMailbox();
- }
-
- public void setSelected( ImapMailboxSession mailbox, boolean readOnly ) throws MailboxManagerException
- {
- SelectedMailboxSession sessionMailbox = new SelectedMailboxSession(mailbox, this, readOnly);
- this.state = ImapSessionState.SELECTED;
- closeMailbox();
- this.selectedMailbox = sessionMailbox;
- }
-
- public SelectedMailboxSession getSelected()
- {
- return this.selectedMailbox;
- }
-
- public ImapSessionState getState()
- {
- return this.state;
- }
-
- public void closeMailbox()
- {
- if (selectedMailbox != null) {
- selectedMailbox.close();
- selectedMailbox=null;
- }
-
- }
-
-
-
- public GeneralManager getMailboxManager() throws MailboxManagerException {
- final boolean usersEqual;
- if (mailboxManagerUser!=null) {
- usersEqual=mailboxManagerUser.equals(user);
- } else {
- usersEqual=(user==null);
- }
- if (mailboxManager==null || !usersEqual) {
- if (mailboxManager!=null) {
- mailboxManager.close();
- }
- mailboxManager=mailboxManagerProvider.getGeneralManagerInstance(user);
- }
- return mailboxManager;
- }
-
-
-
- public String buildFullName(String mailboxName) throws MailboxManagerException {
- if (!mailboxName.startsWith(NAMESPACE_PREFIX)) {
- mailboxName = getMailboxManager().getPersonalDefaultNamespace(user).getName()+HIERARCHY_DELIMITER+mailboxName;
- }
- return mailboxName;
- }
-}
+/****************************************************************
+ * 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.imapserver;
+
+
+import javax.mail.Flags;
+
+import org.apache.james.imapserver.store.MailboxException;
+import org.apache.james.imapserver.store.MessageFlags;
+import org.apache.james.mailboxmanager.MailboxManagerException;
+import org.apache.james.mailboxmanager.MessageResult;
+import org.apache.james.mailboxmanager.mailbox.ImapMailboxSession;
+import org.apache.james.mailboxmanager.manager.GeneralManager;
+import org.apache.james.mailboxmanager.manager.MailboxManagerProvider;
+import org.apache.james.services.User;
+import org.apache.james.services.UsersRepository;
+
+/**
+ *
+ * @author Darrell DeBoer <da...@apache.org>
+ *
+ * @version $Revision: 109034 $
+ */
+public final class ImapSessionImpl implements ImapSession, ImapConstants
+{
+ private ImapSessionState state = ImapSessionState.NON_AUTHENTICATED;
+ private User user = null;
+ private SelectedMailboxSession selectedMailbox = null;
+
+ private String clientHostName;
+ private String clientAddress;
+
+ // TODO these shouldn't be in here - they can be provided directly to command components.
+ private ImapHandlerInterface handler;
+ private MailboxManagerProvider mailboxManagerProvider;
+ private UsersRepository users;
+
+ private GeneralManager mailboxManager = null;
+ private User mailboxManagerUser = null;
+
+ public ImapSessionImpl( MailboxManagerProvider mailboxManagerProvider,
+ UsersRepository users,
+ ImapHandlerInterface handler,
+ String clientHostName,
+ String clientAddress )
+ {
+ this.mailboxManagerProvider = mailboxManagerProvider;
+ this.users = users;
+ this.handler = handler;
+ this.clientHostName = clientHostName;
+ this.clientAddress = clientAddress;
+ }
+
+
+
+ private MailboxManagerProvider getMailboxManagerProvider()
+ {
+ return mailboxManagerProvider;
+ }
+
+ public void unsolicitedResponses( ImapResponse request, boolean useUid ) throws MailboxException {
+ unsolicitedResponses(request, false, useUid);
+ }
+
+ public void unsolicitedResponses(ImapResponse response, boolean omitExpunged, boolean useUid)
+ throws MailboxException {
+ SelectedMailboxSession selected = getSelected();
+ try {
+ if (selected != null) {
+ // New message response
+ if (selected.isSizeChanged()) {
+ response.existsResponse(selected.getMailbox()
+ .getMessageCount());
+ response.recentResponse(selected.getMailbox()
+ .getRecentCount(true));
+ selected.setSizeChanged(false);
+ }
+
+ // Message updates
+ MessageResult[] flagUpdates = selected.getMailbox().getFlagEvents(true);
+ for (int i = 0; i < flagUpdates.length; i++) {
+ MessageResult mr = flagUpdates[i];
+ int msn = mr.getMsn();
+ Flags updatedFlags = mr.getFlags();
+ StringBuffer out = new StringBuffer("FLAGS ");
+ out.append(MessageFlags.format(updatedFlags));
+ if (useUid) {
+ out.append(" UID ");
+ out.append(mr.getUid());
+ }
+ response.fetchResponse(msn, out.toString());
+ }
+
+ // Expunged messages
+ if (!omitExpunged) {
+ MessageResult[] expunged = selected.getMailbox().getExpungedEvents(
+ true);
+ for (int i = 0; i < expunged.length; i++) {
+ MessageResult mr = expunged[i];
+ response.expungeResponse(mr.getMsn());
+ }
+ }
+ }
+ } catch (MailboxManagerException e) {
+ throw new MailboxException(e);
+ }
+ }
+
+ public void closeConnection(String byeMessage) {
+ closeMailbox();
+ handler.forceConnectionClose(byeMessage);
+ }
+
+ public void closeConnection()
+ {
+ closeMailbox();
+ handler.resetHandler();
+ }
+
+ public UsersRepository getUsers()
+ {
+ return users;
+ }
+
+ public String getClientHostname()
+ {
+ return clientHostName;
+ }
+
+ public String getClientIP()
+ {
+ return clientAddress;
+ }
+
+ public void setAuthenticated( User user )
+ {
+ this.state = ImapSessionState.AUTHENTICATED;
+ this.user = user;
+ }
+
+ public User getUser()
+ {
+ return this.user;
+ }
+
+ public void deselect()
+ {
+ this.state = ImapSessionState.AUTHENTICATED;
+ closeMailbox();
+ }
+
+ public void setSelected( ImapMailboxSession mailbox, boolean readOnly ) throws MailboxManagerException
+ {
+ SelectedMailboxSession sessionMailbox = new SelectedMailboxSession(mailbox, this, readOnly);
+ this.state = ImapSessionState.SELECTED;
+ closeMailbox();
+ this.selectedMailbox = sessionMailbox;
+ }
+
+ public SelectedMailboxSession getSelected()
+ {
+ return this.selectedMailbox;
+ }
+
+ public ImapSessionState getState()
+ {
+ return this.state;
+ }
+
+ public void closeMailbox()
+ {
+ if (selectedMailbox != null) {
+ selectedMailbox.close();
+ selectedMailbox=null;
+ }
+
+ }
+
+
+
+ public GeneralManager getMailboxManager() throws MailboxManagerException {
+ final boolean usersEqual;
+ if (mailboxManagerUser!=null) {
+ usersEqual=mailboxManagerUser.equals(user);
+ } else {
+ usersEqual=(user==null);
+ }
+ if (mailboxManager==null || !usersEqual) {
+ if (mailboxManager!=null) {
+ mailboxManager.close();
+ }
+ mailboxManager=mailboxManagerProvider.getGeneralManagerInstance(user);
+ }
+ return mailboxManager;
+ }
+
+
+
+ public String buildFullName(String mailboxName) throws MailboxManagerException {
+ if (!mailboxName.startsWith(NAMESPACE_PREFIX)) {
+ mailboxName = getMailboxManager().getPersonalDefaultNamespace(user).getName()+HIERARCHY_DELIMITER+mailboxName;
+ }
+ return mailboxName;
+ }
+}
Propchange: james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/ImapSessionImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/ImapSessionState.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/ImapSessionState.java?view=diff&rev=454662&r1=454661&r2=454662
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/ImapSessionState.java (original)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/ImapSessionState.java Tue Oct 10 01:34:56 2006
@@ -1,43 +1,43 @@
-/****************************************************************
- * 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.imapserver;
-
-/**
- * Enumerated type representing an IMAP session state.
- */
-public class ImapSessionState
-{
- public static final ImapSessionState NON_AUTHENTICATED = new ImapSessionState( "NON_AUTHENTICATED" );
- public static final ImapSessionState AUTHENTICATED = new ImapSessionState( "AUTHENTICATED" );
- public static final ImapSessionState SELECTED = new ImapSessionState( "SELECTED" );
- public static final ImapSessionState LOGOUT = new ImapSessionState( "LOGOUT" );
-
- private final String myName; // for debug only
-
- private ImapSessionState( String name )
- {
- myName = name;
- }
-
- public String toString()
- {
- return myName;
- }
-}
+/****************************************************************
+ * 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.imapserver;
+
+/**
+ * Enumerated type representing an IMAP session state.
+ */
+public class ImapSessionState
+{
+ public static final ImapSessionState NON_AUTHENTICATED = new ImapSessionState( "NON_AUTHENTICATED" );
+ public static final ImapSessionState AUTHENTICATED = new ImapSessionState( "AUTHENTICATED" );
+ public static final ImapSessionState SELECTED = new ImapSessionState( "SELECTED" );
+ public static final ImapSessionState LOGOUT = new ImapSessionState( "LOGOUT" );
+
+ private final String myName; // for debug only
+
+ private ImapSessionState( String name )
+ {
+ myName = name;
+ }
+
+ public String toString()
+ {
+ return myName;
+ }
+}
Propchange: james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/ImapSessionState.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/ProtocolException.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/ProtocolException.java?view=diff&rev=454662&r1=454661&r2=454662
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/ProtocolException.java (original)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/ProtocolException.java Tue Oct 10 01:34:56 2006
@@ -1,34 +1,34 @@
-/****************************************************************
- * 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.imapserver;
-
-/**
- *
- * @author Darrell DeBoer <da...@apache.org>
- *
- * @version $Revision: 109034 $
- */
-public class ProtocolException extends Exception
-{
- public ProtocolException( String s )
- {
- super( s );
- }
-}
+/****************************************************************
+ * 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.imapserver;
+
+/**
+ *
+ * @author Darrell DeBoer <da...@apache.org>
+ *
+ * @version $Revision: 109034 $
+ */
+public class ProtocolException extends Exception
+{
+ public ProtocolException( String s )
+ {
+ super( s );
+ }
+}
Propchange: james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/ProtocolException.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