use of com.fsck.k9.mail.internet.Viewable.Alternative in project k-9 by k9mail.
the class TextPartFinderTest method findFirstTextPart_withMultipartAlternativeContainingMultipartRelatedContainingTextHtmlFirst.
@Test
public void findFirstTextPart_withMultipartAlternativeContainingMultipartRelatedContainingTextHtmlFirst() throws Exception {
BodyPart expected = createTextPart("text/plain");
Part part = createMultipart("multipart/alternative", createMultipart("multipart/related", createTextPart("text/html"), createPart("image/jpeg")), expected);
Part result = textPartFinder.findFirstTextPart(part);
assertEquals(expected, result);
}
use of com.fsck.k9.mail.internet.Viewable.Alternative in project k-9 by k9mail.
the class TextPartFinderTest method findFirstTextPart_withMultipartMixedContainingMultipartAlternative.
@Test
public void findFirstTextPart_withMultipartMixedContainingMultipartAlternative() throws Exception {
BodyPart expected = createTextPart("text/plain");
Part part = createMultipart("multipart/mixed", createPart("image/jpeg"), createMultipart("multipart/alternative", expected, createTextPart("text/html")), createTextPart("text/plain"));
Part result = textPartFinder.findFirstTextPart(part);
assertEquals(expected, result);
}
use of com.fsck.k9.mail.internet.Viewable.Alternative in project k-9 by k9mail.
the class TextPartFinderTest method findFirstTextPart_withMultipartAlternativeHtmlPartFirst.
@Test
public void findFirstTextPart_withMultipartAlternativeHtmlPartFirst() throws Exception {
BodyPart expected = createTextPart("text/plain");
Part part = createMultipart("multipart/alternative", createTextPart("text/html"), expected);
Part result = textPartFinder.findFirstTextPart(part);
assertEquals(expected, result);
}
use of com.fsck.k9.mail.internet.Viewable.Alternative in project k-9 by k9mail.
the class MigrationTo51 method insertBodyAsMultipartAlternative.
private static MimeStructureState insertBodyAsMultipartAlternative(SQLiteDatabase db, MimeStructureState structureState, MimeHeader mimeHeader, String textContent, String htmlContent) throws IOException {
if (mimeHeader == null) {
mimeHeader = new MimeHeader();
}
String boundary = MimeUtility.getHeaderParameter(mimeHeader.getFirstHeader(MimeHeader.HEADER_CONTENT_TYPE), "boundary");
if (TextUtils.isEmpty(boundary)) {
boundary = MimeUtil.createUniqueBoundary();
}
mimeHeader.setHeader(MimeHeader.HEADER_CONTENT_TYPE, String.format("multipart/alternative; boundary=\"%s\";", boundary));
int dataLocation = textContent != null || htmlContent != null ? DATA_LOCATION__IN_DATABASE : DATA_LOCATION__MISSING;
ContentValues cv = new ContentValues();
cv.put("type", MESSAGE_PART_TYPE__UNKNOWN);
cv.put("data_location", dataLocation);
cv.put("mime_type", "multipart/alternative");
cv.put("header", mimeHeader.toString());
cv.put("boundary", boundary);
structureState.applyValues(cv);
long multipartAlternativePartId = db.insertOrThrow("message_parts", null, cv);
structureState = structureState.nextMultipartChild(multipartAlternativePartId);
if (textContent != null) {
structureState = insertTextualPartIntoDatabase(db, structureState, null, textContent, false);
}
if (htmlContent != null) {
structureState = insertTextualPartIntoDatabase(db, structureState, null, htmlContent, true);
}
return structureState;
}
use of com.fsck.k9.mail.internet.Viewable.Alternative in project k-9 by k9mail.
the class MessageViewInfoExtractor method buildText.
private StringBuilder buildText(Viewable viewable, boolean prependDivider) {
StringBuilder text = new StringBuilder();
if (viewable instanceof Textual) {
Part part = ((Textual) viewable).getPart();
addTextDivider(text, part, prependDivider);
String t = MessageExtractor.getTextFromPart(part);
if (t == null) {
t = "";
} else if (viewable instanceof Html) {
t = HtmlConverter.htmlToText(t);
} else if (viewable instanceof Flowed) {
t = FlowedMessageUtils.deflow(t, false);
} else if (!(viewable instanceof Text)) {
throw new IllegalStateException("unhandled case!");
}
text.append(t);
} else if (viewable instanceof Alternative) {
// That's odd - an Alternative as child of an Alternative; go ahead and try to use the
// text/plain child; fall-back to the text/html part.
Alternative alternative = (Alternative) viewable;
List<Viewable> textAlternative = alternative.getText().isEmpty() ? alternative.getHtml() : alternative.getText();
boolean divider = prependDivider;
for (Viewable textViewable : textAlternative) {
text.append(buildText(textViewable, divider));
divider = true;
}
}
return text;
}
Aggregations