@Test public void findFirstTextPart_withMultipartAlternative() throws Exception { BodyPart expected = createTextPart("text/plain"); Part part = createMultipart("multipart/alternative", expected, createTextPart("text/html")); Part result = textPartFinder.findFirstTextPart(part); assertEquals(expected, result); }
@Nullable public Part findFirstTextPart(@NonNull Part part) { String mimeType = part.getMimeType(); Body body = part.getBody(); if (body instanceof Multipart) { Multipart multipart = (Multipart) body; if (isSameMimeType(mimeType, "multipart/alternative")) { return findTextPartInMultipartAlternative(multipart); } else { return findTextPartInMultipart(multipart); } } else if (isSameMimeType(mimeType, "text/plain") || isSameMimeType(mimeType, "text/html")) { return part; } return null; }
TextPartFinder { @Nullable public Part findFirstTextPart(@NonNull Part part) { String mimeType = part.getMimeType(); Body body = part.getBody(); if (body instanceof Multipart) { Multipart multipart = (Multipart) body; if (isSameMimeType(mimeType, "multipart/alternative")) { return findTextPartInMultipartAlternative(multipart); } else { return findTextPartInMultipart(multipart); } } else if (isSameMimeType(mimeType, "text/plain") || isSameMimeType(mimeType, "text/html")) { return part; } return null; } }
TextPartFinder { @Nullable public Part findFirstTextPart(@NonNull Part part) { String mimeType = part.getMimeType(); Body body = part.getBody(); if (body instanceof Multipart) { Multipart multipart = (Multipart) body; if (isSameMimeType(mimeType, "multipart/alternative")) { return findTextPartInMultipartAlternative(multipart); } else { return findTextPartInMultipart(multipart); } } else if (isSameMimeType(mimeType, "text/plain") || isSameMimeType(mimeType, "text/html")) { return part; } return null; }  }
TextPartFinder { @Nullable public Part findFirstTextPart(@NonNull Part part) { String mimeType = part.getMimeType(); Body body = part.getBody(); if (body instanceof Multipart) { Multipart multipart = (Multipart) body; if (isSameMimeType(mimeType, "multipart/alternative")) { return findTextPartInMultipartAlternative(multipart); } else { return findTextPartInMultipart(multipart); } } else if (isSameMimeType(mimeType, "text/plain") || isSameMimeType(mimeType, "text/html")) { return part; } return null; }  @Nullable Part findFirstTextPart(@NonNull Part part); }
TextPartFinder { @Nullable public Part findFirstTextPart(@NonNull Part part) { String mimeType = part.getMimeType(); Body body = part.getBody(); if (body instanceof Multipart) { Multipart multipart = (Multipart) body; if (isSameMimeType(mimeType, "multipart/alternative")) { return findTextPartInMultipartAlternative(multipart); } else { return findTextPartInMultipart(multipart); } } else if (isSameMimeType(mimeType, "text/plain") || isSameMimeType(mimeType, "text/html")) { return part; } return null; }  @Nullable Part findFirstTextPart(@NonNull Part part);  }