From 994f474aaefdeb14d8b14b7967aa995cbde928e3 Mon Sep 17 00:00:00 2001 From: ashley willis Date: Mon, 14 Nov 2011 20:12:08 -0600 Subject: [PATCH] configured so setting message format to auto does not break k-9 if it is downgraded. --- src/com/fsck/k9/Account.java | 19 ++++++++++++++++++- src/com/fsck/k9/activity/MessageCompose.java | 1 - .../fsck/k9/preferences/AccountSettings.java | 1 + 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/com/fsck/k9/Account.java b/src/com/fsck/k9/Account.java index fc324a2b8..f2722500c 100644 --- a/src/com/fsck/k9/Account.java +++ b/src/com/fsck/k9/Account.java @@ -60,6 +60,7 @@ public class Account implements BaseAccount { private static final String[] networkTypes = { TYPE_WIFI, TYPE_MOBILE, TYPE_OTHER }; public static final MessageFormat DEFAULT_MESSAGE_FORMAT = MessageFormat.HTML; + public static final boolean DEFAULT_AUTO_MESSAGE_FORMAT = false; public static final boolean DEFAULT_MESSAGE_READ_RECEIPT = false; public static final QuoteStyle DEFAULT_QUOTE_STYLE = QuoteStyle.PREFIX; public static final String DEFAULT_QUOTE_PREFIX = ">"; @@ -137,6 +138,7 @@ public class Account implements BaseAccount { // current set of fetched messages private boolean mRingNotified; private MessageFormat mMessageFormat; + private boolean mAutoMessageFormat; private boolean mMessageReadReceipt; private QuoteStyle mQuoteStyle; private String mQuotePrefix; @@ -226,6 +228,7 @@ public class Account implements BaseAccount { maximumPolledMessageAge = -1; maximumAutoDownloadMessageSize = 32768; mMessageFormat = DEFAULT_MESSAGE_FORMAT; + mAutoMessageFormat = DEFAULT_AUTO_MESSAGE_FORMAT; mMessageReadReceipt = DEFAULT_MESSAGE_READ_RECEIPT; mQuoteStyle = DEFAULT_QUOTE_STYLE; mQuotePrefix = DEFAULT_QUOTE_PREFIX; @@ -302,6 +305,10 @@ public class Account implements BaseAccount { maximumPolledMessageAge = prefs.getInt(mUuid + ".maximumPolledMessageAge", -1); maximumAutoDownloadMessageSize = prefs.getInt(mUuid + ".maximumAutoDownloadMessageSize", 32768); mMessageFormat = MessageFormat.valueOf(prefs.getString(mUuid + ".messageFormat", DEFAULT_MESSAGE_FORMAT.name())); + mAutoMessageFormat = prefs.getBoolean(mUuid + ".autoMessageFormat", DEFAULT_AUTO_MESSAGE_FORMAT); + if (mAutoMessageFormat && mMessageFormat == MessageFormat.TEXT) { + mMessageFormat = MessageFormat.AUTO; + } mMessageReadReceipt = prefs.getBoolean(mUuid + ".messageReadReceipt", DEFAULT_MESSAGE_READ_RECEIPT); mQuoteStyle = QuoteStyle.valueOf(prefs.getString(mUuid + ".quoteStyle", DEFAULT_QUOTE_STYLE.name())); mQuotePrefix = prefs.getString(mUuid + ".quotePrefix", DEFAULT_QUOTE_PREFIX); @@ -461,6 +468,7 @@ public class Account implements BaseAccount { editor.remove(mUuid + ".subscribedFoldersOnly"); editor.remove(mUuid + ".maximumPolledMessageAge"); editor.remove(mUuid + ".maximumAutoDownloadMessageSize"); + editor.remove(mUuid + ".autoMessageFormat"); editor.remove(mUuid + ".quoteStyle"); editor.remove(mUuid + ".quotePrefix"); editor.remove(mUuid + ".showPicturesEnum"); @@ -612,7 +620,16 @@ public class Account implements BaseAccount { editor.putBoolean(mUuid + ".subscribedFoldersOnly", subscribedFoldersOnly); editor.putInt(mUuid + ".maximumPolledMessageAge", maximumPolledMessageAge); editor.putInt(mUuid + ".maximumAutoDownloadMessageSize", maximumAutoDownloadMessageSize); - editor.putString(mUuid + ".messageFormat", mMessageFormat.name()); + if (MessageFormat.AUTO.equals(mMessageFormat)) { + // saving MessageFormat.AUTO as is to the database will cause downgrades to crash on + // startup, so we save as MessageFormat.TEXT instead with a separate flag for auto. + editor.putString(mUuid + ".messageFormat", Account.MessageFormat.TEXT.name()); + mAutoMessageFormat = true; + } else { + editor.putString(mUuid + ".messageFormat", mMessageFormat.name()); + mAutoMessageFormat = false; + } + editor.putBoolean(mUuid + ".autoMessageFormat", mAutoMessageFormat); editor.putBoolean(mUuid + ".messageReadReceipt", mMessageReadReceipt); editor.putString(mUuid + ".quoteStyle", mQuoteStyle.name()); editor.putString(mUuid + ".quotePrefix", mQuotePrefix); diff --git a/src/com/fsck/k9/activity/MessageCompose.java b/src/com/fsck/k9/activity/MessageCompose.java index c25279a4d..4b2036d5a 100644 --- a/src/com/fsck/k9/activity/MessageCompose.java +++ b/src/com/fsck/k9/activity/MessageCompose.java @@ -858,7 +858,6 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc mBccWrapper.setVisibility(savedInstanceState .getBoolean(STATE_KEY_BCC_SHOWN) ? View.VISIBLE : View.GONE); showOrHideQuotedText((QuotedTextMode)savedInstanceState.getSerializable(STATE_KEY_QUOTED_TEXT_MODE)); - if (mQuotedTextMode != QuotedTextMode.NONE && mMessageFormat == MessageFormat.HTML) { mQuotedHtmlContent = (InsertableHtmlContent) savedInstanceState.getSerializable(STATE_KEY_HTML_QUOTE); if (mQuotedHtmlContent != null && mQuotedHtmlContent.getQuotedContent() != null) { diff --git a/src/com/fsck/k9/preferences/AccountSettings.java b/src/com/fsck/k9/preferences/AccountSettings.java index 13c4d089a..0b4b0bda2 100644 --- a/src/com/fsck/k9/preferences/AccountSettings.java +++ b/src/com/fsck/k9/preferences/AccountSettings.java @@ -55,6 +55,7 @@ public class AccountSettings { R.array.account_settings_message_age_values)); s.put("messageFormat", new EnumSetting(Account.MessageFormat.class, Account.DEFAULT_MESSAGE_FORMAT)); + //s.put("autoMessageFormat", new BooleanSetting(Account.DEFAULT_AUTO_MESSAGE_FORMAT)); // added to version 2 s.put("messageReadReceipt", new BooleanSetting(Account.DEFAULT_MESSAGE_READ_RECEIPT)); s.put("notificationUnreadCount", new BooleanSetting(true)); s.put("notifyMailCheck", new BooleanSetting(false));