save plaintext subject for encrypted drafts

This commit is contained in:
Vincent Breitmoser 2018-04-27 20:18:32 +02:00
parent d0e588fb9f
commit 7040f855a5
5 changed files with 25 additions and 13 deletions

View file

@ -1443,14 +1443,16 @@ public class MessagingController {
*/
public void sendMessage(final Account account,
final Message message,
String plaintextSubject,
MessagingListener listener) {
try {
LocalStore localStore = account.getLocalStore();
LocalFolder localFolder = localStore.getFolder(account.getOutboxFolder());
localFolder.open(Folder.OPEN_MODE_RW);
localFolder.appendMessages(Collections.singletonList(message));
Message localMessage = localFolder.getMessage(message.getUid());
LocalMessage localMessage = localFolder.getMessage(message.getUid());
localMessage.setFlag(Flag.X_DOWNLOADED_FULL, true);
localMessage.setCachedDecryptedSubject(plaintextSubject);
localFolder.close();
sendPendingMessages(account, listener);
} catch (Exception e) {
@ -2760,8 +2762,8 @@ public class MessagingController {
*
* @return Message representing the entry in the local store.
*/
public Message saveDraft(final Account account, final Message message, long existingDraftId, boolean saveRemotely) {
Message localMessage = null;
public Message saveDraft(final Account account, final Message message, long existingDraftId, String plaintextSubject, boolean saveRemotely) {
LocalMessage localMessage = null;
try {
LocalStore localStore = account.getLocalStore();
LocalFolder localFolder = localStore.getFolder(account.getDraftsFolder());
@ -2777,6 +2779,9 @@ public class MessagingController {
// Fetch the message back from the store. This is the Message that's returned to the caller.
localMessage = localFolder.getMessage(message.getUid());
localMessage.setFlag(Flag.X_DOWNLOADED_FULL, true);
if (plaintextSubject != null) {
localMessage.setCachedDecryptedSubject(plaintextSubject);
}
if (saveRemotely) {
PendingCommand command = PendingAppend.create(localFolder.getServerId(), localMessage.getUid());

View file

@ -329,6 +329,10 @@ public abstract class MessageBuilder {
return this;
}
public String getSubject() {
return subject;
}
public MessageBuilder setSentDate(Date sentDate) {
this.sentDate = sentDate;
return this;

View file

@ -409,10 +409,6 @@ public class PgpMessageBuilder extends MessageBuilder {
}
private void mimeBuildEncryptedMessage(@NonNull Body encryptedBodyPart) throws MessagingException {
if (!cryptoStatus.isEncryptionEnabled()) {
throw new IllegalStateException("call to mimeBuildEncryptedMessage while encryption isn't enabled!");
}
MimeMultipart multipartEncrypted = createMimeMultipart();
multipartEncrypted.setSubType("encrypted");
multipartEncrypted.addBodyPart(new MimeBodyPart(new TextBody("Version: 1"), "application/pgp-encrypted"));

View file

@ -1391,15 +1391,17 @@ public class MessageCompose extends K9Activity implements OnClickListener,
final Contacts contacts;
final Message message;
final Long draftId;
final String plaintextSubject;
final MessageReference messageReference;
SendMessageTask(Context context, Account account, Contacts contacts, Message message,
Long draftId, MessageReference messageReference) {
Long draftId, String plaintextSubject, MessageReference messageReference) {
this.context = context;
this.account = account;
this.contacts = contacts;
this.message = message;
this.draftId = draftId;
this.plaintextSubject = plaintextSubject;
this.messageReference = messageReference;
}
@ -1414,7 +1416,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
Timber.e(e, "Failed to mark contact as contacted.");
}
MessagingController.getInstance(context).sendMessage(account, message, null);
MessagingController.getInstance(context).sendMessage(account, message, plaintextSubject, null);
if (draftId != null) {
// TODO set draft id to invalid in MessageCompose!
MessagingController.getInstance(context).deleteDraft(account, draftId);
@ -1506,6 +1508,9 @@ public class MessageCompose extends K9Activity implements OnClickListener,
@Override
public void onMessageBuildSuccess(MimeMessage message, boolean isDraft) {
String plaintextSubject =
(currentMessageBuilder instanceof PgpMessageBuilder) ? currentMessageBuilder.getSubject() : null;
if (isDraft) {
changesMadeSinceLastSave = false;
currentMessageBuilder = null;
@ -1515,7 +1520,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
}
new SaveMessageTask(getApplicationContext(), account, contacts, internalMessageHandler,
message, draftId, true).execute();
message, draftId, plaintextSubject, true).execute();
if (finishAfterDraftSaved) {
finish();
} else {
@ -1524,7 +1529,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
} else {
currentMessageBuilder = null;
new SendMessageTask(getApplicationContext(), account, contacts, message,
draftId != INVALID_DRAFT_ID ? draftId : null, relatedMessageReference).execute();
draftId != INVALID_DRAFT_ID ? draftId : null, plaintextSubject, relatedMessageReference).execute();
finish();
}
}

View file

@ -17,23 +17,25 @@ public class SaveMessageTask extends AsyncTask<Void, Void, Void> {
Handler handler;
Message message;
long draftId;
String plaintextSubject;
boolean saveRemotely;
public SaveMessageTask(Context context, Account account, Contacts contacts,
Handler handler, Message message, long draftId, boolean saveRemotely) {
Handler handler, Message message, long draftId, String plaintextSubject, boolean saveRemotely) {
this.context = context;
this.account = account;
this.contacts = contacts;
this.handler = handler;
this.message = message;
this.draftId = draftId;
this.plaintextSubject = plaintextSubject;
this.saveRemotely = saveRemotely;
}
@Override
protected Void doInBackground(Void... params) {
final MessagingController messagingController = MessagingController.getInstance(context);
Message draftMessage = messagingController.saveDraft(account, message, draftId, saveRemotely);
Message draftMessage = messagingController.saveDraft(account, message, draftId, plaintextSubject, saveRemotely);
draftId = messagingController.getId(draftMessage);
android.os.Message msg = android.os.Message.obtain(handler, MessageCompose.MSG_SAVED_DRAFT, draftId);