Search in sources :

Example 71 with MessageReference

use of com.fsck.k9.controller.MessageReference in project k-9 by k9mail.

the class LocalFolder method getMessagesByReference.

public List<LocalMessage> getMessagesByReference(@NonNull List<MessageReference> messageReferences) throws MessagingException {
    open();
    String accountUuid = getAccountUuid();
    long folderId = getDatabaseId();
    List<LocalMessage> messages = new ArrayList<>();
    for (MessageReference messageReference : messageReferences) {
        if (!accountUuid.equals(messageReference.getAccountUuid())) {
            throw new IllegalArgumentException("all message references must belong to this Account!");
        }
        if (folderId != messageReference.getFolderId()) {
            throw new IllegalArgumentException("all message references must belong to this LocalFolder!");
        }
        LocalMessage message = getMessage(messageReference.getUid());
        if (message != null) {
            messages.add(message);
        }
    }
    return messages;
}
Also used : ArrayList(java.util.ArrayList) MessageReference(com.fsck.k9.controller.MessageReference)

Example 72 with MessageReference

use of com.fsck.k9.controller.MessageReference in project k-9 by k9mail.

the class MessageProvider method delete.

@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
    Timber.v("MessageProvider/delete: %s", uri);
    // Note: can only delete a message
    List<String> segments = uri.getPathSegments();
    int accountId = Integer.parseInt(segments.get(1));
    long folderId = Long.parseLong(segments.get(2));
    String msgUid = segments.get(3);
    // get account
    Account myAccount = null;
    for (Account account : Preferences.getPreferences(getContext()).getAccounts()) {
        if (account.getAccountNumber() == accountId) {
            myAccount = account;
        }
    }
    if (myAccount == null) {
        Timber.e("Could not find account with id %d", accountId);
    }
    if (myAccount != null) {
        MessageReference messageReference = new MessageReference(myAccount.getUuid(), folderId, msgUid);
        MessagingController controller = MessagingController.getInstance(getContext());
        controller.deleteMessage(messageReference);
    }
    // FIXME return the actual number of deleted messages
    return 0;
}
Also used : SearchAccount(com.fsck.k9.search.SearchAccount) Account(com.fsck.k9.Account) MessagingController(com.fsck.k9.controller.MessagingController) MessageReference(com.fsck.k9.controller.MessageReference)

Example 73 with MessageReference

use of com.fsck.k9.controller.MessageReference in project k-9 by k9mail.

the class RawMessageProvider method query.

@Override
public Cursor query(@NonNull Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    String[] columnNames = (projection == null) ? DEFAULT_PROJECTION : projection;
    List<String> segments = uri.getPathSegments();
    String messageReferenceString = segments.get(0);
    MessageReference messageReference = MessageReference.parse(messageReferenceString);
    LocalMessage message = loadMessage(messageReference);
    if (message == null) {
        return null;
    }
    MatrixCursor ret = new MatrixCursor(columnNames);
    Object[] values = new Object[columnNames.length];
    for (int i = 0, count = columnNames.length; i < count; i++) {
        String column = columnNames[i];
        if (OpenableColumns.DISPLAY_NAME.equals(column)) {
            values[i] = buildAttachmentFileName(message);
        } else if (OpenableColumns.SIZE.equals(column)) {
            values[i] = computeMessageSize(message);
        }
    }
    ret.addRow(values);
    return ret;
}
Also used : LocalMessage(com.fsck.k9.mailstore.LocalMessage) MessageReference(com.fsck.k9.controller.MessageReference) MatrixCursor(android.database.MatrixCursor)

Example 74 with MessageReference

use of com.fsck.k9.controller.MessageReference in project k-9 by k9mail.

the class MessageCompose method processDraftMessage.

private void processDraftMessage(MessageViewInfo messageViewInfo) {
    Message message = messageViewInfo.message;
    draftMessageId = messagingController.getId(message);
    subjectView.setText(messageViewInfo.subject);
    replyToPresenter.initFromDraftMessage(message);
    recipientPresenter.initFromDraftMessage(message);
    // Read In-Reply-To header from draft
    final String[] inReplyTo = message.getHeader("In-Reply-To");
    if (inReplyTo.length >= 1) {
        repliedToMessageId = inReplyTo[0];
    }
    // Read References header from draft
    final String[] references = message.getHeader("References");
    if (references.length >= 1) {
        referencedMessageIds = references[0];
    }
    if (!relatedMessageProcessed) {
        attachmentPresenter.loadAllAvailableAttachments(messageViewInfo);
    }
    // Decode the identity header when loading a draft.
    // See buildIdentityHeader(TextBody) for a detailed description of the composition of this blob.
    Map<IdentityField, String> k9identity = new HashMap<>();
    String[] identityHeaders = message.getHeader(K9.IDENTITY_HEADER);
    if (identityHeaders.length == 0) {
        identityHeaders = messageViewInfo.rootPart.getHeader(K9.IDENTITY_HEADER);
    }
    if (identityHeaders.length > 0 && identityHeaders[0] != null) {
        k9identity = IdentityHeaderParser.parse(identityHeaders[0]);
    }
    Identity newIdentity = new Identity();
    if (k9identity.containsKey(IdentityField.SIGNATURE)) {
        newIdentity = newIdentity.withSignatureUse(true).withSignature(k9identity.get(IdentityField.SIGNATURE));
        signatureChanged = true;
    } else {
        if (message instanceof LocalMessage) {
            newIdentity = newIdentity.withSignatureUse(((LocalMessage) message).getFolder().getSignatureUse());
        }
        newIdentity = newIdentity.withSignature(identity.getSignature());
    }
    if (k9identity.containsKey(IdentityField.NAME)) {
        newIdentity = newIdentity.withName(k9identity.get(IdentityField.NAME));
        identityChanged = true;
    } else {
        newIdentity = newIdentity.withName(identity.getName());
    }
    if (k9identity.containsKey(IdentityField.EMAIL)) {
        newIdentity = newIdentity.withEmail(k9identity.get(IdentityField.EMAIL));
        identityChanged = true;
    } else {
        newIdentity = newIdentity.withEmail(identity.getEmail());
    }
    if (k9identity.containsKey(IdentityField.ORIGINAL_MESSAGE)) {
        relatedMessageReference = null;
        String originalMessage = k9identity.get(IdentityField.ORIGINAL_MESSAGE);
        MessageReference messageReference = MessageReference.parse(originalMessage);
        if (messageReference != null) {
            // Check if this is a valid account in our database
            Account account = preferences.getAccount(messageReference.getAccountUuid());
            if (account != null) {
                relatedMessageReference = messageReference;
            }
        }
    }
    identity = newIdentity;
    updateSignature();
    updateFrom();
    replyToPresenter.setIdentity(identity);
    quotedMessagePresenter.processDraftMessage(messageViewInfo, k9identity);
}
Also used : LocalMessage(com.fsck.k9.mailstore.LocalMessage) Account(com.fsck.k9.Account) LocalMessage(com.fsck.k9.mailstore.LocalMessage) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) HashMap(java.util.HashMap) Identity(com.fsck.k9.Identity) MessageReference(com.fsck.k9.controller.MessageReference) IdentityField(com.fsck.k9.message.IdentityField)

Example 75 with MessageReference

use of com.fsck.k9.controller.MessageReference in project k-9 by k9mail.

the class MessageLoaderHelper method startOrResumeLocalMessageLoader.

// load from database
private void startOrResumeLocalMessageLoader() {
    LocalMessageLoader loader = (LocalMessageLoader) loaderManager.<LocalMessage>getLoader(LOCAL_MESSAGE_LOADER_ID);
    boolean isLoaderStale = (loader == null) || !loader.isCreatedFor(messageReference);
    if (isLoaderStale) {
        Timber.d("Creating new local message loader");
        cancelAndClearCryptoOperation();
        cancelAndClearDecodeLoader();
        loaderManager.restartLoader(LOCAL_MESSAGE_LOADER_ID, null, localMessageLoaderCallback);
    } else {
        Timber.d("Reusing local message loader");
        loaderManager.initLoader(LOCAL_MESSAGE_LOADER_ID, null, localMessageLoaderCallback);
    }
}
Also used : LocalMessageLoader(com.fsck.k9.ui.message.LocalMessageLoader)

Aggregations

MessageReference (com.fsck.k9.activity.MessageReference)49 PendingIntent (android.app.PendingIntent)25 Account (com.fsck.k9.Account)22 Test (org.junit.Test)14 LocalMessage (com.fsck.k9.mailstore.LocalMessage)13 MessageReference (com.fsck.k9.controller.MessageReference)12 NotificationCompat (android.support.v4.app.NotificationCompat)9 ArrayList (java.util.ArrayList)9 Notification (android.app.Notification)8 List (java.util.List)7 MessagingException (com.fsck.k9.mail.MessagingException)6 LocalFolder (com.fsck.k9.mailstore.LocalFolder)5 SearchAccount (com.fsck.k9.search.SearchAccount)5 HashMap (java.util.HashMap)5 Cursor (android.database.Cursor)3 Message (com.fsck.k9.mail.Message)3 LinkedList (java.util.LinkedList)3 Map (java.util.Map)3 Intent (android.content.Intent)2 Uri (android.net.Uri)2