This is an automated email from the ASF dual-hosted git repository. btellier pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 4e68b9154be319c1a206480180f53c002e8f4e8c Author: Benoit Tellier <btell...@linagora.com> AuthorDate: Mon Dec 9 14:34:59 2019 +0700 [Refactoring] Strongly type SectionType This integer representation is common between FetchPartPartDecoder and BodyFetchElement thus no conversion logic is required. --- .../james/imap/api/message/BodyFetchElement.java | 37 +++-------- .../apache/james/imap/api/message/SectionType.java | 29 +++++++++ .../james/imap/decode/FetchPartPathDecoder.java | 64 +++++++------------ .../imap/decode/parser/FetchCommandParser.java | 23 +------ .../imap/processor/fetch/FetchDataConverter.java | 15 ++--- .../imap/processor/fetch/FetchResponseBuilder.java | 17 ++--- .../imap/decode/FetchPartPathDecoderTest.java | 73 +++++++++++----------- .../parser/FetchCommandParserPartialFetchTest.java | 5 +- .../processor/fetch/FetchDataConverterTest.java | 9 ++- 9 files changed, 123 insertions(+), 149 deletions(-) diff --git a/protocols/imap/src/main/java/org/apache/james/imap/api/message/BodyFetchElement.java b/protocols/imap/src/main/java/org/apache/james/imap/api/message/BodyFetchElement.java index 3990ed9..9dee961 100644 --- a/protocols/imap/src/main/java/org/apache/james/imap/api/message/BodyFetchElement.java +++ b/protocols/imap/src/main/java/org/apache/james/imap/api/message/BodyFetchElement.java @@ -29,24 +29,11 @@ import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableList; public class BodyFetchElement { + private static final BodyFetchElement rfc822 = new BodyFetchElement(ImapConstants.FETCH_RFC822, SectionType.CONTENT, null, null, null, null); - public static final int TEXT = 0; + private static final BodyFetchElement rfc822Header = new BodyFetchElement(ImapConstants.FETCH_RFC822_HEADER, SectionType.HEADER, null, null, null, null); - public static final int MIME = 1; - - public static final int HEADER = 2; - - public static final int HEADER_FIELDS = 3; - - public static final int HEADER_NOT_FIELDS = 4; - - public static final int CONTENT = 5; - - private static final BodyFetchElement rfc822 = new BodyFetchElement(ImapConstants.FETCH_RFC822, CONTENT, null, null, null, null); - - private static final BodyFetchElement rfc822Header = new BodyFetchElement(ImapConstants.FETCH_RFC822_HEADER, HEADER, null, null, null, null); - - private static final BodyFetchElement rfc822Text = new BodyFetchElement(ImapConstants.FETCH_RFC822_TEXT, TEXT, null, null, null, null); + private static final BodyFetchElement rfc822Text = new BodyFetchElement(ImapConstants.FETCH_RFC822_TEXT, SectionType.TEXT, null, null, null, null); public static final BodyFetchElement createRFC822() { return rfc822; @@ -61,18 +48,13 @@ public class BodyFetchElement { } private final Long firstOctet; - private final Long numberOfOctets; - private final String name; - - private final int sectionType; - + private final SectionType sectionType; private final int[] path; - private final Collection<String> fieldNames; - public BodyFetchElement(String name, int sectionType, int[] path, Collection<String> fieldNames, Long firstOctet, Long numberOfOctets) { + public BodyFetchElement(String name, SectionType sectionType, int[] path, Collection<String> fieldNames, Long firstOctet, Long numberOfOctets) { this.name = name; this.sectionType = sectionType; this.fieldNames = fieldNames; @@ -88,8 +70,8 @@ public class BodyFetchElement { /** * Gets field names. * - * @return <code>String</code> collection, when {@link #HEADER_FIELDS} or - * {@link #HEADER_NOT_FIELDS} or null otherwise + * @return <code>String</code> collection, when {@link SectionType#HEADER_FIELDS} or + * {@link SectionType#HEADER_NOT_FIELDS} or null otherwise */ public final Collection<String> getFieldNames() { return fieldNames; @@ -106,11 +88,8 @@ public class BodyFetchElement { /** * Gets the type of section. - * - * @return {@link #HEADER_FIELDS}, {@link #TEXT}, {@link #CONTENT}, - * {@link #HEADER}, {@link #MIME} or {@link #HEADER_NOT_FIELDS} */ - public final int getSectionType() { + public final SectionType getSectionType() { return sectionType; } diff --git a/protocols/imap/src/main/java/org/apache/james/imap/api/message/SectionType.java b/protocols/imap/src/main/java/org/apache/james/imap/api/message/SectionType.java new file mode 100644 index 0000000..d2b4239 --- /dev/null +++ b/protocols/imap/src/main/java/org/apache/james/imap/api/message/SectionType.java @@ -0,0 +1,29 @@ +/**************************************************************** + * 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.api.message; + +public enum SectionType { + TEXT, + MIME, + HEADER, + HEADER_FIELDS, + HEADER_NOT_FIELDS, + CONTENT +} diff --git a/protocols/imap/src/main/java/org/apache/james/imap/decode/FetchPartPathDecoder.java b/protocols/imap/src/main/java/org/apache/james/imap/decode/FetchPartPathDecoder.java index ebc8099..c4c757b 100644 --- a/protocols/imap/src/main/java/org/apache/james/imap/decode/FetchPartPathDecoder.java +++ b/protocols/imap/src/main/java/org/apache/james/imap/decode/FetchPartPathDecoder.java @@ -23,21 +23,9 @@ import java.util.ArrayList; import java.util.List; import org.apache.james.imap.api.display.HumanReadableText; +import org.apache.james.imap.api.message.SectionType; public class FetchPartPathDecoder { - - public static final int TEXT = 0; - - public static final int MIME = 1; - - public static final int HEADER = 2; - - public static final int HEADER_FIELDS = 3; - - public static final int HEADER_NOT_FIELDS = 4; - - public static final int CONTENT = 5; - /** * Going to need to make one array copy so might as well ensure plenty of * space @@ -47,7 +35,7 @@ public class FetchPartPathDecoder { /** Embedded RFC882 messages are rare so start size one array */ private static final int ARRAY_INITIAL_SIZE = 1; - private int sectionType; + private SectionType sectionType; private int[] path; @@ -60,7 +48,7 @@ public class FetchPartPathDecoder { public FetchPartPathDecoder() { } - public int decode(CharSequence sectionSpecification) throws DecodingException { + public SectionType decode(CharSequence sectionSpecification) throws DecodingException { init(); sectionType = decode(0, sectionSpecification); prunePath(); @@ -78,8 +66,8 @@ public class FetchPartPathDecoder { } } - private int decode(int at, CharSequence sectionSpecification) throws DecodingException { - int result; + private SectionType decode(int at, CharSequence sectionSpecification) throws DecodingException { + SectionType result; int length = sectionSpecification.length(); if (at < length) { final char next = sectionSpecification.charAt(at); @@ -149,12 +137,12 @@ public class FetchPartPathDecoder { } } else { storePartial(); - result = CONTENT; + result = SectionType.CONTENT; } return result; } - private int mime(int at, CharSequence sectionSpecification) throws DecodingException { + private SectionType mime(int at, CharSequence sectionSpecification) throws DecodingException { if (sectionSpecification.length() == at + 4) { mustBeI(sectionSpecification, at + 1); mustBeM(sectionSpecification, at + 2); @@ -163,7 +151,7 @@ public class FetchPartPathDecoder { } else { throw new DecodingException(HumanReadableText.ILLEGAL_ARGUMENTS, "Unknown body specification"); } - return MIME; + return SectionType.MIME; } private void mustBeI(CharSequence sectionSpecification, int position) throws DecodingException { @@ -271,8 +259,8 @@ public class FetchPartPathDecoder { } } - private int header(int at, CharSequence sectionSpecification) throws DecodingException { - int result; + private SectionType header(int at, CharSequence sectionSpecification) throws DecodingException { + SectionType result; int length = sectionSpecification.length(); if (length > at + 5) { mustBeE(sectionSpecification, at + 1); @@ -282,7 +270,7 @@ public class FetchPartPathDecoder { mustBeR(sectionSpecification, at + 5); storePartial(); if (length == at + 6) { - result = HEADER; + result = SectionType.HEADER; } else { result = headerFields(at + 6, sectionSpecification); } @@ -292,8 +280,8 @@ public class FetchPartPathDecoder { return result; } - private int headerFields(int at, CharSequence sectionSpecification) throws DecodingException { - int result; + private SectionType headerFields(int at, CharSequence sectionSpecification) throws DecodingException { + SectionType result; int length = sectionSpecification.length(); if (length > at + 7) { mustBeDot(sectionSpecification, at); @@ -307,7 +295,7 @@ public class FetchPartPathDecoder { int namesStartAt; switch (next) { case ' ': - result = HEADER_FIELDS; + result = SectionType.HEADER_FIELDS; namesStartAt = skipSpaces(at + 7, sectionSpecification); break; case '.': @@ -315,7 +303,7 @@ public class FetchPartPathDecoder { mustBeN(sectionSpecification, at + 8); mustBeO(sectionSpecification, at + 9); mustBeT(sectionSpecification, at + 10); - result = HEADER_NOT_FIELDS; + result = SectionType.HEADER_NOT_FIELDS; namesStartAt = skipSpaces(at + 11, sectionSpecification); } else { throw new DecodingException(HumanReadableText.ILLEGAL_ARGUMENTS, "Unknown body specification"); @@ -382,7 +370,7 @@ public class FetchPartPathDecoder { return result; } - private int text(int at, CharSequence sectionSpecification) throws DecodingException { + private SectionType text(int at, CharSequence sectionSpecification) throws DecodingException { if (sectionSpecification.length() == at + 4) { mustBeE(sectionSpecification, at + 1); mustBeX(sectionSpecification, at + 2); @@ -391,18 +379,16 @@ public class FetchPartPathDecoder { } else { throw new DecodingException(HumanReadableText.ILLEGAL_ARGUMENTS, "Unknown body specification"); } - return TEXT; + return SectionType.TEXT; } - private int digit(int at, CharSequence sectionSpecification, int digit) throws DecodingException { - int result; + private SectionType digit(int at, CharSequence sectionSpecification, int digit) throws DecodingException { digit(digit); - result = decode(at + 1, sectionSpecification); - return result; + return decode(at + 1, sectionSpecification); } private void init() { - sectionType = CONTENT; + sectionType = SectionType.CONTENT; resetPartial(); path = null; used = 0; @@ -452,13 +438,9 @@ public class FetchPartPathDecoder { } /** - * Gets the - * - * @return {@link #TEXT}, {@link #MIME}, {@link #HEADER}, - * {@link #HEADER_FIELDS}, {@link #HEADER_NOT_FIELDS} or - * {@link #CONTENT} + * Gets the{@link SectionType} */ - public final int getSpecifier() { + public final SectionType getSpecifier() { return sectionType; } @@ -466,7 +448,7 @@ public class FetchPartPathDecoder { * Gets field names. * * @return <code>List</code> of <code>String</code> names when - * {@link #HEADER_FIELDS} or {@link #HEADER_NOT_FIELDS}, null + * {@link SectionType#HEADER_FIELDS} or {@link SectionType#HEADER_NOT_FIELDS}, null * otherwise */ public final List<String> getNames() { diff --git a/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/FetchCommandParser.java b/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/FetchCommandParser.java index eaae520..f929325 100644 --- a/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/FetchCommandParser.java +++ b/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/FetchCommandParser.java @@ -28,6 +28,7 @@ import org.apache.james.imap.api.display.HumanReadableText; import org.apache.james.imap.api.message.BodyFetchElement; import org.apache.james.imap.api.message.FetchData; import org.apache.james.imap.api.message.IdRange; +import org.apache.james.imap.api.message.SectionType; import org.apache.james.imap.api.process.ImapSession; import org.apache.james.imap.decode.DecodingException; import org.apache.james.imap.decode.FetchPartPathDecoder; @@ -213,33 +214,13 @@ public class FetchCommandParser extends AbstractUidCommandParser { final String responseName = "BODY[" + parameter + "]"; FetchPartPathDecoder decoder = new FetchPartPathDecoder(); decoder.decode(parameter); - final int sectionType = getSectionType(decoder); + final SectionType sectionType = decoder.getSpecifier(); final List<String> names = decoder.getNames(); final int[] path = decoder.getPath(); return new BodyFetchElement(responseName, sectionType, path, names, firstOctet, numberOfOctets); } - private int getSectionType(FetchPartPathDecoder decoder) throws DecodingException { - int specifier = decoder.getSpecifier(); - switch (specifier) { - case FetchPartPathDecoder.CONTENT: - return BodyFetchElement.CONTENT; - case FetchPartPathDecoder.HEADER: - return BodyFetchElement.HEADER; - case FetchPartPathDecoder.HEADER_FIELDS: - return BodyFetchElement.HEADER_FIELDS; - case FetchPartPathDecoder.HEADER_NOT_FIELDS: - return BodyFetchElement.HEADER_NOT_FIELDS; - case FetchPartPathDecoder.MIME: - return BodyFetchElement.MIME; - case FetchPartPathDecoder.TEXT: - return BodyFetchElement.TEXT; - default: - throw new DecodingException(HumanReadableText.ILLEGAL_ARGUMENTS, "Section type is unsupported."); - } - } - private String readWord(ImapRequestLineReader request, String terminator) throws DecodingException { StringBuilder builder = new StringBuilder(); char next = request.nextChar(); diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchDataConverter.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchDataConverter.java index 8596c88..a6333e0 100644 --- a/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchDataConverter.java +++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchDataConverter.java @@ -23,6 +23,7 @@ import java.util.Collection; import org.apache.james.imap.api.message.BodyFetchElement; import org.apache.james.imap.api.message.FetchData; +import org.apache.james.imap.api.message.SectionType; import org.apache.james.mailbox.model.FetchGroup; import org.apache.james.mailbox.model.MimePath; @@ -41,26 +42,26 @@ class FetchDataConverter { Collection<BodyFetchElement> bodyElements = fetch.getBodyElements(); if (bodyElements != null) { for (BodyFetchElement element : bodyElements) { - final int sectionType = element.getSectionType(); + final SectionType sectionType = element.getSectionType(); final int[] path = element.getPath(); final boolean isBase = (path == null || path.length == 0); switch (sectionType) { - case BodyFetchElement.CONTENT: + case CONTENT: if (isBase) { result = addContent(result, path, isBase, FetchGroup.Profile.FULL_CONTENT); } else { result = addContent(result, path, isBase, FetchGroup.Profile.MIME_CONTENT); } break; - case BodyFetchElement.HEADER: - case BodyFetchElement.HEADER_NOT_FIELDS: - case BodyFetchElement.HEADER_FIELDS: + case HEADER: + case HEADER_NOT_FIELDS: + case HEADER_FIELDS: result = addContent(result, path, isBase, FetchGroup.Profile.HEADERS); break; - case BodyFetchElement.MIME: + case MIME: result = addContent(result, path, isBase, FetchGroup.Profile.MIME_HEADERS); break; - case BodyFetchElement.TEXT: + case TEXT: result = addContent(result, path, isBase, FetchGroup.Profile.BODY_CONTENT); break; default: diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchResponseBuilder.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchResponseBuilder.java index f83c2cc..0b2e938 100644 --- a/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchResponseBuilder.java +++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchResponseBuilder.java @@ -34,6 +34,7 @@ import javax.mail.Flags; import org.apache.james.imap.api.ImapSessionUtils; import org.apache.james.imap.api.message.BodyFetchElement; import org.apache.james.imap.api.message.FetchData; +import org.apache.james.imap.api.message.SectionType; import org.apache.james.imap.api.process.ImapSession; import org.apache.james.imap.api.process.SelectedMailbox; import org.apache.james.imap.message.response.FetchResponse; @@ -218,7 +219,7 @@ public final class FetchResponseBuilder { final Long firstOctet = fetchElement.getFirstOctet(); final Long numberOfOctets = fetchElement.getNumberOfOctets(); final String name = fetchElement.getResponseName(); - final int specifier = fetchElement.getSectionType(); + final SectionType specifier = fetchElement.getSectionType(); final int[] path = fetchElement.getPath(); final Collection<String> names = fetchElement.getFieldNames(); final boolean isBase = (path == null || path.length == 0); @@ -227,19 +228,19 @@ public final class FetchResponseBuilder { } - private FetchResponse.BodyElement bodyContent(MessageResult messageResult, String name, int specifier, int[] path, Collection<String> names, boolean isBase) throws MailboxException { + private FetchResponse.BodyElement bodyContent(MessageResult messageResult, String name, SectionType specifier, int[] path, Collection<String> names, boolean isBase) throws MailboxException { switch (specifier) { - case BodyFetchElement.CONTENT: + case CONTENT: return content(messageResult, name, path, isBase); - case BodyFetchElement.HEADER_FIELDS: + case HEADER_FIELDS: return fields(messageResult, name, path, names, isBase); - case BodyFetchElement.HEADER_NOT_FIELDS: + case HEADER_NOT_FIELDS: return fieldsNot(messageResult, name, path, names, isBase); - case BodyFetchElement.MIME: + case MIME: return mimeHeaders(messageResult, name, path, isBase); - case BodyFetchElement.HEADER: + case HEADER: return headers(messageResult, name, path, isBase); - case BodyFetchElement.TEXT: + case TEXT: return text(messageResult, name, path, isBase); default: return null; diff --git a/protocols/imap/src/test/java/org/apache/james/imap/decode/FetchPartPathDecoderTest.java b/protocols/imap/src/test/java/org/apache/james/imap/decode/FetchPartPathDecoderTest.java index 7f78757..851202b 100644 --- a/protocols/imap/src/test/java/org/apache/james/imap/decode/FetchPartPathDecoderTest.java +++ b/protocols/imap/src/test/java/org/apache/james/imap/decode/FetchPartPathDecoderTest.java @@ -25,6 +25,7 @@ import static org.assertj.core.api.Fail.fail; import java.util.Collection; import java.util.Iterator; +import org.apache.james.imap.api.message.SectionType; import org.junit.Before; import org.junit.Test; @@ -40,77 +41,77 @@ public class FetchPartPathDecoderTest { @Test public void testShouldDetectText() throws Exception { - assertThat(decoder.decode("TEXT")).isEqualTo(FetchPartPathDecoder.TEXT); - assertThat(decoder.decode("3.TEXT")).isEqualTo(FetchPartPathDecoder.TEXT); - assertThat(decoder.decode("3.1.TEXT")).isEqualTo(FetchPartPathDecoder.TEXT); + assertThat(decoder.decode("TEXT")).isEqualTo(SectionType.TEXT); + assertThat(decoder.decode("3.TEXT")).isEqualTo(SectionType.TEXT); + assertThat(decoder.decode("3.1.TEXT")).isEqualTo(SectionType.TEXT); assertThat(decoder - .decode("3.2.5.7.8.TEXT")).isEqualTo(FetchPartPathDecoder.TEXT); + .decode("3.2.5.7.8.TEXT")).isEqualTo(SectionType.TEXT); } @Test public void testShouldDetectHeader() throws Exception { - assertThat(decoder.decode("HEADER")).isEqualTo(FetchPartPathDecoder.HEADER); - assertThat(decoder.decode("4.HEADER")).isEqualTo(FetchPartPathDecoder.HEADER); - assertThat(decoder.decode("10.1.HEADER")).isEqualTo(FetchPartPathDecoder.HEADER); + assertThat(decoder.decode("HEADER")).isEqualTo(SectionType.HEADER); + assertThat(decoder.decode("4.HEADER")).isEqualTo(SectionType.HEADER); + assertThat(decoder.decode("10.1.HEADER")).isEqualTo(SectionType.HEADER); assertThat(decoder - .decode("8.3.5.11.HEADER")).isEqualTo(FetchPartPathDecoder.HEADER); + .decode("8.3.5.11.HEADER")).isEqualTo(SectionType.HEADER); } @Test public void testShouldDetectHeaderFields() throws Exception { assertThat(decoder - .decode("HEADER.FIELDS ()")).isEqualTo(FetchPartPathDecoder.HEADER_FIELDS); + .decode("HEADER.FIELDS ()")).isEqualTo(SectionType.HEADER_FIELDS); assertThat(decoder - .decode("4.HEADER.FIELDS ()")).isEqualTo(FetchPartPathDecoder.HEADER_FIELDS); + .decode("4.HEADER.FIELDS ()")).isEqualTo(SectionType.HEADER_FIELDS); assertThat(decoder - .decode("10.1.HEADER.FIELDS ()")).isEqualTo(FetchPartPathDecoder.HEADER_FIELDS); + .decode("10.1.HEADER.FIELDS ()")).isEqualTo(SectionType.HEADER_FIELDS); assertThat(decoder - .decode("8.3.5.11.HEADER.FIELDS ()")).isEqualTo(FetchPartPathDecoder.HEADER_FIELDS); + .decode("8.3.5.11.HEADER.FIELDS ()")).isEqualTo(SectionType.HEADER_FIELDS); } @Test public void testShouldDetectHeaderFieldsNot() throws Exception { assertThat(decoder - .decode("HEADER.FIELDS.NOT ()")).isEqualTo(FetchPartPathDecoder.HEADER_NOT_FIELDS); + .decode("HEADER.FIELDS.NOT ()")).isEqualTo(SectionType.HEADER_NOT_FIELDS); assertThat(decoder - .decode("4.HEADER.FIELDS.NOT ()")).isEqualTo(FetchPartPathDecoder.HEADER_NOT_FIELDS); + .decode("4.HEADER.FIELDS.NOT ()")).isEqualTo(SectionType.HEADER_NOT_FIELDS); assertThat(decoder - .decode("10.1.HEADER.FIELDS.NOT ()")).isEqualTo(FetchPartPathDecoder.HEADER_NOT_FIELDS); + .decode("10.1.HEADER.FIELDS.NOT ()")).isEqualTo(SectionType.HEADER_NOT_FIELDS); assertThat(decoder - .decode("8.3.5.11.HEADER.FIELDS.NOT ()")).isEqualTo(FetchPartPathDecoder.HEADER_NOT_FIELDS); + .decode("8.3.5.11.HEADER.FIELDS.NOT ()")).isEqualTo(SectionType.HEADER_NOT_FIELDS); } @Test public void testShouldDetectMime() throws Exception { - assertThat(decoder.decode("MIME")).isEqualTo(FetchPartPathDecoder.MIME); - assertThat(decoder.decode("6.MIME")).isEqualTo(FetchPartPathDecoder.MIME); - assertThat(decoder.decode("2.88.MIME")).isEqualTo(FetchPartPathDecoder.MIME); + assertThat(decoder.decode("MIME")).isEqualTo(SectionType.MIME); + assertThat(decoder.decode("6.MIME")).isEqualTo(SectionType.MIME); + assertThat(decoder.decode("2.88.MIME")).isEqualTo(SectionType.MIME); assertThat(decoder - .decode("32.3.15.11.MIME")).isEqualTo(FetchPartPathDecoder.MIME); + .decode("32.3.15.11.MIME")).isEqualTo(SectionType.MIME); } @Test public void testShouldDetectContent() throws Exception { - assertThat(decoder.decode("34")).isEqualTo(FetchPartPathDecoder.CONTENT); - assertThat(decoder.decode("6")).isEqualTo(FetchPartPathDecoder.CONTENT); - assertThat(decoder.decode("9.88")).isEqualTo(FetchPartPathDecoder.CONTENT); - assertThat(decoder.decode("17.3.15.11")).isEqualTo(FetchPartPathDecoder.CONTENT); + assertThat(decoder.decode("34")).isEqualTo(SectionType.CONTENT); + assertThat(decoder.decode("6")).isEqualTo(SectionType.CONTENT); + assertThat(decoder.decode("9.88")).isEqualTo(SectionType.CONTENT); + assertThat(decoder.decode("17.3.15.11")).isEqualTo(SectionType.CONTENT); } @Test public void testShouldIgnoreCase() throws Exception { - assertThat(decoder.decode("6.MIME")).isEqualTo(FetchPartPathDecoder.MIME); - assertThat(decoder.decode("6.mime")).isEqualTo(FetchPartPathDecoder.MIME); - assertThat(decoder.decode("6.miME")).isEqualTo(FetchPartPathDecoder.MIME); - assertThat(decoder.decode("6.MIme")).isEqualTo(FetchPartPathDecoder.MIME); - assertThat(decoder.decode("6.HEADER")).isEqualTo(FetchPartPathDecoder.HEADER); - assertThat(decoder.decode("6.header")).isEqualTo(FetchPartPathDecoder.HEADER); - assertThat(decoder.decode("6.HEadER")).isEqualTo(FetchPartPathDecoder.HEADER); - assertThat(decoder.decode("6.heADEr")).isEqualTo(FetchPartPathDecoder.HEADER); - assertThat(decoder.decode("6.TEXT")).isEqualTo(FetchPartPathDecoder.TEXT); - assertThat(decoder.decode("6.text")).isEqualTo(FetchPartPathDecoder.TEXT); - assertThat(decoder.decode("6.TExt")).isEqualTo(FetchPartPathDecoder.TEXT); - assertThat(decoder.decode("6.teXT")).isEqualTo(FetchPartPathDecoder.TEXT); + assertThat(decoder.decode("6.MIME")).isEqualTo(SectionType.MIME); + assertThat(decoder.decode("6.mime")).isEqualTo(SectionType.MIME); + assertThat(decoder.decode("6.miME")).isEqualTo(SectionType.MIME); + assertThat(decoder.decode("6.MIme")).isEqualTo(SectionType.MIME); + assertThat(decoder.decode("6.HEADER")).isEqualTo(SectionType.HEADER); + assertThat(decoder.decode("6.header")).isEqualTo(SectionType.HEADER); + assertThat(decoder.decode("6.HEadER")).isEqualTo(SectionType.HEADER); + assertThat(decoder.decode("6.heADEr")).isEqualTo(SectionType.HEADER); + assertThat(decoder.decode("6.TEXT")).isEqualTo(SectionType.TEXT); + assertThat(decoder.decode("6.text")).isEqualTo(SectionType.TEXT); + assertThat(decoder.decode("6.TExt")).isEqualTo(SectionType.TEXT); + assertThat(decoder.decode("6.teXT")).isEqualTo(SectionType.TEXT); } @Test diff --git a/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/FetchCommandParserPartialFetchTest.java b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/FetchCommandParserPartialFetchTest.java index 4f78aff..17cc5f0 100644 --- a/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/FetchCommandParserPartialFetchTest.java +++ b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/FetchCommandParserPartialFetchTest.java @@ -32,6 +32,7 @@ import org.apache.james.imap.api.Tag; import org.apache.james.imap.api.message.BodyFetchElement; import org.apache.james.imap.api.message.FetchData; import org.apache.james.imap.api.message.IdRange; +import org.apache.james.imap.api.message.SectionType; import org.apache.james.imap.api.process.ImapSession; import org.apache.james.imap.decode.DecodingException; import org.apache.james.imap.decode.ImapRequestLineReader; @@ -56,7 +57,7 @@ public class FetchCommandParserPartialFetchTest { public void testShouldParseZeroAndLength() throws Exception { IdRange[] ranges = { new IdRange(1) }; FetchData data = new FetchData(); - data.add(new BodyFetchElement("BODY[]", BodyFetchElement.CONTENT, null, + data.add(new BodyFetchElement("BODY[]", SectionType.CONTENT, null, null, 0L, 100L), false); check("1 (BODY[]<0.100>)\r\n", ranges, false, data, TAG); } @@ -65,7 +66,7 @@ public class FetchCommandParserPartialFetchTest { public void testShouldParseNonZeroAndLength() throws Exception { IdRange[] ranges = { new IdRange(1) }; FetchData data = new FetchData(); - data.add(new BodyFetchElement("BODY[]", BodyFetchElement.CONTENT, null, + data.add(new BodyFetchElement("BODY[]", SectionType.CONTENT, null, null, 20L, 12342348L), false); check("1 (BODY[]<20.12342348>)\r\n", ranges, false, data, TAG); } diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/fetch/FetchDataConverterTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/fetch/FetchDataConverterTest.java index 63e772e..0050bfa 100644 --- a/protocols/imap/src/test/java/org/apache/james/imap/processor/fetch/FetchDataConverterTest.java +++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/fetch/FetchDataConverterTest.java @@ -19,13 +19,12 @@ package org.apache.james.imap.processor.fetch; -import static org.apache.james.imap.api.message.BodyFetchElement.CONTENT; -import static org.apache.james.imap.api.message.BodyFetchElement.HEADER; -import static org.apache.james.imap.api.message.BodyFetchElement.MIME; -import static org.apache.james.imap.api.message.BodyFetchElement.TEXT; +import static org.apache.james.imap.api.message.SectionType.CONTENT; +import static org.apache.james.imap.api.message.SectionType.HEADER; +import static org.apache.james.imap.api.message.SectionType.MIME; +import static org.apache.james.imap.api.message.SectionType.TEXT; import static org.assertj.core.api.Assertions.assertThat; -import java.util.EnumSet; import java.util.stream.Stream; import org.apache.james.imap.api.ImapConstants; --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org