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;
}
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;
}
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;
}
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);
}
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);
}
}
Aggregations