Repository: james-project Updated Branches: refs/heads/master 54f3bf313 -> 085eebba9
MAILBOX-270: getmetadata command, new processor Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/0d3c88b1 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/0d3c88b1 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/0d3c88b1 Branch: refs/heads/master Commit: 0d3c88b12050cdc65757fbd9060009310db7fefd Parents: b855deb Author: Quynh Nguyen <[email protected]> Authored: Tue Jul 5 14:04:07 2016 +0700 Committer: Quynh Nguyen <[email protected]> Committed: Tue Aug 30 09:21:30 2016 +0700 ---------------------------------------------------------------------- .../inmemory/mail/InMemoryAnnotationMapper.java | 48 ++++++++++++++++++++ .../api/message/response/StatusResponse.java | 8 ++++ .../imap/decode/ImapRequestLineReader.java | 8 ++++ .../imap/encode/AnnotationResponseEncoder.java | 20 ++++---- .../message/response/AnnotationResponse.java | 4 +- .../message/response/StatusResponseTest.java | 7 +++ 6 files changed, 85 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/0d3c88b1/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryAnnotationMapper.java ---------------------------------------------------------------------- diff --git a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryAnnotationMapper.java b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryAnnotationMapper.java index f07166e..cc9bcf6 100644 --- a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryAnnotationMapper.java +++ b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryAnnotationMapper.java @@ -65,6 +65,7 @@ public class InMemoryAnnotationMapper implements AnnotationMapper { return Iterables.transform( mailboxesAnnotations.row(maiboxId).entrySet(), new Function<Map.Entry<String, String>, MailboxAnnotation>() { + @Override public MailboxAnnotation apply(Entry<String, String> input) { return MailboxAnnotation.newInstance(input.getKey(), input.getValue()); } @@ -84,6 +85,7 @@ public class InMemoryAnnotationMapper implements AnnotationMapper { return ImmutableList.copyOf( Iterables.filter(retrieveAllAnnotations(mailboxId), new Predicate<MailboxAnnotation>() { + @Override public boolean apply(MailboxAnnotation input) { return keys.contains(input.getKey()); } @@ -91,6 +93,52 @@ public class InMemoryAnnotationMapper implements AnnotationMapper { } @Override + public List<MailboxAnnotation> getAnnotationsByKeysWithAllDepth(final Set<MailboxAnnotationKey> keys) { + return ImmutableList.copyOf(Iterables.filter(retrieveAllAnnotations(mailboxId), getPredicateFilterByAll(keys))); + } + + @Override + public List<MailboxAnnotation> getAnnotationsByKeysWithOneDepth(final Set<MailboxAnnotationKey> keys) { + return ImmutableList.copyOf(Iterables.filter(getAnnotationsByKeysWithAllDepth(keys), getPredicateFilterByOne(keys))); + } + + private Predicate<MailboxAnnotation> getPredicateFilterByAll(final Set<MailboxAnnotationKey> keys) { + return new Predicate<MailboxAnnotation>() { + @Override + public boolean apply(final MailboxAnnotation input) { + return Iterables.tryFind(keys, filterAnnotationsByPrefix(input)).isPresent(); + } + }; + } + + private Predicate<MailboxAnnotation> getPredicateFilterByOne(final Set<MailboxAnnotationKey> keys) { + return new Predicate<MailboxAnnotation>() { + @Override + public boolean apply(final MailboxAnnotation input) { + return Iterables.tryFind(keys, filterAnnotationsByParentKey(input.getKey())).isPresent(); + } + }; + } + + private Predicate<MailboxAnnotationKey> filterAnnotationsByParentKey(final MailboxAnnotationKey input) { + return new Predicate<MailboxAnnotationKey>() { + @Override + public boolean apply(MailboxAnnotationKey key) { + return input.countComponents() <= (key.countComponents() + 1); + } + }; + } + + private Predicate<MailboxAnnotationKey> filterAnnotationsByPrefix(final MailboxAnnotation input) { + return new Predicate<MailboxAnnotationKey>() { + @Override + public boolean apply(MailboxAnnotationKey key) { + return key.equals(input.getKey()) || StringUtils.startsWith(input.getKey().asString(), key.asString() + "/"); + } + }; + } + + @Override public void insertAnnotation(MailboxAnnotation mailboxAnnotation) { Preconditions.checkArgument(!mailboxAnnotation.isNil()); lock.writeLock().lock(); http://git-wip-us.apache.org/repos/asf/james-project/blob/0d3c88b1/protocols/imap/src/main/java/org/apache/james/imap/api/message/response/StatusResponse.java ---------------------------------------------------------------------- diff --git a/protocols/imap/src/main/java/org/apache/james/imap/api/message/response/StatusResponse.java b/protocols/imap/src/main/java/org/apache/james/imap/api/message/response/StatusResponse.java index 045a558..6351cdb 100644 --- a/protocols/imap/src/main/java/org/apache/james/imap/api/message/response/StatusResponse.java +++ b/protocols/imap/src/main/java/org/apache/james/imap/api/message/response/StatusResponse.java @@ -286,6 +286,14 @@ public interface StatusResponse extends ImapResponseMessage { } /** + * Create a RFC5464 getMetadata which support MAXSIZE + * @param entryLong positive non-zero long + * @return <code>ResponseCode</code> + */ + public static ResponseCode longestMetadataEntry(long entryLong) { + return new ResponseCode("METADATA LONGENTRIES", entryLong); + } + /** * Create a RFC4551 <code>NOMODSEQ</code> response code * * @return <code>ResponseCode</code> http://git-wip-us.apache.org/repos/asf/james-project/blob/0d3c88b1/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 a35ddb3..1be6f66 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,6 +685,14 @@ public abstract class ImapRequestLineReader { return (IdRange[]) merged.toArray(new IdRange[merged.size()]); } + /** + * Reads the first non-space character in the current line. This method will continue + * to resume if meet space character until meet the non-space character. + * + * @return The next first non-space character + * @throws DecodingException + * If the end-of-stream is reached. + */ public char nextNonSpaceChar() throws DecodingException { char next = nextChar(); while (next == ' ') { http://git-wip-us.apache.org/repos/asf/james-project/blob/0d3c88b1/protocols/imap/src/main/java/org/apache/james/imap/encode/AnnotationResponseEncoder.java ---------------------------------------------------------------------- diff --git a/protocols/imap/src/main/java/org/apache/james/imap/encode/AnnotationResponseEncoder.java b/protocols/imap/src/main/java/org/apache/james/imap/encode/AnnotationResponseEncoder.java index d78cfb6..d3e14ea 100644 --- a/protocols/imap/src/main/java/org/apache/james/imap/encode/AnnotationResponseEncoder.java +++ b/protocols/imap/src/main/java/org/apache/james/imap/encode/AnnotationResponseEncoder.java @@ -44,26 +44,30 @@ public class AnnotationResponseEncoder extends AbstractChainedImapEncoder { composer.commandName(ImapConstants.ANNOTATION_RESPONSE_NAME); composer.quote(Optional.fromNullable(response.getMailboxName()).or("")); - composeAnnotations(composer, response.getMailboxAnnotations(), session); + composeAnnotations(composer, session, response.getMailboxAnnotations()); composer.end(); } - private void composeAnnotations(ImapResponseComposer composer, List<MailboxAnnotation> annotations, ImapSession session) throws IOException { + private void composeAnnotations(ImapResponseComposer composer, ImapSession session, List<MailboxAnnotation> annotations) throws IOException { if (!annotations.isEmpty()) { composer.openParen(); for (MailboxAnnotation annotation : annotations) { - if (annotation.isNil()) { - session.getLog().warn("There is nil data of key {} on store: ", annotation.getKey().getKey()); - } else { - composer.message(annotation.getKey().getKey()); - composer.quote(annotation.getValue().or("")); - } + composeAnnotation(composer, session, annotation); } composer.closeParen(); } } + private void composeAnnotation(ImapResponseComposer composer, ImapSession session, MailboxAnnotation annotation) throws IOException { + if (annotation.isNil()) { + session.getLog().warn("There is nil data of key {} on store: ", annotation.getKey().asString()); + } else { + composer.message(annotation.getKey().asString()); + composer.quote(annotation.getValue().or("")); + } + } + public boolean isAcceptable(ImapMessage message) { return message instanceof AnnotationResponse; } http://git-wip-us.apache.org/repos/asf/james-project/blob/0d3c88b1/protocols/imap/src/main/java/org/apache/james/imap/message/response/AnnotationResponse.java ---------------------------------------------------------------------- diff --git a/protocols/imap/src/main/java/org/apache/james/imap/message/response/AnnotationResponse.java b/protocols/imap/src/main/java/org/apache/james/imap/message/response/AnnotationResponse.java index 6bd7872..bf83849 100644 --- a/protocols/imap/src/main/java/org/apache/james/imap/message/response/AnnotationResponse.java +++ b/protocols/imap/src/main/java/org/apache/james/imap/message/response/AnnotationResponse.java @@ -55,9 +55,9 @@ public class AnnotationResponse implements ImapResponseMessage { if (obj instanceof AnnotationResponse) { AnnotationResponse o = (AnnotationResponse) obj; return Objects.equal(mailboxName, o.getMailboxName()) && Objects.equal(mailboxAnnotations, o.getMailboxAnnotations()); - } else { - return false; } + + return false; } public String toString() { http://git-wip-us.apache.org/repos/asf/james-project/blob/0d3c88b1/protocols/imap/src/test/java/org/apache/james/imap/api/message/response/StatusResponseTest.java ---------------------------------------------------------------------- diff --git a/protocols/imap/src/test/java/org/apache/james/imap/api/message/response/StatusResponseTest.java b/protocols/imap/src/test/java/org/apache/james/imap/api/message/response/StatusResponseTest.java index adcfccb..0b56900 100644 --- a/protocols/imap/src/test/java/org/apache/james/imap/api/message/response/StatusResponseTest.java +++ b/protocols/imap/src/test/java/org/apache/james/imap/api/message/response/StatusResponseTest.java @@ -20,6 +20,7 @@ package org.apache.james.imap.api.message.response; import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import org.junit.Test; @@ -35,4 +36,10 @@ public class StatusResponseTest { StatusResponse.ResponseCode.createExtension("EXTENSION") .getCode()); } + + @Test + public void ResponseCodeShouldBuildTheLongestEntryForMetadata() throws Exception { + assertThat(StatusResponse.ResponseCode.longestMetadataEntry(1024).getCode()).isEqualTo("METADATA LONGENTRIES"); + assertThat(StatusResponse.ResponseCode.longestMetadataEntry(1024).getNumber()).isEqualTo(1024); + } } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
