Warnings and Finals

Change-Id: I47f29c16c066eb077c64ef8c89e91df88d15caf0
This commit is contained in:
Tony Mantler 2014-04-29 11:45:44 -07:00
parent 5bf5dc9ea4
commit 4aec413a1e
1 changed files with 16 additions and 17 deletions

View File

@ -78,7 +78,7 @@ public class Rfc822Output {
* the <body> tag (e.g. a '>' in a java script block). * the <body> tag (e.g. a '>' in a java script block).
*/ */
/*package*/ static String getHtmlBody(String html) { /*package*/ static String getHtmlBody(String html) {
Matcher match = BODY_PATTERN.matcher(html); final Matcher match = BODY_PATTERN.matcher(html);
if (match.find()) { if (match.find()) {
return match.group(BODY_PATTERN_GROUP); // Found body; return return match.group(BODY_PATTERN_GROUP); // Found body; return
} else { } else {
@ -93,7 +93,7 @@ public class Rfc822Output {
if (body == null) { if (body == null) {
return new String[2]; return new String[2];
} }
String[] messageBody = new String[] { body.mTextContent, body.mHtmlContent }; final String[] messageBody = new String[] { body.mTextContent, body.mHtmlContent };
final int pos = body.mQuotedTextStartPos; final int pos = body.mQuotedTextStartPos;
if (useSmartReply && pos > 0) { if (useSmartReply && pos > 0) {
if (messageBody[0] != null) { if (messageBody[0] != null) {
@ -128,13 +128,13 @@ public class Rfc822Output {
return; return;
} }
OutputStream stream = new BufferedOutputStream(out, 1024); final OutputStream stream = new BufferedOutputStream(out, 1024);
Writer writer = new OutputStreamWriter(stream); final Writer writer = new OutputStreamWriter(stream);
// Write the fixed headers. Ordering is arbitrary (the legacy code iterated through a // Write the fixed headers. Ordering is arbitrary (the legacy code iterated through a
// hashmap here). // hashmap here).
String date = DATE_FORMAT.format(new Date(message.mTimeStamp)); final String date = DATE_FORMAT.format(new Date(message.mTimeStamp));
writeHeader(writer, "Date", date); writeHeader(writer, "Date", date);
writeEncodedHeader(writer, "Subject", message.mSubject); writeEncodedHeader(writer, "Subject", message.mSubject);
@ -153,8 +153,8 @@ public class Rfc822Output {
writeHeader(writer, "MIME-Version", "1.0"); writeHeader(writer, "MIME-Version", "1.0");
// Analyze message and determine if we have multiparts // Analyze message and determine if we have multiparts
Body body = Body.restoreBodyWithMessageId(context, message.mId); final Body body = Body.restoreBodyWithMessageId(context, message.mId);
String[] bodyText = buildBodyText(body, useSmartReply); final String[] bodyText = buildBodyText(body, useSmartReply);
// If a list of attachments hasn't been passed in, build one from the message // If a list of attachments hasn't been passed in, build one from the message
if (attachments == null) { if (attachments == null) {
@ -162,22 +162,21 @@ public class Rfc822Output {
Arrays.asList(Attachment.restoreAttachmentsWithMessageId(context, message.mId)); Arrays.asList(Attachment.restoreAttachmentsWithMessageId(context, message.mId));
} }
boolean multipart = attachments.size() > 0; final boolean multipart = attachments.size() > 0;
String multipartBoundary = null;
String multipartType = "mixed";
// Simplified case for no multipart - just emit text and be done. // Simplified case for no multipart - just emit text and be done.
if (!multipart) { if (!multipart) {
writeTextWithHeaders(writer, stream, bodyText); writeTextWithHeaders(writer, stream, bodyText);
} else { } else {
// continue with multipart headers, then into multipart body // continue with multipart headers, then into multipart body
multipartBoundary = getNextBoundary(); final String multipartBoundary = getNextBoundary();
String multipartType = "mixed";
// Move to the first attachment; this must succeed because multipart is true // Move to the first attachment; this must succeed because multipart is true
if (attachments.size() == 1) { if (attachments.size() == 1) {
// If we've got one attachment and it's an ics "attachment", we want to send // If we've got one attachment and it's an ics "attachment", we want to send
// this as multipart/alternative instead of multipart/mixed // this as multipart/alternative instead of multipart/mixed
int flags = attachments.get(0).mFlags; final int flags = attachments.get(0).mFlags;
if ((flags & Attachment.FLAG_ICS_ALTERNATIVE_PART) != 0) { if ((flags & Attachment.FLAG_ICS_ALTERNATIVE_PART) != 0) {
multipartType = "alternative"; multipartType = "alternative";
} }
@ -195,7 +194,7 @@ public class Rfc822Output {
} }
// Write out the attachments until we run out // Write out the attachments until we run out
for (Attachment att: attachments) { for (final Attachment att: attachments) {
writeBoundary(writer, multipartBoundary, false); writeBoundary(writer, multipartBoundary, false);
writeOneAttachment(context, writer, stream, att); writeOneAttachment(context, writer, stream, att);
writer.write("\r\n"); writer.write("\r\n");
@ -375,11 +374,11 @@ public class Rfc822Output {
writer.write("\r\n"); // a truly empty message writer.write("\r\n"); // a truly empty message
} else { } else {
// first multipart element is the body // first multipart element is the body
String mimeType = "text/" + (html ? "html" : "plain"); final String mimeType = "text/" + (html ? "html" : "plain");
writeHeader(writer, "Content-Type", mimeType + "; charset=utf-8"); writeHeader(writer, "Content-Type", mimeType + "; charset=utf-8");
writeHeader(writer, "Content-Transfer-Encoding", "base64"); writeHeader(writer, "Content-Transfer-Encoding", "base64");
writer.write("\r\n"); writer.write("\r\n");
byte[] textBytes = text.getBytes("UTF-8"); final byte[] textBytes = text.getBytes("UTF-8");
writer.flush(); writer.flush();
out.write(Base64.encode(textBytes, Base64.CRLF)); out.write(Base64.encode(textBytes, Base64.CRLF));
} }
@ -389,10 +388,10 @@ public class Rfc822Output {
* Returns a unique boundary string. * Returns a unique boundary string.
*/ */
/*package*/ static String getNextBoundary() { /*package*/ static String getNextBoundary() {
StringBuilder boundary = new StringBuilder(); final StringBuilder boundary = new StringBuilder();
boundary.append("--_com.android.email_").append(System.nanoTime()); boundary.append("--_com.android.email_").append(System.nanoTime());
synchronized (Rfc822Output.class) { synchronized (Rfc822Output.class) {
boundary = boundary.append(sBoundaryDigit); boundary.append(sBoundaryDigit);
sBoundaryDigit = (byte)((sBoundaryDigit + 1) % 10); sBoundaryDigit = (byte)((sBoundaryDigit + 1) % 10);
} }
return boundary.toString(); return boundary.toString();