use of com.fsck.k9.mailstore.DeferredFileBody in project k-9 by k9mail.
the class DeferredFileBodyTest method setUp.
@Before
public void setUp() throws Exception {
FileFactory fileFactory = new FileFactory() {
@Override
public File createFile() throws IOException {
assertNull("only a single file should be created", createdFile);
createdFile = File.createTempFile("test", "tmp");
createdFile.deleteOnExit();
return createdFile;
}
};
deferredFileBody = new DeferredFileBody(TEST_THRESHOLD, fileFactory, TEST_ENCODING);
}
use of com.fsck.k9.mailstore.DeferredFileBody in project k-9 by k9mail.
the class AttachmentInfoExtractor method extractAttachmentInfo.
@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.getId();
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);
}
use of com.fsck.k9.mailstore.DeferredFileBody in project k-9 by k9mail.
the class AttachmentInfoExtractorTest method extractInfo__withDeferredFileBody.
@Test
public void extractInfo__withDeferredFileBody() throws Exception {
attachmentInfoExtractor = new AttachmentInfoExtractor(context) {
@Nullable
@Override
protected Uri getDecryptedFileProviderUri(DeferredFileBody decryptedTempFileBody, String mimeType) {
return TEST_URI;
}
};
DeferredFileBody body = mock(DeferredFileBody.class);
when(body.getSize()).thenReturn(TEST_SIZE);
MimeBodyPart part = new MimeBodyPart();
part.setBody(body);
part.setHeader(MimeHeader.HEADER_CONTENT_TYPE, TEST_MIME_TYPE);
AttachmentViewInfo attachmentViewInfo = attachmentInfoExtractor.extractAttachmentInfo(part);
assertEquals(TEST_URI, attachmentViewInfo.internalUri);
assertEquals(TEST_SIZE, attachmentViewInfo.size);
assertEquals(TEST_MIME_TYPE, attachmentViewInfo.mimeType);
assertFalse(attachmentViewInfo.inlineAttachment);
assertTrue(attachmentViewInfo.isContentAvailable);
}
Aggregations