Description
Today complex code is required to group headers by name:
static ImmutableMap<String, String> toHeaderMap(Header header) { Function<Map.Entry<String, Collection<Field>>, String> bodyConcatenator = fieldListEntry -> fieldListEntry.getValue() .stream() .map(Field::getBody) .map(MimeUtil::unscrambleHeaderValue) .collect(Collectors.toList()) .stream() .collect(Collectors.joining(JMAP_MULTIVALUED_FIELD_DELIMITER)); return Multimaps.index(header.getFields(), Field::getName) .asMap() .entrySet() .stream() .collect(Guavate.toImmutableMap(Map.Entry::getKey, bodyConcatenator)); }
Carrying over the header map can get this way simpler:
static ImmutableMap<String, String> toHeaderMap(Header header) { return header.getFieldsAsMap() .entrySet() .stream() .collect(Guavate.toImmutableMap(Map.Entry::getKey, entry -> entry.getValue().stream() .map(Field::getBody) .map(body -> DecoderUtil.decodeEncodedWords(body, DecodeMonitor.SILENT)) .collect(Collectors.joining(JMAP_MULTIVALUED_FIELD_DELIMITER)))); }