Uploaded image for project: 'James Mime4j'
  1. James Mime4j
  2. MIME4J-299

Allow to access Header as a map

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 0.8.5
    • 0.8.6
    • dom
    • None

    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))));
              }
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            btellier Benoit Tellier
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 1h
                1h