Commit d8e659de authored by Francisco Cunha's avatar Francisco Cunha Committed by Hussein

P4A-962 Trusted servers: fix messages only appearing on one device.

Previous implementation was discarding alreadyDecrypted message to be stored on LocalFolder, and therefore not shown on UI, this was causing that on multi device setups the messages only appear on the device which decrypted the original one.
parent 53429332
......@@ -1738,7 +1738,7 @@ public class MessagingController implements Sync.MessageToSendCallback, KeyImpor
|| account.ispEpPrivacyProtected() && (result.rating != Rating.pEpRatingUndefined
|| message.getFrom().length > 0 && message.getFrom()[0].getAddress() == null))
) {
MimeMessage decryptedMessage = result.msg;
MimeMessage decryptedMessage = alreadyDecrypted ? ((MimeMessage) message) : result.msg;
if (message.getFolder().getName().equals(account.getSentFolderName())
|| message.getFolder().getName().equals(account.getDraftsFolderName())) {
decryptedMessage.setHeader(MimeHeader.HEADER_PEP_RATING, PEpUtils.ratingToString(pEpProvider.getRating(message)));
......@@ -1748,14 +1748,14 @@ public class MessagingController implements Sync.MessageToSendCallback, KeyImpor
decryptedMessage.setUid(message.getUid()); // sync UID so we know our mail...
if (!alreadyDecrypted) { // Store the updated message locally
// Store the updated message locally
final LocalMessage localMessage = localFolder.storeSmallMessage(decryptedMessage, new Runnable() {
@Override
public void run() {
progress.incrementAndGet();
}
});
if (controller.shouldDownloadMessageInTrustedServer(result, decryptedMessage, account)) {
if (controller.shouldReuploadMessageInTrustedServer(result, decryptedMessage, account, alreadyDecrypted)) {
appendMessageCommand(account, localMessage, localFolder);
}
Timber.d("pep", "in download loop (nr=" + number + ") post pep");// Increment the number of "new messages" if the newly downloaded message is
......@@ -1780,7 +1780,6 @@ public class MessagingController implements Sync.MessageToSendCallback, KeyImpor
// Notify with the localMessage so that we don't have to recalculate the content preview.
notificationController.addNewMailNotification(account, localMessage, unreadBeforeStart);
}
}
}
} catch (MessagingException | RuntimeException me) {
Timber.e(me, "SYNC: fetch small messages");
......
......@@ -19,11 +19,15 @@ import timber.log.Timber;
class TrustedMessageController {
boolean shouldDownloadMessageInTrustedServer(PEpProvider.DecryptResult result, MimeMessage decryptedMessage, Account account) {
boolean shouldReuploadMessageInTrustedServer(PEpProvider.DecryptResult result,
MimeMessage decryptedMessage,
Account account,
boolean alreadyDecrypted) {
return account.ispEpPrivacyProtected()
&& !account.isUntrustedSever()
&& result.flags == -1
&& !decryptedMessage.isSet(Flag.X_PEP_NEVER_UNSECURE);
&& !decryptedMessage.isSet(Flag.X_PEP_NEVER_UNSECURE)
&& !alreadyDecrypted;
}
<T extends Message> boolean shouldAppendMessageInTrustedServer(T message, Account account) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment