@Test public void testShouldNotAddExtensionsWithEncodingBodyStructure() throws Exception { FetchResponse message = new FetchResponse(100, flags, MessageUid.of(72), null, null, null, null, null, stubStructure, null); final Map<String, String> parameters = new HashMap<>(); parameters.put("CHARSET", "US-ASCII"); final List<String> parameterList = new ArrayList<>(); parameterList.add("CHARSET"); parameterList.add("US-ASCII"); when(stubStructure.getMediaType()).thenReturn("TEXT"); when(stubStructure.getSubType()).thenReturn("HTML"); when(stubStructure.getOctets()).thenReturn(2279L); when(stubStructure.getLines()).thenReturn(48L); when(stubStructure.getParameters()).thenReturn(parameterList); when(stubStructure.getEncoding()).thenReturn("7BIT"); when(stubStructure.getId()).thenReturn(""); when(stubStructure.getDescription()).thenReturn(""); final FakeImapSession fakeImapSession = new FakeImapSession(); encoder.doEncode(message, composer, fakeImapSession); assertThat(writer.getString()).isEqualTo("* 100 FETCH (FLAGS (\\Deleted) BODYSTRUCTURE (\"TEXT\" \"HTML\" (\"CHARSET\" \"US-ASCII\") \"\" \"\" \"7BIT\" 2279 48) UID 72)\r\n"); } }
private void encodeMultipart(ImapResponseComposer composer, Structure structure, String subType, boolean includeExtensions, ImapSession session) throws IOException { composer.openParen(); for (Iterator<Structure> it = structure.parts(); it.hasNext();) { final Structure part = it.next(); encodeStructure(composer, part, includeExtensions, true, session); } composer.quoteUpperCaseAscii(subType); if (includeExtensions) { final List<String> languages = structure.getLanguages(); nillableQuotes(composer, structure.getParameters()); bodyFldDsp(structure, composer, session); nillableQuotes(composer, languages); nillableQuote(composer, structure.getLocation()); } composer.closeParen(); }
private void encodeMultipart(ImapResponseComposer composer, Structure structure, final String subType, final boolean includeExtensions, ImapSession session) throws IOException { composer.openParen(); for (Iterator<Structure> it = structure.parts(); it.hasNext();) { final Structure part = it.next(); encodeStructure(composer, part, includeExtensions, true, session); } composer.quoteUpperCaseAscii(subType); if (includeExtensions) { final List<String> languages = structure.getLanguages(); nillableQuotes(composer, structure.getParameters()); bodyFldDsp(structure, composer, session); nillableQuotes(composer, languages); nillableQuote(composer, structure.getLocation()); } composer.closeParen(); }
private void encodeBasic(ImapResponseComposer composer, Structure structure, boolean includeExtensions, String mediaType, String subType, ImapSession session) throws IOException { if (ImapConstants.MIME_TYPE_TEXT.equalsIgnoreCase(mediaType)) { final long lines = structure.getLines(); encodeBodyFields(composer, structure, mediaType, subType); composer.message(lines); } else { encodeBodyFields(composer, structure, mediaType, subType); } if (includeExtensions) { encodeOnePartBodyExtensions(composer, structure, session); } composer.closeParen(); }
private void encodeBasic(final ImapResponseComposer composer, final Structure structure, final boolean includeExtensions, final String mediaType, final String subType, ImapSession session) throws IOException { if (ImapConstants.MIME_TYPE_TEXT.equalsIgnoreCase(mediaType)) { final long lines = structure.getLines(); encodeBodyFields(composer, structure, mediaType, subType); composer.message(lines); } else { encodeBodyFields(composer, structure, mediaType, subType); } if (includeExtensions) { encodeOnePartBodyExtensions(composer, structure, session); } composer.closeParen(); }
private ImapResponseComposer bodyFldDsp(Structure structure, ImapResponseComposer composer, ImapSession session) throws IOException { final String disposition = structure.getDisposition(); if (disposition == null) { composer.nil(); } else { composer.openParen(); composer.quote(disposition); final Map<String, String> params = structure.getDispositionParams(); bodyFldParam(params, composer, session); composer.closeParen(); } return composer; }
private void encodeStructure(ImapResponseComposer composer, Structure structure, boolean includeExtensions, boolean isInnerPart, ImapSession session) throws IOException { final String mediaType; final String subType; final String rawMediaType = structure.getMediaType(); if (rawMediaType == null) { mediaType = ImapConstants.MIME_TYPE_TEXT; subType = ImapConstants.MIME_SUBTYPE_PLAIN; } else { mediaType = rawMediaType; subType = structure.getSubType(); } encodeStructure(composer, structure, includeExtensions, mediaType, subType, isInnerPart, session); }
private ImapResponseComposer bodyFldDsp(final Structure structure, final ImapResponseComposer composer, ImapSession session) throws IOException { final String disposition = structure.getDisposition(); if (disposition == null) { composer.nil(); } else { composer.openParen(); composer.quote(disposition); final Map<String, String> params = structure.getDispositionParams(); bodyFldParam(params, composer, session); composer.closeParen(); } return composer; }
private void encodeRfc822Message(ImapResponseComposer composer, Structure structure, String mediaType, String subType, boolean includeExtensions, ImapSession session) throws IOException { final long lines = structure.getLines(); final FetchResponse.Envelope envelope = structure.getEnvelope(); final FetchResponse.Structure embeddedStructure = structure.getBody(); encodeBodyFields(composer, structure, mediaType, subType); encodeEnvelope(composer, envelope, false); encodeStructure(composer, embeddedStructure, includeExtensions, false, session); composer.message(lines); if (includeExtensions) { encodeOnePartBodyExtensions(composer, structure, session); } composer.closeParen(); }
private void encodeRfc822Message(ImapResponseComposer composer, Structure structure, final String mediaType, final String subType, final boolean includeExtensions, ImapSession session) throws IOException { final long lines = structure.getLines(); final FetchResponse.Envelope envelope = structure.getEnvelope(); final FetchResponse.Structure embeddedStructure = structure.getBody(); encodeBodyFields(composer, structure, mediaType, subType); encodeEnvelope(composer, envelope, false); encodeStructure(composer, embeddedStructure, includeExtensions, false, session); composer.message(lines); if (includeExtensions) { encodeOnePartBodyExtensions(composer, structure, session); } composer.closeParen(); }
private void encodeStructure(final ImapResponseComposer composer, final Structure structure, final boolean includeExtensions, final boolean isInnerPart, ImapSession session) throws IOException { final String mediaType; final String subType; final String rawMediaType = structure.getMediaType(); if (rawMediaType == null) { mediaType = ImapConstants.MIME_TYPE_TEXT; subType = ImapConstants.MIME_SUBTYPE_PLAIN; } else { mediaType = rawMediaType; subType = structure.getSubType(); } encodeStructure(composer, structure, includeExtensions, mediaType, subType, isInnerPart, session); }
private void encodeBodyFields(ImapResponseComposer composer, Structure structure, String mediaType, String subType) throws IOException { final List<String> bodyParams = structure.getParameters(); final String id = structure.getId(); final String description = structure.getDescription(); final String encoding = structure.getEncoding(); final long octets = structure.getOctets(); composer.openParen().quoteUpperCaseAscii(mediaType).quoteUpperCaseAscii(subType); nillableQuotes(composer, bodyParams); nillableQuote(composer, id); nillableQuote(composer, description); composer.quoteUpperCaseAscii(encoding).message(octets); }
private void encodeBodyFields(final ImapResponseComposer composer, final Structure structure, final String mediaType, final String subType) throws IOException { final List<String> bodyParams = structure.getParameters(); final String id = structure.getId(); final String description = structure.getDescription(); final String encoding = structure.getEncoding(); final long octets = structure.getOctets(); composer.openParen().quoteUpperCaseAscii(mediaType).quoteUpperCaseAscii(subType); nillableQuotes(composer, bodyParams); nillableQuote(composer, id); nillableQuote(composer, description); composer.quoteUpperCaseAscii(encoding).message(octets); }