MAILBOX-270: getmetadata command, new command parser which decode command to GetAnnotationRequest.
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/e66a92e8 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/e66a92e8 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/e66a92e8 Branch: refs/heads/master Commit: e66a92e8c5c73e71b345b084968532395e934488 Parents: ced2d52 Author: Quynh Nguyen <[email protected]> Authored: Tue Jul 5 13:46:36 2016 +0700 Committer: Quynh Nguyen <[email protected]> Committed: Tue Aug 30 09:21:30 2016 +0700 ---------------------------------------------------------------------- .../imap/decode/ImapRequestLineReader.java | 9 ++- .../parser/GetAnnotationCommandParser.java | 6 +- .../imap/processor/GetAnnotationProcessor.java | 13 ++-- .../imap/decode/ImapRequestLineReaderTest.java | 62 ++++++++++++++++++++ 4 files changed, 77 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/e66a92e8/protocols/imap/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java ---------------------------------------------------------------------- diff --git a/protocols/imap/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java b/protocols/imap/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java index c637df5..a35ddb3 100644 --- a/protocols/imap/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java +++ b/protocols/imap/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java @@ -685,7 +685,14 @@ public abstract class ImapRequestLineReader { return (IdRange[]) merged.toArray(new IdRange[merged.size()]); } - + public char nextNonSpaceChar() throws DecodingException { + char next = nextChar(); + while (next == ' ') { + consume(); + next = nextChar(); + } + return next; + } /** * Parse a range which use a ":" as delimiter * http://git-wip-us.apache.org/repos/asf/james-project/blob/e66a92e8/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/GetAnnotationCommandParser.java ---------------------------------------------------------------------- diff --git a/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/GetAnnotationCommandParser.java b/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/GetAnnotationCommandParser.java index 07cf408..052a327 100644 --- a/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/GetAnnotationCommandParser.java +++ b/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/GetAnnotationCommandParser.java @@ -60,10 +60,8 @@ public class GetAnnotationCommandParser extends AbstractImapCommandParser { } private ImapMessage buildAnnotationRequest(ImapCommand command, ImapRequestLineReader requestReader, String tag) throws DecodingException { - GetAnnotationRequest.Builder builder = GetAnnotationRequest.builder() - .tag(tag) - .command(command) - .mailboxName(requestReader.mailbox()); + GetAnnotationRequest.Builder builder = GetAnnotationRequest.builder().tag(tag).command(command); + builder.mailboxName(requestReader.mailbox()); consumeOptionsAndKeys(requestReader, builder); http://git-wip-us.apache.org/repos/asf/james-project/blob/e66a92e8/protocols/imap/src/main/java/org/apache/james/imap/processor/GetAnnotationProcessor.java ---------------------------------------------------------------------- diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/GetAnnotationProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/GetAnnotationProcessor.java index 052e533..f8c03fa 100644 --- a/protocols/imap/src/main/java/org/apache/james/imap/processor/GetAnnotationProcessor.java +++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/GetAnnotationProcessor.java @@ -92,14 +92,11 @@ public class GetAnnotationProcessor extends AbstractMailboxProcessor<GetAnnotati } } - private Optional<Integer> getMaxSizeValue(final List<MailboxAnnotation> mailboxAnnotations, Optional<Integer> maxsize) { - if (maxsize.isPresent()) { - return maxsize.transform(new Function<Integer, Optional<Integer>>() { - @Override - public Optional<Integer> apply(Integer input) { - return getMaxSizeOfOversizedItems(mailboxAnnotations, input); - } - }).get(); + private Optional<Integer> getMaxSizeOfItemsOversize(List<MailboxAnnotation> mailboxAnnotations, long maxsize) { + if (maxsize > 0) { + return getMaxValueOverSize(mailboxAnnotations, maxsize); + } else { + return Optional.absent(); } return Optional.absent(); } http://git-wip-us.apache.org/repos/asf/james-project/blob/e66a92e8/protocols/imap/src/test/java/org/apache/james/imap/decode/ImapRequestLineReaderTest.java ---------------------------------------------------------------------- diff --git a/protocols/imap/src/test/java/org/apache/james/imap/decode/ImapRequestLineReaderTest.java b/protocols/imap/src/test/java/org/apache/james/imap/decode/ImapRequestLineReaderTest.java new file mode 100644 index 0000000..63c628a --- /dev/null +++ b/protocols/imap/src/test/java/org/apache/james/imap/decode/ImapRequestLineReaderTest.java @@ -0,0 +1,62 @@ +/**************************************************************** + * 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.imap.decode; + +import static org.assertj.core.api.Assertions.assertThat; + +import com.google.common.base.Charsets; +import org.apache.james.protocols.imap.DecodingException; +import org.junit.Before; +import org.junit.Test; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.io.OutputStream; + +public class ImapRequestLineReaderTest { + + private final OutputStream outputStream = null; + private InputStream inputStream; + private ImapRequestStreamLineReader lineReader; + + @Test + public void nextNonSpaceCharShouldReturnTheFirstCharacter() throws Exception { + inputStream = new ByteArrayInputStream(("anyString \n").getBytes(Charsets.US_ASCII)); + lineReader = new ImapRequestStreamLineReader(inputStream, outputStream); + + assertThat(lineReader.nextNonSpaceChar()).isEqualTo('a'); + } + + @Test + public void nextNonSpaceCharShouldIgnoreTheSpaceAndReturnTheFirstNonSpaceCharacter() throws Exception { + inputStream = new ByteArrayInputStream((" anyString \n").getBytes(Charsets.US_ASCII)); + lineReader = new ImapRequestStreamLineReader(inputStream, outputStream); + + assertThat(lineReader.nextNonSpaceChar()).isEqualTo('a'); + } + + @Test(expected = DecodingException.class) + public void nextNonSpaceCharShouldThrowExceptionWhenNotFound() throws Exception { + inputStream = new ByteArrayInputStream((" ").getBytes(Charsets.US_ASCII)); + lineReader = new ImapRequestStreamLineReader(inputStream, outputStream); + + lineReader.nextNonSpaceChar(); + } +} \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
