use of com.fsck.k9.mailstore.LocalMessage in project k-9 by k9mail.
the class MessagingController method loadSearchResultsSynchronous.
private void loadSearchResultsSynchronous(List<Message> messages, LocalFolder localFolder, Folder remoteFolder, MessagingListener listener) throws MessagingException {
final FetchProfile header = new FetchProfile();
header.add(FetchProfile.Item.FLAGS);
header.add(FetchProfile.Item.ENVELOPE);
final FetchProfile structure = new FetchProfile();
structure.add(FetchProfile.Item.STRUCTURE);
int i = 0;
for (Message message : messages) {
i++;
LocalMessage localMsg = localFolder.getMessage(message.getUid());
if (localMsg == null) {
remoteFolder.fetch(Collections.singletonList(message), header, null);
//fun fact: ImapFolder.fetch can't handle getting STRUCTURE at same time as headers
remoteFolder.fetch(Collections.singletonList(message), structure, null);
localFolder.appendMessages(Collections.singletonList(message));
localMsg = localFolder.getMessage(message.getUid());
}
}
}
use of com.fsck.k9.mailstore.LocalMessage in project k-9 by k9mail.
the class MessagingController method downloadSmallMessages.
private <T extends Message> void downloadSmallMessages(final Account account, final Folder<T> remoteFolder, final LocalFolder localFolder, List<T> smallMessages, final AtomicInteger progress, final int unreadBeforeStart, final AtomicInteger newMessages, final int todo, FetchProfile fp) throws MessagingException {
final String folder = remoteFolder.getName();
final Date earliestDate = account.getEarliestPollDate();
Timber.d("SYNC: Fetching %d small messages for folder %s", smallMessages.size(), folder);
remoteFolder.fetch(smallMessages, fp, new MessageRetrievalListener<T>() {
@Override
public void messageFinished(final T message, int number, int ofTotal) {
try {
if (!shouldImportMessage(account, message, earliestDate)) {
progress.incrementAndGet();
return;
}
// Store the updated message locally
final LocalMessage localMessage = localFolder.storeSmallMessage(message, new Runnable() {
@Override
public void run() {
progress.incrementAndGet();
}
});
// not marked as read.
if (!localMessage.isSet(Flag.SEEN)) {
newMessages.incrementAndGet();
}
Timber.v("About to notify listeners that we got a new small message %s:%s:%s", account, folder, message.getUid());
// Update the listener with what we've found
for (MessagingListener l : getListeners()) {
l.synchronizeMailboxProgress(account, folder, progress.get(), todo);
if (!localMessage.isSet(Flag.SEEN)) {
l.synchronizeMailboxNewMessage(account, folder, localMessage);
}
}
if (shouldNotifyForMessage(account, localFolder, message)) {
// Notify with the localMessage so that we don't have to recalculate the content preview.
notificationController.addNewMailNotification(account, localMessage, unreadBeforeStart);
}
} catch (MessagingException me) {
addErrorMessage(account, null, me);
Timber.e(me, "SYNC: fetch small messages");
}
}
@Override
public void messageStarted(String uid, int number, int ofTotal) {
}
@Override
public void messagesFinished(int total) {
}
});
Timber.d("SYNC: Done fetching small messages for folder %s", folder);
}
use of com.fsck.k9.mailstore.LocalMessage in project k-9 by k9mail.
the class MessagingController method suppressMessages.
private void suppressMessages(Account account, List<LocalMessage> messages) {
EmailProviderCache cache = EmailProviderCache.getCache(account.getUuid(), context);
cache.hideMessages(messages);
}
use of com.fsck.k9.mailstore.LocalMessage in project k-9 by k9mail.
the class MessagingController method collectMessagesInThreads.
private static List<Message> collectMessagesInThreads(Account account, List<? extends Message> messages) throws MessagingException {
LocalStore localStore = account.getLocalStore();
List<Message> messagesInThreads = new ArrayList<>();
for (Message message : messages) {
LocalMessage localMessage = (LocalMessage) message;
long rootId = localMessage.getRootId();
long threadId = (rootId == -1) ? localMessage.getThreadId() : rootId;
List<? extends Message> messagesInThread = localStore.getMessagesInThread(threadId);
messagesInThreads.addAll(messagesInThread);
}
return messagesInThreads;
}
use of com.fsck.k9.mailstore.LocalMessage in project k-9 by k9mail.
the class MessageCompose method processDraftMessage.
private void processDraftMessage(MessageViewInfo messageViewInfo) {
Message message = messageViewInfo.message;
draftId = MessagingController.getInstance(getApplication()).getId(message);
subjectView.setText(message.getSubject());
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.loadNonInlineAttachments(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[0] != null) {
k9identity = IdentityHeaderParser.parse(identityHeaders[0]);
}
Identity newIdentity = new Identity();
if (k9identity.containsKey(IdentityField.SIGNATURE)) {
newIdentity.setSignatureUse(true);
newIdentity.setSignature(k9identity.get(IdentityField.SIGNATURE));
signatureChanged = true;
} else {
if (message instanceof LocalMessage) {
newIdentity.setSignatureUse(((LocalMessage) message).getFolder().getSignatureUse());
}
newIdentity.setSignature(identity.getSignature());
}
if (k9identity.containsKey(IdentityField.NAME)) {
newIdentity.setName(k9identity.get(IdentityField.NAME));
identityChanged = true;
} else {
newIdentity.setName(identity.getName());
}
if (k9identity.containsKey(IdentityField.EMAIL)) {
newIdentity.setEmail(k9identity.get(IdentityField.EMAIL));
identityChanged = true;
} else {
newIdentity.setEmail(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
Preferences prefs = Preferences.getPreferences(getApplicationContext());
Account account = prefs.getAccount(messageReference.getAccountUuid());
if (account != null) {
relatedMessageReference = messageReference;
}
}
}
identity = newIdentity;
updateSignature();
updateFrom();
quotedMessagePresenter.processDraftMessage(messageViewInfo, k9identity);
}
Aggregations