You are viewing a plain text version of this content. The canonical link for it is here.
Posted to mime4j-dev@james.apache.org by "Benoit Tellier (Jira)" <mi...@james.apache.org> on 2021/05/25 00:11:00 UTC
[jira] [Created] (MIME4J-299) Allow to access Header as a map
Benoit Tellier created MIME4J-299:
-------------------------------------
Summary: Allow to access Header as a map
Key: MIME4J-299
URL: https://issues.apache.org/jira/browse/MIME4J-299
Project: James Mime4j
Issue Type: New Feature
Components: dom
Affects Versions: 0.8.5
Reporter: Benoit Tellier
Fix For: 0.8.6
Today complex code is required to group headers by name:
{code:java}
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));
}
{code}
Carrying over the header map can get this way simpler:
{code:java}
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))));
}
{code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)