From 5a8ddaa039ae325bb80f1cc3542f497bd2e5415d Mon Sep 17 00:00:00 2001 From: cketti Date: Thu, 26 Jan 2012 00:37:25 +0100 Subject: [PATCH] Make sure draft id points to a valid message before deleting it Avoids IllegalArgumentException in LocalStore.getMessage() --- src/com/fsck/k9/activity/MessageCompose.java | 5 +++-- src/com/fsck/k9/controller/MessagingController.java | 8 +++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/com/fsck/k9/activity/MessageCompose.java b/src/com/fsck/k9/activity/MessageCompose.java index 6da95c263..2eac71f19 100644 --- a/src/com/fsck/k9/activity/MessageCompose.java +++ b/src/com/fsck/k9/activity/MessageCompose.java @@ -2988,9 +2988,10 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc } MessagingController.getInstance(getApplication()).sendMessage(mAccount, message, null); - if (mDraftId != INVALID_DRAFT_ID) { - MessagingController.getInstance(getApplication()).deleteDraft(mAccount, mDraftId); + long draftId = mDraftId; + if (draftId != INVALID_DRAFT_ID) { mDraftId = INVALID_DRAFT_ID; + MessagingController.getInstance(getApplication()).deleteDraft(mAccount, draftId); } return null; diff --git a/src/com/fsck/k9/controller/MessagingController.java b/src/com/fsck/k9/controller/MessagingController.java index 2aaa48ae1..b3b6b5462 100644 --- a/src/com/fsck/k9/controller/MessagingController.java +++ b/src/com/fsck/k9/controller/MessagingController.java @@ -3311,9 +3311,11 @@ public class MessagingController implements Runnable { localFolder = localStore.getFolder(account.getDraftsFolderName()); localFolder.open(OpenMode.READ_WRITE); String uid = localFolder.getMessageUidById(id); - Message message = localFolder.getMessage(uid); - if (message != null) { - deleteMessages(new Message[] { message }, null); + if (uid != null) { + Message message = localFolder.getMessage(uid); + if (message != null) { + deleteMessages(new Message[] { message }, null); + } } } catch (MessagingException me) { addErrorMessage(account, null, me);