1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-23 18:02:15 -05:00
This commit is contained in:
Koji Arai 2014-05-02 13:18:36 +09:00
parent 4260dc75d3
commit 215ada2e77
2 changed files with 92 additions and 106 deletions

View File

@ -28,13 +28,13 @@ public class TextBodyBuilder {
/** /**
* Build the {@link Body} that will contain the text of the message. * Build the {@link Body} that will contain the text of the message.
* *
* <p> * <p>
* Draft messages are treated somewhat differently in that signatures are * Draft messages are treated somewhat differently in that signatures are
* not appended and HTML separators between composed text and quoted text * not appended and HTML separators between composed text and quoted text
* are not added. * are not added.
* </p> * </p>
* *
* @return {@link TextBody} instance that contains the entered text and * @return {@link TextBody} instance that contains the entered text and
* possibly the quoted original message. * possibly the quoted original message.
*/ */
@ -76,14 +76,13 @@ public class TextBodyBuilder {
*/ */
if (mReplyAfterQuote) { if (mReplyAfterQuote) {
quotedHtmlContent.setInsertionLocation( quotedHtmlContent.setInsertionLocation(
InsertableHtmlContent.InsertionLocation.AFTER_QUOTE); InsertableHtmlContent.InsertionLocation.AFTER_QUOTE);
if (mInsertSeparator) { if (mInsertSeparator) {
text = "<br clear=\"all\">" + text; text = "<br clear=\"all\">" + text;
} }
} } else {
else {
quotedHtmlContent.setInsertionLocation( quotedHtmlContent.setInsertionLocation(
InsertableHtmlContent.InsertionLocation.BEFORE_QUOTE); InsertableHtmlContent.InsertionLocation.BEFORE_QUOTE);
if (mInsertSeparator) { if (mInsertSeparator) {
text += "<br><br>"; text += "<br><br>";
} }
@ -103,8 +102,7 @@ public class TextBodyBuilder {
composedMessageOffset = quotedHtmlContent.getInsertionPoint(); composedMessageOffset = quotedHtmlContent.getInsertionPoint();
text = quotedHtmlContent.toString(); text = quotedHtmlContent.toString();
} } else {
else {
// There is no text to quote so simply append the signature if available // There is no text to quote so simply append the signature if available
if (mAppendSignature) { if (mAppendSignature) {
text += getSignature(); text += getSignature();
@ -128,13 +126,13 @@ public class TextBodyBuilder {
/** /**
* Build the {@link Body} that will contain the text of the message. * Build the {@link Body} that will contain the text of the message.
* *
* <p> * <p>
* Draft messages are treated somewhat differently in that signatures are * Draft messages are treated somewhat differently in that signatures are
* not appended and HTML separators between composed text and quoted text * not appended and HTML separators between composed text and quoted text
* are not added. * are not added.
* </p> * </p>
* *
* @return {@link TextBody} instance that contains the entered text and * @return {@link TextBody} instance that contains the entered text and
* possibly the quoted original message. * possibly the quoted original message.
*/ */
@ -176,8 +174,7 @@ public class TextBodyBuilder {
text += getSignature(); text += getSignature();
} }
} }
} } else {
else {
// There is no text to quote so simply append the signature if available // There is no text to quote so simply append the signature if available
if (mAppendSignature) { if (mAppendSignature) {
// Append signature to the text/reply // 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. * Get an HTML version of the signature in the #mSignatureView, if any.
* *
* @return HTML version of signature. * @return HTML version of signature.
*/ */
private String getSignatureHtml() { private String getSignatureHtml() {

View File

@ -11,21 +11,19 @@ import com.fsck.k9.activity.InsertableHtmlContent;
class TestingTextBodyBuilder extends TextBodyBuilder { class TestingTextBodyBuilder extends TextBodyBuilder {
public TestingTextBodyBuilder( public TestingTextBodyBuilder(boolean includeQuotedText,
boolean includeQuotedText, boolean isDraft,
boolean isDraft, QuoteStyle quoteStyle,
QuoteStyle quoteStyle, boolean replyAfterQuote,
boolean replyAfterQuote, boolean signatureBeforeQuotedText,
boolean signatureBeforeQuotedText, boolean signatureUse,
boolean signatureUse, String messageContent,
String messageContent, String signature) {
String signature) {
super(messageContent); super(messageContent);
if (isDraft || includeQuotedText) { if (isDraft || includeQuotedText) {
this.setIncludeQuotedText(true); this.setIncludeQuotedText(true);
} } else {
else {
this.setIncludeQuotedText(false); this.setIncludeQuotedText(false);
} }
@ -36,8 +34,7 @@ class TestingTextBodyBuilder extends TextBodyBuilder {
if (quoteStyle == QuoteStyle.PREFIX && replyAfterQuote) { if (quoteStyle == QuoteStyle.PREFIX && replyAfterQuote) {
this.setReplyAfterQuote(true); this.setReplyAfterQuote(true);
} } else {
else {
this.setReplyAfterQuote(false); this.setReplyAfterQuote(false);
} }
@ -64,14 +61,12 @@ public class TextBodyBuilderTest {
public static QuoteStyle[] QUOTESTYLES = {QuoteStyle.PREFIX, QuoteStyle.HEADER}; public static QuoteStyle[] QUOTESTYLES = {QuoteStyle.PREFIX, QuoteStyle.HEADER};
@Theory @Theory
public void testBuildTextPlain( public void testBuildTextPlain(boolean includeQuotedText,
boolean includeQuotedText, QuoteStyle quoteStyle,
QuoteStyle quoteStyle, boolean isReplyAfterQuote,
boolean isReplyAfterQuote, boolean isSignatureUse,
boolean isSignatureUse, boolean isSignatureBeforeQuotedText,
boolean isSignatureBeforeQuotedText, boolean isDraft) {
boolean isDraft
) {
String expectedText; String expectedText;
int expectedMessageLength; int expectedMessageLength;
@ -137,15 +132,15 @@ public class TextBodyBuilderTest {
String signature = "signature"; String signature = "signature";
TestingTextBodyBuilder textBodyBuilder = new TestingTextBodyBuilder( TestingTextBodyBuilder textBodyBuilder = new TestingTextBodyBuilder(
includeQuotedText, includeQuotedText,
isDraft, isDraft,
quoteStyle, quoteStyle,
isReplyAfterQuote, isReplyAfterQuote,
isSignatureBeforeQuotedText, isSignatureBeforeQuotedText,
isSignatureUse, isSignatureUse,
messageContent, messageContent,
signature signature
); );
textBodyBuilder.setQuotedText(quotedText); textBodyBuilder.setQuotedText(quotedText);
TextBody textBody = textBodyBuilder.buildTextPlain(); TextBody textBody = textBodyBuilder.buildTextPlain();
@ -154,12 +149,12 @@ public class TextBodyBuilderTest {
assertThat(textBody.getComposedMessageLength(), is(expectedMessageLength)); assertThat(textBody.getComposedMessageLength(), is(expectedMessageLength));
assertThat(textBody.getComposedMessageOffset(), is(expectedMessagePosition)); assertThat(textBody.getComposedMessageOffset(), is(expectedMessagePosition));
assertThat(textBody.getText().substring(expectedMessagePosition, expectedMessagePosition + expectedMessageLength), assertThat(textBody.getText().substring(expectedMessagePosition, expectedMessagePosition + expectedMessageLength),
is("message content")); is("message content"));
} }
/** /**
* generate expected HtmlContent debug string * generate expected HtmlContent debug string
* *
* @param expectedText * @param expectedText
* @param quotedContent * @param quotedContent
* @param footerInsertionPoint * @param footerInsertionPoint
@ -167,31 +162,29 @@ public class TextBodyBuilderTest {
* @param userContent * @param userContent
* @param compiledResult * @param compiledResult
* @return expected string * @return expected string
* *
* @see InsertableHtmlContent#toDebugString() * @see InsertableHtmlContent#toDebugString()
*/ */
public String makeExpectedHtmlContent(String expectedText, String quotedContent, int footerInsertionPoint, boolean isBefore, public String makeExpectedHtmlContent(String expectedText, String quotedContent, int footerInsertionPoint, boolean isBefore,
String userContent, String compiledResult) { String userContent, String compiledResult) {
String expectedHtmlContent = "InsertableHtmlContent{" String expectedHtmlContent = "InsertableHtmlContent{"
+ "headerInsertionPoint=0," + "headerInsertionPoint=0,"
+ " footerInsertionPoint=" + footerInsertionPoint + "," + " footerInsertionPoint=" + footerInsertionPoint + ","
+ " insertionLocation=" + (isBefore ? "BEFORE_QUOTE" : "AFTER_QUOTE") + "," + " insertionLocation=" + (isBefore ? "BEFORE_QUOTE" : "AFTER_QUOTE") + ","
+ " quotedContent=" + quotedContent + "," + " quotedContent=" + quotedContent + ","
+ " userContent=" + userContent + "," + " userContent=" + userContent + ","
+ " compiledResult=" + compiledResult + " compiledResult=" + compiledResult
+ "}"; + "}";
return expectedHtmlContent; return expectedHtmlContent;
} }
@Theory @Theory
public void testBuildTextHtml( public void testBuildTextHtml(boolean includeQuotedText,
boolean includeQuotedText, QuoteStyle quoteStyle,
QuoteStyle quoteStyle, boolean isReplyAfterQuote,
boolean isReplyAfterQuote, boolean isSignatureUse,
boolean isSignatureUse, boolean isSignatureBeforeQuotedText,
boolean isSignatureBeforeQuotedText, boolean isDraft) {
boolean isDraft
) {
String expectedText; String expectedText;
int expectedMessageLength; int expectedMessageLength;
int expectedMessagePosition = 0; int expectedMessagePosition = 0;
@ -212,7 +205,7 @@ public class TextBodyBuilderTest {
// 3.signature // 3.signature
if (quoteStyle == QuoteStyle.PREFIX && isReplyAfterQuote) { if (quoteStyle == QuoteStyle.PREFIX && isReplyAfterQuote) {
expectedText = expectedPrefix expectedText = expectedPrefix
+ "<html>message content"; + "<html>message content";
if (!isDraft && isSignatureUse) { if (!isDraft && isSignatureUse) {
expectedText += "\r\n" + "signature"; expectedText += "\r\n" + "signature";
} }
@ -222,18 +215,17 @@ public class TextBodyBuilderTest {
if (isDraft || includeQuotedText) { if (isDraft || includeQuotedText) {
expectedHtmlContent = makeExpectedHtmlContent(expectedText, quotedContent, expectedHtmlContent = makeExpectedHtmlContent(expectedText, quotedContent,
0, 0,
false, false,
expectedText, expectedText,
expectedText + quotedContent); expectedText + quotedContent);
expectedText += quotedContent; expectedText += quotedContent;
} } else {
else {
expectedHtmlContent = makeExpectedHtmlContent(expectedText, quotedContent, expectedHtmlContent = makeExpectedHtmlContent(expectedText, quotedContent,
0, 0,
true, true,
"", "",
quotedContent); quotedContent);
// expectedText += quotedContent; // expectedText += quotedContent;
} }
} }
@ -242,7 +234,7 @@ public class TextBodyBuilderTest {
// 3.quoted text // 3.quoted text
else if (isSignatureBeforeQuotedText) { else if (isSignatureBeforeQuotedText) {
expectedText = expectedPrefix expectedText = expectedPrefix
+ "<html>message content"; + "<html>message content";
if (!isDraft && isSignatureUse) { if (!isDraft && isSignatureUse) {
expectedText += "\r\n" + "signature"; expectedText += "\r\n" + "signature";
} }
@ -254,18 +246,17 @@ public class TextBodyBuilderTest {
if (isDraft || includeQuotedText) { if (isDraft || includeQuotedText) {
expectedHtmlContent = makeExpectedHtmlContent(expectedText, quotedContent, expectedHtmlContent = makeExpectedHtmlContent(expectedText, quotedContent,
0, 0,
true, true,
expectedText, expectedText,
expectedText + quotedContent); expectedText + quotedContent);
expectedText += quotedContent; expectedText += quotedContent;
} } else {
else {
expectedHtmlContent = makeExpectedHtmlContent(expectedText, quotedContent, expectedHtmlContent = makeExpectedHtmlContent(expectedText, quotedContent,
0, 0,
true, true,
"", "",
quotedContent); quotedContent);
// expectedText += quotedContent; // expectedText += quotedContent;
} }
} }
@ -276,13 +267,12 @@ public class TextBodyBuilderTest {
String expectedSignature = ""; String expectedSignature = "";
expectedText = expectedPrefix expectedText = expectedPrefix
+ "<html>message content"; + "<html>message content";
if (!isDraft && isSignatureUse) { if (!isDraft && isSignatureUse) {
if (!includeQuotedText) { if (!includeQuotedText) {
expectedText += "\r\n" + "signature"; expectedText += "\r\n" + "signature";
} } else {
else {
expectedSignature = "<html>\r\nsignature</html>"; expectedSignature = "<html>\r\nsignature</html>";
} }
} }
@ -294,18 +284,17 @@ public class TextBodyBuilderTest {
if (isDraft || includeQuotedText) { if (isDraft || includeQuotedText) {
expectedHtmlContent = makeExpectedHtmlContent(expectedText, expectedSignature + quotedContent, expectedHtmlContent = makeExpectedHtmlContent(expectedText, expectedSignature + quotedContent,
expectedSignature.length(), expectedSignature.length(),
true, true,
expectedText, expectedText,
expectedText + expectedSignature + quotedContent); expectedText + expectedSignature + quotedContent);
expectedText += expectedSignature + quotedContent; expectedText += expectedSignature + quotedContent;
} } else {
else {
expectedHtmlContent = makeExpectedHtmlContent(expectedText, quotedContent, expectedHtmlContent = makeExpectedHtmlContent(expectedText, quotedContent,
0, 0,
true, true,
"", "",
quotedContent); quotedContent);
// expectedText += quotedContent; // expectedText += quotedContent;
} }
} }
@ -318,15 +307,15 @@ public class TextBodyBuilderTest {
String signature = "signature"; String signature = "signature";
TestingTextBodyBuilder textBodyBuilder = new TestingTextBodyBuilder( TestingTextBodyBuilder textBodyBuilder = new TestingTextBodyBuilder(
includeQuotedText, includeQuotedText,
isDraft, isDraft,
quoteStyle, quoteStyle,
isReplyAfterQuote, isReplyAfterQuote,
isSignatureBeforeQuotedText, isSignatureBeforeQuotedText,
isSignatureUse, isSignatureUse,
messageContent, messageContent,
signature signature
); );
textBodyBuilder.setQuotedTextHtml(insertableHtmlContent); textBodyBuilder.setQuotedTextHtml(insertableHtmlContent);
TextBody textBody = textBodyBuilder.buildTextHtml(); TextBody textBody = textBodyBuilder.buildTextHtml();