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 [4/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/commands/CommandParser.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/commands/CommandParser.java?view=diff&rev=454662&r1=454661&r2=454662
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/commands/CommandParser.java (original)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/commands/CommandParser.java Tue Oct 10 01:34:56 2006
@@ -1,538 +1,538 @@
-/****************************************************************
- * 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.commands;
-
-import java.text.DateFormat;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Date;
-
-import javax.mail.Flags;
-
-import org.apache.james.imapserver.ImapConstants;
-import org.apache.james.imapserver.ImapRequestLineReader;
-import org.apache.james.imapserver.ProtocolException;
-import org.apache.james.imapserver.store.MessageFlags;
-
-/**
- *
- * @author Darrell DeBoer <da...@apache.org>
- *
- * @version $Revision: 109034 $
- */
-public class CommandParser
-{
- private static final char[] EMPTY_CHAR_ARRAY = new char[0];
-
- /**
- * Reads an argument of type "atom" from the request.
- */
- public String atom( ImapRequestLineReader request ) throws ProtocolException
- {
- return consumeWord( request, new ATOM_CHARValidator() );
- }
-
- /**
- * Reads a command "tag" from the request.
- */
- public String tag(ImapRequestLineReader request) throws ProtocolException
- {
- CharacterValidator validator = new TagCharValidator();
- return consumeWord( request, validator );
- }
-
- /**
- * Reads an argument of type "astring" from the request.
- */
- public String astring(ImapRequestLineReader request) throws ProtocolException
- {
- char next = request.nextWordChar();
- switch ( next ) {
- case '"':
- return consumeQuoted( request );
- case '{':
- return consumeLiteral( request );
- default:
- return atom( request );
- }
- }
-
- /**
- * Reads an argument of type "nstring" from the request.
- */
- public String nstring( ImapRequestLineReader request ) throws ProtocolException
- {
- char next = request.nextWordChar();
- switch ( next ) {
- case '"':
- return consumeQuoted( request );
- case '{':
- return consumeLiteral( request );
- default:
- String value = atom( request );
- if ( "NIL".equals( value ) ) {
- return null;
- }
- else {
- throw new ProtocolException( "Invalid nstring value: valid values are '\"...\"', '{12} CRLF *CHAR8', and 'NIL'." );
- }
- }
- }
-
- /**
- * Reads a "mailbox" argument from the request. Not implemented *exactly* as per spec,
- * since a quoted or literal "inbox" still yeilds "INBOX"
- * (ie still case-insensitive if quoted or literal). I think this makes sense.
- *
- * mailbox ::= "INBOX" / astring
- * ;; INBOX is case-insensitive. All case variants of
- * ;; INBOX (e.g. "iNbOx") MUST be interpreted as INBOX
- * ;; not as an astring.
- */
- public String mailbox( ImapRequestLineReader request ) throws ProtocolException
- {
- String mailbox = astring( request );
- if ( mailbox.equalsIgnoreCase( ImapConstants.INBOX_NAME ) ) {
- return ImapConstants.INBOX_NAME;
- }
- else {
- return mailbox;
- }
- }
-
- /**
- * Reads a "date-time" argument from the request.
- * TODO handle timezones properly
- */
- public Date dateTime( ImapRequestLineReader request ) throws ProtocolException
- {
- char next = request.nextWordChar();
- String dateString;
- if ( next == '"' ) {
- dateString = consumeQuoted( request );
- }
- else {
- throw new ProtocolException( "DateTime values must be quoted." );
- }
-
- DateFormat dateFormat = new SimpleDateFormat( "dd-MMM-yyyy hh:mm:ss zzzz" );
- try {
- return dateFormat.parse( dateString );
- }
- catch ( ParseException e ) {
- throw new ProtocolException( "Invalid date format." );
- }
- }
-
- /**
- * Reads a "date" argument from the request.
- * TODO handle timezones properly
- */
- public Date date( ImapRequestLineReader request ) throws ProtocolException
- {
- char next = request.nextWordChar();
- String dateString;
- if ( next == '"' ) {
- dateString = consumeQuoted( request );
- }
- else {
- dateString = atom( request );
- }
-
- DateFormat dateFormat = new SimpleDateFormat( "dd-MMM-yyyy" );
- try {
- return dateFormat.parse( dateString );
- }
- catch ( ParseException e ) {
- throw new ProtocolException( "Invalid date format." );
- }
- }
-
- /**
- * Reads the next "word from the request, comprising all characters up to the next SPACE.
- * Characters are tested by the supplied CharacterValidator, and an exception is thrown
- * if invalid characters are encountered.
- */
- protected String consumeWord( ImapRequestLineReader request,
- CharacterValidator validator )
- throws ProtocolException
- {
- StringBuffer atom = new StringBuffer();
-
- char next = request.nextWordChar();
- while( ! isWhitespace( next ) ) {
- if ( validator.isValid( next ) )
- {
- atom.append( next );
- request.consume();
- }
- else {
- throw new ProtocolException( "Invalid character: '" + next + "'" );
- }
- next = request.nextChar();
- }
- return atom.toString();
- }
-
- private boolean isWhitespace( char next )
- {
- return ( next == ' ' || next == '\n' || next == '\r' || next == '\t' );
- }
-
- /**
- * 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
- {
- // The 1st character must be '{'
- consumeChar( request, '{' );
-
- StringBuffer digits = new StringBuffer();
- char next = request.nextChar();
- while ( next != '}' && next != '+' )
- {
- digits.append( next );
- request.consume();
- next = request.nextChar();
- }
-
- // If the number is *not* suffixed with a '+', we *are* using a synchronized literal,
- // and we need to send command continuation request before reading data.
- boolean synchronizedLiteral = true;
- // '+' indicates a non-synchronized literal (no command continuation request)
- if ( next == '+' ) {
- synchronizedLiteral = false;
- consumeChar(request, '+' );
- }
-
- // Consume the '}' and the newline
- consumeChar( request, '}' );
- consumeCRLF( request );
-
- if ( synchronizedLiteral ) {
- request.commandContinuationRequest();
- }
-
- int size = Integer.parseInt( digits.toString() );
- byte[] buffer = new byte[size];
- request.read( buffer );
-
- return new String( buffer );
- }
-
- /**
- * Consumes a CRLF from the request.
- * TODO we're being liberal, the spec insists on \r\n for new lines.
- * @param request
- * @throws ProtocolException
- */
- private void consumeCRLF( ImapRequestLineReader request )
- throws ProtocolException
- {
- char next = request.nextChar();
- if ( next != '\n' ) {
- consumeChar( request, '\r' );
- }
- consumeChar( request, '\n' );
- }
-
- /**
- * Consumes the next character in the request, checking that it matches the
- * expected one. This method should be used when the
- */
- protected void consumeChar( ImapRequestLineReader request, char expected )
- throws ProtocolException
- {
- char consumed = request.consume();
- if ( consumed != expected ) {
- throw new ProtocolException( "Expected:'" + expected + "' found:'" + consumed + "'" );
- }
- }
-
- /**
- * Reads a quoted string value from the request.
- */
- protected String consumeQuoted( ImapRequestLineReader request )
- throws ProtocolException
- {
- // The 1st character must be '"'
- consumeChar(request, '"' );
-
- StringBuffer quoted = new StringBuffer();
- char next = request.nextChar();
- while( next != '"' ) {
- if ( next == '\\' ) {
- request.consume();
- next = request.nextChar();
- if ( ! isQuotedSpecial( next ) ) {
- throw new ProtocolException( "Invalid escaped character in quote: '" +
- next + "'" );
- }
- }
- quoted.append( next );
- request.consume();
- next = request.nextChar();
- }
-
- consumeChar( request, '"' );
-
- return quoted.toString();
- }
-
- /**
- * Reads a base64 argument from the request.
- */
- public byte[] base64( ImapRequestLineReader request ) throws ProtocolException
- {
- return null;
- }
-
- /**
- * Reads a "flags" argument from the request.
- */
- public Flags flagList( ImapRequestLineReader request ) throws ProtocolException
- {
- Flags flags = new Flags();
- request.nextWordChar();
- consumeChar( request, '(' );
- CharacterValidator validator = new NoopCharValidator();
- String nextWord = consumeWord( request, validator );
- while ( ! nextWord.endsWith(")" ) ) {
- setFlag( nextWord, flags );
- nextWord = consumeWord( request, validator );
- }
- // Got the closing ")", may be attached to a word.
- if ( nextWord.length() > 1 ) {
- setFlag( nextWord.substring(0, nextWord.length() - 1 ), flags );
- }
-
- return flags;
- }
-
- public void setFlag( String flagString, Flags flags ) throws ProtocolException
- {
- if ( flagString.equalsIgnoreCase( MessageFlags.ANSWERED ) ) {
- flags.add(Flags.Flag.ANSWERED);
- }
- else if ( flagString.equalsIgnoreCase( MessageFlags.DELETED ) ) {
- flags.add(Flags.Flag.DELETED);
- }
- else if ( flagString.equalsIgnoreCase( MessageFlags.DRAFT ) ) {
- flags.add(Flags.Flag.DRAFT);
- }
- else if ( flagString.equalsIgnoreCase( MessageFlags.FLAGGED ) ) {
- flags.add(Flags.Flag.FLAGGED);
- }
- else if ( flagString.equalsIgnoreCase( MessageFlags.SEEN ) ) {
- flags.add(Flags.Flag.SEEN);
- }
- else {
- throw new ProtocolException( "Invalid flag string." );
- }
- }
-
- /**
- * Reads an argument of type "number" from the request.
- */
- public long number( ImapRequestLineReader request ) throws ProtocolException
- {
- String digits = consumeWord( request, new DigitCharValidator() );
- return Long.parseLong( digits );
- }
-
- /**
- * Reads an argument of type "nznumber" (a non-zero number)
- * (NOTE this isn't strictly as per the spec, since the spec disallows
- * numbers such as "0123" as nzNumbers (although it's ok as a "number".
- * I think the spec is a bit shonky.)
- */
- public long nzNumber( ImapRequestLineReader request ) throws ProtocolException
- {
- long number = number( request );
- if ( number == 0 ) {
- throw new ProtocolException( "Zero value not permitted." );
- }
- return number;
- }
-
- private boolean isCHAR( char chr )
- {
- return ( chr >= 0x01 && chr <= 0x7f );
- }
-
- private boolean isCHAR8( char chr )
- {
- return ( chr >= 0x01 && chr <= 0xff );
- }
-
- protected boolean isListWildcard( char chr )
- {
- return ( chr == '*' || chr == '%' );
- }
-
- private boolean isQuotedSpecial( char chr )
- {
- return ( chr == '"' || chr == '\\' );
- }
-
- /**
- * Consumes the request up to and including the eno-of-line.
- * @param request The request
- * @throws ProtocolException If characters are encountered before the endLine.
- */
- public void endLine( ImapRequestLineReader request ) throws ProtocolException
- {
- request.eol();
- }
-
- /**
- * Reads a "message set" argument, and parses into an IdSet.
- * Currently only supports a single range of values.
- */
- public IdRange[] parseIdRange( ImapRequestLineReader request )
- throws ProtocolException
- {
- CharacterValidator validator = new MessageSetCharValidator();
- String nextWord = consumeWord( request, validator );
-
- int commaPos = nextWord.indexOf( ',' );
- if ( commaPos == -1 ) {
- return new IdRange[]{ parseRange( nextWord ) };
- }
-
- ArrayList rangeList = new ArrayList();
- int pos = 0;
- while ( commaPos != -1 ) {
- String range = nextWord.substring( pos, commaPos );
- IdRange set = parseRange( range );
- rangeList.add( set );
-
- pos = commaPos + 1;
- commaPos = nextWord.indexOf( ',', pos );
- }
- String range = nextWord.substring( pos );
- rangeList.add( parseRange( range ) );
- return (IdRange[]) rangeList.toArray(new IdRange[rangeList.size()]);
- }
-
- private IdRange parseRange( String range ) throws ProtocolException
- {
- int pos = range.indexOf( ':' );
- try {
- if ( pos == -1 ) {
- long value = parseLong( range );
- return new IdRange( value );
- }
- else {
- long lowVal = parseLong( range.substring(0, pos ) );
- long highVal = parseLong( range.substring( pos + 1 ) );
- return new IdRange( lowVal, highVal );
- }
- }
- catch ( NumberFormatException e ) {
- throw new ProtocolException( "Invalid message set.");
- }
- }
-
- private long parseLong( String value ) {
- if ( value.length() == 1 && value.charAt(0) == '*' ) {
- return Long.MAX_VALUE;
- }
- return Long.parseLong( value );
- }
- /**
- * Provides the ability to ensure characters are part of a permitted set.
- */
- protected interface CharacterValidator
- {
- /**
- * Validates the supplied character.
- * @param chr The character to validate.
- * @return <code>true</code> if chr is valid, <code>false</code> if not.
- */
- boolean isValid( char chr );
- }
-
- protected class NoopCharValidator implements CharacterValidator
- {
- public boolean isValid( char chr )
- {
- return true;
- }
- }
-
- protected class ATOM_CHARValidator implements CharacterValidator
- {
- public boolean isValid( char chr )
- {
- return ( isCHAR( chr ) && !isAtomSpecial( chr ) &&
- !isListWildcard( chr ) && !isQuotedSpecial( chr ) );
- }
-
- private boolean isAtomSpecial( char chr )
- {
- return ( chr == '(' ||
- chr == ')' ||
- chr == '{' ||
- chr == ' ' ||
- chr == Character.CONTROL );
- }
- }
-
- protected class DigitCharValidator implements CharacterValidator
- {
- public boolean isValid( char chr )
- {
- return ( ( chr >= '0' && chr <= '9' ) ||
- chr == '*' );
- }
- }
-
- private class TagCharValidator extends ATOM_CHARValidator
- {
- public boolean isValid( char chr )
- {
- if ( chr == '+' ) return false;
- return super.isValid( chr );
- }
- }
-
- private class MessageSetCharValidator implements CharacterValidator
- {
- public boolean isValid( char chr )
- {
- return ( isDigit( chr ) ||
- chr == ':' ||
- chr == '*' ||
- chr == ',' );
- }
-
- private boolean isDigit( char chr )
- {
- return '0' <= chr && chr <= '9';
- }
- }
-
-}
+/****************************************************************
+ * 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.commands;
+
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+
+import javax.mail.Flags;
+
+import org.apache.james.imapserver.ImapConstants;
+import org.apache.james.imapserver.ImapRequestLineReader;
+import org.apache.james.imapserver.ProtocolException;
+import org.apache.james.imapserver.store.MessageFlags;
+
+/**
+ *
+ * @author Darrell DeBoer <da...@apache.org>
+ *
+ * @version $Revision: 109034 $
+ */
+public class CommandParser
+{
+ private static final char[] EMPTY_CHAR_ARRAY = new char[0];
+
+ /**
+ * Reads an argument of type "atom" from the request.
+ */
+ public String atom( ImapRequestLineReader request ) throws ProtocolException
+ {
+ return consumeWord( request, new ATOM_CHARValidator() );
+ }
+
+ /**
+ * Reads a command "tag" from the request.
+ */
+ public String tag(ImapRequestLineReader request) throws ProtocolException
+ {
+ CharacterValidator validator = new TagCharValidator();
+ return consumeWord( request, validator );
+ }
+
+ /**
+ * Reads an argument of type "astring" from the request.
+ */
+ public String astring(ImapRequestLineReader request) throws ProtocolException
+ {
+ char next = request.nextWordChar();
+ switch ( next ) {
+ case '"':
+ return consumeQuoted( request );
+ case '{':
+ return consumeLiteral( request );
+ default:
+ return atom( request );
+ }
+ }
+
+ /**
+ * Reads an argument of type "nstring" from the request.
+ */
+ public String nstring( ImapRequestLineReader request ) throws ProtocolException
+ {
+ char next = request.nextWordChar();
+ switch ( next ) {
+ case '"':
+ return consumeQuoted( request );
+ case '{':
+ return consumeLiteral( request );
+ default:
+ String value = atom( request );
+ if ( "NIL".equals( value ) ) {
+ return null;
+ }
+ else {
+ throw new ProtocolException( "Invalid nstring value: valid values are '\"...\"', '{12} CRLF *CHAR8', and 'NIL'." );
+ }
+ }
+ }
+
+ /**
+ * Reads a "mailbox" argument from the request. Not implemented *exactly* as per spec,
+ * since a quoted or literal "inbox" still yeilds "INBOX"
+ * (ie still case-insensitive if quoted or literal). I think this makes sense.
+ *
+ * mailbox ::= "INBOX" / astring
+ * ;; INBOX is case-insensitive. All case variants of
+ * ;; INBOX (e.g. "iNbOx") MUST be interpreted as INBOX
+ * ;; not as an astring.
+ */
+ public String mailbox( ImapRequestLineReader request ) throws ProtocolException
+ {
+ String mailbox = astring( request );
+ if ( mailbox.equalsIgnoreCase( ImapConstants.INBOX_NAME ) ) {
+ return ImapConstants.INBOX_NAME;
+ }
+ else {
+ return mailbox;
+ }
+ }
+
+ /**
+ * Reads a "date-time" argument from the request.
+ * TODO handle timezones properly
+ */
+ public Date dateTime( ImapRequestLineReader request ) throws ProtocolException
+ {
+ char next = request.nextWordChar();
+ String dateString;
+ if ( next == '"' ) {
+ dateString = consumeQuoted( request );
+ }
+ else {
+ throw new ProtocolException( "DateTime values must be quoted." );
+ }
+
+ DateFormat dateFormat = new SimpleDateFormat( "dd-MMM-yyyy hh:mm:ss zzzz" );
+ try {
+ return dateFormat.parse( dateString );
+ }
+ catch ( ParseException e ) {
+ throw new ProtocolException( "Invalid date format." );
+ }
+ }
+
+ /**
+ * Reads a "date" argument from the request.
+ * TODO handle timezones properly
+ */
+ public Date date( ImapRequestLineReader request ) throws ProtocolException
+ {
+ char next = request.nextWordChar();
+ String dateString;
+ if ( next == '"' ) {
+ dateString = consumeQuoted( request );
+ }
+ else {
+ dateString = atom( request );
+ }
+
+ DateFormat dateFormat = new SimpleDateFormat( "dd-MMM-yyyy" );
+ try {
+ return dateFormat.parse( dateString );
+ }
+ catch ( ParseException e ) {
+ throw new ProtocolException( "Invalid date format." );
+ }
+ }
+
+ /**
+ * Reads the next "word from the request, comprising all characters up to the next SPACE.
+ * Characters are tested by the supplied CharacterValidator, and an exception is thrown
+ * if invalid characters are encountered.
+ */
+ protected String consumeWord( ImapRequestLineReader request,
+ CharacterValidator validator )
+ throws ProtocolException
+ {
+ StringBuffer atom = new StringBuffer();
+
+ char next = request.nextWordChar();
+ while( ! isWhitespace( next ) ) {
+ if ( validator.isValid( next ) )
+ {
+ atom.append( next );
+ request.consume();
+ }
+ else {
+ throw new ProtocolException( "Invalid character: '" + next + "'" );
+ }
+ next = request.nextChar();
+ }
+ return atom.toString();
+ }
+
+ private boolean isWhitespace( char next )
+ {
+ return ( next == ' ' || next == '\n' || next == '\r' || next == '\t' );
+ }
+
+ /**
+ * 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
+ {
+ // The 1st character must be '{'
+ consumeChar( request, '{' );
+
+ StringBuffer digits = new StringBuffer();
+ char next = request.nextChar();
+ while ( next != '}' && next != '+' )
+ {
+ digits.append( next );
+ request.consume();
+ next = request.nextChar();
+ }
+
+ // If the number is *not* suffixed with a '+', we *are* using a synchronized literal,
+ // and we need to send command continuation request before reading data.
+ boolean synchronizedLiteral = true;
+ // '+' indicates a non-synchronized literal (no command continuation request)
+ if ( next == '+' ) {
+ synchronizedLiteral = false;
+ consumeChar(request, '+' );
+ }
+
+ // Consume the '}' and the newline
+ consumeChar( request, '}' );
+ consumeCRLF( request );
+
+ if ( synchronizedLiteral ) {
+ request.commandContinuationRequest();
+ }
+
+ int size = Integer.parseInt( digits.toString() );
+ byte[] buffer = new byte[size];
+ request.read( buffer );
+
+ return new String( buffer );
+ }
+
+ /**
+ * Consumes a CRLF from the request.
+ * TODO we're being liberal, the spec insists on \r\n for new lines.
+ * @param request
+ * @throws ProtocolException
+ */
+ private void consumeCRLF( ImapRequestLineReader request )
+ throws ProtocolException
+ {
+ char next = request.nextChar();
+ if ( next != '\n' ) {
+ consumeChar( request, '\r' );
+ }
+ consumeChar( request, '\n' );
+ }
+
+ /**
+ * Consumes the next character in the request, checking that it matches the
+ * expected one. This method should be used when the
+ */
+ protected void consumeChar( ImapRequestLineReader request, char expected )
+ throws ProtocolException
+ {
+ char consumed = request.consume();
+ if ( consumed != expected ) {
+ throw new ProtocolException( "Expected:'" + expected + "' found:'" + consumed + "'" );
+ }
+ }
+
+ /**
+ * Reads a quoted string value from the request.
+ */
+ protected String consumeQuoted( ImapRequestLineReader request )
+ throws ProtocolException
+ {
+ // The 1st character must be '"'
+ consumeChar(request, '"' );
+
+ StringBuffer quoted = new StringBuffer();
+ char next = request.nextChar();
+ while( next != '"' ) {
+ if ( next == '\\' ) {
+ request.consume();
+ next = request.nextChar();
+ if ( ! isQuotedSpecial( next ) ) {
+ throw new ProtocolException( "Invalid escaped character in quote: '" +
+ next + "'" );
+ }
+ }
+ quoted.append( next );
+ request.consume();
+ next = request.nextChar();
+ }
+
+ consumeChar( request, '"' );
+
+ return quoted.toString();
+ }
+
+ /**
+ * Reads a base64 argument from the request.
+ */
+ public byte[] base64( ImapRequestLineReader request ) throws ProtocolException
+ {
+ return null;
+ }
+
+ /**
+ * Reads a "flags" argument from the request.
+ */
+ public Flags flagList( ImapRequestLineReader request ) throws ProtocolException
+ {
+ Flags flags = new Flags();
+ request.nextWordChar();
+ consumeChar( request, '(' );
+ CharacterValidator validator = new NoopCharValidator();
+ String nextWord = consumeWord( request, validator );
+ while ( ! nextWord.endsWith(")" ) ) {
+ setFlag( nextWord, flags );
+ nextWord = consumeWord( request, validator );
+ }
+ // Got the closing ")", may be attached to a word.
+ if ( nextWord.length() > 1 ) {
+ setFlag( nextWord.substring(0, nextWord.length() - 1 ), flags );
+ }
+
+ return flags;
+ }
+
+ public void setFlag( String flagString, Flags flags ) throws ProtocolException
+ {
+ if ( flagString.equalsIgnoreCase( MessageFlags.ANSWERED ) ) {
+ flags.add(Flags.Flag.ANSWERED);
+ }
+ else if ( flagString.equalsIgnoreCase( MessageFlags.DELETED ) ) {
+ flags.add(Flags.Flag.DELETED);
+ }
+ else if ( flagString.equalsIgnoreCase( MessageFlags.DRAFT ) ) {
+ flags.add(Flags.Flag.DRAFT);
+ }
+ else if ( flagString.equalsIgnoreCase( MessageFlags.FLAGGED ) ) {
+ flags.add(Flags.Flag.FLAGGED);
+ }
+ else if ( flagString.equalsIgnoreCase( MessageFlags.SEEN ) ) {
+ flags.add(Flags.Flag.SEEN);
+ }
+ else {
+ throw new ProtocolException( "Invalid flag string." );
+ }
+ }
+
+ /**
+ * Reads an argument of type "number" from the request.
+ */
+ public long number( ImapRequestLineReader request ) throws ProtocolException
+ {
+ String digits = consumeWord( request, new DigitCharValidator() );
+ return Long.parseLong( digits );
+ }
+
+ /**
+ * Reads an argument of type "nznumber" (a non-zero number)
+ * (NOTE this isn't strictly as per the spec, since the spec disallows
+ * numbers such as "0123" as nzNumbers (although it's ok as a "number".
+ * I think the spec is a bit shonky.)
+ */
+ public long nzNumber( ImapRequestLineReader request ) throws ProtocolException
+ {
+ long number = number( request );
+ if ( number == 0 ) {
+ throw new ProtocolException( "Zero value not permitted." );
+ }
+ return number;
+ }
+
+ private boolean isCHAR( char chr )
+ {
+ return ( chr >= 0x01 && chr <= 0x7f );
+ }
+
+ private boolean isCHAR8( char chr )
+ {
+ return ( chr >= 0x01 && chr <= 0xff );
+ }
+
+ protected boolean isListWildcard( char chr )
+ {
+ return ( chr == '*' || chr == '%' );
+ }
+
+ private boolean isQuotedSpecial( char chr )
+ {
+ return ( chr == '"' || chr == '\\' );
+ }
+
+ /**
+ * Consumes the request up to and including the eno-of-line.
+ * @param request The request
+ * @throws ProtocolException If characters are encountered before the endLine.
+ */
+ public void endLine( ImapRequestLineReader request ) throws ProtocolException
+ {
+ request.eol();
+ }
+
+ /**
+ * Reads a "message set" argument, and parses into an IdSet.
+ * Currently only supports a single range of values.
+ */
+ public IdRange[] parseIdRange( ImapRequestLineReader request )
+ throws ProtocolException
+ {
+ CharacterValidator validator = new MessageSetCharValidator();
+ String nextWord = consumeWord( request, validator );
+
+ int commaPos = nextWord.indexOf( ',' );
+ if ( commaPos == -1 ) {
+ return new IdRange[]{ parseRange( nextWord ) };
+ }
+
+ ArrayList rangeList = new ArrayList();
+ int pos = 0;
+ while ( commaPos != -1 ) {
+ String range = nextWord.substring( pos, commaPos );
+ IdRange set = parseRange( range );
+ rangeList.add( set );
+
+ pos = commaPos + 1;
+ commaPos = nextWord.indexOf( ',', pos );
+ }
+ String range = nextWord.substring( pos );
+ rangeList.add( parseRange( range ) );
+ return (IdRange[]) rangeList.toArray(new IdRange[rangeList.size()]);
+ }
+
+ private IdRange parseRange( String range ) throws ProtocolException
+ {
+ int pos = range.indexOf( ':' );
+ try {
+ if ( pos == -1 ) {
+ long value = parseLong( range );
+ return new IdRange( value );
+ }
+ else {
+ long lowVal = parseLong( range.substring(0, pos ) );
+ long highVal = parseLong( range.substring( pos + 1 ) );
+ return new IdRange( lowVal, highVal );
+ }
+ }
+ catch ( NumberFormatException e ) {
+ throw new ProtocolException( "Invalid message set.");
+ }
+ }
+
+ private long parseLong( String value ) {
+ if ( value.length() == 1 && value.charAt(0) == '*' ) {
+ return Long.MAX_VALUE;
+ }
+ return Long.parseLong( value );
+ }
+ /**
+ * Provides the ability to ensure characters are part of a permitted set.
+ */
+ protected interface CharacterValidator
+ {
+ /**
+ * Validates the supplied character.
+ * @param chr The character to validate.
+ * @return <code>true</code> if chr is valid, <code>false</code> if not.
+ */
+ boolean isValid( char chr );
+ }
+
+ protected class NoopCharValidator implements CharacterValidator
+ {
+ public boolean isValid( char chr )
+ {
+ return true;
+ }
+ }
+
+ protected class ATOM_CHARValidator implements CharacterValidator
+ {
+ public boolean isValid( char chr )
+ {
+ return ( isCHAR( chr ) && !isAtomSpecial( chr ) &&
+ !isListWildcard( chr ) && !isQuotedSpecial( chr ) );
+ }
+
+ private boolean isAtomSpecial( char chr )
+ {
+ return ( chr == '(' ||
+ chr == ')' ||
+ chr == '{' ||
+ chr == ' ' ||
+ chr == Character.CONTROL );
+ }
+ }
+
+ protected class DigitCharValidator implements CharacterValidator
+ {
+ public boolean isValid( char chr )
+ {
+ return ( ( chr >= '0' && chr <= '9' ) ||
+ chr == '*' );
+ }
+ }
+
+ private class TagCharValidator extends ATOM_CHARValidator
+ {
+ public boolean isValid( char chr )
+ {
+ if ( chr == '+' ) return false;
+ return super.isValid( chr );
+ }
+ }
+
+ private class MessageSetCharValidator implements CharacterValidator
+ {
+ public boolean isValid( char chr )
+ {
+ return ( isDigit( chr ) ||
+ chr == ':' ||
+ chr == '*' ||
+ chr == ',' );
+ }
+
+ private boolean isDigit( char chr )
+ {
+ return '0' <= chr && chr <= '9';
+ }
+ }
+
+}
Propchange: james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/commands/CommandParser.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/commands/CommandTemplate.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/commands/CommandTemplate.java?view=diff&rev=454662&r1=454661&r2=454662
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/commands/CommandTemplate.java (original)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/commands/CommandTemplate.java Tue Oct 10 01:34:56 2006
@@ -1,135 +1,135 @@
-/****************************************************************
- * 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.commands;
-
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
-import org.apache.james.imapserver.AuthorizationException;
-import org.apache.james.imapserver.ImapConstants;
-import org.apache.james.imapserver.ImapRequestLineReader;
-import org.apache.james.imapserver.ImapResponse;
-import org.apache.james.imapserver.ImapSession;
-import org.apache.james.imapserver.ImapSessionState;
-import org.apache.james.imapserver.ProtocolException;
-import org.apache.james.imapserver.store.MailboxException;
-
-/**
- * Base class for all command implementations. This class provides common
- * core functionality useful for all {@link org.apache.james.imapserver.commands.ImapCommand} implementations.
- *
- * @author Darrell DeBoer <da...@apache.org>
- *
- * @version $Revision: 109034 $
- */
-abstract class CommandTemplate
- extends AbstractLogEnabled
- implements ImapCommand, ImapConstants
-{
- protected CommandParser parser = new CommandParser();
-
- /**
- * By default, valid in any state (unless overridden by subclass.
- * @see org.apache.james.imapserver.commands.ImapCommand#validForState
- */
- public boolean validForState( ImapSessionState state )
- {
- return true;
- }
-
- /**
- * Template methods for handling command processing. This method reads
- * argument values (validating them), and checks the request for correctness.
- * If correct, the command processing is delegated to the specific command
- * implemenation.
- *
- * @see ImapCommand#process
- */
- public void process( ImapRequestLineReader request,
- ImapResponse response,
- ImapSession session )
- {
- try {
- doProcess( request, response, session );
- }
- catch ( MailboxException e ) {
- response.commandFailed( this, e.getResponseCode(), e.getMessage() );
- }
- catch ( AuthorizationException e ) {
- String msg = "Authorization error: Lacking permissions to perform requested operation.";
- response.commandFailed( this, msg );
- }
- catch ( ProtocolException e ) {
- String msg = e.getMessage() + " Command should be '" +
- getExpectedMessage() + "'";
- response.commandError( msg );
- }
- }
-
- /**
- * This is the method overridden by specific command implementations to
- * perform commend-specific processing.
- *
- * @param request The client request
- * @param response The server response
- * @param session The current client session
- */
- protected abstract void doProcess( ImapRequestLineReader request,
- ImapResponse response,
- ImapSession session )
- throws ProtocolException, MailboxException, AuthorizationException;
-
- /**
- * Provides a message which describes the expected format and arguments
- * for this command. This is used to provide user feedback when a command
- * request is malformed.
- *
- * @return A message describing the command protocol format.
- */
- protected String getExpectedMessage()
- {
- StringBuffer syntax = new StringBuffer( "<tag> " );
- syntax.append( getName() );
-
- String args = getArgSyntax();
- if ( args != null && args.length() > 0 ) {
- syntax.append( " " );
- syntax.append( args );
- }
-
- return syntax.toString();
- }
-
- /**
- * Provides the syntax for the command arguments if any. This value is used
- * to provide user feedback in the case of a malformed request.
- *
- * For commands which do not allow any arguments, <code>null</code> should
- * be returned.
- *
- * @return The syntax for the command arguments, or <code>null</code> for
- * commands without arguments.
- */
- protected abstract String getArgSyntax();
-
-
- public CommandParser getParser()
- {
- return parser;
- }
-}
+/****************************************************************
+ * 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.commands;
+
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.james.imapserver.AuthorizationException;
+import org.apache.james.imapserver.ImapConstants;
+import org.apache.james.imapserver.ImapRequestLineReader;
+import org.apache.james.imapserver.ImapResponse;
+import org.apache.james.imapserver.ImapSession;
+import org.apache.james.imapserver.ImapSessionState;
+import org.apache.james.imapserver.ProtocolException;
+import org.apache.james.imapserver.store.MailboxException;
+
+/**
+ * Base class for all command implementations. This class provides common
+ * core functionality useful for all {@link org.apache.james.imapserver.commands.ImapCommand} implementations.
+ *
+ * @author Darrell DeBoer <da...@apache.org>
+ *
+ * @version $Revision: 109034 $
+ */
+abstract class CommandTemplate
+ extends AbstractLogEnabled
+ implements ImapCommand, ImapConstants
+{
+ protected CommandParser parser = new CommandParser();
+
+ /**
+ * By default, valid in any state (unless overridden by subclass.
+ * @see org.apache.james.imapserver.commands.ImapCommand#validForState
+ */
+ public boolean validForState( ImapSessionState state )
+ {
+ return true;
+ }
+
+ /**
+ * Template methods for handling command processing. This method reads
+ * argument values (validating them), and checks the request for correctness.
+ * If correct, the command processing is delegated to the specific command
+ * implemenation.
+ *
+ * @see ImapCommand#process
+ */
+ public void process( ImapRequestLineReader request,
+ ImapResponse response,
+ ImapSession session )
+ {
+ try {
+ doProcess( request, response, session );
+ }
+ catch ( MailboxException e ) {
+ response.commandFailed( this, e.getResponseCode(), e.getMessage() );
+ }
+ catch ( AuthorizationException e ) {
+ String msg = "Authorization error: Lacking permissions to perform requested operation.";
+ response.commandFailed( this, msg );
+ }
+ catch ( ProtocolException e ) {
+ String msg = e.getMessage() + " Command should be '" +
+ getExpectedMessage() + "'";
+ response.commandError( msg );
+ }
+ }
+
+ /**
+ * This is the method overridden by specific command implementations to
+ * perform commend-specific processing.
+ *
+ * @param request The client request
+ * @param response The server response
+ * @param session The current client session
+ */
+ protected abstract void doProcess( ImapRequestLineReader request,
+ ImapResponse response,
+ ImapSession session )
+ throws ProtocolException, MailboxException, AuthorizationException;
+
+ /**
+ * Provides a message which describes the expected format and arguments
+ * for this command. This is used to provide user feedback when a command
+ * request is malformed.
+ *
+ * @return A message describing the command protocol format.
+ */
+ protected String getExpectedMessage()
+ {
+ StringBuffer syntax = new StringBuffer( "<tag> " );
+ syntax.append( getName() );
+
+ String args = getArgSyntax();
+ if ( args != null && args.length() > 0 ) {
+ syntax.append( " " );
+ syntax.append( args );
+ }
+
+ return syntax.toString();
+ }
+
+ /**
+ * Provides the syntax for the command arguments if any. This value is used
+ * to provide user feedback in the case of a malformed request.
+ *
+ * For commands which do not allow any arguments, <code>null</code> should
+ * be returned.
+ *
+ * @return The syntax for the command arguments, or <code>null</code> for
+ * commands without arguments.
+ */
+ protected abstract String getArgSyntax();
+
+
+ public CommandParser getParser()
+ {
+ return parser;
+ }
+}
Propchange: james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/commands/CommandTemplate.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/commands/CopyCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/commands/CopyCommand.java?view=diff&rev=454662&r1=454661&r2=454662
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/commands/CopyCommand.java (original)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/commands/CopyCommand.java Tue Oct 10 01:34:56 2006
@@ -1,98 +1,98 @@
-/****************************************************************
- * 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.commands;
-
-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.MailboxException;
-import org.apache.james.mailboxmanager.GeneralMessageSet;
-import org.apache.james.mailboxmanager.MailboxManagerException;
-import org.apache.james.mailboxmanager.impl.GeneralMessageSetImpl;
-import org.apache.james.mailboxmanager.mailbox.ImapMailboxSession;
-
-/**
- * Handles processeing for the COPY imap command.
- *
- * @author Darrell DeBoer <da...@apache.org>
- *
- * @version $Revision: 109034 $
- */
-class CopyCommand extends SelectedStateCommand implements UidEnabledCommand
-{
- public static final String NAME = "COPY";
- public static final String ARGS = "<message-set> <mailbox>";
-
- /** @see CommandTemplate#doProcess */
- protected void doProcess( ImapRequestLineReader request,
- ImapResponse response,
- ImapSession session )
- throws ProtocolException, MailboxException
- {
- doProcess( request, response, session, false );
- }
-
- public void doProcess( ImapRequestLineReader request,
- ImapResponse response,
- ImapSession session,
- boolean useUids)
- throws ProtocolException, MailboxException
- {
- IdRange[] idSet = parser.parseIdRange( request );
- String mailboxName = parser.mailbox( request );
- parser.endLine( request );
-
- ImapMailboxSession currentMailbox = session.getSelected().getMailbox();
-
-
- try {
- mailboxName=session.buildFullName(mailboxName);
- if (!session.getMailboxManager().existsMailbox(mailboxName)) {
- MailboxException e=new MailboxException("Mailbox does not exists");
- e.setResponseCode( "TRYCREATE" );
- throw e;
- }
- for (int i = 0; i < idSet.length; i++) {
- GeneralMessageSet messageSet=GeneralMessageSetImpl.range(idSet[i].getLowVal(),idSet[i].getHighVal(),useUids);
- session.getMailboxManager().copyMessages(currentMailbox,messageSet,mailboxName);
- }
- } catch (MailboxManagerException e) {
- throw new MailboxException(e);
- }
-
-
-
- session.unsolicitedResponses( response, useUids);
- response.commandComplete( this );
- }
-
- /** @see ImapCommand#getName */
- public String getName()
- {
- return NAME;
- }
-
- /** @see CommandTemplate#getArgSyntax */
- public String getArgSyntax()
- {
- return ARGS;
- }
-}
+/****************************************************************
+ * 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.commands;
+
+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.MailboxException;
+import org.apache.james.mailboxmanager.GeneralMessageSet;
+import org.apache.james.mailboxmanager.MailboxManagerException;
+import org.apache.james.mailboxmanager.impl.GeneralMessageSetImpl;
+import org.apache.james.mailboxmanager.mailbox.ImapMailboxSession;
+
+/**
+ * Handles processeing for the COPY imap command.
+ *
+ * @author Darrell DeBoer <da...@apache.org>
+ *
+ * @version $Revision: 109034 $
+ */
+class CopyCommand extends SelectedStateCommand implements UidEnabledCommand
+{
+ public static final String NAME = "COPY";
+ public static final String ARGS = "<message-set> <mailbox>";
+
+ /** @see CommandTemplate#doProcess */
+ protected void doProcess( ImapRequestLineReader request,
+ ImapResponse response,
+ ImapSession session )
+ throws ProtocolException, MailboxException
+ {
+ doProcess( request, response, session, false );
+ }
+
+ public void doProcess( ImapRequestLineReader request,
+ ImapResponse response,
+ ImapSession session,
+ boolean useUids)
+ throws ProtocolException, MailboxException
+ {
+ IdRange[] idSet = parser.parseIdRange( request );
+ String mailboxName = parser.mailbox( request );
+ parser.endLine( request );
+
+ ImapMailboxSession currentMailbox = session.getSelected().getMailbox();
+
+
+ try {
+ mailboxName=session.buildFullName(mailboxName);
+ if (!session.getMailboxManager().existsMailbox(mailboxName)) {
+ MailboxException e=new MailboxException("Mailbox does not exists");
+ e.setResponseCode( "TRYCREATE" );
+ throw e;
+ }
+ for (int i = 0; i < idSet.length; i++) {
+ GeneralMessageSet messageSet=GeneralMessageSetImpl.range(idSet[i].getLowVal(),idSet[i].getHighVal(),useUids);
+ session.getMailboxManager().copyMessages(currentMailbox,messageSet,mailboxName);
+ }
+ } catch (MailboxManagerException e) {
+ throw new MailboxException(e);
+ }
+
+
+
+ session.unsolicitedResponses( response, useUids);
+ response.commandComplete( this );
+ }
+
+ /** @see ImapCommand#getName */
+ public String getName()
+ {
+ return NAME;
+ }
+
+ /** @see CommandTemplate#getArgSyntax */
+ public String getArgSyntax()
+ {
+ return ARGS;
+ }
+}
Propchange: james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/commands/CopyCommand.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/commands/CreateCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/commands/CreateCommand.java?view=diff&rev=454662&r1=454661&r2=454662
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/commands/CreateCommand.java (original)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/commands/CreateCommand.java Tue Oct 10 01:34:56 2006
@@ -1,125 +1,125 @@
-/****************************************************************
- * 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.commands;
-
-import org.apache.james.imapserver.AuthorizationException;
-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.MailboxException;
-import org.apache.james.mailboxmanager.MailboxManagerException;
-
-/**
- * Handles processeing for the CREATE imap command.
- *
- * @author Darrell DeBoer <da...@apache.org>
- *
- * @version $Revision: 109034 $
- */
-class CreateCommand extends AuthenticatedStateCommand
-{
- public static final String NAME = "CREATE";
- public static final String ARGS = "<mailbox>";
-
- /** @see CommandTemplate#doProcess */
- protected void doProcess( ImapRequestLineReader request,
- ImapResponse response,
- ImapSession session )
- throws ProtocolException, MailboxException, AuthorizationException
- {
- String mailboxName = parser.mailbox( request );
- parser.endLine( request );
-
-
- try {
-
- mailboxName=session.buildFullName(mailboxName);
- session.getMailboxManager().createMailbox(mailboxName );
- } catch (MailboxManagerException e) {
- throw new MailboxException(e);
- }
- session.unsolicitedResponses( response, false );
- response.commandComplete( this );
- }
-
- /** @see ImapCommand#getName */
- public String getName()
- {
- return NAME;
- }
-
- /** @see CommandTemplate#getArgSyntax */
- public String getArgSyntax()
- {
- return ARGS;
- }
-
-}
-
-/*
-6.3.3. CREATE Command
-
- Arguments: mailbox name
-
- Responses: no specific responses for this command
-
- Result: OK - create completed
- NO - create failure: can't create mailbox with that name
- BAD - command unknown or arguments invalid
-
- The CREATE command creates a mailbox with the given name. An OK
- response is returned only if a new mailbox with that name has been
- created. It is an error to attempt to create INBOX or a mailbox
- with a name that refers to an extant mailbox. Any error in
- creation will return a tagged NO response.
-
- If the mailbox name is suffixed with the server's hierarchy
- separator character (as returned from the server by a LIST
- command), this is a declaration that the client intends to create
- mailbox names under this name in the hierarchy. Server
- implementations that do not require this declaration MUST ignore
- it.
-
- If the server's hierarchy separator character appears elsewhere in
- the name, the server SHOULD create any superior hierarchical names
- that are needed for the CREATE command to complete successfully.
- In other words, an attempt to create "foo/bar/zap" on a server in
- which "/" is the hierarchy separator character SHOULD create foo/
- and foo/bar/ if they do not already exist.
-
- If a new mailbox is created with the same name as a mailbox which
- was deleted, its unique identifiers MUST be greater than any
- unique identifiers used in the previous incarnation of the mailbox
- UNLESS the new incarnation has a different unique identifier
- validity value. See the description of the UID command for more
- detail.
-
- Example: C: A003 CREATE owatagusiam/
- S: A003 OK CREATE completed
- C: A004 CREATE owatagusiam/blurdybloop
- S: A004 OK CREATE completed
-
- Note: the interpretation of this example depends on whether "/"
- was returned as the hierarchy separator from LIST. If "/" is the
- hierarchy separator, a new level of hierarchy named "owatagusiam"
- with a member called "blurdybloop" is created. Otherwise, two
- mailboxes at the same hierarchy level are created.
-*/
+/****************************************************************
+ * 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.commands;
+
+import org.apache.james.imapserver.AuthorizationException;
+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.MailboxException;
+import org.apache.james.mailboxmanager.MailboxManagerException;
+
+/**
+ * Handles processeing for the CREATE imap command.
+ *
+ * @author Darrell DeBoer <da...@apache.org>
+ *
+ * @version $Revision: 109034 $
+ */
+class CreateCommand extends AuthenticatedStateCommand
+{
+ public static final String NAME = "CREATE";
+ public static final String ARGS = "<mailbox>";
+
+ /** @see CommandTemplate#doProcess */
+ protected void doProcess( ImapRequestLineReader request,
+ ImapResponse response,
+ ImapSession session )
+ throws ProtocolException, MailboxException, AuthorizationException
+ {
+ String mailboxName = parser.mailbox( request );
+ parser.endLine( request );
+
+
+ try {
+
+ mailboxName=session.buildFullName(mailboxName);
+ session.getMailboxManager().createMailbox(mailboxName );
+ } catch (MailboxManagerException e) {
+ throw new MailboxException(e);
+ }
+ session.unsolicitedResponses( response, false );
+ response.commandComplete( this );
+ }
+
+ /** @see ImapCommand#getName */
+ public String getName()
+ {
+ return NAME;
+ }
+
+ /** @see CommandTemplate#getArgSyntax */
+ public String getArgSyntax()
+ {
+ return ARGS;
+ }
+
+}
+
+/*
+6.3.3. CREATE Command
+
+ Arguments: mailbox name
+
+ Responses: no specific responses for this command
+
+ Result: OK - create completed
+ NO - create failure: can't create mailbox with that name
+ BAD - command unknown or arguments invalid
+
+ The CREATE command creates a mailbox with the given name. An OK
+ response is returned only if a new mailbox with that name has been
+ created. It is an error to attempt to create INBOX or a mailbox
+ with a name that refers to an extant mailbox. Any error in
+ creation will return a tagged NO response.
+
+ If the mailbox name is suffixed with the server's hierarchy
+ separator character (as returned from the server by a LIST
+ command), this is a declaration that the client intends to create
+ mailbox names under this name in the hierarchy. Server
+ implementations that do not require this declaration MUST ignore
+ it.
+
+ If the server's hierarchy separator character appears elsewhere in
+ the name, the server SHOULD create any superior hierarchical names
+ that are needed for the CREATE command to complete successfully.
+ In other words, an attempt to create "foo/bar/zap" on a server in
+ which "/" is the hierarchy separator character SHOULD create foo/
+ and foo/bar/ if they do not already exist.
+
+ If a new mailbox is created with the same name as a mailbox which
+ was deleted, its unique identifiers MUST be greater than any
+ unique identifiers used in the previous incarnation of the mailbox
+ UNLESS the new incarnation has a different unique identifier
+ validity value. See the description of the UID command for more
+ detail.
+
+ Example: C: A003 CREATE owatagusiam/
+ S: A003 OK CREATE completed
+ C: A004 CREATE owatagusiam/blurdybloop
+ S: A004 OK CREATE completed
+
+ Note: the interpretation of this example depends on whether "/"
+ was returned as the hierarchy separator from LIST. If "/" is the
+ hierarchy separator, a new level of hierarchy named "owatagusiam"
+ with a member called "blurdybloop" is created. Otherwise, two
+ mailboxes at the same hierarchy level are created.
+*/
Propchange: james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/commands/CreateCommand.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/commands/DeleteCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/commands/DeleteCommand.java?view=diff&rev=454662&r1=454661&r2=454662
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/commands/DeleteCommand.java (original)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/commands/DeleteCommand.java Tue Oct 10 01:34:56 2006
@@ -1,153 +1,153 @@
-/****************************************************************
- * 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.commands;
-
-import org.apache.james.imapserver.AuthorizationException;
-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.MailboxException;
-import org.apache.james.mailboxmanager.MailboxManagerException;
-import org.apache.james.mailboxmanager.mailbox.ImapMailboxSession;
-
-/**
- * Handles processeing for the DELETE imap command.
- *
- * @author Darrell DeBoer <da...@apache.org>
- *
- * @version $Revision: 109034 $
- */
-class DeleteCommand extends AuthenticatedStateCommand
-{
- public static final String NAME = "DELETE";
- public static final String ARGS = "<mailbox>";
-
- /** @see CommandTemplate#doProcess */
- protected void doProcess( ImapRequestLineReader request,
- ImapResponse response,
- ImapSession session )
- throws ProtocolException, MailboxException, AuthorizationException
- {
-
- String mailboxName = parser.mailbox( request );
- parser.endLine( request );
-
- try {
- mailboxName = session.buildFullName(mailboxName);
- if (session.getSelected() != null) {
- if (session.getSelected().getMailbox().getName().equals(
- mailboxName)) {
- session.deselect();
- }
- }
- session.getMailboxManager().deleteMailbox(mailboxName);
- } catch (MailboxManagerException e) {
- throw new MailboxException(e);
- }
-
- session.unsolicitedResponses( response, false );
- response.commandComplete( this );
- }
-
- /** @see ImapCommand#getName */
- public String getName()
- {
- return NAME;
- }
-
- /** @see CommandTemplate#getArgSyntax */
- public String getArgSyntax()
- {
- return ARGS;
- }
-}
-
-/*
-6.3.4. DELETE Command
-
- Arguments: mailbox name
-
- Responses: no specific responses for this command
-
- Result: OK - delete completed
- NO - delete failure: can't delete mailbox with that name
- BAD - command unknown or arguments invalid
-
- The DELETE command permanently removes the mailbox with the given
- name. A tagged OK response is returned only if the mailbox has
- been deleted. It is an error to attempt to delete INBOX or a
- mailbox name that does not exist.
-
- The DELETE command MUST NOT remove inferior hierarchical names.
- For example, if a mailbox "foo" has an inferior "foo.bar"
- (assuming "." is the hierarchy delimiter character), removing
- "foo" MUST NOT remove "foo.bar". It is an error to attempt to
- delete a name that has inferior hierarchical names and also has
- the \Noselect mailbox name attribute (see the description of the
- LIST response for more details).
-
- It is permitted to delete a name that has inferior hierarchical
- names and does not have the \Noselect mailbox name attribute. In
- this case, all messages in that mailbox are removed, and the name
- will acquire the \Noselect mailbox name attribute.
-
- The value of the highest-used unique identifier of the deleted
- mailbox MUST be preserved so that a new mailbox created with the
- same name will not reuse the identifiers of the former
- incarnation, UNLESS the new incarnation has a different unique
- identifier validity value. See the description of the UID command
- for more detail.
-
-
- Examples: C: A682 LIST "" *
- S: * LIST () "/" blurdybloop
- S: * LIST (\Noselect) "/" foo
- S: * LIST () "/" foo/bar
- S: A682 OK LIST completed
- C: A683 DELETE blurdybloop
- S: A683 OK DELETE completed
- C: A684 DELETE foo
- S: A684 NO Name "foo" has inferior hierarchical names
- C: A685 DELETE foo/bar
- S: A685 OK DELETE Completed
- C: A686 LIST "" *
- S: * LIST (\Noselect) "/" foo
- S: A686 OK LIST completed
- C: A687 DELETE foo
- S: A687 OK DELETE Completed
-
-
- C: A82 LIST "" *
- S: * LIST () "." blurdybloop
- S: * LIST () "." foo
- S: * LIST () "." foo.bar
- S: A82 OK LIST completed
- C: A83 DELETE blurdybloop
- S: A83 OK DELETE completed
- C: A84 DELETE foo
- S: A84 OK DELETE Completed
- C: A85 LIST "" *
- S: * LIST () "." foo.bar
- S: A85 OK LIST completed
- C: A86 LIST "" %
- S: * LIST (\Noselect) "." foo
- S: A86 OK LIST completed
-*/
+/****************************************************************
+ * 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.commands;
+
+import org.apache.james.imapserver.AuthorizationException;
+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.MailboxException;
+import org.apache.james.mailboxmanager.MailboxManagerException;
+import org.apache.james.mailboxmanager.mailbox.ImapMailboxSession;
+
+/**
+ * Handles processeing for the DELETE imap command.
+ *
+ * @author Darrell DeBoer <da...@apache.org>
+ *
+ * @version $Revision: 109034 $
+ */
+class DeleteCommand extends AuthenticatedStateCommand
+{
+ public static final String NAME = "DELETE";
+ public static final String ARGS = "<mailbox>";
+
+ /** @see CommandTemplate#doProcess */
+ protected void doProcess( ImapRequestLineReader request,
+ ImapResponse response,
+ ImapSession session )
+ throws ProtocolException, MailboxException, AuthorizationException
+ {
+
+ String mailboxName = parser.mailbox( request );
+ parser.endLine( request );
+
+ try {
+ mailboxName = session.buildFullName(mailboxName);
+ if (session.getSelected() != null) {
+ if (session.getSelected().getMailbox().getName().equals(
+ mailboxName)) {
+ session.deselect();
+ }
+ }
+ session.getMailboxManager().deleteMailbox(mailboxName);
+ } catch (MailboxManagerException e) {
+ throw new MailboxException(e);
+ }
+
+ session.unsolicitedResponses( response, false );
+ response.commandComplete( this );
+ }
+
+ /** @see ImapCommand#getName */
+ public String getName()
+ {
+ return NAME;
+ }
+
+ /** @see CommandTemplate#getArgSyntax */
+ public String getArgSyntax()
+ {
+ return ARGS;
+ }
+}
+
+/*
+6.3.4. DELETE Command
+
+ Arguments: mailbox name
+
+ Responses: no specific responses for this command
+
+ Result: OK - delete completed
+ NO - delete failure: can't delete mailbox with that name
+ BAD - command unknown or arguments invalid
+
+ The DELETE command permanently removes the mailbox with the given
+ name. A tagged OK response is returned only if the mailbox has
+ been deleted. It is an error to attempt to delete INBOX or a
+ mailbox name that does not exist.
+
+ The DELETE command MUST NOT remove inferior hierarchical names.
+ For example, if a mailbox "foo" has an inferior "foo.bar"
+ (assuming "." is the hierarchy delimiter character), removing
+ "foo" MUST NOT remove "foo.bar". It is an error to attempt to
+ delete a name that has inferior hierarchical names and also has
+ the \Noselect mailbox name attribute (see the description of the
+ LIST response for more details).
+
+ It is permitted to delete a name that has inferior hierarchical
+ names and does not have the \Noselect mailbox name attribute. In
+ this case, all messages in that mailbox are removed, and the name
+ will acquire the \Noselect mailbox name attribute.
+
+ The value of the highest-used unique identifier of the deleted
+ mailbox MUST be preserved so that a new mailbox created with the
+ same name will not reuse the identifiers of the former
+ incarnation, UNLESS the new incarnation has a different unique
+ identifier validity value. See the description of the UID command
+ for more detail.
+
+
+ Examples: C: A682 LIST "" *
+ S: * LIST () "/" blurdybloop
+ S: * LIST (\Noselect) "/" foo
+ S: * LIST () "/" foo/bar
+ S: A682 OK LIST completed
+ C: A683 DELETE blurdybloop
+ S: A683 OK DELETE completed
+ C: A684 DELETE foo
+ S: A684 NO Name "foo" has inferior hierarchical names
+ C: A685 DELETE foo/bar
+ S: A685 OK DELETE Completed
+ C: A686 LIST "" *
+ S: * LIST (\Noselect) "/" foo
+ S: A686 OK LIST completed
+ C: A687 DELETE foo
+ S: A687 OK DELETE Completed
+
+
+ C: A82 LIST "" *
+ S: * LIST () "." blurdybloop
+ S: * LIST () "." foo
+ S: * LIST () "." foo.bar
+ S: A82 OK LIST completed
+ C: A83 DELETE blurdybloop
+ S: A83 OK DELETE completed
+ C: A84 DELETE foo
+ S: A84 OK DELETE Completed
+ C: A85 LIST "" *
+ S: * LIST () "." foo.bar
+ S: A85 OK LIST completed
+ C: A86 LIST "" %
+ S: * LIST (\Noselect) "." foo
+ S: A86 OK LIST completed
+*/
Propchange: james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/commands/DeleteCommand.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/commands/ExamineCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/commands/ExamineCommand.java?view=diff&rev=454662&r1=454661&r2=454662
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/commands/ExamineCommand.java (original)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/commands/ExamineCommand.java Tue Oct 10 01:34:56 2006
@@ -1,36 +1,36 @@
-/****************************************************************
- * 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.commands;
-
-/**
- *
- * @author Darrell DeBoer <da...@apache.org>
- *
- * @version $Revision: 109034 $
- */
-class ExamineCommand extends SelectCommand
-{
- public static final String NAME = "EXAMINE";
-
- public String getName()
- {
- return NAME;
- }
-}
+/****************************************************************
+ * 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.commands;
+
+/**
+ *
+ * @author Darrell DeBoer <da...@apache.org>
+ *
+ * @version $Revision: 109034 $
+ */
+class ExamineCommand extends SelectCommand
+{
+ public static final String NAME = "EXAMINE";
+
+ public String getName()
+ {
+ return NAME;
+ }
+}
Propchange: james/server/sandbox/imap-integration/src/java/org/apache/james/imapserver/commands/ExamineCommand.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