use of com.fsck.k9.mailstore.LocalMessage in project k-9 by k9mail.
the class LocalStore method writeRawBodyToStream.
private void writeRawBodyToStream(Cursor cursor, SQLiteDatabase db, OutputStream outputStream) throws IOException, MessagingException {
long partId = cursor.getLong(ATTACH_PART_ID_INDEX);
String rootPart = cursor.getString(ATTACH_ROOT_INDEX);
LocalMessage message = loadLocalMessageByRootPartId(db, rootPart);
if (message == null) {
throw new MessagingException("Unable to find message for attachment!");
}
Part part = findPartById(message, partId);
if (part == null) {
throw new MessagingException("Unable to find attachment part in associated message (db integrity error?)");
}
Body body = part.getBody();
if (body == null) {
throw new MessagingException("Attachment part isn't available!");
}
body.writeTo(outputStream);
}
use of com.fsck.k9.mailstore.LocalMessage 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.LocalMessage in project k-9 by k9mail.
the class LocalStore method loadLocalMessageByMessageId.
@Nullable
private LocalMessage loadLocalMessageByMessageId(long messageId) throws MessagingException {
Map<String, List<String>> foldersAndUids = getFoldersAndUids(Collections.singletonList(messageId), false);
if (foldersAndUids.isEmpty()) {
return null;
}
Map.Entry<String, List<String>> entry = foldersAndUids.entrySet().iterator().next();
String folderName = entry.getKey();
String uid = entry.getValue().get(0);
LocalFolder folder = getFolder(folderName);
LocalMessage localMessage = folder.getMessage(uid);
FetchProfile fp = new FetchProfile();
fp.add(Item.BODY);
folder.fetch(Collections.singletonList(localMessage), fp, null);
return localMessage;
}
use of com.fsck.k9.mailstore.LocalMessage 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.LocalMessage in project k-9 by k9mail.
the class NotificationContentCreator method createFromMessage.
public NotificationContent createFromMessage(Account account, LocalMessage message) {
MessageReference messageReference = message.makeMessageReference();
String sender = getMessageSender(account, message);
String displaySender = getMessageSenderForDisplay(sender);
String subject = getMessageSubject(message);
CharSequence preview = getMessagePreview(message);
CharSequence summary = buildMessageSummary(sender, subject);
boolean starred = message.isSet(Flag.FLAGGED);
return new NotificationContent(messageReference, displaySender, subject, preview, summary, starred);
}
Aggregations