Continue purging the unused reply parts

Change-Id: I47b5bbe50ba36e68ad7ba80647f401b992660ba1
This commit is contained in:
Tony Mantler 2014-04-18 14:04:23 -07:00
parent f0db9ce9ab
commit 3c73a04bec
6 changed files with 12 additions and 168 deletions

View File

@ -766,8 +766,6 @@ public abstract class EmailContent {
Uri.parse(EmailContent.CONTENT_NOTIFIER_URI + "/message");
}
public static final String KEY_TIMESTAMP_DESC = MessageColumns.TIMESTAMP + " desc";
public static final int CONTENT_ID_COLUMN = 0;
public static final int CONTENT_DISPLAY_NAME_COLUMN = 1;
public static final int CONTENT_TIMESTAMP_COLUMN = 2;
@ -960,11 +958,8 @@ public abstract class EmailContent {
// but they are NOT persisted directly by EmailProvider. See Body for related fields.
transient public String mText;
transient public String mHtml;
transient public String mTextReply;
transient public String mHtmlReply;
transient public long mSourceKey;
transient public ArrayList<Attachment> mAttachments = null;
transient public String mIntroText;
transient public int mQuotedTextStartPos;
@ -1116,7 +1111,7 @@ public abstract class EmailContent {
// This logic is in place so I can (a) short circuit the expensive stuff when
// possible, and (b) override (and throw) if anyone tries to call save() or update()
// directly for Message, which are unsupported.
if (mText == null && mHtml == null && mTextReply == null && mHtmlReply == null &&
if (mText == null && mHtml == null &&
(mAttachments == null || mAttachments.isEmpty())) {
if (doSave) {
return super.save(context);

View File

@ -67,13 +67,6 @@ public class LegacyConversions {
private static final HashMap<String, Integer>
sServerMailboxNames = new HashMap<String, Integer>();
/**
* Values for HEADER_ANDROID_BODY_QUOTED_PART to tag body parts
*/
/* package */ static final String BODY_QUOTED_PART_REPLY = "quoted-reply";
/* package */ static final String BODY_QUOTED_PART_FORWARD = "quoted-forward";
/* package */ static final String BODY_QUOTED_PART_INTRO = "quoted-intro";
/**
* Copy field-by-field from a "store" message to a "provider" message
*

View File

@ -337,9 +337,6 @@ public class LegacyConversionsTests extends ProviderTestCase2<EmailProvider> {
// Test message 2: Simple body
EmailContent.Message localMessage2 = ProviderTestUtils.setupMessage("make-legacy",
account1Id, mailbox1Id, true, false, mProviderContext);
localMessage2.mTextReply = null;
localMessage2.mHtmlReply = null;
localMessage2.mIntroText = null;
localMessage2.mFlags &= ~EmailContent.Message.FLAG_TYPE_MASK;
localMessage2.save(mProviderContext);
Message getMessage2 = LegacyConversions.makeMessage(mProviderContext, localMessage2);
@ -389,48 +386,16 @@ public class LegacyConversionsTests extends ProviderTestCase2<EmailProvider> {
MimeUtility.collectParts(actual, viewables, attachments);
String get1Text = null;
String get1Html = null;
String get1TextReply = null;
String get1HtmlReply = null;
String get1TextIntro = null;
for (Part viewable : viewables) {
String text = MimeUtility.getTextFromPart(viewable);
boolean isHtml = viewable.getMimeType().equalsIgnoreCase("text/html");
String[] headers = viewable.getHeader(MimeHeader.HEADER_ANDROID_BODY_QUOTED_PART);
if (headers != null) {
String header = headers[0];
boolean isReply = LegacyConversions.BODY_QUOTED_PART_REPLY.equalsIgnoreCase(header);
boolean isFwd = LegacyConversions.BODY_QUOTED_PART_FORWARD.equalsIgnoreCase(header);
boolean isIntro = LegacyConversions.BODY_QUOTED_PART_INTRO.equalsIgnoreCase(header);
if (isReply || isFwd) {
if (isHtml) {
get1HtmlReply = text;
} else {
get1TextReply = text;
}
} else if (isIntro) {
get1TextIntro = text;
}
// Check flags
int replyTypeFlags = expect.mFlags & EmailContent.Message.FLAG_TYPE_MASK;
if (isReply) {
assertEquals(tag, EmailContent.Message.FLAG_TYPE_REPLY, replyTypeFlags);
}
if (isFwd) {
assertEquals(tag, EmailContent.Message.FLAG_TYPE_FORWARD, replyTypeFlags);
}
if (viewable.getMimeType().equalsIgnoreCase("text/html")) {
get1Html = text;
} else {
if (isHtml) {
get1Html = text;
} else {
get1Text = text;
}
get1Text = text;
}
}
assertEquals(tag, expect.mText, get1Text);
assertEquals(tag, expect.mHtml, get1Html);
assertEquals(tag, expect.mTextReply, get1TextReply);
assertEquals(tag, expect.mHtmlReply, get1HtmlReply);
assertEquals(tag, expect.mIntroText, get1TextIntro);
// TODO Check the attachments

View File

@ -192,10 +192,7 @@ public class ProviderTestUtils extends Assert {
if (addBody) {
message.mText = "body text " + name;
message.mHtml = "body html " + name;
message.mTextReply = "reply text " + name;
message.mHtmlReply = "reply html " + name;
message.mSourceKey = 400 + name.length();
message.mIntroText = "intro text " + name;
}
if (saveIt) {
@ -426,10 +423,7 @@ public class ProviderTestUtils extends Assert {
assertEquals(caller + " mText", expect.mText, actual.mText);
assertEquals(caller + " mHtml", expect.mHtml, actual.mHtml);
assertEquals(caller + " mTextReply", expect.mTextReply, actual.mTextReply);
assertEquals(caller + " mHtmlReply", expect.mHtmlReply, actual.mHtmlReply);
assertEquals(caller + " mSourceKey", expect.mSourceKey, actual.mSourceKey);
assertEquals(caller + " mIntroText", expect.mIntroText, actual.mIntroText);
assertEquals(caller + " mQuotedTextStartPos", expect.mQuotedTextStartPos, actual.mQuotedTextStartPos);
}

View File

@ -464,10 +464,7 @@ public class ProviderTests extends ProviderTestCase2<EmailProvider> {
long sourceKey2 = message2.mSourceKey;
message2.mText = null;
message2.mHtml = null;
message2.mTextReply = null;
message2.mHtmlReply = null;
message2.mSourceKey = 0;
message2.mIntroText = null;
Message message2get = EmailContent.Message.restoreMessageWithId(mMockContext, message2Id);
ProviderTestUtils.assertMessageEqual("testMessageSave", message2, message2get);

View File

@ -54,30 +54,22 @@ public class Rfc822OutputTests extends ProviderTestCase2<EmailProvider> {
private static final String RECIPIENT_CC = "recipient-cc@android.com";
private static final String SUBJECT = "This is the subject";
private static final String REPLY_TEXT_BODY = "This is the body. This is also the body.";
/** HTML reply body */
private static final String BODY_HTML_REPLY =
"<a href=\"m.google.com\">This</a> is the body.<br>This is also the body.";
/** Text-only version of the HTML reply body */
private static final String BODY_TEXT_REPLY_HTML =
">This is the body.\n>This is also the body.";
private static final String TEXT = "Here is some new text.";
// Full HTML document
private static String HTML_FULL_BODY = "<html><head><title>MyTitle</title></head>"
private static final String HTML_FULL_BODY = "<html><head><title>MyTitle</title></head>"
+ "<body bgcolor=\"#ffffff\" text=\"#000000\">"
+ "<a href=\"google.com\">test1</a></body></html>";
private static String HTML_FULL_RESULT = "<a href=\"google.com\">test1</a>";
private static final String HTML_FULL_RESULT = "<a href=\"google.com\">test1</a>";
// <body/> element w/ content
private static String HTML_BODY_BODY =
private static final String HTML_BODY_BODY =
"<body bgcolor=\"#ffffff\" text=\"#000000\"><a href=\"google.com\">test2</a></body>";
private static String HTML_BODY_RESULT = "<a href=\"google.com\">test2</a>";
private static final String HTML_BODY_RESULT = "<a href=\"google.com\">test2</a>";
// No <body/> tag; just content
private static String HTML_NO_BODY_BODY =
private static final String HTML_NO_BODY_BODY =
"<a href=\"google.com\">test3</a>";
private static String HTML_NO_BODY_RESULT = "<a href=\"google.com\">test3</a>";
private static final String HTML_NO_BODY_RESULT = "<a href=\"google.com\">test3</a>";
private static String REPLY_INTRO_TEXT = "\n\n" + SENDER + " wrote:\n\n";
private static String REPLY_INTRO_HTML = "<br><br>" + SENDER + " wrote:<br><br>";
private Context mMockContext;
private String mForwardIntro;
@ -99,98 +91,8 @@ public class Rfc822OutputTests extends ProviderTestCase2<EmailProvider> {
// TODO Write test that ensures that bcc is handled properly (i.e. sent/not send depending
// on the flag passed to writeTo
private Message createTestMessage(String text, boolean save) {
Message message = new Message();
message.mText = text;
message.mFrom = SENDER;
message.mFlags = Message.FLAG_TYPE_REPLY;
message.mTextReply = REPLY_TEXT_BODY;
message.mHtmlReply = BODY_HTML_REPLY;
message.mIntroText = REPLY_INTRO_TEXT;
if (save) {
message.save(mMockContext);
}
return message;
}
private Body createTestBody(Message message) {
Body body = Body.restoreBodyWithMessageId(mMockContext, message.mId);
return body;
}
/**
* Test for buildBodyText().
* Compare with expected values.
* Also test the situation where the message has no body.
*/
public void testBuildBodyText() {
// Test sending a message *without* using smart reply
Message message1 = createTestMessage("", true);
Body body1 = createTestBody(message1);
String[] bodyParts;
bodyParts = Rfc822Output.buildBodyText(body1, false);
assertEquals(REPLY_INTRO_TEXT + ">" + REPLY_TEXT_BODY, bodyParts[0]);
message1.mId = -1; // Changing the message; need to reset the id
message1.mText = TEXT;
message1.save(mMockContext);
body1 = createTestBody(message1);
bodyParts = Rfc822Output.buildBodyText(body1, false);
assertEquals(TEXT + REPLY_INTRO_TEXT + ">" + REPLY_TEXT_BODY, bodyParts[0]);
// We have an HTML reply and no text reply; use the HTML reply
message1.mId = -1; // Changing the message; need to reset the id
message1.mTextReply = null;
message1.save(mMockContext);
body1 = createTestBody(message1);
bodyParts = Rfc822Output.buildBodyText(body1, false);
assertEquals(TEXT + REPLY_INTRO_TEXT + BODY_TEXT_REPLY_HTML, bodyParts[0]);
// We have no HTML or text reply; use nothing
message1.mId = -1; // Changing the message; need to reset the id
message1.mHtmlReply = null;
message1.save(mMockContext);
body1 = createTestBody(message1);
bodyParts = Rfc822Output.buildBodyText(body1, false);
assertEquals(TEXT + REPLY_INTRO_TEXT, bodyParts[0]);
// Test sending a message *with* using smart reply
Message message2 = createTestMessage("", true);
Body body2 = createTestBody(message2);
bodyParts = Rfc822Output.buildBodyText(body2, true);
assertEquals(REPLY_INTRO_TEXT, bodyParts[0]);
message2.mId = -1; // Changing the message; need to reset the id
message2.mText = TEXT;
message2.save(mMockContext);
body2 = createTestBody(message2);
bodyParts = Rfc822Output.buildBodyText(body2, true);
assertEquals(TEXT + REPLY_INTRO_TEXT, bodyParts[0]);
// We have an HTML reply and no text reply; use nothing (smart reply)
message2.mId = -1; // Changing the message; need to reset the id
message2.mTextReply = null;
message2.save(mMockContext);
body2 = createTestBody(message2);
bodyParts = Rfc822Output.buildBodyText(body2, true);
assertEquals(TEXT + REPLY_INTRO_TEXT, bodyParts[0]);
// We have no HTML or text reply; use nothing
message2.mId = -1; // Changing the message; need to reset the id
message2.mTextReply = null;
message2.mHtmlReply = null;
message2.save(mMockContext);
body2 = createTestBody(message2);
bodyParts = Rfc822Output.buildBodyText(body2, true);
assertEquals(TEXT + REPLY_INTRO_TEXT, bodyParts[0]);
return Body.restoreBodyWithMessageId(mMockContext, message.mId);
}
/**
@ -205,8 +107,6 @@ public class Rfc822OutputTests extends ProviderTestCase2<EmailProvider> {
msg.mCc = RECIPIENT_CC;
msg.mSubject = SUBJECT;
msg.mFlags = Message.FLAG_TYPE_FORWARD;
msg.mTextReply = REPLY_TEXT_BODY;
msg.mIntroText = mForwardIntro;
msg.save(mMockContext);
Body body = createTestBody(msg);
String[] bodyParts = Rfc822Output.buildBodyText(body, false);
@ -370,7 +270,7 @@ public class Rfc822OutputTests extends ProviderTestCase2<EmailProvider> {
assertEquals(0, Rfc822Output.sBoundaryDigit);
}
private final int BOUNDARY_COUNT = 12;
private static final int BOUNDARY_COUNT = 12;
public void testGetNextBoundary() {
String[] resultArray = new String[BOUNDARY_COUNT];
for (int i = 0; i < BOUNDARY_COUNT; i++) {