Loading k9mail/src/main/java/com/fsck/k9/mailstore/AttachmentResolver.java +4 −5 Original line number Diff line number Diff line Loading @@ -6,7 +6,6 @@ import java.util.HashMap; import java.util.Map; import java.util.Stack; import android.content.Context; import android.net.Uri; import android.support.annotation.Nullable; import android.support.annotation.VisibleForTesting; Loading Loading @@ -42,14 +41,14 @@ public class AttachmentResolver { } @WorkerThread public static AttachmentResolver createFromPart(Context context, Part part) { public static AttachmentResolver createFromPart(Part part) { AttachmentInfoExtractor attachmentInfoExtractor = AttachmentInfoExtractor.getInstance(); Map<String, Uri> contentIdToAttachmentUriMap = buildCidToAttachmentUriMap(context, attachmentInfoExtractor, part); Map<String, Uri> contentIdToAttachmentUriMap = buildCidToAttachmentUriMap(attachmentInfoExtractor, part); return new AttachmentResolver(contentIdToAttachmentUriMap); } @VisibleForTesting static Map<String,Uri> buildCidToAttachmentUriMap(Context context, AttachmentInfoExtractor attachmentInfoExtractor, static Map<String,Uri> buildCidToAttachmentUriMap(AttachmentInfoExtractor attachmentInfoExtractor, Part rootPart) { HashMap<String,Uri> result = new HashMap<>(); Loading @@ -69,7 +68,7 @@ public class AttachmentResolver { try { String contentId = part.getContentId(); if (contentId != null) { AttachmentViewInfo attachmentInfo = attachmentInfoExtractor.extractAttachmentInfo(context, part); AttachmentViewInfo attachmentInfo = attachmentInfoExtractor.extractAttachmentInfo(part); result.put(contentId, attachmentInfo.uri); } } catch (MessagingException e) { Loading k9mail/src/main/java/com/fsck/k9/mailstore/MessageViewInfoExtractor.java +2 −2 Original line number Diff line number Diff line Loading @@ -74,7 +74,7 @@ public class MessageViewInfoExtractor { extraViewableText = extraViewable.text; } AttachmentResolver attachmentResolver = AttachmentResolver.createFromPart(context, rootPart); AttachmentResolver attachmentResolver = AttachmentResolver.createFromPart(rootPart); return MessageViewInfo.createWithExtractedContent(message, rootPart, viewable.html, attachmentInfos, cryptoResultAnnotation, extraViewableText, extraAttachmentInfos, attachmentResolver); Loading @@ -89,7 +89,7 @@ public class MessageViewInfoExtractor { MessageExtractor.findViewablesAndAttachments(part, viewableParts, attachments); } attachmentInfos.addAll(attachmentInfoExtractor.extractAttachmentInfos(context, attachments)); attachmentInfos.addAll(attachmentInfoExtractor.extractAttachmentInfos(attachments)); return MessageViewInfoExtractor.extractTextFromViewables(context, viewableParts); } Loading k9mail/src/main/java/com/fsck/k9/message/extractors/AttachmentInfoExtractor.java +15 −9 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ import android.support.annotation.Nullable; import android.support.annotation.VisibleForTesting; import android.util.Log; import com.fsck.k9.Globals; import com.fsck.k9.K9; import com.fsck.k9.mail.Body; import com.fsck.k9.mail.MessagingException; Loading @@ -26,25 +27,30 @@ import com.fsck.k9.provider.DecryptedFileProvider; public class AttachmentInfoExtractor { @VisibleForTesting AttachmentInfoExtractor() { } private final Context context; public static AttachmentInfoExtractor getInstance() { return new AttachmentInfoExtractor(); Context context = Globals.getContext(); return new AttachmentInfoExtractor(context); } @VisibleForTesting AttachmentInfoExtractor(Context context) { this.context = context; } public List<AttachmentViewInfo> extractAttachmentInfos(Context context, List<Part> attachmentParts) throws MessagingException { public List<AttachmentViewInfo> extractAttachmentInfos(List<Part> attachmentParts) throws MessagingException { List<AttachmentViewInfo> attachments = new ArrayList<>(); for (Part part : attachmentParts) { attachments.add(extractAttachmentInfo(context, part)); attachments.add(extractAttachmentInfo(part)); } return attachments; } public AttachmentViewInfo extractAttachmentInfo(Context context, Part part) throws MessagingException { public AttachmentViewInfo extractAttachmentInfo(Part part) throws MessagingException { Uri uri; long size; if (part instanceof LocalPart) { Loading @@ -58,7 +64,7 @@ public class AttachmentInfoExtractor { if (body instanceof DeferredFileBody) { DeferredFileBody decryptedTempFileBody = (DeferredFileBody) body; size = decryptedTempFileBody.getSize(); uri = getDecryptedFileProviderUri(context, decryptedTempFileBody, part.getMimeType()); uri = getDecryptedFileProviderUri(decryptedTempFileBody, part.getMimeType()); return extractAttachmentInfo(part, uri, size); } else { throw new IllegalArgumentException("Unsupported part type provided"); Loading @@ -70,7 +76,7 @@ public class AttachmentInfoExtractor { @Nullable @VisibleForTesting protected Uri getDecryptedFileProviderUri(Context context, DeferredFileBody decryptedTempFileBody, String mimeType) { protected Uri getDecryptedFileProviderUri(DeferredFileBody decryptedTempFileBody, String mimeType) { Uri uri; try { File file = decryptedTempFileBody.getFile(); Loading k9mail/src/main/java/com/fsck/k9/ui/compose/QuotedMessagePresenter.java +3 −3 Original line number Diff line number Diff line Loading @@ -133,7 +133,7 @@ public class QuotedMessagePresenter { // Load the message with the reply header. TODO replace with MessageViewInfo data view.setQuotedHtml(quotedHtmlContent.getQuotedContent(), AttachmentResolver.createFromPart(messageCompose, sourceMessage)); AttachmentResolver.createFromPart(sourceMessage)); // TODO: Also strip the signature from the text/plain part view.setQuotedText(QuotedMessageHelper.quoteOriginalTextMessage(resources, sourceMessage, Loading Loading @@ -298,7 +298,7 @@ public class QuotedMessagePresenter { } // TODO replace with MessageViewInfo data view.setQuotedHtml(quotedHtmlContent.getQuotedContent(), AttachmentResolver.createFromPart(messageCompose, message)); AttachmentResolver.createFromPart(message)); } } if (bodyPlainOffset != null && bodyPlainLength != null) { Loading k9mail/src/test/java/com/fsck/k9/mailstore/AttachmentResolverTest.java +7 −18 Original line number Diff line number Diff line package com.fsck.k9.mailstore; import java.util.Arrays; import java.util.Collections; import java.util.Map; import android.net.Uri; Loading @@ -17,7 +15,6 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; import static org.junit.Assert.*; Loading Loading @@ -46,8 +43,7 @@ public class AttachmentResolverTest { public void buildCidMap__onPartWithNoBody__shouldReturnEmptyMap() throws Exception { Part part = new MimeBodyPart(); Map<String,Uri> result = AttachmentResolver.buildCidToAttachmentUriMap( RuntimeEnvironment.application, attachmentInfoExtractor, part); Map<String,Uri> result = AttachmentResolver.buildCidToAttachmentUriMap(attachmentInfoExtractor, part); assertTrue(result.isEmpty()); } Loading @@ -57,8 +53,7 @@ public class AttachmentResolverTest { Multipart multipartBody = new MimeMultipart(); Part multipartPart = new MimeBodyPart(multipartBody); Map<String,Uri> result = AttachmentResolver.buildCidToAttachmentUriMap( RuntimeEnvironment.application, attachmentInfoExtractor, multipartPart); Map<String,Uri> result = AttachmentResolver.buildCidToAttachmentUriMap(attachmentInfoExtractor, multipartPart); assertTrue(result.isEmpty()); } Loading @@ -70,10 +65,7 @@ public class AttachmentResolverTest { Part multipartPart = new MimeBodyPart(multipartBody); multipartBody.addBodyPart(bodyPart); Map<String,Uri> result = AttachmentResolver.buildCidToAttachmentUriMap( RuntimeEnvironment.application, attachmentInfoExtractor, multipartPart); Map<String,Uri> result = AttachmentResolver.buildCidToAttachmentUriMap(attachmentInfoExtractor, multipartPart); verify(bodyPart).getContentId(); assertTrue(result.isEmpty()); Loading @@ -92,19 +84,16 @@ public class AttachmentResolverTest { when(subPart1.getContentId()).thenReturn("cid-1"); when(subPart2.getContentId()).thenReturn("cid-2"); when(attachmentInfoExtractor.extractAttachmentInfo(RuntimeEnvironment.application, subPart1)).thenReturn( when(attachmentInfoExtractor.extractAttachmentInfo(subPart1)).thenReturn( new AttachmentViewInfo(null, null, AttachmentViewInfo.UNKNOWN_SIZE, ATTACHMENT_TEST_URI_1, true, subPart1)); when(attachmentInfoExtractor.extractAttachmentInfo(RuntimeEnvironment.application, subPart2)).thenReturn( when(attachmentInfoExtractor.extractAttachmentInfo(subPart2)).thenReturn( new AttachmentViewInfo(null, null, AttachmentViewInfo.UNKNOWN_SIZE, ATTACHMENT_TEST_URI_2, true, subPart2)); Map<String,Uri> result = AttachmentResolver.buildCidToAttachmentUriMap(RuntimeEnvironment.application, attachmentInfoExtractor, multipartPart); Map<String,Uri> result = AttachmentResolver.buildCidToAttachmentUriMap(attachmentInfoExtractor, multipartPart); assertEquals(2, result.size()); assertEquals(ATTACHMENT_TEST_URI_1, result.get("cid-1")); assertEquals(ATTACHMENT_TEST_URI_2, result.get("cid-2")); } } Loading
k9mail/src/main/java/com/fsck/k9/mailstore/AttachmentResolver.java +4 −5 Original line number Diff line number Diff line Loading @@ -6,7 +6,6 @@ import java.util.HashMap; import java.util.Map; import java.util.Stack; import android.content.Context; import android.net.Uri; import android.support.annotation.Nullable; import android.support.annotation.VisibleForTesting; Loading Loading @@ -42,14 +41,14 @@ public class AttachmentResolver { } @WorkerThread public static AttachmentResolver createFromPart(Context context, Part part) { public static AttachmentResolver createFromPart(Part part) { AttachmentInfoExtractor attachmentInfoExtractor = AttachmentInfoExtractor.getInstance(); Map<String, Uri> contentIdToAttachmentUriMap = buildCidToAttachmentUriMap(context, attachmentInfoExtractor, part); Map<String, Uri> contentIdToAttachmentUriMap = buildCidToAttachmentUriMap(attachmentInfoExtractor, part); return new AttachmentResolver(contentIdToAttachmentUriMap); } @VisibleForTesting static Map<String,Uri> buildCidToAttachmentUriMap(Context context, AttachmentInfoExtractor attachmentInfoExtractor, static Map<String,Uri> buildCidToAttachmentUriMap(AttachmentInfoExtractor attachmentInfoExtractor, Part rootPart) { HashMap<String,Uri> result = new HashMap<>(); Loading @@ -69,7 +68,7 @@ public class AttachmentResolver { try { String contentId = part.getContentId(); if (contentId != null) { AttachmentViewInfo attachmentInfo = attachmentInfoExtractor.extractAttachmentInfo(context, part); AttachmentViewInfo attachmentInfo = attachmentInfoExtractor.extractAttachmentInfo(part); result.put(contentId, attachmentInfo.uri); } } catch (MessagingException e) { Loading
k9mail/src/main/java/com/fsck/k9/mailstore/MessageViewInfoExtractor.java +2 −2 Original line number Diff line number Diff line Loading @@ -74,7 +74,7 @@ public class MessageViewInfoExtractor { extraViewableText = extraViewable.text; } AttachmentResolver attachmentResolver = AttachmentResolver.createFromPart(context, rootPart); AttachmentResolver attachmentResolver = AttachmentResolver.createFromPart(rootPart); return MessageViewInfo.createWithExtractedContent(message, rootPart, viewable.html, attachmentInfos, cryptoResultAnnotation, extraViewableText, extraAttachmentInfos, attachmentResolver); Loading @@ -89,7 +89,7 @@ public class MessageViewInfoExtractor { MessageExtractor.findViewablesAndAttachments(part, viewableParts, attachments); } attachmentInfos.addAll(attachmentInfoExtractor.extractAttachmentInfos(context, attachments)); attachmentInfos.addAll(attachmentInfoExtractor.extractAttachmentInfos(attachments)); return MessageViewInfoExtractor.extractTextFromViewables(context, viewableParts); } Loading
k9mail/src/main/java/com/fsck/k9/message/extractors/AttachmentInfoExtractor.java +15 −9 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ import android.support.annotation.Nullable; import android.support.annotation.VisibleForTesting; import android.util.Log; import com.fsck.k9.Globals; import com.fsck.k9.K9; import com.fsck.k9.mail.Body; import com.fsck.k9.mail.MessagingException; Loading @@ -26,25 +27,30 @@ import com.fsck.k9.provider.DecryptedFileProvider; public class AttachmentInfoExtractor { @VisibleForTesting AttachmentInfoExtractor() { } private final Context context; public static AttachmentInfoExtractor getInstance() { return new AttachmentInfoExtractor(); Context context = Globals.getContext(); return new AttachmentInfoExtractor(context); } @VisibleForTesting AttachmentInfoExtractor(Context context) { this.context = context; } public List<AttachmentViewInfo> extractAttachmentInfos(Context context, List<Part> attachmentParts) throws MessagingException { public List<AttachmentViewInfo> extractAttachmentInfos(List<Part> attachmentParts) throws MessagingException { List<AttachmentViewInfo> attachments = new ArrayList<>(); for (Part part : attachmentParts) { attachments.add(extractAttachmentInfo(context, part)); attachments.add(extractAttachmentInfo(part)); } return attachments; } public AttachmentViewInfo extractAttachmentInfo(Context context, Part part) throws MessagingException { public AttachmentViewInfo extractAttachmentInfo(Part part) throws MessagingException { Uri uri; long size; if (part instanceof LocalPart) { Loading @@ -58,7 +64,7 @@ public class AttachmentInfoExtractor { if (body instanceof DeferredFileBody) { DeferredFileBody decryptedTempFileBody = (DeferredFileBody) body; size = decryptedTempFileBody.getSize(); uri = getDecryptedFileProviderUri(context, decryptedTempFileBody, part.getMimeType()); uri = getDecryptedFileProviderUri(decryptedTempFileBody, part.getMimeType()); return extractAttachmentInfo(part, uri, size); } else { throw new IllegalArgumentException("Unsupported part type provided"); Loading @@ -70,7 +76,7 @@ public class AttachmentInfoExtractor { @Nullable @VisibleForTesting protected Uri getDecryptedFileProviderUri(Context context, DeferredFileBody decryptedTempFileBody, String mimeType) { protected Uri getDecryptedFileProviderUri(DeferredFileBody decryptedTempFileBody, String mimeType) { Uri uri; try { File file = decryptedTempFileBody.getFile(); Loading
k9mail/src/main/java/com/fsck/k9/ui/compose/QuotedMessagePresenter.java +3 −3 Original line number Diff line number Diff line Loading @@ -133,7 +133,7 @@ public class QuotedMessagePresenter { // Load the message with the reply header. TODO replace with MessageViewInfo data view.setQuotedHtml(quotedHtmlContent.getQuotedContent(), AttachmentResolver.createFromPart(messageCompose, sourceMessage)); AttachmentResolver.createFromPart(sourceMessage)); // TODO: Also strip the signature from the text/plain part view.setQuotedText(QuotedMessageHelper.quoteOriginalTextMessage(resources, sourceMessage, Loading Loading @@ -298,7 +298,7 @@ public class QuotedMessagePresenter { } // TODO replace with MessageViewInfo data view.setQuotedHtml(quotedHtmlContent.getQuotedContent(), AttachmentResolver.createFromPart(messageCompose, message)); AttachmentResolver.createFromPart(message)); } } if (bodyPlainOffset != null && bodyPlainLength != null) { Loading
k9mail/src/test/java/com/fsck/k9/mailstore/AttachmentResolverTest.java +7 −18 Original line number Diff line number Diff line package com.fsck.k9.mailstore; import java.util.Arrays; import java.util.Collections; import java.util.Map; import android.net.Uri; Loading @@ -17,7 +15,6 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; import static org.junit.Assert.*; Loading Loading @@ -46,8 +43,7 @@ public class AttachmentResolverTest { public void buildCidMap__onPartWithNoBody__shouldReturnEmptyMap() throws Exception { Part part = new MimeBodyPart(); Map<String,Uri> result = AttachmentResolver.buildCidToAttachmentUriMap( RuntimeEnvironment.application, attachmentInfoExtractor, part); Map<String,Uri> result = AttachmentResolver.buildCidToAttachmentUriMap(attachmentInfoExtractor, part); assertTrue(result.isEmpty()); } Loading @@ -57,8 +53,7 @@ public class AttachmentResolverTest { Multipart multipartBody = new MimeMultipart(); Part multipartPart = new MimeBodyPart(multipartBody); Map<String,Uri> result = AttachmentResolver.buildCidToAttachmentUriMap( RuntimeEnvironment.application, attachmentInfoExtractor, multipartPart); Map<String,Uri> result = AttachmentResolver.buildCidToAttachmentUriMap(attachmentInfoExtractor, multipartPart); assertTrue(result.isEmpty()); } Loading @@ -70,10 +65,7 @@ public class AttachmentResolverTest { Part multipartPart = new MimeBodyPart(multipartBody); multipartBody.addBodyPart(bodyPart); Map<String,Uri> result = AttachmentResolver.buildCidToAttachmentUriMap( RuntimeEnvironment.application, attachmentInfoExtractor, multipartPart); Map<String,Uri> result = AttachmentResolver.buildCidToAttachmentUriMap(attachmentInfoExtractor, multipartPart); verify(bodyPart).getContentId(); assertTrue(result.isEmpty()); Loading @@ -92,19 +84,16 @@ public class AttachmentResolverTest { when(subPart1.getContentId()).thenReturn("cid-1"); when(subPart2.getContentId()).thenReturn("cid-2"); when(attachmentInfoExtractor.extractAttachmentInfo(RuntimeEnvironment.application, subPart1)).thenReturn( when(attachmentInfoExtractor.extractAttachmentInfo(subPart1)).thenReturn( new AttachmentViewInfo(null, null, AttachmentViewInfo.UNKNOWN_SIZE, ATTACHMENT_TEST_URI_1, true, subPart1)); when(attachmentInfoExtractor.extractAttachmentInfo(RuntimeEnvironment.application, subPart2)).thenReturn( when(attachmentInfoExtractor.extractAttachmentInfo(subPart2)).thenReturn( new AttachmentViewInfo(null, null, AttachmentViewInfo.UNKNOWN_SIZE, ATTACHMENT_TEST_URI_2, true, subPart2)); Map<String,Uri> result = AttachmentResolver.buildCidToAttachmentUriMap(RuntimeEnvironment.application, attachmentInfoExtractor, multipartPart); Map<String,Uri> result = AttachmentResolver.buildCidToAttachmentUriMap(attachmentInfoExtractor, multipartPart); assertEquals(2, result.size()); assertEquals(ATTACHMENT_TEST_URI_1, result.get("cid-1")); assertEquals(ATTACHMENT_TEST_URI_2, result.get("cid-2")); } }