From 33e74567c570bcbb4ba19b7317b7299e0697a9a1 Mon Sep 17 00:00:00 2001 From: M Madison Phillips Date: Tue, 14 Aug 2018 20:55:00 -0500 Subject: [PATCH] Don't crash when MessageCompose is started with no account configured --- .../k9/activity/compose/MessageActions.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/app/ui/src/main/java/com/fsck/k9/activity/compose/MessageActions.java b/app/ui/src/main/java/com/fsck/k9/activity/compose/MessageActions.java index f62093190..6c929d485 100644 --- a/app/ui/src/main/java/com/fsck/k9/activity/compose/MessageActions.java +++ b/app/ui/src/main/java/com/fsck/k9/activity/compose/MessageActions.java @@ -7,22 +7,29 @@ import android.os.Parcelable; import com.fsck.k9.Account; import com.fsck.k9.Preferences; import com.fsck.k9.activity.MessageCompose; +import com.fsck.k9.activity.setup.AccountSetupBasics; import com.fsck.k9.controller.MessageReference; public class MessageActions { /** * Compose a new message using the given account. If account is null the default account - * will be used. + * will be used. If there is no default account set, user will be sent to AccountSetupBasics + * activity. */ public static void actionCompose(Context context, Account account) { - String accountUuid = (account == null) ? - Preferences.getPreferences(context).getDefaultAccount().getUuid() : - account.getUuid(); + Account defaultAccount = Preferences.getPreferences(context).getDefaultAccount(); + if (account == null && defaultAccount == null) { + AccountSetupBasics.actionNewAccount(context); + } else { + String accountUuid = (account == null) ? + defaultAccount.getUuid() : + account.getUuid(); - Intent i = new Intent(context, MessageCompose.class); - i.putExtra(MessageCompose.EXTRA_ACCOUNT, accountUuid); - i.setAction(MessageCompose.ACTION_COMPOSE); - context.startActivity(i); + Intent i = new Intent(context, MessageCompose.class); + i.putExtra(MessageCompose.EXTRA_ACCOUNT, accountUuid); + i.setAction(MessageCompose.ACTION_COMPOSE); + context.startActivity(i); + } } /**