From 9a99c77653cb29d4165aa24b42a44f5dae585443 Mon Sep 17 00:00:00 2001 From: Koji Arai Date: Tue, 29 Apr 2014 21:48:51 +0900 Subject: [PATCH 01/16] Add a gradle task testsOnJVM. --- build.gradle | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/build.gradle b/build.gradle index 02a139d31..2fae19a89 100644 --- a/build.gradle +++ b/build.gradle @@ -50,3 +50,8 @@ android { exclude 'META-INF/NOTICE' } } + +task testsOnJVM(type :GradleBuild, dependsOn: assemble) { + buildFile = 'tests-on-jvm/build.gradle' + tasks = ['test'] +} From 6155a65f65d20944bb1259cffc373b596c53a59e Mon Sep 17 00:00:00 2001 From: Koji Arai Date: Sun, 22 Sep 2013 12:50:01 +0900 Subject: [PATCH 02/16] Refactoring: extract a class TextBodyBuilder --- .../k9/activity/InsertableHtmlContent.java | 2 +- src/com/fsck/k9/activity/MessageCompose.java | 186 ++-------- .../k9/mail/internet/TextBodyBuilder.java | 261 ++++++++++++++ tests-on-jvm/src/com/fsck/k9/K9.java | 5 + .../k9/mail/internet/TextBodyBuilderTest.java | 335 ++++++++++++++++++ 5 files changed, 639 insertions(+), 150 deletions(-) create mode 100644 src/com/fsck/k9/mail/internet/TextBodyBuilder.java create mode 100644 tests-on-jvm/src/com/fsck/k9/K9.java create mode 100644 tests-on-jvm/src/com/fsck/k9/mail/internet/TextBodyBuilderTest.java diff --git a/src/com/fsck/k9/activity/InsertableHtmlContent.java b/src/com/fsck/k9/activity/InsertableHtmlContent.java index 851f0ca9a..9821ad784 100644 --- a/src/com/fsck/k9/activity/InsertableHtmlContent.java +++ b/src/com/fsck/k9/activity/InsertableHtmlContent.java @@ -12,7 +12,7 @@ import java.io.Serializable; * * TODO: This container should also have a text part, along with its insertion point. Or maybe a generic InsertableContent and maintain one each for Html and Text? */ -class InsertableHtmlContent implements Serializable { +public class InsertableHtmlContent implements Serializable { private static final long serialVersionUID = 2397327034L; // Default to a headerInsertionPoint at the beginning of the message. private int headerInsertionPoint = 0; diff --git a/src/com/fsck/k9/activity/MessageCompose.java b/src/com/fsck/k9/activity/MessageCompose.java index d792c4dcc..7db2e3bce 100644 --- a/src/com/fsck/k9/activity/MessageCompose.java +++ b/src/com/fsck/k9/activity/MessageCompose.java @@ -88,6 +88,7 @@ import com.fsck.k9.mail.Part; import com.fsck.k9.mail.internet.MimeBodyPart; import com.fsck.k9.mail.internet.MimeHeader; import com.fsck.k9.mail.internet.MimeMessage; +import com.fsck.k9.mail.internet.TextBodyBuilder; import com.fsck.k9.mail.internet.MimeMultipart; import com.fsck.k9.mail.internet.MimeUtility; import com.fsck.k9.mail.internet.TextBody; @@ -111,6 +112,7 @@ import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.text.DateFormat; + import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -1350,136 +1352,51 @@ public class MessageCompose extends K9Activity implements OnClickListener, * original message. */ private TextBody buildText(boolean isDraft, SimpleMessageFormat messageFormat) { - // The length of the formatted version of the user-supplied text/reply - int composedMessageLength; - - // The offset of the user-supplied text/reply in the final text body - int composedMessageOffset; + TextBodyBuilder textBodyBuilder = + new TextBodyBuilder( + mMessageContentView.getText().toString(), + mIdentity.getSignatureUse() ? mSignatureView.getCharacters() : null + ); /* * Find out if we need to include the original message as quoted text. * - * We include the quoted text in the body if the user didn't choose to hide it. We always - * include the quoted text when we're saving a draft. That's so the user is able to - * "un-hide" the quoted text if (s)he opens a saved draft. + * We include the quoted text in the body if the user didn't choose to + * hide it. We always include the quoted text when we're saving a draft. + * That's so the user is able to "un-hide" the quoted text if (s)he + * opens a saved draft. */ - boolean includeQuotedText = (mQuotedTextMode.equals(QuotedTextMode.SHOW) || isDraft); + if (isDraft || mQuotedTextMode == QuotedTextMode.SHOW) { + textBodyBuilder.setIncludeQuotedText(true); + } + else { + textBodyBuilder.setIncludeQuotedText(false); + } + if (!isDraft) { + textBodyBuilder.setAppendSignature(true); + } + else { + textBodyBuilder.setAppendSignature(false); + } + textBodyBuilder.setDraft(isDraft); + textBodyBuilder.setSignatureBeforeQuotedText(mAccount.isSignatureBeforeQuotedText()); - // Reply after quote makes no sense for HEADER style replies - boolean replyAfterQuote = (mQuoteStyle == QuoteStyle.HEADER) ? - false : mAccount.isReplyAfterQuote(); - - boolean signatureBeforeQuotedText = mAccount.isSignatureBeforeQuotedText(); - - // Get the user-supplied text - String text = mMessageContentView.getCharacters(); - - // Handle HTML separate from the rest of the text content - if (messageFormat == SimpleMessageFormat.HTML) { - - // Do we have to modify an existing message to include our reply? - if (includeQuotedText && mQuotedHtmlContent != null) { - if (K9.DEBUG) { - Log.d(K9.LOG_TAG, "insertable: " + mQuotedHtmlContent.toDebugString()); - } - - if (!isDraft) { - // Append signature to the reply - if (replyAfterQuote || signatureBeforeQuotedText) { - text = appendSignature(text); - } - } - - // Convert the text to HTML - text = HtmlConverter.textToHtmlFragment(text); - - /* - * Set the insertion location based upon our reply after quote setting. - * Additionally, add some extra separators between the composed message and quoted - * message depending on the quote location. We only add the extra separators when - * we're sending, that way when we load a draft, we don't have to know the length - * of the separators to remove them before editing. - */ - if (replyAfterQuote) { - mQuotedHtmlContent.setInsertionLocation( - InsertableHtmlContent.InsertionLocation.AFTER_QUOTE); - if (!isDraft) { - text = "
" + text; - } - } else { - mQuotedHtmlContent.setInsertionLocation( - InsertableHtmlContent.InsertionLocation.BEFORE_QUOTE); - if (!isDraft) { - text += "

"; - } - } - - if (!isDraft) { - // Place signature immediately after the quoted text - if (!(replyAfterQuote || signatureBeforeQuotedText)) { - mQuotedHtmlContent.insertIntoQuotedFooter(getSignatureHtml()); - } - } - - mQuotedHtmlContent.setUserContent(text); - - // Save length of the body and its offset. This is used when thawing drafts. - composedMessageLength = text.length(); - composedMessageOffset = mQuotedHtmlContent.getInsertionPoint(); - text = mQuotedHtmlContent.toString(); - - } else { - // There is no text to quote so simply append the signature if available - if (!isDraft) { - text = appendSignature(text); - } - - // Convert the text to HTML - text = HtmlConverter.textToHtmlFragment(text); - - //TODO: Wrap this in proper HTML tags - - composedMessageLength = text.length(); - composedMessageOffset = 0; - } - - } else { - // Capture composed message length before we start attaching quoted parts and signatures. - composedMessageLength = text.length(); - composedMessageOffset = 0; - - if (!isDraft) { - // Append signature to the text/reply - if (replyAfterQuote || signatureBeforeQuotedText) { - text = appendSignature(text); - } - } - - String quotedText = mQuotedText.getCharacters(); - if (includeQuotedText && quotedText.length() > 0) { - if (replyAfterQuote) { - composedMessageOffset = quotedText.length() + "\r\n".length(); - text = quotedText + "\r\n" + text; - } else { - text += "\r\n\r\n" + quotedText.toString(); - } - } - - if (!isDraft) { - // Place signature immediately after the quoted text - if (!(replyAfterQuote || signatureBeforeQuotedText)) { - text = appendSignature(text); - } - } + if (mQuoteStyle == QuoteStyle.PREFIX && mAccount.isReplyAfterQuote()) { + textBodyBuilder.setReplyAfterQuote(true); + } + else { + textBodyBuilder.setReplyAfterQuote(false); } - TextBody body = new TextBody(text); - body.setComposedMessageLength(composedMessageLength); - body.setComposedMessageOffset(composedMessageOffset); - + TextBody body; + if (messageFormat == SimpleMessageFormat.HTML) { + body = textBodyBuilder.buildTextHtml(mQuotedHtmlContent); + } + else { + body = textBodyBuilder.buildTextPlain(mQuotedText.getText().toString()); + } return body; } - /** * Build the final message to be sent (or saved). If there is another message quoted in this one, it will be baked * into the final message here. @@ -1827,35 +1744,6 @@ public class MessageCompose extends K9Activity implements OnClickListener, return identity; } - - private String appendSignature(String originalText) { - String text = originalText; - if (mIdentity.getSignatureUse()) { - String signature = mSignatureView.getCharacters(); - - if (signature != null && !signature.contentEquals("")) { - text += "\r\n" + signature; - } - } - - return text; - } - - /** - * Get an HTML version of the signature in the #mSignatureView, if any. - * @return HTML version of signature. - */ - private String getSignatureHtml() { - String signature = ""; - if (mIdentity.getSignatureUse()) { - signature = mSignatureView.getCharacters(); - if(!StringUtils.isNullOrEmpty(signature)) { - signature = HtmlConverter.textToHtmlFragment("\r\n" + signature); - } - } - return signature; - } - private void sendMessage() { new SendMessageTask().execute(); } diff --git a/src/com/fsck/k9/mail/internet/TextBodyBuilder.java b/src/com/fsck/k9/mail/internet/TextBodyBuilder.java new file mode 100644 index 000000000..7728e1951 --- /dev/null +++ b/src/com/fsck/k9/mail/internet/TextBodyBuilder.java @@ -0,0 +1,261 @@ +package com.fsck.k9.mail.internet; + +import android.util.Log; + +import com.fsck.k9.K9; +import com.fsck.k9.activity.InsertableHtmlContent; +import com.fsck.k9.helper.HtmlConverter; +import com.fsck.k9.helper.StringUtils; +import com.fsck.k9.mail.Body; + +public class TextBodyBuilder { + // option + private boolean mIncludeQuotedText = true; + private boolean mReplyAfterQuote = false; + private boolean mSignatureBeforeQuotedText = false; + private boolean mDraft = false; + private boolean mAppendSignature = true; + + // message parts + private String mMessageContent; + private String mSignature; + + public TextBodyBuilder( + String messageContent, + String signature + ) { + mMessageContent = messageContent; + mSignature = signature; + } + + /** + * Build the {@link Body} that will contain the text of the message. + * + *

+ * Draft messages are treated somewhat differently in that signatures are + * not appended and HTML separators between composed text and quoted text + * are not added. + *

+ * + * @return {@link TextBody} instance that contains the entered text and + * possibly the quoted original message. + */ + public TextBody buildTextHtml(InsertableHtmlContent quotedHtmlContent) { + // The length of the formatted version of the user-supplied text/reply + int composedMessageLength; + + // The offset of the user-supplied text/reply in the final text body + int composedMessageOffset; + + // Get the user-supplied text + String text = mMessageContent; + + // Do we have to modify an existing message to include our reply? + if (mIncludeQuotedText && quotedHtmlContent != null) { + if (K9.DEBUG) { + Log.d(K9.LOG_TAG, "insertable: " + quotedHtmlContent.toDebugString()); + } + + if (mAppendSignature) { + // Append signature to the reply + if (mReplyAfterQuote || mSignatureBeforeQuotedText) { + text += getSignature(); + } + } + + // Convert the text to HTML + text = textToHtmlFragment(text); + + /* + * Set the insertion location based upon our reply after quote + * setting. Additionally, add some extra separators between the + * composed message and quoted message depending on the quote + * location. We only add the extra separators when we're + * sending, that way when we load a draft, we don't have to know + * the length of the separators to remove them before editing. + */ + if (mReplyAfterQuote) { + quotedHtmlContent.setInsertionLocation( + InsertableHtmlContent.InsertionLocation.AFTER_QUOTE); + if (!mDraft) { + text = "
" + text; + } + } + else { + quotedHtmlContent.setInsertionLocation( + InsertableHtmlContent.InsertionLocation.BEFORE_QUOTE); + if (!mDraft) { + text += "

"; + } + } + + if (mAppendSignature) { + // Place signature immediately after the quoted text + if (!(mReplyAfterQuote || mSignatureBeforeQuotedText)) { + quotedHtmlContent.insertIntoQuotedFooter(getSignatureHtml()); + } + } + + quotedHtmlContent.setUserContent(text); + + // Save length of the body and its offset. This is used when thawing drafts. + composedMessageLength = text.length(); + composedMessageOffset = quotedHtmlContent.getInsertionPoint(); + text = quotedHtmlContent.toString(); + + } + else { + // There is no text to quote so simply append the signature if available + if (mAppendSignature) { + text += getSignature(); + } + + // Convert the text to HTML + text = textToHtmlFragment(text); + + //TODO: Wrap this in proper HTML tags + + composedMessageLength = text.length(); + composedMessageOffset = 0; + } + + TextBody body = new TextBody(text); + body.setComposedMessageLength(composedMessageLength); + body.setComposedMessageOffset(composedMessageOffset); + + return body; + } + + /** + * Build the {@link Body} that will contain the text of the message. + * + *

+ * Draft messages are treated somewhat differently in that signatures are + * not appended and HTML separators between composed text and quoted text + * are not added. + *

+ * + * @return {@link TextBody} instance that contains the entered text and + * possibly the quoted original message. + */ + public TextBody buildTextPlain(String quotedText) { + // The length of the formatted version of the user-supplied text/reply + int composedMessageLength; + + // The offset of the user-supplied text/reply in the final text body + int composedMessageOffset; + + // Get the user-supplied text + String text = mMessageContent; + + // Capture composed message length before we start attaching quoted parts and signatures. + composedMessageLength = text.length(); + composedMessageOffset = 0; + + // Do we have to modify an existing message to include our reply? + if (mIncludeQuotedText && !StringUtils.isNullOrEmpty(quotedText)) { + + if (mAppendSignature) { + // Append signature to the text/reply + if (mReplyAfterQuote || mSignatureBeforeQuotedText) { + text += getSignature(); + } + } + + if (mReplyAfterQuote) { + composedMessageOffset = quotedText.length() + "\r\n".length(); + text = quotedText + "\r\n" + text; + } else { + text += "\r\n\r\n" + quotedText; + } + + if (mAppendSignature) { + // Place signature immediately after the quoted text + if (!(mReplyAfterQuote || mSignatureBeforeQuotedText)) { + text += getSignature(); + } + } + } + else { + // There is no text to quote so simply append the signature if available + if (mAppendSignature) { + // Append signature to the text/reply + text += getSignature(); + } + } + + TextBody body = new TextBody(text); + body.setComposedMessageLength(composedMessageLength); + body.setComposedMessageOffset(composedMessageOffset); + + return body; + } + + private String getSignature() { + String signature = ""; + if (!StringUtils.isNullOrEmpty(mSignature)) { + signature = "\r\n" + mSignature; + } + + return signature; + } + + /** + * Get an HTML version of the signature in the #mSignatureView, if any. + * + * @return HTML version of signature. + */ + private String getSignatureHtml() { + String signature = ""; + if (!StringUtils.isNullOrEmpty(mSignature)) { + signature = textToHtmlFragment("\r\n" + mSignature); + } + return signature; + } + + public String textToHtmlFragment(String text) { + return HtmlConverter.textToHtmlFragment(text); + } + + // getter and setter + + public boolean isIncludeQuotedText() { + return mIncludeQuotedText; + } + + public void setIncludeQuotedText(boolean includeQuotedText) { + mIncludeQuotedText = includeQuotedText; + } + + public boolean isDraft() { + return mDraft; + } + + public void setDraft(boolean draft) { + mDraft = draft; + } + + public boolean isSignatureBeforeQuotedText() { + return mSignatureBeforeQuotedText; + } + + public void setSignatureBeforeQuotedText(boolean signatureBeforeQuotedText) { + mSignatureBeforeQuotedText = signatureBeforeQuotedText; + } + + public boolean isReplyAfterQuote() { + return mReplyAfterQuote; + } + + public void setReplyAfterQuote(boolean replyAfterQuote) { + mReplyAfterQuote = replyAfterQuote; + } + + public boolean isAppendSignature() { + return mAppendSignature; + } + + public void setAppendSignature(boolean appendSignature) { + mAppendSignature = appendSignature; + } +} diff --git a/tests-on-jvm/src/com/fsck/k9/K9.java b/tests-on-jvm/src/com/fsck/k9/K9.java new file mode 100644 index 000000000..64c6b7c47 --- /dev/null +++ b/tests-on-jvm/src/com/fsck/k9/K9.java @@ -0,0 +1,5 @@ +package com.fsck.k9; + +public class K9 { + public static boolean DEBUG = false; +} diff --git a/tests-on-jvm/src/com/fsck/k9/mail/internet/TextBodyBuilderTest.java b/tests-on-jvm/src/com/fsck/k9/mail/internet/TextBodyBuilderTest.java new file mode 100644 index 000000000..dc39a268f --- /dev/null +++ b/tests-on-jvm/src/com/fsck/k9/mail/internet/TextBodyBuilderTest.java @@ -0,0 +1,335 @@ +package com.fsck.k9.mail.internet; + +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.*; + +import org.junit.experimental.theories.*; +import org.junit.runner.RunWith; + +import com.fsck.k9.Account.QuoteStyle; +import com.fsck.k9.activity.InsertableHtmlContent; + +class TestingTextBodyBuilder extends TextBodyBuilder { + + public TestingTextBodyBuilder( + boolean includeQuotedText, + boolean isDraft, + QuoteStyle quoteStyle, + boolean replyAfterQuote, + boolean signatureBeforeQuotedText, + boolean signatureUse, + String messageContent, + String signature) { + super(messageContent, + signatureUse ? signature : null); + + if (isDraft || includeQuotedText) { + this.setIncludeQuotedText(true); + } + else { + this.setIncludeQuotedText(false); + } + if (!isDraft) { + this.setAppendSignature(true); + } + else { + this.setAppendSignature(false); + } + this.setDraft(isDraft); + this.setSignatureBeforeQuotedText(signatureBeforeQuotedText); + + if (quoteStyle == QuoteStyle.PREFIX && replyAfterQuote) { + this.setReplyAfterQuote(true); + } + else { + this.setReplyAfterQuote(false); + } + } + + // HtmlConverter depends on Android. + // So we use dummy method for tests. + @Override + public String textToHtmlFragment(String text) { + return "" + text + ""; + } +} + +@RunWith(Theories.class) +public class TextBodyBuilderTest { + + @DataPoints + public static boolean[] BOOLEANS = { true, false }; + + @DataPoints + public static QuoteStyle[] QUOTESTYLES = {QuoteStyle.PREFIX, QuoteStyle.HEADER}; + + @Theory + public void testBuildTextPlain( + boolean includeQuotedText, + QuoteStyle quoteStyle, + boolean isReplyAfterQuote, + boolean isSignatureUse, + boolean isSignatureBeforeQuotedText, + boolean isDraft + ) { + + String expectedText; + int expectedMessageLength; + int expectedMessagePosition; + + // 1.quoted text + // 2.message content + // 3.signature + if (quoteStyle == QuoteStyle.PREFIX && isReplyAfterQuote) { + String expectedQuotedText = ""; + + if (isDraft || includeQuotedText) { + expectedQuotedText = "quoted text" + "\r\n"; + } + + expectedText = expectedQuotedText; + + expectedText += "message content"; + + if (!isDraft && isSignatureUse) { + expectedText += "\r\n" + "signature"; + } + expectedMessageLength = "message content".length(); + expectedMessagePosition = expectedQuotedText.length(); + } + // 1.message content + // 2.signature + // 3.quoted text + else if (isSignatureBeforeQuotedText) { + expectedText = "message content"; + + if (!isDraft && isSignatureUse) { + expectedText += "\r\n" + "signature"; + } + + if (isDraft || includeQuotedText) { + expectedText += "\r\n\r\nquoted text"; + } + + expectedMessageLength = "message content".length(); + expectedMessagePosition = 0; + } + // 1.message content + // 2.quoted text + // 3.signature + else { + expectedText = "message content"; + + if (isDraft || includeQuotedText) { + expectedText += "\r\n\r\nquoted text"; + } + + if (!isDraft && isSignatureUse) { + expectedText += "\r\n" + "signature"; + } + + expectedMessageLength = "message content".length(); + expectedMessagePosition = 0; + } + + String quotedText = "quoted text"; + String messageContent = "message content"; + String signature = "signature"; + + TextBody textBody = new TestingTextBodyBuilder( + includeQuotedText, + isDraft, + quoteStyle, + isReplyAfterQuote, + isSignatureBeforeQuotedText, + isSignatureUse, + messageContent, + signature + ).buildTextPlain(quotedText); + + assertThat(textBody, instanceOf(TextBody.class)); + assertThat(textBody.getText(), is(expectedText)); + assertThat(textBody.getComposedMessageLength(), is(expectedMessageLength)); + assertThat(textBody.getComposedMessageOffset(), is(expectedMessagePosition)); + assertThat(textBody.getText().substring(expectedMessagePosition, expectedMessagePosition + expectedMessageLength), + is("message content")); + } + + /** + * generate expected HtmlContent debug string + * + * @param expectedText + * @param quotedContent + * @param footerInsertionPoint + * @param isBefore + * @param userContent + * @param compiledResult + * @return expected string + * + * @see InsertableHtmlContent#toDebugString() + */ + public String makeExpectedHtmlContent(String expectedText, String quotedContent, int footerInsertionPoint, boolean isBefore, + String userContent, String compiledResult) { + String expectedHtmlContent = "InsertableHtmlContent{" + + "headerInsertionPoint=0," + + " footerInsertionPoint=" + footerInsertionPoint + "," + + " insertionLocation=" + (isBefore ? "BEFORE_QUOTE" : "AFTER_QUOTE") + "," + + " quotedContent=" + quotedContent + "," + + " userContent=" + userContent + "," + + " compiledResult=" + compiledResult + + "}"; + return expectedHtmlContent; + } + + @Theory + public void testBuildTextHtml( + boolean includeQuotedText, + QuoteStyle quoteStyle, + boolean isReplyAfterQuote, + boolean isSignatureUse, + boolean isSignatureBeforeQuotedText, + boolean isDraft + ) { + String expectedText; + int expectedMessageLength; + int expectedMessagePosition = 0; + String expectedHtmlContent; + + String expectedPrefix = ""; + + if (includeQuotedText && quoteStyle == QuoteStyle.PREFIX && isReplyAfterQuote && !isDraft) { + expectedPrefix = "
"; + } + String expectedPostfix = ""; + if (!isDraft && includeQuotedText) { + expectedPostfix = "

"; + } + + // 1.quoted text + // 2.message content + // 3.signature + if (quoteStyle == QuoteStyle.PREFIX && isReplyAfterQuote) { + expectedText = expectedPrefix + + "message content"; + if (!isDraft && isSignatureUse) { + expectedText += "\r\n" + "signature"; + } + expectedText += ""; + expectedMessageLength = expectedText.length(); + String quotedContent = "quoted text"; + + if (isDraft || includeQuotedText) { + expectedHtmlContent = makeExpectedHtmlContent(expectedText, quotedContent, + 0, + false, + expectedText, + expectedText + quotedContent); + expectedText += quotedContent; + } + else { + expectedHtmlContent = makeExpectedHtmlContent(expectedText, quotedContent, + 0, + true, + "", + quotedContent); + // expectedText += quotedContent; + } + } + // 1.message content + // 2.signature + // 3.quoted text + else if (isSignatureBeforeQuotedText) { + expectedText = expectedPrefix + + "message content"; + if (!isDraft && isSignatureUse) { + expectedText += "\r\n" + "signature"; + } + expectedText += ""; + expectedText += expectedPostfix; + + expectedMessageLength = expectedText.length(); + String quotedContent = "quoted text"; + + if (isDraft || includeQuotedText) { + expectedHtmlContent = makeExpectedHtmlContent(expectedText, quotedContent, + 0, + true, + expectedText, + expectedText + quotedContent); + expectedText += quotedContent; + } + else { + expectedHtmlContent = makeExpectedHtmlContent(expectedText, quotedContent, + 0, + true, + "", + quotedContent); + // expectedText += quotedContent; + } + } + // 1.message content + // 2.quoted text + // 3.signature + else { + String expectedSignature = ""; + + expectedText = expectedPrefix + + "message content"; + + if (!isDraft && isSignatureUse) { + if (!includeQuotedText) { + expectedText += "\r\n" + "signature"; + } + else { + expectedSignature = "\r\nsignature"; + } + } + expectedText += ""; + expectedText += expectedPostfix; + + expectedMessageLength = expectedText.length(); + String quotedContent = "quoted text"; + + if (isDraft || includeQuotedText) { + expectedHtmlContent = makeExpectedHtmlContent(expectedText, expectedSignature + quotedContent, + expectedSignature.length(), + true, + expectedText, + expectedText + expectedSignature + quotedContent); + expectedText += expectedSignature + quotedContent; + } + else { + expectedHtmlContent = makeExpectedHtmlContent(expectedText, quotedContent, + 0, + true, + "", + quotedContent); + // expectedText += quotedContent; + } + } + + InsertableHtmlContent insertableHtmlContent = new InsertableHtmlContent(); + + String quotedText = "quoted text"; + insertableHtmlContent.setQuotedContent(new StringBuilder(quotedText)); + String messageContent = "message content"; + String signature = "signature"; + TextBody textBody = new TestingTextBodyBuilder( + includeQuotedText, + isDraft, + quoteStyle, + isReplyAfterQuote, + isSignatureBeforeQuotedText, + isSignatureUse, + messageContent, + signature + ).buildTextHtml(insertableHtmlContent); + + assertThat(textBody, instanceOf(TextBody.class)); + assertThat(textBody.getText(), is(expectedText)); + assertThat(textBody.getComposedMessageLength(), is(expectedMessageLength)); + assertThat(textBody.getComposedMessageOffset(), is(expectedMessagePosition)); + assertThat(insertableHtmlContent.toDebugString(), is(expectedHtmlContent)); + } + +} From a08687b70e2e3ace85f144ff8ac9f41361e23320 Mon Sep 17 00:00:00 2001 From: Koji Arai Date: Fri, 2 May 2014 08:28:42 +0900 Subject: [PATCH 03/16] Use local variable for more readability. --- src/com/fsck/k9/activity/MessageCompose.java | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/com/fsck/k9/activity/MessageCompose.java b/src/com/fsck/k9/activity/MessageCompose.java index 7db2e3bce..d6ceb13d0 100644 --- a/src/com/fsck/k9/activity/MessageCompose.java +++ b/src/com/fsck/k9/activity/MessageCompose.java @@ -1352,11 +1352,10 @@ public class MessageCompose extends K9Activity implements OnClickListener, * original message. */ private TextBody buildText(boolean isDraft, SimpleMessageFormat messageFormat) { - TextBodyBuilder textBodyBuilder = - new TextBodyBuilder( - mMessageContentView.getText().toString(), - mIdentity.getSignatureUse() ? mSignatureView.getCharacters() : null - ); + String messageText = mMessageContentView.getText().toString(); + String signatureText = mIdentity.getSignatureUse() ? mSignatureView.getCharacters() : null; + + TextBodyBuilder textBodyBuilder = new TextBodyBuilder(messageText, signatureText); /* * Find out if we need to include the original message as quoted text. @@ -1366,12 +1365,9 @@ public class MessageCompose extends K9Activity implements OnClickListener, * That's so the user is able to "un-hide" the quoted text if (s)he * opens a saved draft. */ - if (isDraft || mQuotedTextMode == QuotedTextMode.SHOW) { - textBodyBuilder.setIncludeQuotedText(true); - } - else { - textBodyBuilder.setIncludeQuotedText(false); - } + boolean includeQuotedText = (isDraft || mQuotedTextMode == QuotedTextMode.SHOW); + textBodyBuilder.setIncludeQuotedText(includeQuotedText); + if (!isDraft) { textBodyBuilder.setAppendSignature(true); } From 56a48476e4cf0aa1c2421f608538363b7755f1f6 Mon Sep 17 00:00:00 2001 From: Koji Arai Date: Fri, 2 May 2014 08:36:46 +0900 Subject: [PATCH 04/16] Rename mDraft to mInsertSeparator. --- src/com/fsck/k9/activity/MessageCompose.java | 10 +++------- .../fsck/k9/mail/internet/TextBodyBuilder.java | 15 ++++++++------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/com/fsck/k9/activity/MessageCompose.java b/src/com/fsck/k9/activity/MessageCompose.java index d6ceb13d0..4b0e3d156 100644 --- a/src/com/fsck/k9/activity/MessageCompose.java +++ b/src/com/fsck/k9/activity/MessageCompose.java @@ -1368,13 +1368,9 @@ public class MessageCompose extends K9Activity implements OnClickListener, boolean includeQuotedText = (isDraft || mQuotedTextMode == QuotedTextMode.SHOW); textBodyBuilder.setIncludeQuotedText(includeQuotedText); - if (!isDraft) { - textBodyBuilder.setAppendSignature(true); - } - else { - textBodyBuilder.setAppendSignature(false); - } - textBodyBuilder.setDraft(isDraft); + textBodyBuilder.setAppendSignature(!isDraft); + textBodyBuilder.setInsertSeparator(!isDraft); + textBodyBuilder.setSignatureBeforeQuotedText(mAccount.isSignatureBeforeQuotedText()); if (mQuoteStyle == QuoteStyle.PREFIX && mAccount.isReplyAfterQuote()) { diff --git a/src/com/fsck/k9/mail/internet/TextBodyBuilder.java b/src/com/fsck/k9/mail/internet/TextBodyBuilder.java index 7728e1951..380e290d4 100644 --- a/src/com/fsck/k9/mail/internet/TextBodyBuilder.java +++ b/src/com/fsck/k9/mail/internet/TextBodyBuilder.java @@ -13,7 +13,8 @@ public class TextBodyBuilder { private boolean mIncludeQuotedText = true; private boolean mReplyAfterQuote = false; private boolean mSignatureBeforeQuotedText = false; - private boolean mDraft = false; + + private boolean mInsertSeparator = false; private boolean mAppendSignature = true; // message parts @@ -77,14 +78,14 @@ public class TextBodyBuilder { if (mReplyAfterQuote) { quotedHtmlContent.setInsertionLocation( InsertableHtmlContent.InsertionLocation.AFTER_QUOTE); - if (!mDraft) { + if (mInsertSeparator) { text = "
" + text; } } else { quotedHtmlContent.setInsertionLocation( InsertableHtmlContent.InsertionLocation.BEFORE_QUOTE); - if (!mDraft) { + if (mInsertSeparator) { text += "

"; } } @@ -227,12 +228,12 @@ public class TextBodyBuilder { mIncludeQuotedText = includeQuotedText; } - public boolean isDraft() { - return mDraft; + public boolean isInsertSeparator() { + return mInsertSeparator; } - public void setDraft(boolean draft) { - mDraft = draft; + public void setInsertSeparator(boolean insertSeparator) { + mInsertSeparator = insertSeparator; } public boolean isSignatureBeforeQuotedText() { From 421879e9cfb2530c85c461a86f07745c35d8ddeb Mon Sep 17 00:00:00 2001 From: Koji Arai Date: Fri, 2 May 2014 08:39:07 +0900 Subject: [PATCH 05/16] Remove unused getter --- .../k9/mail/internet/TextBodyBuilder.java | 22 +------------------ 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/src/com/fsck/k9/mail/internet/TextBodyBuilder.java b/src/com/fsck/k9/mail/internet/TextBodyBuilder.java index 380e290d4..3555034ed 100644 --- a/src/com/fsck/k9/mail/internet/TextBodyBuilder.java +++ b/src/com/fsck/k9/mail/internet/TextBodyBuilder.java @@ -218,44 +218,24 @@ public class TextBodyBuilder { return HtmlConverter.textToHtmlFragment(text); } - // getter and setter - - public boolean isIncludeQuotedText() { - return mIncludeQuotedText; - } + // setter public void setIncludeQuotedText(boolean includeQuotedText) { mIncludeQuotedText = includeQuotedText; } - public boolean isInsertSeparator() { - return mInsertSeparator; - } - public void setInsertSeparator(boolean insertSeparator) { mInsertSeparator = insertSeparator; } - public boolean isSignatureBeforeQuotedText() { - return mSignatureBeforeQuotedText; - } - public void setSignatureBeforeQuotedText(boolean signatureBeforeQuotedText) { mSignatureBeforeQuotedText = signatureBeforeQuotedText; } - public boolean isReplyAfterQuote() { - return mReplyAfterQuote; - } - public void setReplyAfterQuote(boolean replyAfterQuote) { mReplyAfterQuote = replyAfterQuote; } - public boolean isAppendSignature() { - return mAppendSignature; - } - public void setAppendSignature(boolean appendSignature) { mAppendSignature = appendSignature; } From 7fd52a735d9972bff8393aa220a3efb426f408c6 Mon Sep 17 00:00:00 2001 From: Koji Arai Date: Fri, 2 May 2014 08:43:40 +0900 Subject: [PATCH 06/16] fixup! Rename mDraft to mInsertSeparator. --- .../fsck/k9/mail/internet/TextBodyBuilderTest.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/tests-on-jvm/src/com/fsck/k9/mail/internet/TextBodyBuilderTest.java b/tests-on-jvm/src/com/fsck/k9/mail/internet/TextBodyBuilderTest.java index dc39a268f..a568fb65f 100644 --- a/tests-on-jvm/src/com/fsck/k9/mail/internet/TextBodyBuilderTest.java +++ b/tests-on-jvm/src/com/fsck/k9/mail/internet/TextBodyBuilderTest.java @@ -29,13 +29,10 @@ class TestingTextBodyBuilder extends TextBodyBuilder { else { this.setIncludeQuotedText(false); } - if (!isDraft) { - this.setAppendSignature(true); - } - else { - this.setAppendSignature(false); - } - this.setDraft(isDraft); + + this.setAppendSignature(!isDraft); + this.setInsertSeparator(!isDraft); + this.setSignatureBeforeQuotedText(signatureBeforeQuotedText); if (quoteStyle == QuoteStyle.PREFIX && replyAfterQuote) { From 00fb83e1b3cb95db4a877006a0310ee3cb839fc7 Mon Sep 17 00:00:00 2001 From: Koji Arai Date: Fri, 2 May 2014 08:49:01 +0900 Subject: [PATCH 07/16] fixup! Use local variable for more readability --- src/com/fsck/k9/activity/MessageCompose.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/com/fsck/k9/activity/MessageCompose.java b/src/com/fsck/k9/activity/MessageCompose.java index 4b0e3d156..99813391c 100644 --- a/src/com/fsck/k9/activity/MessageCompose.java +++ b/src/com/fsck/k9/activity/MessageCompose.java @@ -1373,12 +1373,8 @@ public class MessageCompose extends K9Activity implements OnClickListener, textBodyBuilder.setSignatureBeforeQuotedText(mAccount.isSignatureBeforeQuotedText()); - if (mQuoteStyle == QuoteStyle.PREFIX && mAccount.isReplyAfterQuote()) { - textBodyBuilder.setReplyAfterQuote(true); - } - else { - textBodyBuilder.setReplyAfterQuote(false); - } + boolean isReplyAfterQuote = (mQuoteStyle == QuoteStyle.PREFIX && mAccount.isReplyAfterQuote()); + textBodyBuilder.setReplyAfterQuote(isReplyAfterQuote); TextBody body; if (messageFormat == SimpleMessageFormat.HTML) { From e163fb87e14c80c5ab3053d478d97899baf40f55 Mon Sep 17 00:00:00 2001 From: Koji Arai Date: Fri, 2 May 2014 09:06:23 +0900 Subject: [PATCH 08/16] set signature parameter when it is only necessary --- src/com/fsck/k9/activity/MessageCompose.java | 17 ++++++++++++----- .../fsck/k9/mail/internet/TextBodyBuilder.java | 11 +++++------ 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/com/fsck/k9/activity/MessageCompose.java b/src/com/fsck/k9/activity/MessageCompose.java index 99813391c..b804710ce 100644 --- a/src/com/fsck/k9/activity/MessageCompose.java +++ b/src/com/fsck/k9/activity/MessageCompose.java @@ -1353,9 +1353,8 @@ public class MessageCompose extends K9Activity implements OnClickListener, */ private TextBody buildText(boolean isDraft, SimpleMessageFormat messageFormat) { String messageText = mMessageContentView.getText().toString(); - String signatureText = mIdentity.getSignatureUse() ? mSignatureView.getCharacters() : null; - TextBodyBuilder textBodyBuilder = new TextBodyBuilder(messageText, signatureText); + TextBodyBuilder textBodyBuilder = new TextBodyBuilder(messageText); /* * Find out if we need to include the original message as quoted text. @@ -1368,14 +1367,22 @@ public class MessageCompose extends K9Activity implements OnClickListener, boolean includeQuotedText = (isDraft || mQuotedTextMode == QuotedTextMode.SHOW); textBodyBuilder.setIncludeQuotedText(includeQuotedText); - textBodyBuilder.setAppendSignature(!isDraft); textBodyBuilder.setInsertSeparator(!isDraft); - textBodyBuilder.setSignatureBeforeQuotedText(mAccount.isSignatureBeforeQuotedText()); - boolean isReplyAfterQuote = (mQuoteStyle == QuoteStyle.PREFIX && mAccount.isReplyAfterQuote()); textBodyBuilder.setReplyAfterQuote(isReplyAfterQuote); + boolean useSignature = (!isDraft && mIdentity.getSignatureUse()); + if (useSignature) { + textBodyBuilder.setAppendSignature(true); + textBodyBuilder.setSignature(mSignatureView.getCharacters()); + textBodyBuilder.setSignatureBeforeQuotedText(mAccount.isSignatureBeforeQuotedText()); + } + else { + textBodyBuilder.setAppendSignature(false); + } + + TextBody body; if (messageFormat == SimpleMessageFormat.HTML) { body = textBodyBuilder.buildTextHtml(mQuotedHtmlContent); diff --git a/src/com/fsck/k9/mail/internet/TextBodyBuilder.java b/src/com/fsck/k9/mail/internet/TextBodyBuilder.java index 3555034ed..dd3a3c90e 100644 --- a/src/com/fsck/k9/mail/internet/TextBodyBuilder.java +++ b/src/com/fsck/k9/mail/internet/TextBodyBuilder.java @@ -13,7 +13,6 @@ public class TextBodyBuilder { private boolean mIncludeQuotedText = true; private boolean mReplyAfterQuote = false; private boolean mSignatureBeforeQuotedText = false; - private boolean mInsertSeparator = false; private boolean mAppendSignature = true; @@ -21,12 +20,8 @@ public class TextBodyBuilder { private String mMessageContent; private String mSignature; - public TextBodyBuilder( - String messageContent, - String signature - ) { + public TextBodyBuilder(String messageContent) { mMessageContent = messageContent; - mSignature = signature; } /** @@ -220,6 +215,10 @@ public class TextBodyBuilder { // setter + public void setSignature(String signature) { + mSignature = signature; + } + public void setIncludeQuotedText(boolean includeQuotedText) { mIncludeQuotedText = includeQuotedText; } From 71e766999c3de215fa22996e52ab1cf4d3c709d5 Mon Sep 17 00:00:00 2001 From: Koji Arai Date: Fri, 2 May 2014 09:11:31 +0900 Subject: [PATCH 09/16] adapt to product code --- .../src/com/fsck/k9/mail/internet/TextBodyBuilderTest.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests-on-jvm/src/com/fsck/k9/mail/internet/TextBodyBuilderTest.java b/tests-on-jvm/src/com/fsck/k9/mail/internet/TextBodyBuilderTest.java index a568fb65f..a813580ba 100644 --- a/tests-on-jvm/src/com/fsck/k9/mail/internet/TextBodyBuilderTest.java +++ b/tests-on-jvm/src/com/fsck/k9/mail/internet/TextBodyBuilderTest.java @@ -20,8 +20,7 @@ class TestingTextBodyBuilder extends TextBodyBuilder { boolean signatureUse, String messageContent, String signature) { - super(messageContent, - signatureUse ? signature : null); + super(messageContent); if (isDraft || includeQuotedText) { this.setIncludeQuotedText(true); @@ -41,6 +40,10 @@ class TestingTextBodyBuilder extends TextBodyBuilder { else { this.setReplyAfterQuote(false); } + + if (signatureUse) { + this.setSignature(signature); + } } // HtmlConverter depends on Android. From 68850b1dc94ddcd94d499d3b98e3d7237dae7096 Mon Sep 17 00:00:00 2001 From: Koji Arai Date: Fri, 2 May 2014 09:43:14 +0900 Subject: [PATCH 10/16] Use setter for quoted text like signature --- src/com/fsck/k9/activity/MessageCompose.java | 12 +++++-- .../k9/mail/internet/TextBodyBuilder.java | 33 ++++++++++++++++--- .../k9/mail/internet/TextBodyBuilderTest.java | 13 +++++--- 3 files changed, 47 insertions(+), 11 deletions(-) diff --git a/src/com/fsck/k9/activity/MessageCompose.java b/src/com/fsck/k9/activity/MessageCompose.java index b804710ce..9e8e4bdb5 100644 --- a/src/com/fsck/k9/activity/MessageCompose.java +++ b/src/com/fsck/k9/activity/MessageCompose.java @@ -1382,13 +1382,19 @@ public class MessageCompose extends K9Activity implements OnClickListener, textBodyBuilder.setAppendSignature(false); } - TextBody body; if (messageFormat == SimpleMessageFormat.HTML) { - body = textBodyBuilder.buildTextHtml(mQuotedHtmlContent); + if (mQuotedHtmlContent == null) { + textBodyBuilder.setIncludeQuotedText(false); + } + else { + textBodyBuilder.setQuotedTextHtml(mQuotedHtmlContent); + } + body = textBodyBuilder.buildTextHtml(); } else { - body = textBodyBuilder.buildTextPlain(mQuotedText.getText().toString()); + textBodyBuilder.setQuotedText(mQuotedText.getText().toString()); + body = textBodyBuilder.buildTextPlain(); } return body; } diff --git a/src/com/fsck/k9/mail/internet/TextBodyBuilder.java b/src/com/fsck/k9/mail/internet/TextBodyBuilder.java index dd3a3c90e..38d71fcdf 100644 --- a/src/com/fsck/k9/mail/internet/TextBodyBuilder.java +++ b/src/com/fsck/k9/mail/internet/TextBodyBuilder.java @@ -19,6 +19,8 @@ public class TextBodyBuilder { // message parts private String mMessageContent; private String mSignature; + private String mQuotedText; + private InsertableHtmlContent mQuotedTextHtml; public TextBodyBuilder(String messageContent) { mMessageContent = messageContent; @@ -36,7 +38,7 @@ public class TextBodyBuilder { * @return {@link TextBody} instance that contains the entered text and * possibly the quoted original message. */ - public TextBody buildTextHtml(InsertableHtmlContent quotedHtmlContent) { + public TextBody buildTextHtml() { // The length of the formatted version of the user-supplied text/reply int composedMessageLength; @@ -47,7 +49,9 @@ public class TextBodyBuilder { String text = mMessageContent; // Do we have to modify an existing message to include our reply? - if (mIncludeQuotedText && quotedHtmlContent != null) { + if (mIncludeQuotedText) { + InsertableHtmlContent quotedHtmlContent = getQuotedTextHtml(); + if (K9.DEBUG) { Log.d(K9.LOG_TAG, "insertable: " + quotedHtmlContent.toDebugString()); } @@ -134,7 +138,7 @@ public class TextBodyBuilder { * @return {@link TextBody} instance that contains the entered text and * possibly the quoted original message. */ - public TextBody buildTextPlain(String quotedText) { + public TextBody buildTextPlain() { // The length of the formatted version of the user-supplied text/reply int composedMessageLength; @@ -149,7 +153,8 @@ public class TextBodyBuilder { composedMessageOffset = 0; // Do we have to modify an existing message to include our reply? - if (mIncludeQuotedText && !StringUtils.isNullOrEmpty(quotedText)) { + if (mIncludeQuotedText) { + String quotedText = getQuotedText(); if (mAppendSignature) { // Append signature to the text/reply @@ -209,6 +214,18 @@ public class TextBodyBuilder { return signature; } + private String getQuotedText() { + String quotedText = ""; + if (!StringUtils.isNullOrEmpty(mQuotedText)) { + quotedText = mQuotedText; + } + return quotedText; + } + + private InsertableHtmlContent getQuotedTextHtml() { + return mQuotedTextHtml; + } + public String textToHtmlFragment(String text) { return HtmlConverter.textToHtmlFragment(text); } @@ -223,6 +240,14 @@ public class TextBodyBuilder { mIncludeQuotedText = includeQuotedText; } + public void setQuotedText(String quotedText) { + mQuotedText = quotedText; + } + + public void setQuotedTextHtml(InsertableHtmlContent quotedTextHtml) { + mQuotedTextHtml = quotedTextHtml; + } + public void setInsertSeparator(boolean insertSeparator) { mInsertSeparator = insertSeparator; } diff --git a/tests-on-jvm/src/com/fsck/k9/mail/internet/TextBodyBuilderTest.java b/tests-on-jvm/src/com/fsck/k9/mail/internet/TextBodyBuilderTest.java index a813580ba..a3daafae4 100644 --- a/tests-on-jvm/src/com/fsck/k9/mail/internet/TextBodyBuilderTest.java +++ b/tests-on-jvm/src/com/fsck/k9/mail/internet/TextBodyBuilderTest.java @@ -136,7 +136,7 @@ public class TextBodyBuilderTest { String messageContent = "message content"; String signature = "signature"; - TextBody textBody = new TestingTextBodyBuilder( + TestingTextBodyBuilder textBodyBuilder = new TestingTextBodyBuilder( includeQuotedText, isDraft, quoteStyle, @@ -145,7 +145,9 @@ public class TextBodyBuilderTest { isSignatureUse, messageContent, signature - ).buildTextPlain(quotedText); + ); + textBodyBuilder.setQuotedText(quotedText); + TextBody textBody = textBodyBuilder.buildTextPlain(); assertThat(textBody, instanceOf(TextBody.class)); assertThat(textBody.getText(), is(expectedText)); @@ -314,7 +316,8 @@ public class TextBodyBuilderTest { insertableHtmlContent.setQuotedContent(new StringBuilder(quotedText)); String messageContent = "message content"; String signature = "signature"; - TextBody textBody = new TestingTextBodyBuilder( + + TestingTextBodyBuilder textBodyBuilder = new TestingTextBodyBuilder( includeQuotedText, isDraft, quoteStyle, @@ -323,7 +326,9 @@ public class TextBodyBuilderTest { isSignatureUse, messageContent, signature - ).buildTextHtml(insertableHtmlContent); + ); + textBodyBuilder.setQuotedTextHtml(insertableHtmlContent); + TextBody textBody = textBodyBuilder.buildTextHtml(); assertThat(textBody, instanceOf(TextBody.class)); assertThat(textBody.getText(), is(expectedText)); From 4260dc75d3f386c2f4ffcb05f5fef026b9136f49 Mon Sep 17 00:00:00 2001 From: Koji Arai Date: Fri, 2 May 2014 10:45:20 +0900 Subject: [PATCH 11/16] more refactor about quoted text --- src/com/fsck/k9/activity/MessageCompose.java | 26 +++++++++++--------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/com/fsck/k9/activity/MessageCompose.java b/src/com/fsck/k9/activity/MessageCompose.java index 9e8e4bdb5..1240f2235 100644 --- a/src/com/fsck/k9/activity/MessageCompose.java +++ b/src/com/fsck/k9/activity/MessageCompose.java @@ -1365,13 +1365,24 @@ public class MessageCompose extends K9Activity implements OnClickListener, * opens a saved draft. */ boolean includeQuotedText = (isDraft || mQuotedTextMode == QuotedTextMode.SHOW); - textBodyBuilder.setIncludeQuotedText(includeQuotedText); + boolean isReplyAfterQuote = (mQuoteStyle == QuoteStyle.PREFIX && mAccount.isReplyAfterQuote()); + + textBodyBuilder.setIncludeQuotedText(false); + if (includeQuotedText) { + if (messageFormat == SimpleMessageFormat.HTML && mQuotedHtmlContent != null) { + textBodyBuilder.setIncludeQuotedText(true); + textBodyBuilder.setQuotedTextHtml(mQuotedHtmlContent); + textBodyBuilder.setReplyAfterQuote(isReplyAfterQuote); + } + if (messageFormat == SimpleMessageFormat.TEXT) { + textBodyBuilder.setIncludeQuotedText(true); + textBodyBuilder.setQuotedText(mQuotedText.getText().toString()); + textBodyBuilder.setReplyAfterQuote(isReplyAfterQuote); + } + } textBodyBuilder.setInsertSeparator(!isDraft); - boolean isReplyAfterQuote = (mQuoteStyle == QuoteStyle.PREFIX && mAccount.isReplyAfterQuote()); - textBodyBuilder.setReplyAfterQuote(isReplyAfterQuote); - boolean useSignature = (!isDraft && mIdentity.getSignatureUse()); if (useSignature) { textBodyBuilder.setAppendSignature(true); @@ -1384,16 +1395,9 @@ public class MessageCompose extends K9Activity implements OnClickListener, TextBody body; if (messageFormat == SimpleMessageFormat.HTML) { - if (mQuotedHtmlContent == null) { - textBodyBuilder.setIncludeQuotedText(false); - } - else { - textBodyBuilder.setQuotedTextHtml(mQuotedHtmlContent); - } body = textBodyBuilder.buildTextHtml(); } else { - textBodyBuilder.setQuotedText(mQuotedText.getText().toString()); body = textBodyBuilder.buildTextPlain(); } return body; From 215ada2e77c72b80caf6039e0a66359655bf04dd Mon Sep 17 00:00:00 2001 From: Koji Arai Date: Fri, 2 May 2014 13:18:36 +0900 Subject: [PATCH 12/16] astyle --- .../k9/mail/internet/TextBodyBuilder.java | 23 +-- .../k9/mail/internet/TextBodyBuilderTest.java | 175 ++++++++---------- 2 files changed, 92 insertions(+), 106 deletions(-) diff --git a/src/com/fsck/k9/mail/internet/TextBodyBuilder.java b/src/com/fsck/k9/mail/internet/TextBodyBuilder.java index 38d71fcdf..2a403f124 100644 --- a/src/com/fsck/k9/mail/internet/TextBodyBuilder.java +++ b/src/com/fsck/k9/mail/internet/TextBodyBuilder.java @@ -28,13 +28,13 @@ public class TextBodyBuilder { /** * Build the {@link Body} that will contain the text of the message. - * + * *

* Draft messages are treated somewhat differently in that signatures are * not appended and HTML separators between composed text and quoted text * are not added. *

- * + * * @return {@link TextBody} instance that contains the entered text and * possibly the quoted original message. */ @@ -76,14 +76,13 @@ public class TextBodyBuilder { */ if (mReplyAfterQuote) { quotedHtmlContent.setInsertionLocation( - InsertableHtmlContent.InsertionLocation.AFTER_QUOTE); + InsertableHtmlContent.InsertionLocation.AFTER_QUOTE); if (mInsertSeparator) { text = "
" + text; } - } - else { + } else { quotedHtmlContent.setInsertionLocation( - InsertableHtmlContent.InsertionLocation.BEFORE_QUOTE); + InsertableHtmlContent.InsertionLocation.BEFORE_QUOTE); if (mInsertSeparator) { text += "

"; } @@ -103,8 +102,7 @@ public class TextBodyBuilder { composedMessageOffset = quotedHtmlContent.getInsertionPoint(); text = quotedHtmlContent.toString(); - } - else { + } else { // There is no text to quote so simply append the signature if available if (mAppendSignature) { text += getSignature(); @@ -128,13 +126,13 @@ public class TextBodyBuilder { /** * Build the {@link Body} that will contain the text of the message. - * + * *

* Draft messages are treated somewhat differently in that signatures are * not appended and HTML separators between composed text and quoted text * are not added. *

- * + * * @return {@link TextBody} instance that contains the entered text and * possibly the quoted original message. */ @@ -176,8 +174,7 @@ public class TextBodyBuilder { text += getSignature(); } } - } - else { + } else { // There is no text to quote so simply append the signature if available if (mAppendSignature) { // Append signature to the text/reply @@ -203,7 +200,7 @@ public class TextBodyBuilder { /** * Get an HTML version of the signature in the #mSignatureView, if any. - * + * * @return HTML version of signature. */ private String getSignatureHtml() { diff --git a/tests-on-jvm/src/com/fsck/k9/mail/internet/TextBodyBuilderTest.java b/tests-on-jvm/src/com/fsck/k9/mail/internet/TextBodyBuilderTest.java index a3daafae4..9682fe565 100644 --- a/tests-on-jvm/src/com/fsck/k9/mail/internet/TextBodyBuilderTest.java +++ b/tests-on-jvm/src/com/fsck/k9/mail/internet/TextBodyBuilderTest.java @@ -11,21 +11,19 @@ import com.fsck.k9.activity.InsertableHtmlContent; class TestingTextBodyBuilder extends TextBodyBuilder { - public TestingTextBodyBuilder( - boolean includeQuotedText, - boolean isDraft, - QuoteStyle quoteStyle, - boolean replyAfterQuote, - boolean signatureBeforeQuotedText, - boolean signatureUse, - String messageContent, - String signature) { + public TestingTextBodyBuilder(boolean includeQuotedText, + boolean isDraft, + QuoteStyle quoteStyle, + boolean replyAfterQuote, + boolean signatureBeforeQuotedText, + boolean signatureUse, + String messageContent, + String signature) { super(messageContent); if (isDraft || includeQuotedText) { this.setIncludeQuotedText(true); - } - else { + } else { this.setIncludeQuotedText(false); } @@ -36,8 +34,7 @@ class TestingTextBodyBuilder extends TextBodyBuilder { if (quoteStyle == QuoteStyle.PREFIX && replyAfterQuote) { this.setReplyAfterQuote(true); - } - else { + } else { this.setReplyAfterQuote(false); } @@ -64,14 +61,12 @@ public class TextBodyBuilderTest { public static QuoteStyle[] QUOTESTYLES = {QuoteStyle.PREFIX, QuoteStyle.HEADER}; @Theory - public void testBuildTextPlain( - boolean includeQuotedText, - QuoteStyle quoteStyle, - boolean isReplyAfterQuote, - boolean isSignatureUse, - boolean isSignatureBeforeQuotedText, - boolean isDraft - ) { + public void testBuildTextPlain(boolean includeQuotedText, + QuoteStyle quoteStyle, + boolean isReplyAfterQuote, + boolean isSignatureUse, + boolean isSignatureBeforeQuotedText, + boolean isDraft) { String expectedText; int expectedMessageLength; @@ -137,15 +132,15 @@ public class TextBodyBuilderTest { String signature = "signature"; TestingTextBodyBuilder textBodyBuilder = new TestingTextBodyBuilder( - includeQuotedText, - isDraft, - quoteStyle, - isReplyAfterQuote, - isSignatureBeforeQuotedText, - isSignatureUse, - messageContent, - signature - ); + includeQuotedText, + isDraft, + quoteStyle, + isReplyAfterQuote, + isSignatureBeforeQuotedText, + isSignatureUse, + messageContent, + signature + ); textBodyBuilder.setQuotedText(quotedText); TextBody textBody = textBodyBuilder.buildTextPlain(); @@ -154,12 +149,12 @@ public class TextBodyBuilderTest { assertThat(textBody.getComposedMessageLength(), is(expectedMessageLength)); assertThat(textBody.getComposedMessageOffset(), is(expectedMessagePosition)); assertThat(textBody.getText().substring(expectedMessagePosition, expectedMessagePosition + expectedMessageLength), - is("message content")); + is("message content")); } /** * generate expected HtmlContent debug string - * + * * @param expectedText * @param quotedContent * @param footerInsertionPoint @@ -167,31 +162,29 @@ public class TextBodyBuilderTest { * @param userContent * @param compiledResult * @return expected string - * + * * @see InsertableHtmlContent#toDebugString() */ public String makeExpectedHtmlContent(String expectedText, String quotedContent, int footerInsertionPoint, boolean isBefore, - String userContent, String compiledResult) { + String userContent, String compiledResult) { String expectedHtmlContent = "InsertableHtmlContent{" - + "headerInsertionPoint=0," - + " footerInsertionPoint=" + footerInsertionPoint + "," - + " insertionLocation=" + (isBefore ? "BEFORE_QUOTE" : "AFTER_QUOTE") + "," - + " quotedContent=" + quotedContent + "," - + " userContent=" + userContent + "," - + " compiledResult=" + compiledResult - + "}"; + + "headerInsertionPoint=0," + + " footerInsertionPoint=" + footerInsertionPoint + "," + + " insertionLocation=" + (isBefore ? "BEFORE_QUOTE" : "AFTER_QUOTE") + "," + + " quotedContent=" + quotedContent + "," + + " userContent=" + userContent + "," + + " compiledResult=" + compiledResult + + "}"; return expectedHtmlContent; } @Theory - public void testBuildTextHtml( - boolean includeQuotedText, - QuoteStyle quoteStyle, - boolean isReplyAfterQuote, - boolean isSignatureUse, - boolean isSignatureBeforeQuotedText, - boolean isDraft - ) { + public void testBuildTextHtml(boolean includeQuotedText, + QuoteStyle quoteStyle, + boolean isReplyAfterQuote, + boolean isSignatureUse, + boolean isSignatureBeforeQuotedText, + boolean isDraft) { String expectedText; int expectedMessageLength; int expectedMessagePosition = 0; @@ -212,7 +205,7 @@ public class TextBodyBuilderTest { // 3.signature if (quoteStyle == QuoteStyle.PREFIX && isReplyAfterQuote) { expectedText = expectedPrefix - + "message content"; + + "message content"; if (!isDraft && isSignatureUse) { expectedText += "\r\n" + "signature"; } @@ -222,18 +215,17 @@ public class TextBodyBuilderTest { if (isDraft || includeQuotedText) { expectedHtmlContent = makeExpectedHtmlContent(expectedText, quotedContent, - 0, - false, - expectedText, - expectedText + quotedContent); + 0, + false, + expectedText, + expectedText + quotedContent); expectedText += quotedContent; - } - else { + } else { expectedHtmlContent = makeExpectedHtmlContent(expectedText, quotedContent, - 0, - true, - "", - quotedContent); + 0, + true, + "", + quotedContent); // expectedText += quotedContent; } } @@ -242,7 +234,7 @@ public class TextBodyBuilderTest { // 3.quoted text else if (isSignatureBeforeQuotedText) { expectedText = expectedPrefix - + "message content"; + + "message content"; if (!isDraft && isSignatureUse) { expectedText += "\r\n" + "signature"; } @@ -254,18 +246,17 @@ public class TextBodyBuilderTest { if (isDraft || includeQuotedText) { expectedHtmlContent = makeExpectedHtmlContent(expectedText, quotedContent, - 0, - true, - expectedText, - expectedText + quotedContent); + 0, + true, + expectedText, + expectedText + quotedContent); expectedText += quotedContent; - } - else { + } else { expectedHtmlContent = makeExpectedHtmlContent(expectedText, quotedContent, - 0, - true, - "", - quotedContent); + 0, + true, + "", + quotedContent); // expectedText += quotedContent; } } @@ -276,13 +267,12 @@ public class TextBodyBuilderTest { String expectedSignature = ""; expectedText = expectedPrefix - + "message content"; + + "message content"; if (!isDraft && isSignatureUse) { if (!includeQuotedText) { expectedText += "\r\n" + "signature"; - } - else { + } else { expectedSignature = "\r\nsignature"; } } @@ -294,18 +284,17 @@ public class TextBodyBuilderTest { if (isDraft || includeQuotedText) { expectedHtmlContent = makeExpectedHtmlContent(expectedText, expectedSignature + quotedContent, - expectedSignature.length(), - true, - expectedText, - expectedText + expectedSignature + quotedContent); + expectedSignature.length(), + true, + expectedText, + expectedText + expectedSignature + quotedContent); expectedText += expectedSignature + quotedContent; - } - else { + } else { expectedHtmlContent = makeExpectedHtmlContent(expectedText, quotedContent, - 0, - true, - "", - quotedContent); + 0, + true, + "", + quotedContent); // expectedText += quotedContent; } } @@ -318,15 +307,15 @@ public class TextBodyBuilderTest { String signature = "signature"; TestingTextBodyBuilder textBodyBuilder = new TestingTextBodyBuilder( - includeQuotedText, - isDraft, - quoteStyle, - isReplyAfterQuote, - isSignatureBeforeQuotedText, - isSignatureUse, - messageContent, - signature - ); + includeQuotedText, + isDraft, + quoteStyle, + isReplyAfterQuote, + isSignatureBeforeQuotedText, + isSignatureUse, + messageContent, + signature + ); textBodyBuilder.setQuotedTextHtml(insertableHtmlContent); TextBody textBody = textBodyBuilder.buildTextHtml(); From 0a09060ed76fa1c44dedf7005637b8eaac43b200 Mon Sep 17 00:00:00 2001 From: Koji Arai Date: Fri, 2 May 2014 13:42:05 +0900 Subject: [PATCH 13/16] adapt to product code --- .../k9/mail/internet/TextBodyBuilderTest.java | 44 +++++++++---------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/tests-on-jvm/src/com/fsck/k9/mail/internet/TextBodyBuilderTest.java b/tests-on-jvm/src/com/fsck/k9/mail/internet/TextBodyBuilderTest.java index 9682fe565..28d7d5143 100644 --- a/tests-on-jvm/src/com/fsck/k9/mail/internet/TextBodyBuilderTest.java +++ b/tests-on-jvm/src/com/fsck/k9/mail/internet/TextBodyBuilderTest.java @@ -16,30 +16,28 @@ class TestingTextBodyBuilder extends TextBodyBuilder { QuoteStyle quoteStyle, boolean replyAfterQuote, boolean signatureBeforeQuotedText, - boolean signatureUse, - String messageContent, - String signature) { - super(messageContent); + boolean useSignature, + String messageText, + String signatureText) { + super(messageText); - if (isDraft || includeQuotedText) { + includeQuotedText = (isDraft || includeQuotedText); + if (includeQuotedText) { this.setIncludeQuotedText(true); + this.setReplyAfterQuote(quoteStyle == QuoteStyle.PREFIX && replyAfterQuote); } else { this.setIncludeQuotedText(false); } - this.setAppendSignature(!isDraft); this.setInsertSeparator(!isDraft); - this.setSignatureBeforeQuotedText(signatureBeforeQuotedText); - - if (quoteStyle == QuoteStyle.PREFIX && replyAfterQuote) { - this.setReplyAfterQuote(true); + useSignature = (!isDraft && useSignature); + if (useSignature) { + this.setAppendSignature(true); + this.setSignature(signatureText); + this.setSignatureBeforeQuotedText(signatureBeforeQuotedText); } else { - this.setReplyAfterQuote(false); - } - - if (signatureUse) { - this.setSignature(signature); + this.setAppendSignature(false); } } @@ -128,8 +126,8 @@ public class TextBodyBuilderTest { } String quotedText = "quoted text"; - String messageContent = "message content"; - String signature = "signature"; + String messageText = "message content"; + String signatureText = "signature"; TestingTextBodyBuilder textBodyBuilder = new TestingTextBodyBuilder( includeQuotedText, @@ -138,8 +136,8 @@ public class TextBodyBuilderTest { isReplyAfterQuote, isSignatureBeforeQuotedText, isSignatureUse, - messageContent, - signature + messageText, + signatureText ); textBodyBuilder.setQuotedText(quotedText); TextBody textBody = textBodyBuilder.buildTextPlain(); @@ -303,8 +301,8 @@ public class TextBodyBuilderTest { String quotedText = "quoted text"; insertableHtmlContent.setQuotedContent(new StringBuilder(quotedText)); - String messageContent = "message content"; - String signature = "signature"; + String messageText = "message content"; + String signatureText = "signature"; TestingTextBodyBuilder textBodyBuilder = new TestingTextBodyBuilder( includeQuotedText, @@ -313,8 +311,8 @@ public class TextBodyBuilderTest { isReplyAfterQuote, isSignatureBeforeQuotedText, isSignatureUse, - messageContent, - signature + messageText, + signatureText ); textBodyBuilder.setQuotedTextHtml(insertableHtmlContent); TextBody textBody = textBodyBuilder.buildTextHtml(); From 3a02bfb0a95adc66bcc687b4868aefc38141088e Mon Sep 17 00:00:00 2001 From: Koji Arai Date: Fri, 2 May 2014 14:07:03 +0900 Subject: [PATCH 14/16] I have deleted a change in 0323af0. --- src/com/fsck/k9/activity/MessageCompose.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/com/fsck/k9/activity/MessageCompose.java b/src/com/fsck/k9/activity/MessageCompose.java index 1240f2235..f195af02e 100644 --- a/src/com/fsck/k9/activity/MessageCompose.java +++ b/src/com/fsck/k9/activity/MessageCompose.java @@ -1352,7 +1352,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, * original message. */ private TextBody buildText(boolean isDraft, SimpleMessageFormat messageFormat) { - String messageText = mMessageContentView.getText().toString(); + String messageText = mMessageContentView.getCharacters(); TextBodyBuilder textBodyBuilder = new TextBodyBuilder(messageText); @@ -1374,9 +1374,11 @@ public class MessageCompose extends K9Activity implements OnClickListener, textBodyBuilder.setQuotedTextHtml(mQuotedHtmlContent); textBodyBuilder.setReplyAfterQuote(isReplyAfterQuote); } - if (messageFormat == SimpleMessageFormat.TEXT) { + + String quotedText = mQuotedText.getCharacters(); + if (messageFormat == SimpleMessageFormat.TEXT && quotedText.length() > 0) { textBodyBuilder.setIncludeQuotedText(true); - textBodyBuilder.setQuotedText(mQuotedText.getText().toString()); + textBodyBuilder.setQuotedText(quotedText); textBodyBuilder.setReplyAfterQuote(isReplyAfterQuote); } } From a9cfa9ae684ad6c6362fa0299fd30d9a9290f0f3 Mon Sep 17 00:00:00 2001 From: cketti Date: Sat, 3 May 2014 06:06:15 +0200 Subject: [PATCH 15/16] Code style No functional changes --- src/com/fsck/k9/activity/MessageCompose.java | 581 +++++++++--------- .../k9/mail/internet/TextBodyBuilder.java | 4 +- .../k9/mail/internet/TextBodyBuilderTest.java | 143 ++--- 3 files changed, 370 insertions(+), 358 deletions(-) diff --git a/src/com/fsck/k9/activity/MessageCompose.java b/src/com/fsck/k9/activity/MessageCompose.java index f195af02e..d785d14a7 100644 --- a/src/com/fsck/k9/activity/MessageCompose.java +++ b/src/com/fsck/k9/activity/MessageCompose.java @@ -196,7 +196,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, private static final int CONTACT_PICKER_BCC2 = 9; private static final Account[] EMPTY_ACCOUNT_ARRAY = new Account[0]; - + private static final int REQUEST_CODE_SIGN_ENCRYPT = 12; /** @@ -320,10 +320,10 @@ public class MessageCompose extends K9Activity implements OnClickListener, private PgpData mPgpData = null; private boolean mAutoEncrypt = false; private boolean mContinueWithoutPublicKey = false; - + private String mOpenPgpProvider; private OpenPgpServiceConnection mOpenPgpServiceConnection; - + private String mReferences; private String mInReplyTo; private Menu mMenu; @@ -383,36 +383,36 @@ public class MessageCompose extends K9Activity implements OnClickListener, @Override public void handleMessage(android.os.Message msg) { switch (msg.what) { - case MSG_PROGRESS_ON: - setSupportProgressBarIndeterminateVisibility(true); - break; - case MSG_PROGRESS_OFF: - setSupportProgressBarIndeterminateVisibility(false); - break; - case MSG_SKIPPED_ATTACHMENTS: - Toast.makeText( - MessageCompose.this, - getString(R.string.message_compose_attachments_skipped_toast), - Toast.LENGTH_LONG).show(); - break; - case MSG_SAVED_DRAFT: - Toast.makeText( - MessageCompose.this, - getString(R.string.message_saved_toast), - Toast.LENGTH_LONG).show(); - break; - case MSG_DISCARDED_DRAFT: - Toast.makeText( - MessageCompose.this, - getString(R.string.message_discarded_toast), - Toast.LENGTH_LONG).show(); - break; - case MSG_PERFORM_STALLED_ACTION: - performStalledAction(); - break; - default: - super.handleMessage(msg); - break; + case MSG_PROGRESS_ON: + setSupportProgressBarIndeterminateVisibility(true); + break; + case MSG_PROGRESS_OFF: + setSupportProgressBarIndeterminateVisibility(false); + break; + case MSG_SKIPPED_ATTACHMENTS: + Toast.makeText( + MessageCompose.this, + getString(R.string.message_compose_attachments_skipped_toast), + Toast.LENGTH_LONG).show(); + break; + case MSG_SAVED_DRAFT: + Toast.makeText( + MessageCompose.this, + getString(R.string.message_saved_toast), + Toast.LENGTH_LONG).show(); + break; + case MSG_DISCARDED_DRAFT: + Toast.makeText( + MessageCompose.this, + getString(R.string.message_discarded_toast), + Toast.LENGTH_LONG).show(); + break; + case MSG_PERFORM_STALLED_ACTION: + performStalledAction(); + break; + default: + super.handleMessage(msg); + break; } } }; @@ -562,8 +562,9 @@ public class MessageCompose extends K9Activity implements OnClickListener, mMessageReference = intent.getParcelableExtra(EXTRA_MESSAGE_REFERENCE); mSourceMessageBody = intent.getStringExtra(EXTRA_MESSAGE_BODY); - if (K9.DEBUG && mSourceMessageBody != null) + if (K9.DEBUG && mSourceMessageBody != null) { Log.d(K9.LOG_TAG, "Composing message with explicitly specified message body."); + } final String accountUuid = (mMessageReference != null) ? mMessageReference.accountUuid : @@ -871,7 +872,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, } initializeCrypto(); - + final CryptoProvider crypto = mAccount.getCryptoProvider(); mOpenPgpProvider = mAccount.getOpenPgpProvider(); if (mOpenPgpProvider != null) { @@ -880,7 +881,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, // bind to service mOpenPgpServiceConnection = new OpenPgpServiceConnection(this, mOpenPgpProvider); mOpenPgpServiceConnection.bindToService(); - + mEncryptLayout.setVisibility(View.VISIBLE); mCryptoSignatureCheckbox.setOnClickListener(new OnClickListener() { @Override @@ -949,7 +950,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, setTitle(); } - + @Override public void onDestroy() { super.onDestroy(); @@ -1390,16 +1391,14 @@ public class MessageCompose extends K9Activity implements OnClickListener, textBodyBuilder.setAppendSignature(true); textBodyBuilder.setSignature(mSignatureView.getCharacters()); textBodyBuilder.setSignatureBeforeQuotedText(mAccount.isSignatureBeforeQuotedText()); - } - else { + } else { textBodyBuilder.setAppendSignature(false); } TextBody body; if (messageFormat == SimpleMessageFormat.HTML) { body = textBodyBuilder.buildTextHtml(); - } - else { + } else { body = textBodyBuilder.buildTextPlain(); } return body; @@ -1552,8 +1551,8 @@ public class MessageCompose extends K9Activity implements OnClickListener, * title*3="isn't it!" */ bp.addHeader(MimeHeader.HEADER_CONTENT_DISPOSITION, String.format(Locale.US, - "attachment;\r\n filename=\"%s\";\r\n size=%d", - attachment.name, attachment.size)); + "attachment;\r\n filename=\"%s\";\r\n size=%d", + attachment.name, attachment.size)); mp.addBodyPart(bp); } @@ -1686,8 +1685,9 @@ public class MessageCompose extends K9Activity implements OnClickListener, private Map parseIdentityHeader(final String identityString) { Map identity = new HashMap(); - if (K9.DEBUG) + if (K9.DEBUG) { Log.d(K9.LOG_TAG, "Decoding identity: " + identityString); + } if (identityString == null || identityString.length() < 1) { return identity; @@ -1705,8 +1705,9 @@ public class MessageCompose extends K9Activity implements OnClickListener, } } - if (K9.DEBUG) + if (K9.DEBUG) { Log.d(K9.LOG_TAG, "Decoded identity: " + identity.toString()); + } // Sanity check our Integers so that recipients of this result don't have to. for (IdentityField key : IdentityField.getIntegerFields()) { @@ -1721,8 +1722,9 @@ public class MessageCompose extends K9Activity implements OnClickListener, } else { // Legacy identity - if (K9.DEBUG) + if (K9.DEBUG) { Log.d(K9.LOG_TAG, "Got a saved legacy identity: " + identityString); + } StringTokenizer tokenizer = new StringTokenizer(identityString, ":", false); // First item is the body length. We use this to separate the composed reply from the quoted text. @@ -1806,7 +1808,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, private void performSend() { final CryptoProvider crypto = mAccount.getCryptoProvider(); - + if (mOpenPgpProvider != null) { // OpenPGP Provider API @@ -1824,19 +1826,19 @@ public class MessageCompose extends K9Activity implements OnClickListener, } emailsArray = emails.toArray(new String[emails.size()]); } - if (mEncryptCheckbox.isChecked() && mCryptoSignatureCheckbox.isChecked()) { - Intent intent = new Intent(OpenPgpApi.ACTION_SIGN_AND_ENCRYPT); - intent.putExtra(OpenPgpApi.EXTRA_USER_IDS, emailsArray); - executeOpenPgpMethod(intent); - } else if (mCryptoSignatureCheckbox.isChecked()) { - String text = buildText(false).getText(); - Intent intent = new Intent(OpenPgpApi.ACTION_SIGN); - executeOpenPgpMethod(intent); - } else if (mEncryptCheckbox.isChecked()) { - Intent intent = new Intent(OpenPgpApi.ACTION_ENCRYPT); - intent.putExtra(OpenPgpApi.EXTRA_USER_IDS, emailsArray); - executeOpenPgpMethod(intent); - } + if (mEncryptCheckbox.isChecked() && mCryptoSignatureCheckbox.isChecked()) { + Intent intent = new Intent(OpenPgpApi.ACTION_SIGN_AND_ENCRYPT); + intent.putExtra(OpenPgpApi.EXTRA_USER_IDS, emailsArray); + executeOpenPgpMethod(intent); + } else if (mCryptoSignatureCheckbox.isChecked()) { + String text = buildText(false).getText(); + Intent intent = new Intent(OpenPgpApi.ACTION_SIGN); + executeOpenPgpMethod(intent); + } else if (mEncryptCheckbox.isChecked()) { + Intent intent = new Intent(OpenPgpApi.ACTION_ENCRYPT); + intent.putExtra(OpenPgpApi.EXTRA_USER_IDS, emailsArray); + executeOpenPgpMethod(intent); + } // onSend() is called again in SignEncryptCallback and with // encryptedData set in pgpData! @@ -1844,7 +1846,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, } } else if (crypto.isAvailable(this)) { // Legacy APG API - + if (mEncryptCheckbox.isChecked() && !mPgpData.hasEncryptionKeys()) { // key selection before encryption StringBuilder emails = new StringBuilder(); @@ -1884,8 +1886,9 @@ public class MessageCompose extends K9Activity implements OnClickListener, sendMessage(); if (mMessageReference != null && mMessageReference.flag != null) { - if (K9.DEBUG) + if (K9.DEBUG) { Log.d(K9.LOG_TAG, "Setting referenced message (" + mMessageReference.folderName + ", " + mMessageReference.uid + ") flag to " + mMessageReference.flag); + } final Account account = Preferences.getPreferences(this).getAccount(mMessageReference.accountUuid); final String folderName = mMessageReference.folderName; @@ -1896,7 +1899,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, mDraftNeedsSaving = false; finish(); } - + private InputStream getOpenPgpInputStream() { String text = buildText(false).getText(); @@ -1908,7 +1911,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, } return is; } - + private void executeOpenPgpMethod(Intent intent) { intent.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true); // this follows user id format of OpenPGP to allow key generation based on it @@ -1924,7 +1927,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OpenPgpApi api = new OpenPgpApi(this, mOpenPgpServiceConnection.getService()); api.executeApiAsync(intent, is, os, callback); } - + /** * Called on successful encrypt/verify */ @@ -1945,8 +1948,8 @@ public class MessageCompose extends K9Activity implements OnClickListener, final String output = os.toString("UTF-8"); if (K9.DEBUG) - Log.d(OpenPgpApi.TAG, "result: " + os.toByteArray().length - + " str=" + output); + Log.d(OpenPgpApi.TAG, "result: " + os.toByteArray().length + + " str=" + output); mPgpData.setEncryptedData(output); onSend(); @@ -1974,7 +1977,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, } } } - + private void handleOpenPgpErrors(final OpenPgpError error) { runOnUiThread(new Runnable() { @@ -1982,7 +1985,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, public void run() { Log.e(K9.LOG_TAG, "OpenPGP Error ID:" + error.getErrorId()); Log.e(K9.LOG_TAG, "OpenPGP Error Message:" + error.getMessage()); - + Toast.makeText(MessageCompose.this, getString(R.string.openpgp_error) + " " + error.getMessage(), Toast.LENGTH_LONG).show(); @@ -2260,7 +2263,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, protected void onActivityResult(int requestCode, int resultCode, Intent data) { // if a CryptoSystem activity is returning, then mPreventDraftSaving was set to true mPreventDraftSaving = false; - + // OpenPGP: try again after user interaction if (resultCode == RESULT_OK && requestCode == REQUEST_CODE_SIGN_ENCRYPT) { /* @@ -2278,71 +2281,72 @@ public class MessageCompose extends K9Activity implements OnClickListener, return; } - if (resultCode != RESULT_OK) + if (resultCode != RESULT_OK) { return; + } if (data == null) { return; } switch (requestCode) { - case ACTIVITY_REQUEST_PICK_ATTACHMENT: - addAttachmentsFromResultIntent(data); - mDraftNeedsSaving = true; - break; - case CONTACT_PICKER_TO: - case CONTACT_PICKER_CC: - case CONTACT_PICKER_BCC: - ContactItem contact = mContacts.extractInfoFromContactPickerIntent(data); - if (contact == null) { - Toast.makeText(this, getString(R.string.error_contact_address_not_found), Toast.LENGTH_LONG).show(); - return; - } - if (contact.emailAddresses.size() > 1) { - Intent i = new Intent(this, EmailAddressList.class); - i.putExtra(EmailAddressList.EXTRA_CONTACT_ITEM, contact); + case ACTIVITY_REQUEST_PICK_ATTACHMENT: + addAttachmentsFromResultIntent(data); + mDraftNeedsSaving = true; + break; + case CONTACT_PICKER_TO: + case CONTACT_PICKER_CC: + case CONTACT_PICKER_BCC: + ContactItem contact = mContacts.extractInfoFromContactPickerIntent(data); + if (contact == null) { + Toast.makeText(this, getString(R.string.error_contact_address_not_found), Toast.LENGTH_LONG).show(); + return; + } + if (contact.emailAddresses.size() > 1) { + Intent i = new Intent(this, EmailAddressList.class); + i.putExtra(EmailAddressList.EXTRA_CONTACT_ITEM, contact); + if (requestCode == CONTACT_PICKER_TO) { + startActivityForResult(i, CONTACT_PICKER_TO2); + } else if (requestCode == CONTACT_PICKER_CC) { + startActivityForResult(i, CONTACT_PICKER_CC2); + } else if (requestCode == CONTACT_PICKER_BCC) { + startActivityForResult(i, CONTACT_PICKER_BCC2); + } + return; + } + if (K9.DEBUG) { + List emails = contact.emailAddresses; + for (int i = 0; i < emails.size(); i++) { + Log.v(K9.LOG_TAG, "email[" + i + "]: " + emails.get(i)); + } + } + + + String email = contact.emailAddresses.get(0); if (requestCode == CONTACT_PICKER_TO) { - startActivityForResult(i, CONTACT_PICKER_TO2); + addAddress(mToView, new Address(email, "")); } else if (requestCode == CONTACT_PICKER_CC) { - startActivityForResult(i, CONTACT_PICKER_CC2); + addAddress(mCcView, new Address(email, "")); } else if (requestCode == CONTACT_PICKER_BCC) { - startActivityForResult(i, CONTACT_PICKER_BCC2); + addAddress(mBccView, new Address(email, "")); + } else { + return; } - return; - } - if (K9.DEBUG) { - List emails = contact.emailAddresses; - for (int i = 0; i < emails.size(); i++) { - Log.v(K9.LOG_TAG, "email[" + i + "]: " + emails.get(i)); + + + + break; + case CONTACT_PICKER_TO2: + case CONTACT_PICKER_CC2: + case CONTACT_PICKER_BCC2: + String emailAddr = data.getStringExtra(EmailAddressList.EXTRA_EMAIL_ADDRESS); + if (requestCode == CONTACT_PICKER_TO2) { + addAddress(mToView, new Address(emailAddr, "")); + } else if (requestCode == CONTACT_PICKER_CC2) { + addAddress(mCcView, new Address(emailAddr, "")); + } else if (requestCode == CONTACT_PICKER_BCC2) { + addAddress(mBccView, new Address(emailAddr, "")); } - } - - - String email = contact.emailAddresses.get(0); - if (requestCode == CONTACT_PICKER_TO) { - addAddress(mToView, new Address(email, "")); - } else if (requestCode == CONTACT_PICKER_CC) { - addAddress(mCcView, new Address(email, "")); - } else if (requestCode == CONTACT_PICKER_BCC) { - addAddress(mBccView, new Address(email, "")); - } else { - return; - } - - - - break; - case CONTACT_PICKER_TO2: - case CONTACT_PICKER_CC2: - case CONTACT_PICKER_BCC2: - String emailAddr = data.getStringExtra(EmailAddressList.EXTRA_EMAIL_ADDRESS); - if (requestCode == CONTACT_PICKER_TO2) { - addAddress(mToView, new Address(emailAddr, "")); - } else if (requestCode == CONTACT_PICKER_CC2) { - addAddress(mCcView, new Address(emailAddr, "")); - } else if (requestCode == CONTACT_PICKER_BCC2) { - addAddress(mBccView, new Address(emailAddr, "")); - } - break; + break; } } @@ -2459,39 +2463,39 @@ public class MessageCompose extends K9Activity implements OnClickListener, @Override public void onClick(View view) { switch (view.getId()) { - case R.id.attachment_delete: - /* - * The view is the delete button, and we have previously set the tag of - * the delete button to the view that owns it. We don't use parent because the - * view is very complex and could change in the future. - */ - mAttachments.removeView((View) view.getTag()); - mDraftNeedsSaving = true; - break; - case R.id.quoted_text_show: - showOrHideQuotedText(QuotedTextMode.SHOW); - updateMessageFormat(); - mDraftNeedsSaving = true; - break; - case R.id.quoted_text_delete: - showOrHideQuotedText(QuotedTextMode.HIDE); - updateMessageFormat(); - mDraftNeedsSaving = true; - break; - case R.id.quoted_text_edit: - mForcePlainText = true; - if (mMessageReference != null) { // shouldn't happen... - // TODO - Should we check if mSourceMessageBody is already present and bypass the MessagingController call? - MessagingController.getInstance(getApplication()).addListener(mListener); - final Account account = Preferences.getPreferences(this).getAccount(mMessageReference.accountUuid); - final String folderName = mMessageReference.folderName; - final String sourceMessageUid = mMessageReference.uid; - MessagingController.getInstance(getApplication()).loadMessageForView(account, folderName, sourceMessageUid, null); - } - break; - case R.id.identity: - showDialog(DIALOG_CHOOSE_IDENTITY); - break; + case R.id.attachment_delete: + /* + * The view is the delete button, and we have previously set the tag of + * the delete button to the view that owns it. We don't use parent because the + * view is very complex and could change in the future. + */ + mAttachments.removeView((View) view.getTag()); + mDraftNeedsSaving = true; + break; + case R.id.quoted_text_show: + showOrHideQuotedText(QuotedTextMode.SHOW); + updateMessageFormat(); + mDraftNeedsSaving = true; + break; + case R.id.quoted_text_delete: + showOrHideQuotedText(QuotedTextMode.HIDE); + updateMessageFormat(); + mDraftNeedsSaving = true; + break; + case R.id.quoted_text_edit: + mForcePlainText = true; + if (mMessageReference != null) { // shouldn't happen... + // TODO - Should we check if mSourceMessageBody is already present and bypass the MessagingController call? + MessagingController.getInstance(getApplication()).addListener(mListener); + final Account account = Preferences.getPreferences(this).getAccount(mMessageReference.accountUuid); + final String folderName = mMessageReference.folderName; + final String sourceMessageUid = mMessageReference.uid; + MessagingController.getInstance(getApplication()).loadMessageForView(account, folderName, sourceMessageUid, null); + } + break; + case R.id.identity: + showDialog(DIALOG_CHOOSE_IDENTITY); + break; } } @@ -2538,36 +2542,36 @@ public class MessageCompose extends K9Activity implements OnClickListener, @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { - case R.id.send: - mPgpData.setEncryptionKeys(null); - onSend(); - break; - case R.id.save: - if (mEncryptCheckbox.isChecked()) { - showDialog(DIALOG_REFUSE_TO_SAVE_DRAFT_MARKED_ENCRYPTED); - } else { - onSave(); - } - break; - case R.id.discard: - onDiscard(); - break; - case R.id.add_cc_bcc: - onAddCcBcc(); - break; - case R.id.add_attachment: - onAddAttachment(); - break; - case R.id.add_attachment_image: - onAddAttachment2("image/*"); - break; - case R.id.add_attachment_video: - onAddAttachment2("video/*"); - break; - case R.id.read_receipt: - onReadReceipt(); - default: - return super.onOptionsItemSelected(item); + case R.id.send: + mPgpData.setEncryptionKeys(null); + onSend(); + break; + case R.id.save: + if (mEncryptCheckbox.isChecked()) { + showDialog(DIALOG_REFUSE_TO_SAVE_DRAFT_MARKED_ENCRYPTED); + } else { + onSave(); + } + break; + case R.id.discard: + onDiscard(); + break; + case R.id.add_cc_bcc: + onAddCcBcc(); + break; + case R.id.add_attachment: + onAddAttachment(); + break; + case R.id.add_attachment_image: + onAddAttachment2("image/*"); + break; + case R.id.add_attachment_video: + onAddAttachment2("video/*"); + break; + case R.id.read_receipt: + onReadReceipt(); + default: + return super.onOptionsItemSelected(item); } return true; } @@ -2665,94 +2669,94 @@ public class MessageCompose extends K9Activity implements OnClickListener, @Override public Dialog onCreateDialog(int id) { switch (id) { - case DIALOG_SAVE_OR_DISCARD_DRAFT_MESSAGE: - return new AlertDialog.Builder(this) - .setTitle(R.string.save_or_discard_draft_message_dlg_title) - .setMessage(R.string.save_or_discard_draft_message_instructions_fmt) - .setPositiveButton(R.string.save_draft_action, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int whichButton) { - dismissDialog(DIALOG_SAVE_OR_DISCARD_DRAFT_MESSAGE); - onSave(); - } - }) - .setNegativeButton(R.string.discard_action, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int whichButton) { - dismissDialog(DIALOG_SAVE_OR_DISCARD_DRAFT_MESSAGE); - onDiscard(); - } - }) - .create(); - case DIALOG_REFUSE_TO_SAVE_DRAFT_MARKED_ENCRYPTED: - return new AlertDialog.Builder(this) - .setTitle(R.string.refuse_to_save_draft_marked_encrypted_dlg_title) - .setMessage(R.string.refuse_to_save_draft_marked_encrypted_instructions_fmt) - .setNeutralButton(R.string.okay_action, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int whichButton) { - dismissDialog(DIALOG_REFUSE_TO_SAVE_DRAFT_MARKED_ENCRYPTED); - } - }) - .create(); - case DIALOG_CONTINUE_WITHOUT_PUBLIC_KEY: - return new AlertDialog.Builder(this) - .setTitle(R.string.continue_without_public_key_dlg_title) - .setMessage(R.string.continue_without_public_key_instructions_fmt) - .setPositiveButton(R.string.continue_action, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int whichButton) { - dismissDialog(DIALOG_CONTINUE_WITHOUT_PUBLIC_KEY); - mContinueWithoutPublicKey = true; - onSend(); - } - }) - .setNegativeButton(R.string.back_action, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int whichButton) { - dismissDialog(DIALOG_CONTINUE_WITHOUT_PUBLIC_KEY); - mContinueWithoutPublicKey = false; - } - }) - .create(); - case DIALOG_CONFIRM_DISCARD_ON_BACK: - return new AlertDialog.Builder(this) - .setTitle(R.string.confirm_discard_draft_message_title) - .setMessage(R.string.confirm_discard_draft_message) - .setPositiveButton(R.string.cancel_action, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int whichButton) { - dismissDialog(DIALOG_CONFIRM_DISCARD_ON_BACK); - } - }) - .setNegativeButton(R.string.discard_action, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int whichButton) { - dismissDialog(DIALOG_CONFIRM_DISCARD_ON_BACK); - Toast.makeText(MessageCompose.this, - getString(R.string.message_discarded_toast), - Toast.LENGTH_LONG).show(); - onDiscard(); - } - }) - .create(); - case DIALOG_CHOOSE_IDENTITY: - Context context = new ContextThemeWrapper(this, - (K9.getK9Theme() == K9.Theme.LIGHT) ? - R.style.Theme_K9_Dialog_Light : - R.style.Theme_K9_Dialog_Dark); - Builder builder = new AlertDialog.Builder(context); - builder.setTitle(R.string.send_as); - final IdentityAdapter adapter = new IdentityAdapter(context); - builder.setAdapter(adapter, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - IdentityContainer container = (IdentityContainer) adapter.getItem(which); - onAccountChosen(container.account, container.identity); - } - }); + case DIALOG_SAVE_OR_DISCARD_DRAFT_MESSAGE: + return new AlertDialog.Builder(this) + .setTitle(R.string.save_or_discard_draft_message_dlg_title) + .setMessage(R.string.save_or_discard_draft_message_instructions_fmt) + .setPositiveButton(R.string.save_draft_action, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int whichButton) { + dismissDialog(DIALOG_SAVE_OR_DISCARD_DRAFT_MESSAGE); + onSave(); + } + }) + .setNegativeButton(R.string.discard_action, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int whichButton) { + dismissDialog(DIALOG_SAVE_OR_DISCARD_DRAFT_MESSAGE); + onDiscard(); + } + }) + .create(); + case DIALOG_REFUSE_TO_SAVE_DRAFT_MARKED_ENCRYPTED: + return new AlertDialog.Builder(this) + .setTitle(R.string.refuse_to_save_draft_marked_encrypted_dlg_title) + .setMessage(R.string.refuse_to_save_draft_marked_encrypted_instructions_fmt) + .setNeutralButton(R.string.okay_action, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int whichButton) { + dismissDialog(DIALOG_REFUSE_TO_SAVE_DRAFT_MARKED_ENCRYPTED); + } + }) + .create(); + case DIALOG_CONTINUE_WITHOUT_PUBLIC_KEY: + return new AlertDialog.Builder(this) + .setTitle(R.string.continue_without_public_key_dlg_title) + .setMessage(R.string.continue_without_public_key_instructions_fmt) + .setPositiveButton(R.string.continue_action, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int whichButton) { + dismissDialog(DIALOG_CONTINUE_WITHOUT_PUBLIC_KEY); + mContinueWithoutPublicKey = true; + onSend(); + } + }) + .setNegativeButton(R.string.back_action, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int whichButton) { + dismissDialog(DIALOG_CONTINUE_WITHOUT_PUBLIC_KEY); + mContinueWithoutPublicKey = false; + } + }) + .create(); + case DIALOG_CONFIRM_DISCARD_ON_BACK: + return new AlertDialog.Builder(this) + .setTitle(R.string.confirm_discard_draft_message_title) + .setMessage(R.string.confirm_discard_draft_message) + .setPositiveButton(R.string.cancel_action, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int whichButton) { + dismissDialog(DIALOG_CONFIRM_DISCARD_ON_BACK); + } + }) + .setNegativeButton(R.string.discard_action, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int whichButton) { + dismissDialog(DIALOG_CONFIRM_DISCARD_ON_BACK); + Toast.makeText(MessageCompose.this, + getString(R.string.message_discarded_toast), + Toast.LENGTH_LONG).show(); + onDiscard(); + } + }) + .create(); + case DIALOG_CHOOSE_IDENTITY: + Context context = new ContextThemeWrapper(this, + (K9.getK9Theme() == K9.Theme.LIGHT) ? + R.style.Theme_K9_Dialog_Light : + R.style.Theme_K9_Dialog_Dark); + Builder builder = new AlertDialog.Builder(context); + builder.setTitle(R.string.send_as); + final IdentityAdapter adapter = new IdentityAdapter(context); + builder.setAdapter(adapter, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + IdentityContainer container = (IdentityContainer) adapter.getItem(which); + onAccountChosen(container.account, container.identity); + } + }); - return builder.create(); + return builder.create(); } return super.onCreateDialog(id); } @@ -2889,8 +2893,9 @@ public class MessageCompose extends K9Activity implements OnClickListener, } } else { - if (K9.DEBUG) + if (K9.DEBUG) { Log.d(K9.LOG_TAG, "could not get Message-ID."); + } } // Quote the message and setup the UI. @@ -3283,10 +3288,10 @@ public class MessageCompose extends K9Activity implements OnClickListener, List start = new ArrayList(); List end = new ArrayList(); - while(blockquoteStart.find()) { + while (blockquoteStart.find()) { start.add(blockquoteStart.start()); } - while(blockquoteEnd.find()) { + while (blockquoteEnd.find()) { end.add(blockquoteEnd.start()); } if (start.size() != end.size()) { @@ -3301,8 +3306,8 @@ public class MessageCompose extends K9Activity implements OnClickListener, } else { for (int i = 0; i < start.size() - 1; i++) { // within blockquotes. - if (end.get(i) < start.get(i+1)) { - dashSignatureHtml.region(end.get(i), start.get(i+1)); + if (end.get(i) < start.get(i + 1)) { + dashSignatureHtml.region(end.get(i), start.get(i + 1)); if (dashSignatureHtml.find()) { content = content.substring(0, dashSignatureHtml.start()); break; @@ -3389,30 +3394,34 @@ public class MessageCompose extends K9Activity implements OnClickListener, // HTML takes precedence, then text. part = MimeUtility.findFirstPartByMimeType(message, "text/html"); if (part != null) { - if (K9.DEBUG) + if (K9.DEBUG) { Log.d(K9.LOG_TAG, "getBodyTextFromMessage: HTML requested, HTML found."); + } return MimeUtility.getTextFromPart(part); } part = MimeUtility.findFirstPartByMimeType(message, "text/plain"); if (part != null) { - if (K9.DEBUG) + if (K9.DEBUG) { Log.d(K9.LOG_TAG, "getBodyTextFromMessage: HTML requested, text found."); + } return HtmlConverter.textToHtml(MimeUtility.getTextFromPart(part)); } } else if (format == SimpleMessageFormat.TEXT) { // Text takes precedence, then html. part = MimeUtility.findFirstPartByMimeType(message, "text/plain"); if (part != null) { - if (K9.DEBUG) + if (K9.DEBUG) { Log.d(K9.LOG_TAG, "getBodyTextFromMessage: Text requested, text found."); + } return MimeUtility.getTextFromPart(part); } part = MimeUtility.findFirstPartByMimeType(message, "text/html"); if (part != null) { - if (K9.DEBUG) + if (K9.DEBUG) { Log.d(K9.LOG_TAG, "getBodyTextFromMessage: Text requested, HTML found."); + } return HtmlConverter.htmlToText(MimeUtility.getTextFromPart(part)); } } @@ -3479,8 +3488,9 @@ public class MessageCompose extends K9Activity implements OnClickListener, hasBodyTag = true; } - if (K9.DEBUG) + if (K9.DEBUG) { Log.d(K9.LOG_TAG, "Open: hasHtmlTag:" + hasHtmlTag + " hasHeadTag:" + hasHeadTag + " hasBodyTag:" + hasBodyTag); + } // Given our inspections, let's figure out where to start our content. // This is the ideal case -- there's a BODY tag and we insert ourselves just after it. @@ -3531,8 +3541,9 @@ public class MessageCompose extends K9Activity implements OnClickListener, hasBodyEndTag = true; } - if (K9.DEBUG) + if (K9.DEBUG) { Log.d(K9.LOG_TAG, "Close: hasHtmlEndTag:" + hasHtmlEndTag + " hasBodyEndTag:" + hasBodyEndTag); + } // Now figure out where to put our footer. // This is the ideal case -- there's a BODY tag and we insert ourselves just before it. diff --git a/src/com/fsck/k9/mail/internet/TextBodyBuilder.java b/src/com/fsck/k9/mail/internet/TextBodyBuilder.java index 2a403f124..ac17126c8 100644 --- a/src/com/fsck/k9/mail/internet/TextBodyBuilder.java +++ b/src/com/fsck/k9/mail/internet/TextBodyBuilder.java @@ -76,13 +76,13 @@ public class TextBodyBuilder { */ if (mReplyAfterQuote) { quotedHtmlContent.setInsertionLocation( - InsertableHtmlContent.InsertionLocation.AFTER_QUOTE); + InsertableHtmlContent.InsertionLocation.AFTER_QUOTE); if (mInsertSeparator) { text = "
" + text; } } else { quotedHtmlContent.setInsertionLocation( - InsertableHtmlContent.InsertionLocation.BEFORE_QUOTE); + InsertableHtmlContent.InsertionLocation.BEFORE_QUOTE); if (mInsertSeparator) { text += "

"; } diff --git a/tests-on-jvm/src/com/fsck/k9/mail/internet/TextBodyBuilderTest.java b/tests-on-jvm/src/com/fsck/k9/mail/internet/TextBodyBuilderTest.java index 28d7d5143..de7701b6a 100644 --- a/tests-on-jvm/src/com/fsck/k9/mail/internet/TextBodyBuilderTest.java +++ b/tests-on-jvm/src/com/fsck/k9/mail/internet/TextBodyBuilderTest.java @@ -12,13 +12,13 @@ import com.fsck.k9.activity.InsertableHtmlContent; class TestingTextBodyBuilder extends TextBodyBuilder { public TestingTextBodyBuilder(boolean includeQuotedText, - boolean isDraft, - QuoteStyle quoteStyle, - boolean replyAfterQuote, - boolean signatureBeforeQuotedText, - boolean useSignature, - String messageText, - String signatureText) { + boolean isDraft, + QuoteStyle quoteStyle, + boolean replyAfterQuote, + boolean signatureBeforeQuotedText, + boolean useSignature, + String messageText, + String signatureText) { super(messageText); includeQuotedText = (isDraft || includeQuotedText); @@ -56,15 +56,15 @@ public class TextBodyBuilderTest { public static boolean[] BOOLEANS = { true, false }; @DataPoints - public static QuoteStyle[] QUOTESTYLES = {QuoteStyle.PREFIX, QuoteStyle.HEADER}; + public static QuoteStyle[] QUOTESTYLES = { QuoteStyle.PREFIX, QuoteStyle.HEADER }; @Theory public void testBuildTextPlain(boolean includeQuotedText, - QuoteStyle quoteStyle, - boolean isReplyAfterQuote, - boolean isSignatureUse, - boolean isSignatureBeforeQuotedText, - boolean isDraft) { + QuoteStyle quoteStyle, + boolean isReplyAfterQuote, + boolean isSignatureUse, + boolean isSignatureBeforeQuotedText, + boolean isDraft) { String expectedText; int expectedMessageLength; @@ -130,14 +130,14 @@ public class TextBodyBuilderTest { String signatureText = "signature"; TestingTextBodyBuilder textBodyBuilder = new TestingTextBodyBuilder( - includeQuotedText, - isDraft, - quoteStyle, - isReplyAfterQuote, - isSignatureBeforeQuotedText, - isSignatureUse, - messageText, - signatureText + includeQuotedText, + isDraft, + quoteStyle, + isReplyAfterQuote, + isSignatureBeforeQuotedText, + isSignatureUse, + messageText, + signatureText ); textBodyBuilder.setQuotedText(quotedText); TextBody textBody = textBodyBuilder.buildTextPlain(); @@ -147,7 +147,7 @@ public class TextBodyBuilderTest { assertThat(textBody.getComposedMessageLength(), is(expectedMessageLength)); assertThat(textBody.getComposedMessageOffset(), is(expectedMessagePosition)); assertThat(textBody.getText().substring(expectedMessagePosition, expectedMessagePosition + expectedMessageLength), - is("message content")); + is("message content")); } /** @@ -163,26 +163,27 @@ public class TextBodyBuilderTest { * * @see InsertableHtmlContent#toDebugString() */ - public String makeExpectedHtmlContent(String expectedText, String quotedContent, int footerInsertionPoint, boolean isBefore, - String userContent, String compiledResult) { + public String makeExpectedHtmlContent(String expectedText, String quotedContent, + int footerInsertionPoint, boolean isBefore, + String userContent, String compiledResult) { String expectedHtmlContent = "InsertableHtmlContent{" - + "headerInsertionPoint=0," - + " footerInsertionPoint=" + footerInsertionPoint + "," - + " insertionLocation=" + (isBefore ? "BEFORE_QUOTE" : "AFTER_QUOTE") + "," - + " quotedContent=" + quotedContent + "," - + " userContent=" + userContent + "," - + " compiledResult=" + compiledResult - + "}"; + + "headerInsertionPoint=0," + + " footerInsertionPoint=" + footerInsertionPoint + "," + + " insertionLocation=" + (isBefore ? "BEFORE_QUOTE" : "AFTER_QUOTE") + "," + + " quotedContent=" + quotedContent + "," + + " userContent=" + userContent + "," + + " compiledResult=" + compiledResult + + "}"; return expectedHtmlContent; } @Theory public void testBuildTextHtml(boolean includeQuotedText, - QuoteStyle quoteStyle, - boolean isReplyAfterQuote, - boolean isSignatureUse, - boolean isSignatureBeforeQuotedText, - boolean isDraft) { + QuoteStyle quoteStyle, + boolean isReplyAfterQuote, + boolean isSignatureUse, + boolean isSignatureBeforeQuotedText, + boolean isDraft) { String expectedText; int expectedMessageLength; int expectedMessagePosition = 0; @@ -203,7 +204,7 @@ public class TextBodyBuilderTest { // 3.signature if (quoteStyle == QuoteStyle.PREFIX && isReplyAfterQuote) { expectedText = expectedPrefix - + "message content"; + + "message content"; if (!isDraft && isSignatureUse) { expectedText += "\r\n" + "signature"; } @@ -213,17 +214,17 @@ public class TextBodyBuilderTest { if (isDraft || includeQuotedText) { expectedHtmlContent = makeExpectedHtmlContent(expectedText, quotedContent, - 0, - false, - expectedText, - expectedText + quotedContent); + 0, + false, + expectedText, + expectedText + quotedContent); expectedText += quotedContent; } else { expectedHtmlContent = makeExpectedHtmlContent(expectedText, quotedContent, - 0, - true, - "", - quotedContent); + 0, + true, + "", + quotedContent); // expectedText += quotedContent; } } @@ -232,7 +233,7 @@ public class TextBodyBuilderTest { // 3.quoted text else if (isSignatureBeforeQuotedText) { expectedText = expectedPrefix - + "message content"; + + "message content"; if (!isDraft && isSignatureUse) { expectedText += "\r\n" + "signature"; } @@ -244,17 +245,17 @@ public class TextBodyBuilderTest { if (isDraft || includeQuotedText) { expectedHtmlContent = makeExpectedHtmlContent(expectedText, quotedContent, - 0, - true, - expectedText, - expectedText + quotedContent); + 0, + true, + expectedText, + expectedText + quotedContent); expectedText += quotedContent; } else { expectedHtmlContent = makeExpectedHtmlContent(expectedText, quotedContent, - 0, - true, - "", - quotedContent); + 0, + true, + "", + quotedContent); // expectedText += quotedContent; } } @@ -265,7 +266,7 @@ public class TextBodyBuilderTest { String expectedSignature = ""; expectedText = expectedPrefix - + "message content"; + + "message content"; if (!isDraft && isSignatureUse) { if (!includeQuotedText) { @@ -282,17 +283,17 @@ public class TextBodyBuilderTest { if (isDraft || includeQuotedText) { expectedHtmlContent = makeExpectedHtmlContent(expectedText, expectedSignature + quotedContent, - expectedSignature.length(), - true, - expectedText, - expectedText + expectedSignature + quotedContent); + expectedSignature.length(), + true, + expectedText, + expectedText + expectedSignature + quotedContent); expectedText += expectedSignature + quotedContent; } else { expectedHtmlContent = makeExpectedHtmlContent(expectedText, quotedContent, - 0, - true, - "", - quotedContent); + 0, + true, + "", + quotedContent); // expectedText += quotedContent; } } @@ -305,14 +306,14 @@ public class TextBodyBuilderTest { String signatureText = "signature"; TestingTextBodyBuilder textBodyBuilder = new TestingTextBodyBuilder( - includeQuotedText, - isDraft, - quoteStyle, - isReplyAfterQuote, - isSignatureBeforeQuotedText, - isSignatureUse, - messageText, - signatureText + includeQuotedText, + isDraft, + quoteStyle, + isReplyAfterQuote, + isSignatureBeforeQuotedText, + isSignatureUse, + messageText, + signatureText ); textBodyBuilder.setQuotedTextHtml(insertableHtmlContent); TextBody textBody = textBodyBuilder.buildTextHtml(); From e2cffa074fa966eaadc6d89e85d94a90beb45c62 Mon Sep 17 00:00:00 2001 From: cketti Date: Sat, 3 May 2014 06:33:33 +0200 Subject: [PATCH 16/16] Update/remove comments --- .../k9/mail/internet/TextBodyBuilder.java | 21 ------------------- 1 file changed, 21 deletions(-) diff --git a/src/com/fsck/k9/mail/internet/TextBodyBuilder.java b/src/com/fsck/k9/mail/internet/TextBodyBuilder.java index ac17126c8..96e19e9e9 100644 --- a/src/com/fsck/k9/mail/internet/TextBodyBuilder.java +++ b/src/com/fsck/k9/mail/internet/TextBodyBuilder.java @@ -9,14 +9,12 @@ import com.fsck.k9.helper.StringUtils; import com.fsck.k9.mail.Body; public class TextBodyBuilder { - // option private boolean mIncludeQuotedText = true; private boolean mReplyAfterQuote = false; private boolean mSignatureBeforeQuotedText = false; private boolean mInsertSeparator = false; private boolean mAppendSignature = true; - // message parts private String mMessageContent; private String mSignature; private String mQuotedText; @@ -29,12 +27,6 @@ public class TextBodyBuilder { /** * Build the {@link Body} that will contain the text of the message. * - *

- * Draft messages are treated somewhat differently in that signatures are - * not appended and HTML separators between composed text and quoted text - * are not added. - *

- * * @return {@link TextBody} instance that contains the entered text and * possibly the quoted original message. */ @@ -127,12 +119,6 @@ public class TextBodyBuilder { /** * Build the {@link Body} that will contain the text of the message. * - *

- * Draft messages are treated somewhat differently in that signatures are - * not appended and HTML separators between composed text and quoted text - * are not added. - *

- * * @return {@link TextBody} instance that contains the entered text and * possibly the quoted original message. */ @@ -198,11 +184,6 @@ public class TextBodyBuilder { return signature; } - /** - * Get an HTML version of the signature in the #mSignatureView, if any. - * - * @return HTML version of signature. - */ private String getSignatureHtml() { String signature = ""; if (!StringUtils.isNullOrEmpty(mSignature)) { @@ -227,8 +208,6 @@ public class TextBodyBuilder { return HtmlConverter.textToHtmlFragment(text); } - // setter - public void setSignature(String signature) { mSignature = signature; }