DO NOT MERGE: Send intro text with SmartForward
* We need to include the intro text (--Original Message--, etc.) to SmartForwards, and somehow this got in a past updat * Add unit test for forwarding * Fix unit test for reply so that it works localized Backport of I8d92f00d37a434840ec3eb237f3901cd5dc7ad09 Bug: 2477988 Bug: 2685784 Change-Id: I2b6654413a8eb5ca900f958f49ec9eee5161a365
This commit is contained in:
parent
ff0712cb1e
commit
9afbf947de
@ -70,17 +70,16 @@ public class Rfc822Output {
|
|||||||
int flags = message.mFlags;
|
int flags = message.mFlags;
|
||||||
boolean isReply = (flags & Message.FLAG_TYPE_REPLY) != 0;
|
boolean isReply = (flags & Message.FLAG_TYPE_REPLY) != 0;
|
||||||
boolean isForward = (flags & Message.FLAG_TYPE_FORWARD) != 0;
|
boolean isForward = (flags & Message.FLAG_TYPE_FORWARD) != 0;
|
||||||
String intro = body.mIntroText == null ? "" : body.mIntroText;
|
// For all forwards/replies, we add the intro text
|
||||||
|
if (isReply || isForward) {
|
||||||
|
String intro = body.mIntroText == null ? "" : body.mIntroText;
|
||||||
|
text += intro;
|
||||||
|
}
|
||||||
if (!appendQuotedText) {
|
if (!appendQuotedText) {
|
||||||
// appendQuotedText is set to false for use by SmartReply/SmartForward in EAS.
|
// appendQuotedText is set to false for use by SmartReply/SmartForward in EAS.
|
||||||
// SmartReply doesn't appear to work properly, so we will still add the header into
|
// SmartForward doesn't put a break between the original and new text, so we add an LF
|
||||||
// the original message.
|
if (isForward) {
|
||||||
// SmartForward doesn't put any kind of break between the original and the new text,
|
text += "\n";
|
||||||
// so we add a CRLF
|
|
||||||
if (isReply) {
|
|
||||||
text += intro;
|
|
||||||
} else if (isForward) {
|
|
||||||
text += "\r\n";
|
|
||||||
}
|
}
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
@ -92,13 +91,11 @@ public class Rfc822Output {
|
|||||||
quotedText = matcher.replaceAll("\n");
|
quotedText = matcher.replaceAll("\n");
|
||||||
}
|
}
|
||||||
if (isReply) {
|
if (isReply) {
|
||||||
text += intro;
|
|
||||||
if (quotedText != null) {
|
if (quotedText != null) {
|
||||||
Matcher matcher = PATTERN_START_OF_LINE.matcher(quotedText);
|
Matcher matcher = PATTERN_START_OF_LINE.matcher(quotedText);
|
||||||
text += matcher.replaceAll(">");
|
text += matcher.replaceAll(">");
|
||||||
}
|
}
|
||||||
} else if (isForward) {
|
} else if (isForward) {
|
||||||
text += intro;
|
|
||||||
if (quotedText != null) {
|
if (quotedText != null) {
|
||||||
text += quotedText;
|
text += quotedText;
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.email.mail.transport;
|
package com.android.email.mail.transport;
|
||||||
|
|
||||||
|
import com.android.email.R;
|
||||||
import com.android.email.mail.MessagingException;
|
import com.android.email.mail.MessagingException;
|
||||||
import com.android.email.provider.EmailProvider;
|
import com.android.email.provider.EmailProvider;
|
||||||
import com.android.email.provider.EmailContent.Attachment;
|
import com.android.email.provider.EmailContent.Attachment;
|
||||||
@ -52,10 +53,11 @@ public class Rfc822OutputTests extends ProviderTestCase2<EmailProvider> {
|
|||||||
private static final String SUBJECT = "This is the subject";
|
private static final String SUBJECT = "This is the subject";
|
||||||
private static final String BODY = "This is the body. This is also the body.";
|
private static final String BODY = "This is the body. This is also the body.";
|
||||||
private static final String TEXT = "Here is some new text.";
|
private static final String TEXT = "Here is some new text.";
|
||||||
private static final String REPLY_BODY_SHORT = "\n\n" + SENDER + " wrote:\n\n";
|
|
||||||
private static final String REPLY_BODY = REPLY_BODY_SHORT + ">" + BODY;
|
|
||||||
|
|
||||||
private Context mMockContext;
|
private Context mMockContext;
|
||||||
|
private String mForwardIntro;
|
||||||
|
private String mReplyIntro;
|
||||||
|
private String mReplyBody;
|
||||||
|
|
||||||
public Rfc822OutputTests () {
|
public Rfc822OutputTests () {
|
||||||
super(EmailProvider.class, EmailProvider.EMAIL_AUTHORITY);
|
super(EmailProvider.class, EmailProvider.EMAIL_AUTHORITY);
|
||||||
@ -65,6 +67,10 @@ public class Rfc822OutputTests extends ProviderTestCase2<EmailProvider> {
|
|||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
mMockContext = getMockContext();
|
mMockContext = getMockContext();
|
||||||
|
mForwardIntro = mMockContext.getString(R.string.message_compose_fwd_header_fmt, SUBJECT,
|
||||||
|
SENDER, RECIPIENT_TO, RECIPIENT_CC);
|
||||||
|
mReplyIntro = mMockContext.getString(R.string.message_compose_reply_header_fmt, SENDER);
|
||||||
|
mReplyBody = mReplyIntro + ">" + BODY;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Create more tests here. Specifically, we should test to make sure that forward works
|
// TODO Create more tests here. Specifically, we should test to make sure that forward works
|
||||||
@ -73,16 +79,10 @@ public class Rfc822OutputTests extends ProviderTestCase2<EmailProvider> {
|
|||||||
// TODO Write test that ensures that bcc is handled properly (i.e. sent/not send depending
|
// TODO Write test that ensures that bcc is handled properly (i.e. sent/not send depending
|
||||||
// on the flag passed to writeTo
|
// on the flag passed to writeTo
|
||||||
|
|
||||||
// TODO Localize the following test, which will not work properly in other than English
|
|
||||||
// speaking locales!
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for buildBodyText().
|
* Test for buildBodyText().
|
||||||
* Compare with expected values.
|
* Compare with expected values.
|
||||||
* Also test the situation where the message has no body.
|
* Also test the situation where the message has no body.
|
||||||
*
|
|
||||||
* WARNING: This test is NOT localized, so it will fail if run on a device in a
|
|
||||||
* non-English speaking locale!
|
|
||||||
*/
|
*/
|
||||||
public void testBuildBodyTextWithReply() {
|
public void testBuildBodyTextWithReply() {
|
||||||
// Create the least necessary; sender, flags, and the body of the reply
|
// Create the least necessary; sender, flags, and the body of the reply
|
||||||
@ -91,18 +91,18 @@ public class Rfc822OutputTests extends ProviderTestCase2<EmailProvider> {
|
|||||||
msg.mFrom = SENDER;
|
msg.mFrom = SENDER;
|
||||||
msg.mFlags = Message.FLAG_TYPE_REPLY;
|
msg.mFlags = Message.FLAG_TYPE_REPLY;
|
||||||
msg.mTextReply = BODY;
|
msg.mTextReply = BODY;
|
||||||
msg.mIntroText = REPLY_BODY_SHORT;
|
msg.mIntroText = mReplyIntro;
|
||||||
msg.save(mMockContext);
|
msg.save(mMockContext);
|
||||||
|
|
||||||
String body = Rfc822Output.buildBodyText(mMockContext, msg, true);
|
String body = Rfc822Output.buildBodyText(mMockContext, msg, true);
|
||||||
assertEquals(REPLY_BODY, body);
|
assertEquals(mReplyBody, body);
|
||||||
|
|
||||||
// Save a different message with no reply body (so we reset the id)
|
// Save a different message with no reply body (so we reset the id)
|
||||||
msg.mId = -1;
|
msg.mId = -1;
|
||||||
msg.mTextReply = null;
|
msg.mTextReply = null;
|
||||||
msg.save(mMockContext);
|
msg.save(mMockContext);
|
||||||
body = Rfc822Output.buildBodyText(mMockContext, msg, true);
|
body = Rfc822Output.buildBodyText(mMockContext, msg, true);
|
||||||
assertEquals(REPLY_BODY_SHORT, body);
|
assertEquals(mReplyIntro, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -117,18 +117,37 @@ public class Rfc822OutputTests extends ProviderTestCase2<EmailProvider> {
|
|||||||
msg.mFrom = SENDER;
|
msg.mFrom = SENDER;
|
||||||
msg.mFlags = Message.FLAG_TYPE_REPLY;
|
msg.mFlags = Message.FLAG_TYPE_REPLY;
|
||||||
msg.mTextReply = BODY;
|
msg.mTextReply = BODY;
|
||||||
msg.mIntroText = REPLY_BODY_SHORT;
|
msg.mIntroText = mReplyIntro;
|
||||||
msg.save(mMockContext);
|
msg.save(mMockContext);
|
||||||
|
|
||||||
String body = Rfc822Output.buildBodyText(mMockContext, msg, false);
|
String body = Rfc822Output.buildBodyText(mMockContext, msg, false);
|
||||||
assertEquals(TEXT + REPLY_BODY_SHORT, body);
|
assertEquals(TEXT + mReplyIntro, body);
|
||||||
|
|
||||||
// Save a different message with no reply body (so we reset the id)
|
// Save a different message with no reply body (so we reset the id)
|
||||||
msg.mId = -1;
|
msg.mId = -1;
|
||||||
msg.mTextReply = null;
|
msg.mTextReply = null;
|
||||||
msg.save(mMockContext);
|
msg.save(mMockContext);
|
||||||
body = Rfc822Output.buildBodyText(mMockContext, msg, false);
|
body = Rfc822Output.buildBodyText(mMockContext, msg, false);
|
||||||
assertEquals(TEXT + REPLY_BODY_SHORT, body);
|
assertEquals(TEXT + mReplyIntro, body);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for buildBodyText().
|
||||||
|
* Compare with expected values.
|
||||||
|
*/
|
||||||
|
public void testBuildBodyTextWithForward() {
|
||||||
|
Message msg = new Message();
|
||||||
|
msg.mText = TEXT;
|
||||||
|
msg.mFrom = SENDER;
|
||||||
|
msg.mTo = RECIPIENT_TO;
|
||||||
|
msg.mCc = RECIPIENT_CC;
|
||||||
|
msg.mSubject = SUBJECT;
|
||||||
|
msg.mFlags = Message.FLAG_TYPE_FORWARD;
|
||||||
|
msg.mTextReply = BODY;
|
||||||
|
msg.mIntroText = mForwardIntro;
|
||||||
|
msg.save(mMockContext);
|
||||||
|
String body = Rfc822Output.buildBodyText(mMockContext, msg, true);
|
||||||
|
assertEquals(TEXT + mForwardIntro + BODY, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWriteToText() throws IOException, MessagingException {
|
public void testWriteToText() throws IOException, MessagingException {
|
||||||
@ -201,6 +220,7 @@ public class Rfc822OutputTests extends ProviderTestCase2<EmailProvider> {
|
|||||||
assertNull(header.getField("content-disposition"));
|
assertNull(header.getField("content-disposition"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public void testWriteToMixedPart() throws IOException, MessagingException {
|
public void testWriteToMixedPart() throws IOException, MessagingException {
|
||||||
// Create a message with a mixed part
|
// Create a message with a mixed part
|
||||||
Message msg = new Message();
|
Message msg = new Message();
|
||||||
|
Loading…
Reference in New Issue
Block a user