1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-08-13 17:03:48 -04:00

Merge pull request #34 from jca02266/possible-to-toggle-quoted-text-display

Possible to toggle quoted text display
This commit is contained in:
Koji Arai 2011-05-24 08:33:53 -07:00
commit 90a5ca8ec2
6 changed files with 195 additions and 129 deletions

View File

@ -237,6 +237,17 @@
android:textColor="@android:color/primary_text_light"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="@+id/quoted_text_show"
android:text="@string/message_compose_show_quoted_text_action"
android:textSize="16dip"
android:padding="0dip"
android:layout_gravity="right"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true" />
<!-- Quoted text bar -->
<RelativeLayout
android:id="@+id/quoted_text_bar"

View File

@ -270,7 +270,7 @@ Welcome to K-9 Mail setup. K-9 is an open source mail client for Android origin
<string name="error_contact_address_not_found">No email address could be found.</string>
<string name="message_compose_downloading_attachments_toast">Some attachments were not downloaded. They will be downloaded automatically before this message is sent.</string>
<string name="message_compose_attachments_skipped_toast">Some attachments cannot be forwarded because they have not been downloaded.</string>
<string name="message_compose_show_quoted_text_action">Quote message</string>
<string name="message_view_from_format">From: <xliff:g id="name">%s</xliff:g> &lt;<xliff:g id="email">%s</xliff:g>&gt;</string>
@ -564,6 +564,9 @@ Welcome to K-9 Mail setup. K-9 is an open source mail client for Android origin
<string name="account_settings_composition">Sending mail</string>
<string name="account_settings_default_quoted_text_shown_label">Quote original message when replying</string>
<string name="account_settings_default_quoted_text_shown_summary">When replying to messages, the original message is in your reply.</string>
<string name="account_settings_reply_after_quote_label">Reply after quoted text</string>
<string name="account_settings_reply_after_quote_summary">When replying to messages, the original message will appear above your reply.</string>
@ -1049,4 +1052,5 @@ Welcome to K-9 Mail setup. K-9 is an open source mail client for Android origin
<string name="settings_attachment_default_path">Save attachments to...</string>
<string name="attachment_save_title">Save attachment</string>
<string name="attachment_save_desc">No file browser found. Where would you like to save this attachment?</string>
</resources>

View File

@ -239,6 +239,13 @@
android:entries="@array/account_settings_quote_style_entries"
android:entryValues="@array/account_settings_quote_style_values" />
<CheckBoxPreference
android:persistent="false"
android:key="default_quoted_text_shown"
android:title="@string/account_settings_default_quoted_text_shown_label"
android:defaultValue="true"
android:summary="@string/account_settings_default_quoted_text_shown_summary" />
<CheckBoxPreference
android:persistent="false"
android:key="reply_after_quote"

View File

@ -60,6 +60,7 @@ public class Account implements BaseAccount {
private static final MessageFormat DEFAULT_MESSAGE_FORMAT = MessageFormat.HTML;
private static final QuoteStyle DEFAULT_QUOTE_STYLE = QuoteStyle.PREFIX;
private static final String DEFAULT_QUOTE_PREFIX = ">";
private static final boolean DEFAULT_QUOTED_TEXT_SHOWN = true;
private static final boolean DEFAULT_REPLY_AFTER_QUOTE = false;
/**
@ -126,6 +127,7 @@ public class Account implements BaseAccount {
private MessageFormat mMessageFormat;
private QuoteStyle mQuoteStyle;
private String mQuotePrefix;
private boolean mDefaultQuotedTextShown;
private boolean mReplyAfterQuote;
private boolean mSyncRemoteDeletions;
private String mCryptoApp;
@ -203,6 +205,7 @@ public class Account implements BaseAccount {
mMessageFormat = DEFAULT_MESSAGE_FORMAT;
mQuoteStyle = DEFAULT_QUOTE_STYLE;
mQuotePrefix = DEFAULT_QUOTE_PREFIX;
mDefaultQuotedTextShown = DEFAULT_QUOTED_TEXT_SHOWN;
mReplyAfterQuote = DEFAULT_REPLY_AFTER_QUOTE;
mSyncRemoteDeletions = true;
mCryptoApp = Apg.NAME;
@ -276,6 +279,7 @@ public class Account implements BaseAccount {
mMessageFormat = MessageFormat.valueOf(prefs.getString(mUuid + ".messageFormat", DEFAULT_MESSAGE_FORMAT.name()));
mQuoteStyle = QuoteStyle.valueOf(prefs.getString(mUuid + ".quoteStyle", DEFAULT_QUOTE_STYLE.name()));
mQuotePrefix = prefs.getString(mUuid + ".quotePrefix", DEFAULT_QUOTE_PREFIX);
mDefaultQuotedTextShown = prefs.getBoolean(mUuid + ".defaultQuotedTextShown", DEFAULT_QUOTED_TEXT_SHOWN);
mReplyAfterQuote = prefs.getBoolean(mUuid + ".replyAfterQuote", DEFAULT_REPLY_AFTER_QUOTE);
for (String type : networkTypes) {
Boolean useCompression = prefs.getBoolean(mUuid + ".useCompression." + type,
@ -527,6 +531,7 @@ public class Account implements BaseAccount {
editor.putString(mUuid + ".messageFormat", mMessageFormat.name());
editor.putString(mUuid + ".quoteStyle", mQuoteStyle.name());
editor.putString(mUuid + ".quotePrefix", mQuotePrefix);
editor.putBoolean(mUuid + ".defaultQuotedTextShown", mDefaultQuotedTextShown);
editor.putBoolean(mUuid + ".replyAfterQuote", mReplyAfterQuote);
editor.putString(mUuid + ".cryptoApp", mCryptoApp);
editor.putBoolean(mUuid + ".cryptoAutoSignature", mCryptoAutoSignature);
@ -1283,6 +1288,14 @@ public class Account implements BaseAccount {
mQuotePrefix = quotePrefix;
}
public synchronized boolean isDefaultQuotedTextShown() {
return mDefaultQuotedTextShown;
}
public synchronized void setDefaultQuotedTextShown(boolean shown) {
mDefaultQuotedTextShown = shown;
}
public synchronized boolean isReplyAfterQuote() {
return mReplyAfterQuote;
}

View File

@ -1,6 +1,6 @@
package com.fsck.k9.activity;
import java.io.File;
import java.io.Serializable;
import java.util.*;
@ -38,6 +38,7 @@ import android.view.View.OnFocusChangeListener;
import android.view.Window;
import android.webkit.WebView;
import android.widget.AutoCompleteTextView.Validator;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageButton;
@ -89,8 +90,8 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
"com.fsck.k9.activity.MessageCompose.ccShown";
private static final String STATE_KEY_BCC_SHOWN =
"com.fsck.k9.activity.MessageCompose.bccShown";
private static final String STATE_KEY_QUOTED_TEXT_SHOWN =
"com.fsck.k9.activity.MessageCompose.quotedTextShown";
private static final String STATE_KEY_QUOTED_TEXT_MODE =
"com.fsck.k9.activity.MessageCompose.QuotedTextShown";
private static final String STATE_KEY_SOURCE_MESSAGE_PROCED =
"com.fsck.k9.activity.MessageCompose.stateKeySourceMessageProced";
private static final String STATE_KEY_DRAFT_UID =
@ -161,6 +162,13 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
*/
private boolean mSourceMessageProcessed = false;
private enum QuotedTextMode {
NONE,
SHOW,
HIDE
};
private QuotedTextMode mQuotedTextMode = QuotedTextMode.NONE;
private TextView mFromView;
private LinearLayout mCcWrapper;
@ -172,6 +180,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
private EditText mSignatureView;
private EditText mMessageContentView;
private LinearLayout mAttachments;
private Button mQuotedTextShow;
private View mQuotedTextBar;
private ImageButton mQuotedTextEdit;
private ImageButton mQuotedTextDelete;
@ -391,6 +400,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
mMessageContentView = (EditText)findViewById(R.id.message_content);
mMessageContentView.getInputExtras(true).putBoolean("allowEmoji", true);
mAttachments = (LinearLayout)findViewById(R.id.attachments);
mQuotedTextShow = (Button)findViewById(R.id.quoted_text_show);
mQuotedTextBar = findViewById(R.id.quoted_text_bar);
mQuotedTextEdit = (ImageButton)findViewById(R.id.quoted_text_edit);
mQuotedTextDelete = (ImageButton)findViewById(R.id.quoted_text_delete);
@ -467,11 +477,10 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
* We set this to invisible by default. Other methods will turn it back on if it's
* needed.
*/
mQuotedTextBar.setVisibility(View.GONE);
mQuotedText.setVisibility(View.GONE);
mQuotedHTML.setVisibility(View.GONE);
mQuotedTextEdit.setVisibility(View.GONE);
showOrHideQuotedText(QuotedTextMode.NONE);
mQuotedTextShow.setOnClickListener(this);
mQuotedTextEdit.setOnClickListener(this);
mQuotedTextDelete.setOnClickListener(this);
@ -801,7 +810,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
outState.putParcelableArrayList(STATE_KEY_ATTACHMENTS, attachments);
outState.putBoolean(STATE_KEY_CC_SHOWN, mCcView.getVisibility() == View.VISIBLE);
outState.putBoolean(STATE_KEY_BCC_SHOWN, mBccView.getVisibility() == View.VISIBLE);
outState.putBoolean(STATE_KEY_QUOTED_TEXT_SHOWN, mQuotedTextBar.getVisibility() == View.VISIBLE);
outState.putSerializable(STATE_KEY_QUOTED_TEXT_MODE, mQuotedTextMode);
outState.putBoolean(STATE_KEY_SOURCE_MESSAGE_PROCED, mSourceMessageProcessed);
outState.putString(STATE_KEY_DRAFT_UID, mDraftUid);
outState.putSerializable(STATE_IDENTITY, mIdentity);
@ -829,17 +838,13 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
: View.GONE);
mBccWrapper.setVisibility(savedInstanceState
.getBoolean(STATE_KEY_BCC_SHOWN) ? View.VISIBLE : View.GONE);
if (mMessageFormat == MessageFormat.HTML) {
showOrHideQuotedText((QuotedTextMode)savedInstanceState.getSerializable(STATE_KEY_QUOTED_TEXT_MODE));
if (mQuotedTextMode != QuotedTextMode.NONE && mMessageFormat == MessageFormat.HTML) {
mQuotedHtmlContent = (InsertableHtmlContent) savedInstanceState.getSerializable(STATE_KEY_HTML_QUOTE);
mQuotedTextBar.setVisibility(savedInstanceState.getBoolean(STATE_KEY_QUOTED_TEXT_SHOWN) ? View.VISIBLE : View.GONE);
mQuotedHTML.setVisibility(savedInstanceState.getBoolean(STATE_KEY_QUOTED_TEXT_SHOWN) ? View.VISIBLE : View.GONE);
if (mQuotedHtmlContent != null && mQuotedHtmlContent.getQuotedContent() != null) {
mQuotedHTML.loadDataWithBaseURL("http://", mQuotedHtmlContent.getQuotedContent(), "text/html", "utf-8", null);
mQuotedTextEdit.setVisibility(View.VISIBLE);
}
} else {
mQuotedTextBar.setVisibility(savedInstanceState.getBoolean(STATE_KEY_QUOTED_TEXT_SHOWN) ? View.VISIBLE : View.GONE);
mQuotedText.setVisibility(savedInstanceState.getBoolean(STATE_KEY_QUOTED_TEXT_SHOWN) ? View.VISIBLE : View.GONE);
}
mDraftUid = savedInstanceState.getString(STATE_KEY_DRAFT_UID);
mIdentity = (Identity)savedInstanceState.getSerializable(STATE_IDENTITY);
@ -904,10 +909,27 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
String text = mMessageContentView.getText().toString();
boolean discardQuotedText = false;
if (!isDraft && !mQuotedTextMode.equals(QuotedTextMode.SHOW)) {
discardQuotedText = true;
}
if (discardQuotedText) {
if (!isDraft) {
text = appendSignature(text);
}
// Build the body.
TextBody body = new TextBody(text);
body.setComposedMessageLength(text.length());
body.setComposedMessageOffset(0);
return body;
}
// Handle HTML separate from the rest of the text content. HTML mode doesn't allow signature after the quoted
// text, nor does it allow reply after quote. Users who want that functionality will need to stick with text
// mode.
if (mMessageFormat == MessageFormat.HTML) {
else if (mMessageFormat == MessageFormat.HTML) {
// Add the signature.
if (!isDraft) {
text = appendSignature(text);
@ -917,10 +939,6 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
if (K9.DEBUG && mQuotedHtmlContent != null)
Log.d(K9.LOG_TAG, "insertable: " + mQuotedHtmlContent.toDebugString());
if (mQuotedHtmlContent != null) {
// Remove the quoted part if it's no longer visible.
if (mQuotedTextBar.getVisibility() != View.VISIBLE) {
mQuotedHtmlContent.clearQuotedContent();
}
// Set the insertion location based upon our reply after quote setting. Reply after
// quote makes no sense for HEADER style replies. In addition, add some extra
@ -965,7 +983,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
text = appendSignature(text);
}
if (mQuotedTextBar.getVisibility() == View.VISIBLE) {
if (mQuotedTextMode != QuotedTextMode.NONE) {
if (replyAfterQuote) {
composedMessageOffset = mQuotedText.getText().toString().length() + "\n".length();
text = mQuotedText.getText().toString() + "\n" + text;
@ -1140,7 +1158,8 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
EMAIL("e"),
// TODO - store a reference to the message being replied so we can mark it at the time of send.
ORIGINAL_MESSAGE("m"),
CURSOR_POSITION("p"); // Where in the message your cursor was when you saved.
CURSOR_POSITION("p"), // Where in the message your cursor was when you saved.
QUOTED_TEXT_MODE("q");
private final String value;
@ -1205,6 +1224,8 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
uri.appendQueryParameter(IdentityField.CURSOR_POSITION.value(), Integer.toString(mMessageContentView.getSelectionStart()));
uri.appendQueryParameter(IdentityField.QUOTED_TEXT_MODE.value(), mQuotedTextMode.name());
String k9identity = IDENTITY_VERSION_1 + uri.build().getEncodedQuery();
if (K9.DEBUG) {
@ -1279,6 +1300,9 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
if (tokens.hasMoreTokens()) {
identity.put(IdentityField.EMAIL, Utility.base64Decode(tokens.nextToken()));
}
if (tokens.hasMoreTokens()) {
identity.put(IdentityField.QUOTED_TEXT_MODE, Utility.base64Decode(tokens.nextToken()));
}
}
return identity;
@ -1655,8 +1679,12 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
mAttachments.removeView((View) view.getTag());
mDraftNeedsSaving = true;
break;
case R.id.quoted_text_show:
showOrHideQuotedText(QuotedTextMode.SHOW);
mDraftNeedsSaving = true;
break;
case R.id.quoted_text_delete:
deleteQuotedText();
showOrHideQuotedText(QuotedTextMode.HIDE);
mDraftNeedsSaving = true;
break;
case R.id.quoted_text_edit:
@ -1673,15 +1701,40 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
}
}
/**
* Delete the quoted text.
/*
* Show or Hide the quoted text according to mQuotedTextMode.
*/
private void deleteQuotedText() {
mQuotedTextBar.setVisibility(View.GONE);
mQuotedText.setVisibility(View.GONE);
mQuotedHTML.setVisibility(View.GONE);
if (mQuotedHtmlContent != null) {
mQuotedHtmlContent.clearQuotedContent();
private void showOrHideQuotedText(QuotedTextMode mode) {
mQuotedTextMode = mode;
if (mQuotedTextMode == QuotedTextMode.NONE) {
mQuotedTextShow.setVisibility(View.GONE);
mQuotedTextBar.setVisibility(View.GONE);
mQuotedText.setVisibility(View.GONE);
mQuotedHTML.setVisibility(View.GONE);
mQuotedTextEdit.setVisibility(View.GONE);
}
else if (mQuotedTextMode == QuotedTextMode.SHOW) {
mQuotedTextShow.setVisibility(View.GONE);
mQuotedTextBar.setVisibility(View.VISIBLE);
if (mMessageFormat == MessageFormat.HTML){
mQuotedText.setVisibility(View.GONE);
mQuotedHTML.setVisibility(View.VISIBLE);
mQuotedTextEdit.setVisibility(View.VISIBLE);
}
else {
mQuotedText.setVisibility(View.VISIBLE);
mQuotedHTML.setVisibility(View.GONE);
mQuotedTextEdit.setVisibility(View.GONE);
}
}
else if (mQuotedTextMode == QuotedTextMode.HIDE) {
mQuotedTextShow.setVisibility(View.VISIBLE);
mQuotedTextBar.setVisibility(View.GONE);
mQuotedText.setVisibility(View.GONE);
mQuotedHTML.setVisibility(View.GONE);
mQuotedTextEdit.setVisibility(View.GONE);
}
}
@ -1911,7 +1964,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
}
// Quote the message and setup the UI.
populateUIWithQuotedMessage();
populateUIWithQuotedMessage(mAccount.isDefaultQuotedTextShown());
if (ACTION_REPLY_ALL.equals(action) || ACTION_REPLY.equals(action)) {
Identity useIdentity = null;
@ -1966,7 +2019,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
}
// Quote the message and setup the UI.
populateUIWithQuotedMessage();
populateUIWithQuotedMessage(true);
if (!mSourceMessageProcessed) {
if (!loadAttachments(message, 0)) {
@ -1974,6 +2027,8 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
}
}
} else if (ACTION_EDIT_DRAFT.equals(action)) {
String showQuotedTextMode = "NONE";
mDraftUid = message.getUid();
mSubjectView.setText(message.getSubject());
addAddresses(mToView, message.getRecipients(RecipientType.TO));
@ -2059,6 +2114,10 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
}
}
if (k9identity.containsKey(IdentityField.QUOTED_TEXT_MODE)) {
showQuotedTextMode = k9identity.get(IdentityField.QUOTED_TEXT_MODE);
}
mIdentity = newIdentity;
updateSignature();
@ -2073,95 +2132,62 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
// Always respect the user's current composition format preference, even if the
// draft was saved in a different format.
// TODO - The current implementation doesn't allow a user in HTML mode to edit a draft that wasn't saved with K9mail.
String messageFormat = k9identity.get(IdentityField.MESSAGE_FORMAT);
if (messageFormat == null) {
// This message probably wasn't created by us. The exception is legacy
// drafts created before the advent of HTML composition. In those cases,
// we'll display the whole message (including the quoted part) in the
// composition window. If that's the case, try and convert it to text to
// match the behavior in text mode.
mMessageContentView.setText(getBodyTextFromMessage(message, MessageFormat.TEXT));
mMessageFormat = MessageFormat.TEXT;
showOrHideQuotedText(QuotedTextMode.valueOf(showQuotedTextMode));
return;
}
mMessageFormat = MessageFormat.valueOf(messageFormat);
if (mMessageFormat == MessageFormat.HTML) {
if (k9identity.get(IdentityField.MESSAGE_FORMAT) == null || !MessageFormat.valueOf(k9identity.get(IdentityField.MESSAGE_FORMAT)).equals(MessageFormat.HTML)) {
// This message probably wasn't created by us. The exception is legacy
// drafts created before the advent of HTML composition. In those cases,
// we'll display the whole message (including the quoted part) in the
// composition window. If that's the case, try and convert it to text to
// match the behavior in text mode.
mMessageContentView.setText(getBodyTextFromMessage(message, MessageFormat.TEXT));
} else {
Part part = MimeUtility.findFirstPartByMimeType(message, "text/html");
if (part != null) { // Shouldn't happen if we were the one who saved it.
String text = MimeUtility.getTextFromPart(part);
if (K9.DEBUG) {
Log.d(K9.LOG_TAG, "Loading message with offset " + bodyOffset + ", length " + bodyLength + ". Text length is " + text.length() + ".");
}
Part part = MimeUtility.findFirstPartByMimeType(message, "text/html");
if (part != null) { // Shouldn't happen if we were the one who saved it.
String text = MimeUtility.getTextFromPart(part);
if (K9.DEBUG) {
Log.d(K9.LOG_TAG, "Loading message with offset " + bodyOffset + ", length " + bodyLength + ". Text length is " + text.length() + ".");
}
// Grab our reply text.
String bodyText = text.substring(bodyOffset, bodyOffset + bodyLength);
mMessageContentView.setText(HtmlConverter.htmlToText(bodyText));
// Grab our reply text.
String bodyText = text.substring(bodyOffset, bodyOffset + bodyLength);
mMessageContentView.setText(HtmlConverter.htmlToText(bodyText));
// Regenerate the quoted html without our user content in it.
StringBuilder quotedHTML = new StringBuilder();
quotedHTML.append(text.substring(0, bodyOffset)); // stuff before the reply
quotedHTML.append(text.substring(bodyOffset + bodyLength));
if (quotedHTML.length() > 0) {
mQuotedHtmlContent = new InsertableHtmlContent();
mQuotedHtmlContent.setQuotedContent(quotedHTML);
mQuotedHtmlContent.setHeaderInsertionPoint(bodyOffset);
mQuotedHTML.loadDataWithBaseURL("http://", mQuotedHtmlContent.getQuotedContent(), "text/html", "utf-8", null);
mQuotedHTML.setVisibility(View.VISIBLE);
mQuotedTextBar.setVisibility(View.VISIBLE);
mQuotedTextEdit.setVisibility(View.VISIBLE);
}
// Regenerate the quoted html without our user content in it.
StringBuilder quotedHTML = new StringBuilder();
quotedHTML.append(text.substring(0, bodyOffset)); // stuff before the reply
quotedHTML.append(text.substring(bodyOffset + bodyLength));
if (quotedHTML.length() > 0) {
mQuotedHtmlContent = new InsertableHtmlContent();
mQuotedHtmlContent.setQuotedContent(quotedHTML);
mQuotedHtmlContent.setHeaderInsertionPoint(bodyOffset);
mQuotedHTML.loadDataWithBaseURL("http://", mQuotedHtmlContent.getQuotedContent(), "text/html", "utf-8", null);
}
}
} else if (mMessageFormat == MessageFormat.TEXT) {
MessageFormat format = k9identity.get(IdentityField.MESSAGE_FORMAT) != null
? MessageFormat.valueOf(k9identity.get(IdentityField.MESSAGE_FORMAT))
: null;
if (format == null) {
mMessageContentView.setText(getBodyTextFromMessage(message, MessageFormat.TEXT));
} else if (format.equals(MessageFormat.HTML)) {
// We are in text mode, but have an HTML message.
Part htmlPart = MimeUtility.findFirstPartByMimeType(message, "text/html");
if (htmlPart != null) { // Shouldn't happen if we were the one who saved it.
String text = MimeUtility.getTextFromPart(htmlPart);
if (K9.DEBUG) {
Log.d(K9.LOG_TAG, "Loading message with offset " + bodyOffset + ", length " + bodyLength + ". Text length is " + text.length() + ".");
}
Part textPart = MimeUtility.findFirstPartByMimeType(message, "text/plain");
if (textPart != null) {
String text = MimeUtility.getTextFromPart(textPart);
// If we had a body length (and it was valid), separate the composition from the quoted text
// and put them in their respective places in the UI.
if (bodyLength != null && bodyLength + 1 < text.length()) { // + 1 to get rid of the newline we added when saving the draft
String bodyText = text.substring(0, bodyLength);
String quotedText = text.substring(bodyLength + 1, text.length());
// Grab our reply text.
String bodyText = text.substring(bodyOffset, bodyOffset + bodyLength);
mMessageContentView.setText(Html.fromHtml(bodyText).toString());
// Regenerate the quoted html without out content in it.
StringBuilder quotedHTML = new StringBuilder();
quotedHTML.append(text.substring(0, bodyOffset)); // stuff before the reply
quotedHTML.append(text.substring(bodyOffset + bodyLength));
// Convert it to text.
mQuotedText.setText(HtmlConverter.htmlToText(quotedHTML.toString()));
mQuotedTextBar.setVisibility(View.VISIBLE);
mQuotedText.setVisibility(View.VISIBLE);
mMessageContentView.setText(bodyText);
mQuotedText.setText(quotedText);
} else {
Log.e(K9.LOG_TAG, "Found an HTML draft but couldn't find the HTML part! Something's wrong.");
mMessageContentView.setText(text);
}
} else if (format.equals(MessageFormat.TEXT)) {
Part textPart = MimeUtility.findFirstPartByMimeType(message, "text/plain");
if (textPart != null) {
String text = MimeUtility.getTextFromPart(textPart);
// If we had a body length (and it was valid), separate the composition from the quoted text
// and put them in their respective places in the UI.
if (bodyLength != null && bodyLength + 1 < text.length()) { // + 1 to get rid of the newline we added when saving the draft
String bodyText = text.substring(0, bodyLength);
String quotedText = text.substring(bodyLength + 1, text.length());
mMessageContentView.setText(bodyText);
mQuotedText.setText(quotedText);
mQuotedTextBar.setVisibility(View.VISIBLE);
mQuotedText.setVisibility(View.VISIBLE);
mQuotedHTML.setVisibility(View.VISIBLE);
} else {
mMessageContentView.setText(text);
}
}
} else {
Log.e(K9.LOG_TAG, "Unhandled message format.");
}
} else {
Log.e(K9.LOG_TAG, "Unhandled message format.");
}
// Set the cursor position if we have it.
@ -2170,6 +2196,8 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
} catch(Exception e) {
Log.e(K9.LOG_TAG, "Could not set cursor position in MessageCompose; ignoring.", e);
}
showOrHideQuotedText(QuotedTextMode.valueOf(showQuotedTextMode));
}
} catch (MessagingException me) {
/**
@ -2178,15 +2206,17 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
*/
Log.e(K9.LOG_TAG, "Error while processing source message: ", me);
}
mSourceMessageProcessed = true;
mDraftNeedsSaving = false;
finally {
mSourceMessageProcessed = true;
mDraftNeedsSaving = false;
}
}
/**
* Build and populate the UI with the quoted message.
* @throws MessagingException
*/
private void populateUIWithQuotedMessage() throws MessagingException {
private void populateUIWithQuotedMessage(boolean shown) throws MessagingException {
// TODO -- I am assuming that mSourceMessageBody will always be a text part. Is this a safe assumption?
// Handle the original message in the reply
@ -2200,20 +2230,15 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
// Load the message with the reply header.
mQuotedHTML.loadDataWithBaseURL("http://", mQuotedHtmlContent.getQuotedContent(), "text/html", "utf-8", null);
mQuotedTextBar.setVisibility(View.VISIBLE);
mQuotedHTML.setVisibility(View.VISIBLE);
mQuotedTextEdit.setVisibility(View.VISIBLE);
mQuotedText.setVisibility(View.GONE);
} else if (mMessageFormat == MessageFormat.TEXT) {
mQuotedText.setText(quoteOriginalTextMessage(mSourceMessage, content, mAccount.getQuoteStyle()));
}
mQuotedTextBar.setVisibility(View.VISIBLE);
mQuotedText.setVisibility(View.VISIBLE);
mQuotedHtmlContent = null;
mQuotedTextEdit.setVisibility(View.GONE);
mQuotedHTML.setVisibility(View.GONE);
if (shown) {
showOrHideQuotedText(QuotedTextMode.SHOW);
}
else {
showOrHideQuotedText(QuotedTextMode.HIDE);
}
}
@ -2425,10 +2450,10 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
// part).
if (mSourceProcessed) {
try {
populateUIWithQuotedMessage();
populateUIWithQuotedMessage(true);
} catch (MessagingException e) {
// Hm, if we couldn't populate the UI after source reprocessing, let's just delete it?
deleteQuotedText();
showOrHideQuotedText(QuotedTextMode.HIDE);
Log.e(K9.LOG_TAG, "Could not re-process source message; deleting quoted text to be safe.", e);
}
} else {

View File

@ -88,6 +88,7 @@ public class AccountSettings extends K9PreferenceActivity {
private static final String PREFERENCE_MESSAGE_FORMAT = "message_format";
private static final String PREFERENCE_QUOTE_PREFIX = "account_quote_prefix";
private static final String PREFERENCE_QUOTE_STYLE = "quote_style";
private static final String PREFERENCE_DEFAULT_QUOTED_TEXT_SHOWN = "default_quoted_text_shown";
private static final String PREFERENCE_REPLY_AFTER_QUOTE = "reply_after_quote";
private static final String PREFERENCE_SYNC_REMOTE_DELETIONS = "account_sync_remote_deletetions";
private static final String PREFERENCE_CRYPTO_APP = "crypto_app";
@ -145,6 +146,7 @@ public class AccountSettings extends K9PreferenceActivity {
private ListPreference mMessageFormat;
private ListPreference mQuoteStyle;
private EditTextPreference mAccountQuotePrefix;
private CheckBoxPreference mAccountDefaultQuotedTextShown;
private CheckBoxPreference mReplyAfterQuote;
private CheckBoxPreference mSyncRemoteDeletions;
private CheckBoxPreference mSaveAllHeaders;
@ -226,6 +228,9 @@ public class AccountSettings extends K9PreferenceActivity {
}
});
mAccountDefaultQuotedTextShown = (CheckBoxPreference) findPreference(PREFERENCE_DEFAULT_QUOTED_TEXT_SHOWN);
mAccountDefaultQuotedTextShown.setChecked(mAccount.isDefaultQuotedTextShown());
mReplyAfterQuote = (CheckBoxPreference) findPreference(PREFERENCE_REPLY_AFTER_QUOTE);
mReplyAfterQuote.setChecked(mAccount.isReplyAfterQuote());
@ -695,6 +700,7 @@ public class AccountSettings extends K9PreferenceActivity {
mAccount.setMessageFormat(Account.MessageFormat.valueOf(mMessageFormat.getValue()));
mAccount.setQuoteStyle(QuoteStyle.valueOf(mQuoteStyle.getValue()));
mAccount.setQuotePrefix(mAccountQuotePrefix.getText());
mAccount.setDefaultQuotedTextShown(mAccountDefaultQuotedTextShown.isChecked());
mAccount.setReplyAfterQuote(mReplyAfterQuote.isChecked());
mAccount.setCryptoApp(mCryptoApp.getValue());
mAccount.setCryptoAutoSignature(mCryptoAutoSignature.isChecked());