1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-12-25 09:08:49 -05:00

Merge pull request #100 from ashleywillis/autoformat

Message Format: Automatic (plain text unless replying to an HTML message)
This commit is contained in:
Andrew Chen 2011-11-15 10:13:45 -08:00
commit ec17cd3c38
5 changed files with 41 additions and 3 deletions

View File

@ -677,11 +677,13 @@
<string-array name="account_settings_message_format_entries"> <string-array name="account_settings_message_format_entries">
<item>@string/account_settings_message_format_text</item> <item>@string/account_settings_message_format_text</item>
<item>@string/account_settings_message_format_html</item> <item>@string/account_settings_message_format_html</item>
<item>@string/account_settings_message_format_auto</item>
</string-array> </string-array>
<string-array name="account_settings_message_format_values"> <string-array name="account_settings_message_format_values">
<item>TEXT</item> <item>TEXT</item>
<item>HTML</item> <item>HTML</item>
<item>AUTO</item>
</string-array> </string-array>
</resources> </resources>

View File

@ -572,6 +572,7 @@ Welcome to K-9 Mail setup. K-9 is an open source mail client for Android origin
<string name="account_settings_message_format_label">Message Format</string> <string name="account_settings_message_format_label">Message Format</string>
<string name="account_settings_message_format_text">Plain Text (images and formatting will be removed)</string> <string name="account_settings_message_format_text">Plain Text (images and formatting will be removed)</string>
<string name="account_settings_message_format_html">HTML (images and formatting are preserved)</string> <string name="account_settings_message_format_html">HTML (images and formatting are preserved)</string>
<string name="account_settings_message_format_auto">Automatic (plain text unless replying to an HTML message)</string>
<string name="account_settings_message_read_receipt_label">Read receipt</string> <string name="account_settings_message_read_receipt_label">Read receipt</string>
<string name="account_settings_message_read_receipt_summary">Always request a read receipt</string> <string name="account_settings_message_read_receipt_summary">Always request a read receipt</string>

View File

@ -60,6 +60,7 @@ public class Account implements BaseAccount {
private static final String[] networkTypes = { TYPE_WIFI, TYPE_MOBILE, TYPE_OTHER }; private static final String[] networkTypes = { TYPE_WIFI, TYPE_MOBILE, TYPE_OTHER };
public static final MessageFormat DEFAULT_MESSAGE_FORMAT = MessageFormat.HTML; 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 boolean DEFAULT_MESSAGE_READ_RECEIPT = false;
public static final QuoteStyle DEFAULT_QUOTE_STYLE = QuoteStyle.PREFIX; public static final QuoteStyle DEFAULT_QUOTE_STYLE = QuoteStyle.PREFIX;
public static final String DEFAULT_QUOTE_PREFIX = ">"; public static final String DEFAULT_QUOTE_PREFIX = ">";
@ -138,6 +139,7 @@ public class Account implements BaseAccount {
// current set of fetched messages // current set of fetched messages
private boolean mRingNotified; private boolean mRingNotified;
private MessageFormat mMessageFormat; private MessageFormat mMessageFormat;
private boolean mMessageFormatAuto;
private boolean mMessageReadReceipt; private boolean mMessageReadReceipt;
private QuoteStyle mQuoteStyle; private QuoteStyle mQuoteStyle;
private String mQuotePrefix; private String mQuotePrefix;
@ -193,7 +195,7 @@ public class Account implements BaseAccount {
} }
public enum MessageFormat { public enum MessageFormat {
TEXT, HTML TEXT, HTML, AUTO
} }
protected Account(Context context) { protected Account(Context context) {
@ -228,6 +230,7 @@ public class Account implements BaseAccount {
maximumPolledMessageAge = -1; maximumPolledMessageAge = -1;
maximumAutoDownloadMessageSize = 32768; maximumAutoDownloadMessageSize = 32768;
mMessageFormat = DEFAULT_MESSAGE_FORMAT; mMessageFormat = DEFAULT_MESSAGE_FORMAT;
mMessageFormatAuto = DEFAULT_MESSAGE_FORMAT_AUTO;
mMessageReadReceipt = DEFAULT_MESSAGE_READ_RECEIPT; mMessageReadReceipt = DEFAULT_MESSAGE_READ_RECEIPT;
mQuoteStyle = DEFAULT_QUOTE_STYLE; mQuoteStyle = DEFAULT_QUOTE_STYLE;
mQuotePrefix = DEFAULT_QUOTE_PREFIX; mQuotePrefix = DEFAULT_QUOTE_PREFIX;
@ -305,6 +308,10 @@ public class Account implements BaseAccount {
maximumPolledMessageAge = prefs.getInt(mUuid + ".maximumPolledMessageAge", -1); maximumPolledMessageAge = prefs.getInt(mUuid + ".maximumPolledMessageAge", -1);
maximumAutoDownloadMessageSize = prefs.getInt(mUuid + ".maximumAutoDownloadMessageSize", 32768); maximumAutoDownloadMessageSize = prefs.getInt(mUuid + ".maximumAutoDownloadMessageSize", 32768);
mMessageFormat = MessageFormat.valueOf(prefs.getString(mUuid + ".messageFormat", DEFAULT_MESSAGE_FORMAT.name())); 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); mMessageReadReceipt = prefs.getBoolean(mUuid + ".messageReadReceipt", DEFAULT_MESSAGE_READ_RECEIPT);
mQuoteStyle = QuoteStyle.valueOf(prefs.getString(mUuid + ".quoteStyle", DEFAULT_QUOTE_STYLE.name())); mQuoteStyle = QuoteStyle.valueOf(prefs.getString(mUuid + ".quoteStyle", DEFAULT_QUOTE_STYLE.name()));
mQuotePrefix = prefs.getString(mUuid + ".quotePrefix", DEFAULT_QUOTE_PREFIX); mQuotePrefix = prefs.getString(mUuid + ".quotePrefix", DEFAULT_QUOTE_PREFIX);
@ -465,6 +472,7 @@ public class Account implements BaseAccount {
editor.remove(mUuid + ".subscribedFoldersOnly"); editor.remove(mUuid + ".subscribedFoldersOnly");
editor.remove(mUuid + ".maximumPolledMessageAge"); editor.remove(mUuid + ".maximumPolledMessageAge");
editor.remove(mUuid + ".maximumAutoDownloadMessageSize"); editor.remove(mUuid + ".maximumAutoDownloadMessageSize");
editor.remove(mUuid + ".messageFormatAuto");
editor.remove(mUuid + ".quoteStyle"); editor.remove(mUuid + ".quoteStyle");
editor.remove(mUuid + ".quotePrefix"); editor.remove(mUuid + ".quotePrefix");
editor.remove(mUuid + ".showPicturesEnum"); editor.remove(mUuid + ".showPicturesEnum");
@ -617,7 +625,16 @@ public class Account implements BaseAccount {
editor.putBoolean(mUuid + ".subscribedFoldersOnly", subscribedFoldersOnly); editor.putBoolean(mUuid + ".subscribedFoldersOnly", subscribedFoldersOnly);
editor.putInt(mUuid + ".maximumPolledMessageAge", maximumPolledMessageAge); editor.putInt(mUuid + ".maximumPolledMessageAge", maximumPolledMessageAge);
editor.putInt(mUuid + ".maximumAutoDownloadMessageSize", maximumAutoDownloadMessageSize); editor.putInt(mUuid + ".maximumAutoDownloadMessageSize", maximumAutoDownloadMessageSize);
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()); editor.putString(mUuid + ".messageFormat", mMessageFormat.name());
mMessageFormatAuto = false;
}
editor.putBoolean(mUuid + ".messageFormatAuto", mMessageFormatAuto);
editor.putBoolean(mUuid + ".messageReadReceipt", mMessageReadReceipt); editor.putBoolean(mUuid + ".messageReadReceipt", mMessageReadReceipt);
editor.putString(mUuid + ".quoteStyle", mQuoteStyle.name()); editor.putString(mUuid + ".quoteStyle", mQuoteStyle.name());
editor.putString(mUuid + ".quotePrefix", mQuotePrefix); editor.putString(mUuid + ".quotePrefix", mQuotePrefix);

View File

@ -81,6 +81,7 @@ import com.fsck.k9.mail.store.LocalStore.LocalAttachmentBody;
public class MessageCompose extends K9Activity implements OnClickListener, OnFocusChangeListener { public class MessageCompose extends K9Activity implements OnClickListener, OnFocusChangeListener {
private static final int DIALOG_SAVE_OR_DISCARD_DRAFT_MESSAGE = 1; 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 = "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_REPLY_ALL = "com.fsck.k9.intent.action.REPLY_ALL";
private static final String ACTION_FORWARD = "com.fsck.k9.intent.action.FORWARD"; 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); Intent i = new Intent(context, MessageCompose.class);
i.putExtra(EXTRA_ACCOUNT, account.getUuid()); i.putExtra(EXTRA_ACCOUNT, account.getUuid());
i.setAction(ACTION_COMPOSE);
context.startActivity(i); context.startActivity(i);
} }
@ -540,6 +542,16 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
} }
mMessageFormat = mAccount.getMessageFormat(); 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(); mReadReceipt = mAccount.isMessageReadReceiptAlways();
mQuoteStyle = mAccount.getQuoteStyle(); mQuoteStyle = mAccount.getQuoteStyle();
@ -854,7 +866,6 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
mBccWrapper.setVisibility(savedInstanceState mBccWrapper.setVisibility(savedInstanceState
.getBoolean(STATE_KEY_BCC_SHOWN) ? View.VISIBLE : View.GONE); .getBoolean(STATE_KEY_BCC_SHOWN) ? View.VISIBLE : View.GONE);
showOrHideQuotedText((QuotedTextMode)savedInstanceState.getSerializable(STATE_KEY_QUOTED_TEXT_MODE)); showOrHideQuotedText((QuotedTextMode)savedInstanceState.getSerializable(STATE_KEY_QUOTED_TEXT_MODE));
if (mQuotedTextMode != QuotedTextMode.NONE && mMessageFormat == MessageFormat.HTML) { if (mQuotedTextMode != QuotedTextMode.NONE && mMessageFormat == MessageFormat.HTML) {
mQuotedHtmlContent = (InsertableHtmlContent) savedInstanceState.getSerializable(STATE_KEY_HTML_QUOTE); mQuotedHtmlContent = (InsertableHtmlContent) savedInstanceState.getSerializable(STATE_KEY_HTML_QUOTE);
if (mQuotedHtmlContent != null && mQuotedHtmlContent.getQuotedContent() != null) { if (mQuotedHtmlContent != null && mQuotedHtmlContent.getQuotedContent() != null) {
@ -2378,6 +2389,12 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
* @throws MessagingException * @throws MessagingException
*/ */
private void populateUIWithQuotedMessage(boolean shown) 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? // TODO -- I am assuming that mSourceMessageBody will always be a text part. Is this a safe assumption?
// Handle the original message in the reply // Handle the original message in the reply

View File

@ -55,6 +55,7 @@ public class AccountSettings {
R.array.account_settings_message_age_values)); R.array.account_settings_message_age_values));
s.put("messageFormat", s.put("messageFormat",
new EnumSetting(Account.MessageFormat.class, Account.DEFAULT_MESSAGE_FORMAT)); 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("messageReadReceipt", new BooleanSetting(Account.DEFAULT_MESSAGE_READ_RECEIPT));
s.put("notificationUnreadCount", new BooleanSetting(true)); s.put("notificationUnreadCount", new BooleanSetting(true));
s.put("notifyMailCheck", new BooleanSetting(false)); s.put("notifyMailCheck", new BooleanSetting(false));