use of com.fsck.k9.mailstore.AttachmentViewInfo in project k-9 by k9mail.
the class MessageViewInfoExtractor method extractMessageForView.
@WorkerThread
public MessageViewInfo extractMessageForView(Message message, @Nullable MessageCryptoAnnotations annotations) throws MessagingException {
Part rootPart;
CryptoResultAnnotation cryptoResultAnnotation;
List<Part> extraParts;
CryptoMessageParts cryptoMessageParts = MessageCryptoSplitter.split(message, annotations);
if (cryptoMessageParts != null) {
rootPart = cryptoMessageParts.contentPart;
cryptoResultAnnotation = cryptoMessageParts.contentCryptoAnnotation;
extraParts = cryptoMessageParts.extraParts;
} else {
if (annotations != null && !annotations.isEmpty()) {
Timber.e("Got message annotations but no crypto root part!");
}
rootPart = message;
cryptoResultAnnotation = null;
extraParts = null;
}
List<AttachmentViewInfo> attachmentInfos = new ArrayList<>();
ViewableExtractedText viewable = extractViewableAndAttachments(Collections.singletonList(rootPart), attachmentInfos);
List<AttachmentViewInfo> extraAttachmentInfos = new ArrayList<>();
String extraViewableText = null;
if (extraParts != null) {
ViewableExtractedText extraViewable = extractViewableAndAttachments(extraParts, extraAttachmentInfos);
extraViewableText = extraViewable.text;
}
AttachmentResolver attachmentResolver = AttachmentResolver.createFromPart(rootPart);
boolean isMessageIncomplete = !message.isSet(Flag.X_DOWNLOADED_FULL) || MessageExtractor.hasMissingParts(message);
return MessageViewInfo.createWithExtractedContent(message, isMessageIncomplete, rootPart, viewable.html, attachmentInfos, cryptoResultAnnotation, attachmentResolver, extraViewableText, extraAttachmentInfos);
}
use of com.fsck.k9.mailstore.AttachmentViewInfo in project k-9 by k9mail.
the class AttachmentPresenter method addInternalAttachment.
private void addInternalAttachment(AttachmentViewInfo attachmentViewInfo) {
if (attachments.containsKey(attachmentViewInfo.internalUri)) {
throw new IllegalStateException("Received the same attachmentViewInfo twice!");
}
int loaderId = getNextFreeLoaderId();
Attachment attachment = Attachment.createAttachment(attachmentViewInfo.internalUri, loaderId, attachmentViewInfo.mimeType, true, true);
attachment = attachment.deriveWithMetadataLoaded(attachmentViewInfo.mimeType, attachmentViewInfo.displayName, attachmentViewInfo.size);
addAttachmentAndStartLoader(attachment);
}
use of com.fsck.k9.mailstore.AttachmentViewInfo in project k-9 by k9mail.
the class AttachmentPresenter method addInlineAttachment.
private void addInlineAttachment(AttachmentViewInfo attachmentViewInfo) {
if (inlineAttachments.containsKey(attachmentViewInfo.internalUri)) {
throw new IllegalStateException("Received the same attachmentViewInfo twice!");
}
int loaderId = getNextFreeLoaderId();
Attachment attachment = Attachment.createAttachment(attachmentViewInfo.internalUri, loaderId, attachmentViewInfo.mimeType, true, true);
attachment = attachment.deriveWithMetadataLoaded(attachmentViewInfo.mimeType, attachmentViewInfo.displayName, attachmentViewInfo.size);
inlineAttachments.put(attachment.uri, new InlineAttachment(attachmentViewInfo.part.getContentId(), attachment));
Bundle bundle = new Bundle();
bundle.putParcelable(LOADER_ARG_ATTACHMENT, attachment.uri);
loaderManager.initLoader(attachment.loaderId, bundle, mInlineAttachmentContentLoaderCallback);
}
use of com.fsck.k9.mailstore.AttachmentViewInfo in project k-9 by k9mail.
the class AttachmentInfoExtractor method extractAttachmentInfoForView.
@WorkerThread
public List<AttachmentViewInfo> extractAttachmentInfoForView(List<Part> attachmentParts) throws MessagingException {
List<AttachmentViewInfo> attachments = new ArrayList<>();
for (Part part : attachmentParts) {
AttachmentViewInfo attachmentViewInfo = extractAttachmentInfo(part);
attachments.add(attachmentViewInfo);
}
return attachments;
}
use of com.fsck.k9.mailstore.AttachmentViewInfo in project k-9 by k9mail.
the class LocalFolder method leafPartToContentValues.
private File leafPartToContentValues(ContentValues cv, Part part, Body body) throws MessagingException, IOException {
AttachmentViewInfo attachment = attachmentInfoExtractor.extractAttachmentInfoForDatabase(part);
cv.put("display_name", attachment.displayName);
String encoding = getTransferEncoding(part);
if (!(body instanceof SizeAware)) {
throw new IllegalStateException("Body needs to implement SizeAware");
}
SizeAware sizeAwareBody = (SizeAware) body;
long fileSize = sizeAwareBody.getSize();
File file = null;
int dataLocation;
if (fileSize > MAX_BODY_SIZE_FOR_DATABASE) {
dataLocation = DataLocation.ON_DISK;
file = writeBodyToDiskIfNecessary(part);
long size = decodeAndCountBytes(file, encoding, fileSize);
cv.put("decoded_body_size", size);
} else {
dataLocation = DataLocation.IN_DATABASE;
byte[] bodyData = getBodyBytes(body);
cv.put("data", bodyData);
long size = decodeAndCountBytes(bodyData, encoding, bodyData.length);
cv.put("decoded_body_size", size);
}
cv.put("data_location", dataLocation);
cv.put("encoding", encoding);
cv.put("content_id", part.getContentId());
return file;
}
Aggregations