code: private static void checkPartForTextType(HashMap<String, Collection<String>> bodies, Part part) throws IOException, MessagingException {
          Object content = part.getContent();
          if (content instanceof CharSequence) {
              String ct = part.getContentType();
              Collection<String> value = bodies.get(ct);
              if (value != null) {
                  value.add(content.toString());
              } else {
                  value = new LinkedList<>();
                  value.add(content.toString());
                  bodies.put(ct, value);
              }
          } else if (content instanceof Multipart) {
              Multipart mp = (Multipart) content;
              for(int i = 0; i < mp.getCount(); i++) {
                  checkPartForTextType(bodies, mp.getBodyPart(i));
              }
          }
      }
docs: Recursive find body parts and save them to HashMap