diff --git a/res/values/arrays.xml b/res/values/arrays.xml index 7089a8471..d90e51f8f 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -677,11 +677,13 @@ @string/account_settings_message_format_text @string/account_settings_message_format_html + @string/account_settings_message_format_auto TEXT HTML + AUTO diff --git a/res/values/strings.xml b/res/values/strings.xml index 4f024ecae..1361e3aaf 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -572,6 +572,7 @@ Welcome to K-9 Mail setup. K-9 is an open source mail client for Android origin Message Format Plain Text (images and formatting will be removed) HTML (images and formatting are preserved) + Automatic (plain text unless replying to an HTML message) Read receipt Always request a read receipt diff --git a/src/com/fsck/k9/Account.java b/src/com/fsck/k9/Account.java index 5c54282e8..c3c0bbf99 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_MESSAGE_FORMAT_AUTO = 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 = ">"; @@ -138,6 +139,7 @@ public class Account implements BaseAccount { // current set of fetched messages private boolean mRingNotified; private MessageFormat mMessageFormat; + private boolean mMessageFormatAuto; private boolean mMessageReadReceipt; private QuoteStyle mQuoteStyle; private String mQuotePrefix; @@ -193,7 +195,7 @@ public class Account implements BaseAccount { } public enum MessageFormat { - TEXT, HTML + TEXT, HTML, AUTO } protected Account(Context context) { @@ -228,6 +230,7 @@ public class Account implements BaseAccount { maximumPolledMessageAge = -1; maximumAutoDownloadMessageSize = 32768; mMessageFormat = DEFAULT_MESSAGE_FORMAT; + mMessageFormatAuto = DEFAULT_MESSAGE_FORMAT_AUTO; mMessageReadReceipt = DEFAULT_MESSAGE_READ_RECEIPT; mQuoteStyle = DEFAULT_QUOTE_STYLE; mQuotePrefix = DEFAULT_QUOTE_PREFIX; @@ -305,6 +308,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())); + mMessageFormatAuto = prefs.getBoolean(mUuid + ".messageFormatAuto", DEFAULT_MESSAGE_FORMAT_AUTO); + if (mMessageFormatAuto && 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); @@ -465,6 +472,7 @@ public class Account implements BaseAccount { editor.remove(mUuid + ".subscribedFoldersOnly"); editor.remove(mUuid + ".maximumPolledMessageAge"); editor.remove(mUuid + ".maximumAutoDownloadMessageSize"); + editor.remove(mUuid + ".messageFormatAuto"); editor.remove(mUuid + ".quoteStyle"); editor.remove(mUuid + ".quotePrefix"); editor.remove(mUuid + ".showPicturesEnum"); @@ -617,7 +625,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()); + mMessageFormatAuto = true; + } else { + editor.putString(mUuid + ".messageFormat", mMessageFormat.name()); + mMessageFormatAuto = false; + } + editor.putBoolean(mUuid + ".messageFormatAuto", mMessageFormatAuto); 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 0160e8bee..c4ee2c4a1 100644 --- a/src/com/fsck/k9/activity/MessageCompose.java +++ b/src/com/fsck/k9/activity/MessageCompose.java @@ -81,6 +81,7 @@ import com.fsck.k9.mail.store.LocalStore.LocalAttachmentBody; public class MessageCompose extends K9Activity implements OnClickListener, OnFocusChangeListener { private static final int DIALOG_SAVE_OR_DISCARD_DRAFT_MESSAGE = 1; + private static final String ACTION_COMPOSE = "com.fsck.k9.intent.action.COMPOSE"; private static final String ACTION_REPLY = "com.fsck.k9.intent.action.REPLY"; private static final String ACTION_REPLY_ALL = "com.fsck.k9.intent.action.REPLY_ALL"; private static final String ACTION_FORWARD = "com.fsck.k9.intent.action.FORWARD"; @@ -287,6 +288,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc } Intent i = new Intent(context, MessageCompose.class); i.putExtra(EXTRA_ACCOUNT, account.getUuid()); + i.setAction(ACTION_COMPOSE); context.startActivity(i); } @@ -540,6 +542,16 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc } mMessageFormat = mAccount.getMessageFormat(); + if (mMessageFormat == MessageFormat.AUTO) { + if (ACTION_COMPOSE.equals(action)) { + mMessageFormat = MessageFormat.TEXT; + } else if (mSourceMessageBody != null) { + // mSourceMessageBody is set to something when replying to and forwarding decrypted + // messages, so we set the format to plain text. + mMessageFormat = MessageFormat.TEXT; + } + } + mReadReceipt = mAccount.isMessageReadReceiptAlways(); mQuoteStyle = mAccount.getQuoteStyle(); @@ -854,7 +866,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) { @@ -2378,6 +2389,12 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc * @throws MessagingException */ private void populateUIWithQuotedMessage(boolean shown) throws MessagingException { + if (mMessageFormat == MessageFormat.AUTO) { + mMessageFormat = MimeUtility.findFirstPartByMimeType(mSourceMessage, "text/html") == null + ? MessageFormat.TEXT + : MessageFormat.HTML; + } + // TODO -- I am assuming that mSourceMessageBody will always be a text part. Is this a safe assumption? // Handle the original message in the reply diff --git a/src/com/fsck/k9/preferences/AccountSettings.java b/src/com/fsck/k9/preferences/AccountSettings.java index 060833cc2..07e3a9164 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("messageFormatAuto", new BooleanSetting(Account.DEFAULT_MESSAGE_FORMAT_AUTO)); // 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));