diff --git a/src/com/fsck/k9/cache/TemporaryAttachmentStore.java b/src/com/fsck/k9/cache/TemporaryAttachmentStore.java index c2a4a264a..098e919e9 100644 --- a/src/com/fsck/k9/cache/TemporaryAttachmentStore.java +++ b/src/com/fsck/k9/cache/TemporaryAttachmentStore.java @@ -15,7 +15,13 @@ public class TemporaryAttachmentStore { private static String TEMPORARY_ATTACHMENT_DIRECTORY = "attachments"; private static long MAX_FILE_AGE = 12 * 60 * 60 * 1000; // 12h - public static File getFile(Context context, String attachmentName) throws IOException { + public static File getFile(Context context, String attachmentName) { + File directory = getTemporaryAttachmentDirectory(context); + String filename = FileHelper.sanitizeFilename(attachmentName); + return new File(directory, filename); + } + + public static File getFileForWriting(Context context, String attachmentName) throws IOException { File directory = createOrCleanAttachmentDirectory(context); String filename = FileHelper.sanitizeFilename(attachmentName); return new File(directory, filename); diff --git a/src/com/fsck/k9/view/AttachmentView.java b/src/com/fsck/k9/view/AttachmentView.java index e18884734..93966d9b4 100644 --- a/src/com/fsck/k9/view/AttachmentView.java +++ b/src/com/fsck/k9/view/AttachmentView.java @@ -286,7 +286,7 @@ public class AttachmentView extends FrameLayout implements OnClickListener, OnLo Intent viewIntent; if (resolvedIntentInfo.hasResolvedActivities() && resolvedIntentInfo.containsFileUri()) { try { - File tempFile = TemporaryAttachmentStore.getFile(context, name); + File tempFile = TemporaryAttachmentStore.getFileForWriting(context, name); writeAttachmentToStorage(tempFile); viewIntent = createViewIntentForFileUri(resolvedIntentInfo.getMimeType(), Uri.fromFile(tempFile)); } catch (IOException e) { @@ -310,8 +310,9 @@ public class AttachmentView extends FrameLayout implements OnClickListener, OnLo return new IntentAndResolvedActivitiesCount(contentUriIntent, contentUriActivitiesCount); } - Uri dummyFileUri = getDummyFileUri(); - Intent fileUriIntent = createViewIntentForFileUri(mimeType, dummyFileUri); + File tempFile = TemporaryAttachmentStore.getFile(context, name); + Uri tempFileUri = Uri.fromFile(tempFile); + Intent fileUriIntent = createViewIntentForFileUri(mimeType, tempFileUri); int fileUriActivitiesCount = getResolvedIntentActivitiesCount(fileUriIntent); if (fileUriActivitiesCount > 0) { @@ -321,11 +322,6 @@ public class AttachmentView extends FrameLayout implements OnClickListener, OnLo return new IntentAndResolvedActivitiesCount(contentUriIntent, contentUriActivitiesCount); } - private Uri getDummyFileUri() { - File dummyFile = new File(FileHelper.sanitizeFilename(name)); - return Uri.fromFile(dummyFile); - } - private Intent createViewIntentForAttachmentProviderUri(String mimeType) { Uri uri = AttachmentProvider.getAttachmentUriForViewing(account, part.getAttachmentId(), mimeType, name);