@Test(expected = IllegalArgumentException.class) public void extractInfo__withGenericPart_shouldThrow() throws Exception { Part part = mock(Part.class); attachmentInfoExtractor.extractAttachmentInfo(part); }
@WorkerThread public AttachmentViewInfo extractAttachmentInfo(Part part) throws MessagingException { Uri uri; long size; boolean isContentAvailable; if (part instanceof LocalPart) { LocalPart localPart = (LocalPart) part; String accountUuid = localPart.getAccountUuid(); long messagePartId = localPart.getPartId(); size = localPart.getSize(); isContentAvailable = part.getBody() != null; uri = AttachmentProvider.getAttachmentUri(accountUuid, messagePartId); } else if (part instanceof LocalMessage) { LocalMessage localMessage = (LocalMessage) part; String accountUuid = localMessage.getAccount().getUuid(); long messagePartId = localMessage.getMessagePartId(); size = localMessage.getSize(); isContentAvailable = part.getBody() != null; uri = AttachmentProvider.getAttachmentUri(accountUuid, messagePartId); } else { Body body = part.getBody(); if (body instanceof DeferredFileBody) { DeferredFileBody decryptedTempFileBody = (DeferredFileBody) body; size = decryptedTempFileBody.getSize(); uri = getDecryptedFileProviderUri(decryptedTempFileBody, part.getMimeType()); isContentAvailable = true; } else { throw new IllegalArgumentException("Unsupported part type provided"); } } return extractAttachmentInfo(part, uri, size, isContentAvailable); }
AttachmentInfoExtractor { @WorkerThread public AttachmentViewInfo extractAttachmentInfo(Part part) throws MessagingException { Uri uri; long size; boolean isContentAvailable; if (part instanceof LocalPart) { LocalPart localPart = (LocalPart) part; String accountUuid = localPart.getAccountUuid(); long messagePartId = localPart.getPartId(); size = localPart.getSize(); isContentAvailable = part.getBody() != null; uri = AttachmentProvider.getAttachmentUri(accountUuid, messagePartId); } else if (part instanceof LocalMessage) { LocalMessage localMessage = (LocalMessage) part; String accountUuid = localMessage.getAccount().getUuid(); long messagePartId = localMessage.getMessagePartId(); size = localMessage.getSize(); isContentAvailable = part.getBody() != null; uri = AttachmentProvider.getAttachmentUri(accountUuid, messagePartId); } else { Body body = part.getBody(); if (body instanceof DeferredFileBody) { DeferredFileBody decryptedTempFileBody = (DeferredFileBody) body; size = decryptedTempFileBody.getSize(); uri = getDecryptedFileProviderUri(decryptedTempFileBody, part.getMimeType()); isContentAvailable = true; } else { throw new IllegalArgumentException("Unsupported part type provided"); } } return extractAttachmentInfo(part, uri, size, isContentAvailable); } }
AttachmentInfoExtractor { @WorkerThread public AttachmentViewInfo extractAttachmentInfo(Part part) throws MessagingException { Uri uri; long size; boolean isContentAvailable; if (part instanceof LocalPart) { LocalPart localPart = (LocalPart) part; String accountUuid = localPart.getAccountUuid(); long messagePartId = localPart.getPartId(); size = localPart.getSize(); isContentAvailable = part.getBody() != null; uri = AttachmentProvider.getAttachmentUri(accountUuid, messagePartId); } else if (part instanceof LocalMessage) { LocalMessage localMessage = (LocalMessage) part; String accountUuid = localMessage.getAccount().getUuid(); long messagePartId = localMessage.getMessagePartId(); size = localMessage.getSize(); isContentAvailable = part.getBody() != null; uri = AttachmentProvider.getAttachmentUri(accountUuid, messagePartId); } else { Body body = part.getBody(); if (body instanceof DeferredFileBody) { DeferredFileBody decryptedTempFileBody = (DeferredFileBody) body; size = decryptedTempFileBody.getSize(); uri = getDecryptedFileProviderUri(decryptedTempFileBody, part.getMimeType()); isContentAvailable = true; } else { throw new IllegalArgumentException("Unsupported part type provided"); } } return extractAttachmentInfo(part, uri, size, isContentAvailable); } @VisibleForTesting  AttachmentInfoExtractor(Context context); }
AttachmentInfoExtractor { @WorkerThread public AttachmentViewInfo extractAttachmentInfo(Part part) throws MessagingException { Uri uri; long size; boolean isContentAvailable; if (part instanceof LocalPart) { LocalPart localPart = (LocalPart) part; String accountUuid = localPart.getAccountUuid(); long messagePartId = localPart.getPartId(); size = localPart.getSize(); isContentAvailable = part.getBody() != null; uri = AttachmentProvider.getAttachmentUri(accountUuid, messagePartId); } else if (part instanceof LocalMessage) { LocalMessage localMessage = (LocalMessage) part; String accountUuid = localMessage.getAccount().getUuid(); long messagePartId = localMessage.getMessagePartId(); size = localMessage.getSize(); isContentAvailable = part.getBody() != null; uri = AttachmentProvider.getAttachmentUri(accountUuid, messagePartId); } else { Body body = part.getBody(); if (body instanceof DeferredFileBody) { DeferredFileBody decryptedTempFileBody = (DeferredFileBody) body; size = decryptedTempFileBody.getSize(); uri = getDecryptedFileProviderUri(decryptedTempFileBody, part.getMimeType()); isContentAvailable = true; } else { throw new IllegalArgumentException("Unsupported part type provided"); } } return extractAttachmentInfo(part, uri, size, isContentAvailable); } @VisibleForTesting  AttachmentInfoExtractor(Context context); static AttachmentInfoExtractor getInstance(); @WorkerThread List<AttachmentViewInfo> extractAttachmentInfoForView(List<Part> attachmentParts); @WorkerThread AttachmentViewInfo extractAttachmentInfo(Part part); AttachmentViewInfo extractAttachmentInfoForDatabase(Part part); }
AttachmentInfoExtractor { @WorkerThread public AttachmentViewInfo extractAttachmentInfo(Part part) throws MessagingException { Uri uri; long size; boolean isContentAvailable; if (part instanceof LocalPart) { LocalPart localPart = (LocalPart) part; String accountUuid = localPart.getAccountUuid(); long messagePartId = localPart.getPartId(); size = localPart.getSize(); isContentAvailable = part.getBody() != null; uri = AttachmentProvider.getAttachmentUri(accountUuid, messagePartId); } else if (part instanceof LocalMessage) { LocalMessage localMessage = (LocalMessage) part; String accountUuid = localMessage.getAccount().getUuid(); long messagePartId = localMessage.getMessagePartId(); size = localMessage.getSize(); isContentAvailable = part.getBody() != null; uri = AttachmentProvider.getAttachmentUri(accountUuid, messagePartId); } else { Body body = part.getBody(); if (body instanceof DeferredFileBody) { DeferredFileBody decryptedTempFileBody = (DeferredFileBody) body; size = decryptedTempFileBody.getSize(); uri = getDecryptedFileProviderUri(decryptedTempFileBody, part.getMimeType()); isContentAvailable = true; } else { throw new IllegalArgumentException("Unsupported part type provided"); } } return extractAttachmentInfo(part, uri, size, isContentAvailable); } @VisibleForTesting  AttachmentInfoExtractor(Context context); static AttachmentInfoExtractor getInstance(); @WorkerThread List<AttachmentViewInfo> extractAttachmentInfoForView(List<Part> attachmentParts); @WorkerThread AttachmentViewInfo extractAttachmentInfo(Part part); AttachmentViewInfo extractAttachmentInfoForDatabase(Part part);  }