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/06/20 02:47:00 UTC
[jira] [Closed] (MIME4J-299) Allow to access Header as a map
[ https://issues.apache.org/jira/browse/MIME4J-299?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Benoit Tellier closed MIME4J-299.
---------------------------------
Resolution: Fixed
> 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
> Priority: Major
> Fix For: 0.8.6
>
> Time Spent: 1h
> Remaining Estimate: 0h
>
> 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)