Search in sources :

Example 41 with LocalMessage

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);
}
Also used : MessagingException(com.fsck.k9.mail.MessagingException) BodyPart(com.fsck.k9.mail.BodyPart) Part(com.fsck.k9.mail.Part) Body(com.fsck.k9.mail.Body)

Example 42 with LocalMessage

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;
}
Also used : BodyPart(com.fsck.k9.mail.BodyPart) Multipart(com.fsck.k9.mail.Multipart) BodyPart(com.fsck.k9.mail.BodyPart) Part(com.fsck.k9.mail.Part) Body(com.fsck.k9.mail.Body) Stack(java.util.Stack)

Example 43 with LocalMessage

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;
}
Also used : FetchProfile(com.fsck.k9.mail.FetchProfile) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Nullable(android.support.annotation.Nullable)

Example 44 with 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);
}
Also used : LocalMessage(com.fsck.k9.mailstore.LocalMessage) LocalPart(com.fsck.k9.mailstore.LocalPart) Uri(android.net.Uri) Body(com.fsck.k9.mail.Body) DeferredFileBody(com.fsck.k9.mailstore.DeferredFileBody) DeferredFileBody(com.fsck.k9.mailstore.DeferredFileBody) WorkerThread(android.support.annotation.WorkerThread)

Example 45 with LocalMessage

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);
}
Also used : MessageReference(com.fsck.k9.activity.MessageReference)

Aggregations

LocalMessage (com.fsck.k9.mailstore.LocalMessage)42 Test (org.junit.Test)23 FetchProfile (com.fsck.k9.mail.FetchProfile)19 Message (com.fsck.k9.mail.Message)19 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)19 MessagingException (com.fsck.k9.mail.MessagingException)15 LocalFolder (com.fsck.k9.mailstore.LocalFolder)13 LocalStore (com.fsck.k9.mailstore.LocalStore)12 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)10 ArrayList (java.util.ArrayList)9 Notification (android.app.Notification)8 Part (com.fsck.k9.mail.Part)8 MessageReference (com.fsck.k9.activity.MessageReference)7 Multipart (com.fsck.k9.mail.Multipart)7 Date (java.util.Date)7 HashMap (java.util.HashMap)7 SuppressLint (android.annotation.SuppressLint)6 UnavailableStorageException (com.fsck.k9.mailstore.UnavailableStorageException)6 IOException (java.io.IOException)6 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)5