Loading src/com/fsck/k9/mail/internet/MimeUtility.java +57 −0 Original line number Diff line number Diff line Loading @@ -3260,4 +3260,61 @@ public class MimeUtility { return charset; } public static ViewableContainer extractPartsFromDraft(Message message) throws MessagingException { Body body = message.getBody(); if (message.isMimeType("multipart/mixed") && body instanceof MimeMultipart) { MimeMultipart multipart = (MimeMultipart) body; ViewableContainer container; int count = multipart.getCount(); if (count >= 1) { // The first part is either a text/plain or a multipart/alternative BodyPart firstPart = multipart.getBodyPart(0); container = extractTextual(firstPart); // The rest should be attachments for (int i = 1; i < count; i++) { BodyPart bodyPart = multipart.getBodyPart(i); container.attachments.add(bodyPart); } } else { container = new ViewableContainer(null, null, new ArrayList<Part>()); } return container; } return extractTextual(message); } private static ViewableContainer extractTextual(Part part) throws MessagingException { String text = null; String html = null; List<Part> attachments = new ArrayList<Part>(); Body firstBody = part.getBody(); if (part.isMimeType("text/plain") && firstBody instanceof TextBody) { text = ((TextBody) firstBody).getText(); } else if (part.isMimeType("multipart/alternative") && firstBody instanceof MimeMultipart) { MimeMultipart multipart = (MimeMultipart) firstBody; for (int i = 0, count = multipart.getCount(); i < count; i++) { BodyPart bodyPart = multipart.getBodyPart(i); if (bodyPart.getBody() instanceof TextBody) { TextBody textBody = (TextBody) bodyPart.getBody(); if (text == null && bodyPart.isMimeType("text/plain")) { text = textBody.getText(); } else if (html == null && bodyPart.isMimeType("text/html")) { html = textBody.getText(); } } } } return new ViewableContainer(text, html, attachments); } } src/com/fsck/k9/mail/store/LocalStore.java +22 −5 Original line number Diff line number Diff line Loading @@ -2134,12 +2134,29 @@ public class LocalStore extends Store implements Serializable { deleteAttachments(message.getUid()); } boolean isDraft = (message.getHeader(K9.IDENTITY_HEADER) != null); List<Part> attachments; String text; String html; if (isDraft) { // Don't modify the text/plain or text/html part of our own // draft messages because this will cause the values stored in // the identity header to be wrong. ViewableContainer container = MimeUtility.extractPartsFromDraft(message); text = container.text; html = container.html; attachments = container.attachments; } else { ViewableContainer container = MimeUtility.extractTextAndAttachments(mApplication, message); List<Part> attachments = container.attachments; String text = container.text; String html = HtmlConverter.convertEmoji2Img(container.html); attachments = container.attachments; text = container.text; html = HtmlConverter.convertEmoji2Img(container.html); } String preview = calculateContentPreview(text); Loading Loading
src/com/fsck/k9/mail/internet/MimeUtility.java +57 −0 Original line number Diff line number Diff line Loading @@ -3260,4 +3260,61 @@ public class MimeUtility { return charset; } public static ViewableContainer extractPartsFromDraft(Message message) throws MessagingException { Body body = message.getBody(); if (message.isMimeType("multipart/mixed") && body instanceof MimeMultipart) { MimeMultipart multipart = (MimeMultipart) body; ViewableContainer container; int count = multipart.getCount(); if (count >= 1) { // The first part is either a text/plain or a multipart/alternative BodyPart firstPart = multipart.getBodyPart(0); container = extractTextual(firstPart); // The rest should be attachments for (int i = 1; i < count; i++) { BodyPart bodyPart = multipart.getBodyPart(i); container.attachments.add(bodyPart); } } else { container = new ViewableContainer(null, null, new ArrayList<Part>()); } return container; } return extractTextual(message); } private static ViewableContainer extractTextual(Part part) throws MessagingException { String text = null; String html = null; List<Part> attachments = new ArrayList<Part>(); Body firstBody = part.getBody(); if (part.isMimeType("text/plain") && firstBody instanceof TextBody) { text = ((TextBody) firstBody).getText(); } else if (part.isMimeType("multipart/alternative") && firstBody instanceof MimeMultipart) { MimeMultipart multipart = (MimeMultipart) firstBody; for (int i = 0, count = multipart.getCount(); i < count; i++) { BodyPart bodyPart = multipart.getBodyPart(i); if (bodyPart.getBody() instanceof TextBody) { TextBody textBody = (TextBody) bodyPart.getBody(); if (text == null && bodyPart.isMimeType("text/plain")) { text = textBody.getText(); } else if (html == null && bodyPart.isMimeType("text/html")) { html = textBody.getText(); } } } } return new ViewableContainer(text, html, attachments); } }
src/com/fsck/k9/mail/store/LocalStore.java +22 −5 Original line number Diff line number Diff line Loading @@ -2134,12 +2134,29 @@ public class LocalStore extends Store implements Serializable { deleteAttachments(message.getUid()); } boolean isDraft = (message.getHeader(K9.IDENTITY_HEADER) != null); List<Part> attachments; String text; String html; if (isDraft) { // Don't modify the text/plain or text/html part of our own // draft messages because this will cause the values stored in // the identity header to be wrong. ViewableContainer container = MimeUtility.extractPartsFromDraft(message); text = container.text; html = container.html; attachments = container.attachments; } else { ViewableContainer container = MimeUtility.extractTextAndAttachments(mApplication, message); List<Part> attachments = container.attachments; String text = container.text; String html = HtmlConverter.convertEmoji2Img(container.html); attachments = container.attachments; text = container.text; html = HtmlConverter.convertEmoji2Img(container.html); } String preview = calculateContentPreview(text); Loading