use of com.fsck.k9.mailstore.LocalPart in project k-9 by k9mail.
the class AttachmentController method downloadAttachment.
private void downloadAttachment(LocalPart localPart, final Runnable attachmentDownloadedCallback) {
String accountUuid = localPart.getAccountUuid();
Account account = Preferences.getPreferences(context).getAccount(accountUuid);
LocalMessage message = localPart.getMessage();
messageViewFragment.showAttachmentLoadingDialog();
controller.loadAttachment(account, message, attachment.part, new SimpleMessagingListener() {
@Override
public void loadAttachmentFinished(Account account, Message message, Part part) {
messageViewFragment.hideAttachmentLoadingDialogOnMainThread();
messageViewFragment.runOnMainThread(attachmentDownloadedCallback);
}
@Override
public void loadAttachmentFailed(Account account, Message message, Part part, String reason) {
messageViewFragment.hideAttachmentLoadingDialogOnMainThread();
}
});
}
use of com.fsck.k9.mailstore.LocalPart in project k-9 by k9mail.
the class LocalStore method findPartById.
static Part findPartById(Part searchRoot, long partId) {
if (searchRoot instanceof LocalMessage) {
LocalMessage localMessage = (LocalMessage) searchRoot;
if (localMessage.getMessagePartId() == partId) {
return localMessage;
}
}
Stack<Part> partStack = new Stack<>();
partStack.add(searchRoot);
while (!partStack.empty()) {
Part part = partStack.pop();
if (part instanceof LocalPart) {
LocalPart localBodyPart = (LocalPart) part;
if (localBodyPart.getId() == partId) {
return part;
}
}
Body body = part.getBody();
if (body instanceof Multipart) {
Multipart innerMultipart = (Multipart) body;
for (BodyPart innerPart : innerMultipart.getBodyParts()) {
partStack.add(innerPart);
}
}
if (body instanceof Part) {
partStack.add((Part) body);
}
}
return null;
}
use of com.fsck.k9.mailstore.LocalPart 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);
}
Aggregations