From 8369df095a73a77b3715f8ae7ba06089cebca4ce Mon Sep 17 00:00:00 2001 From: Eric Erfanian Date: Wed, 3 May 2017 10:27:13 -0700 Subject: This change reflects the Dialer V10 RC00 branch. RC00 is based on: branch: dialer-android_release_branch/153304843.1 synced to: 153304843 following the instructions at go/dialer-aosp-release. In this release: * Removes final apache sources. * Uses native lite compilation. More drops will follow with subsequent release candidates until we reach our final v10 release, in cadence with our prebuilt drops. Test: TreeHugger, on device Change-Id: Ic9684057230f9b579c777820c746cd21bf45ec0f --- java/com/android/voicemail/impl/mail/Address.java | 8 +++-- .../voicemail/impl/mail/internet/MimeMessage.java | 40 ++++++++-------------- .../voicemail/impl/mail/internet/MimeUtility.java | 9 ++--- .../voicemail/impl/mail/store/ImapFolder.java | 36 +++++++++++-------- .../voicemail/impl/mail/store/ImapStore.java | 3 +- 5 files changed, 49 insertions(+), 47 deletions(-) (limited to 'java/com/android/voicemail/impl/mail') diff --git a/java/com/android/voicemail/impl/mail/Address.java b/java/com/android/voicemail/impl/mail/Address.java index 3a7a86607..ac8e8a294 100644 --- a/java/com/android/voicemail/impl/mail/Address.java +++ b/java/com/android/voicemail/impl/mail/Address.java @@ -25,8 +25,9 @@ import android.text.util.Rfc822Tokenizer; import com.android.voicemail.impl.mail.utils.LogUtils; import java.util.ArrayList; import java.util.regex.Pattern; +import org.apache.james.mime4j.codec.DecodeMonitor; +import org.apache.james.mime4j.codec.DecoderUtil; import org.apache.james.mime4j.codec.EncoderUtil; -import org.apache.james.mime4j.decoder.DecoderUtil; /** * This class represent email address. @@ -121,7 +122,8 @@ public class Address implements Parcelable { if (TextUtils.isEmpty(rawAddress)) { return null; } - String name, address; + String name; + String address; final Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(rawAddress); if (tokens.length > 0) { final String tokenizedName = tokens[0].getName(); @@ -171,7 +173,7 @@ public class Address implements Parcelable { if (personal != null) { personal = REMOVE_OPTIONAL_DQUOTE.matcher(personal).replaceAll("$1"); personal = UNQUOTE.matcher(personal).replaceAll("$1"); - personal = DecoderUtil.decodeEncodedWords(personal); + personal = DecoderUtil.decodeEncodedWords(personal, DecodeMonitor.STRICT); if (personal.length() == 0) { personal = null; } diff --git a/java/com/android/voicemail/impl/mail/internet/MimeMessage.java b/java/com/android/voicemail/impl/mail/internet/MimeMessage.java index dfb7d7c25..589720660 100644 --- a/java/com/android/voicemail/impl/mail/internet/MimeMessage.java +++ b/java/com/android/voicemail/impl/mail/internet/MimeMessage.java @@ -34,12 +34,14 @@ import java.util.Date; import java.util.Locale; import java.util.Stack; import java.util.regex.Pattern; -import org.apache.james.mime4j.BodyDescriptor; -import org.apache.james.mime4j.ContentHandler; -import org.apache.james.mime4j.EOLConvertingInputStream; -import org.apache.james.mime4j.MimeStreamParser; -import org.apache.james.mime4j.field.DateTimeField; -import org.apache.james.mime4j.field.Field; +import org.apache.james.mime4j.MimeException; +import org.apache.james.mime4j.dom.field.DateTimeField; +import org.apache.james.mime4j.field.DefaultFieldParser; +import org.apache.james.mime4j.io.EOLConvertingInputStream; +import org.apache.james.mime4j.parser.ContentHandler; +import org.apache.james.mime4j.parser.MimeStreamParser; +import org.apache.james.mime4j.stream.BodyDescriptor; +import org.apache.james.mime4j.stream.Field; /** * An implementation of Message that stores all of its metadata in RFC 822 and RFC 2045 style @@ -64,7 +66,6 @@ public class MimeMessage extends Message { private Body mBody; protected int mSize; private boolean mInhibitLocalMessageId = false; - private boolean mComplete = true; // Shared random source for generating local message-id values private static final java.util.Random sRandom = new java.util.Random(); @@ -114,7 +115,7 @@ public class MimeMessage extends Message { * @throws IOException * @throws MessagingException */ - public MimeMessage(InputStream in) throws IOException, MessagingException { + public MimeMessage(InputStream in) throws IOException, MessagingException, MimeException { parse(in); } @@ -136,17 +137,9 @@ public class MimeMessage extends Message { return parser; } - protected void parse(InputStream in) throws IOException, MessagingException { + public void parse(InputStream in) throws IOException, MessagingException, MimeException { final MimeStreamParser parser = init(); parser.parse(new EOLConvertingInputStream(in)); - mComplete = !parser.getPrematureEof(); - } - - public void parse(InputStream in, EOLConvertingInputStream.Callback callback) - throws IOException, MessagingException { - final MimeStreamParser parser = init(); - parser.parse(new EOLConvertingInputStream(in, getSize(), callback)); - mComplete = !parser.getPrematureEof(); } /** @@ -171,7 +164,8 @@ public class MimeMessage extends Message { try { DateTimeField field = (DateTimeField) - Field.parse("Date: " + MimeUtility.unfoldAndDecode(getFirstHeader("Date"))); + DefaultFieldParser.parse( + "Date: " + MimeUtility.unfoldAndDecode(getFirstHeader("Date"))); mSentDate = field.getDate(); // TODO: We should make it more clear what exceptions can be thrown here, // and whether they reflect a normal or error condition. @@ -184,7 +178,7 @@ public class MimeMessage extends Message { try { DateTimeField field = (DateTimeField) - Field.parse( + DefaultFieldParser.parse( "Date: " + MimeUtility.unfoldAndDecode(getFirstHeader("Delivery-date"))); mSentDate = field.getDate(); // TODO: We should make it more clear what exceptions can be thrown here, @@ -228,10 +222,6 @@ public class MimeMessage extends Message { } } - public boolean isComplete() { - return mComplete; - } - @Override public String getMimeType() throws MessagingException { return MimeUtility.getHeaderParameter(getContentType(), null); @@ -577,10 +567,10 @@ public class MimeMessage extends Message { } @Override - public void field(String fieldData) { + public void field(Field rawField) { expect(Part.class); try { - final String[] tokens = fieldData.split(":", 2); + final String[] tokens = rawField.getRaw().toString().split(":", 2); ((Part) stack.peek()).addHeader(tokens[0], tokens[1].trim()); } catch (MessagingException me) { throw new Error(me); diff --git a/java/com/android/voicemail/impl/mail/internet/MimeUtility.java b/java/com/android/voicemail/impl/mail/internet/MimeUtility.java index 99846027b..bd85e478c 100644 --- a/java/com/android/voicemail/impl/mail/internet/MimeUtility.java +++ b/java/com/android/voicemail/impl/mail/internet/MimeUtility.java @@ -34,9 +34,10 @@ import java.util.ArrayList; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.apache.commons.io.IOUtils; +import org.apache.james.mime4j.codec.DecodeMonitor; +import org.apache.james.mime4j.codec.DecoderUtil; import org.apache.james.mime4j.codec.EncoderUtil; -import org.apache.james.mime4j.decoder.DecoderUtil; -import org.apache.james.mime4j.decoder.QuotedPrintableInputStream; +import org.apache.james.mime4j.codec.QuotedPrintableInputStream; import org.apache.james.mime4j.util.CharsetUtil; public class MimeUtility { @@ -65,7 +66,7 @@ public class MimeUtility { if (s == null) { return null; } - return DecoderUtil.decodeEncodedWords(s); + return DecoderUtil.decodeEncodedWords(s, DecodeMonitor.STRICT); } public static String unfoldAndDecode(String s) { @@ -235,7 +236,7 @@ public class MimeUtility { /* * See if there is conversion from the MIME charset to the Java one. */ - charset = CharsetUtil.toJavaCharset(charset); + charset = CharsetUtil.lookup(charset).name(); } /* * No encoding, so use us-ascii, which is the standard. diff --git a/java/com/android/voicemail/impl/mail/store/ImapFolder.java b/java/com/android/voicemail/impl/mail/store/ImapFolder.java index 1d9b01120..5760ee216 100644 --- a/java/com/android/voicemail/impl/mail/store/ImapFolder.java +++ b/java/com/android/voicemail/impl/mail/store/ImapFolder.java @@ -22,6 +22,7 @@ import android.text.TextUtils; import android.util.ArrayMap; import android.util.Base64DataException; import com.android.voicemail.impl.OmtpEvents; +import com.android.voicemail.impl.VvmLog; import com.android.voicemail.impl.mail.AuthenticationFailedException; import com.android.voicemail.impl.mail.Body; import com.android.voicemail.impl.mail.FetchProfile; @@ -41,7 +42,6 @@ import com.android.voicemail.impl.mail.store.imap.ImapElement; import com.android.voicemail.impl.mail.store.imap.ImapList; import com.android.voicemail.impl.mail.store.imap.ImapResponse; import com.android.voicemail.impl.mail.store.imap.ImapString; -import com.android.voicemail.impl.mail.utils.LogUtils; import com.android.voicemail.impl.mail.utils.Utility; import java.io.IOException; import java.io.InputStream; @@ -66,7 +66,7 @@ public class ImapFolder { private String mMode; private boolean mExists; /** A set of hashes that can be used to track dirtiness */ - Object mHash[]; + Object[] mHash; public static final String MODE_READ_ONLY = "mode_read_only"; public static final String MODE_READ_WRITE = "mode_read_write"; @@ -136,7 +136,7 @@ public class ImapFolder { try { expunge(); } catch (MessagingException e) { - LogUtils.e(TAG, e, "Messaging Exception"); + VvmLog.e(TAG, "Messaging Exception", e); } } mMessageCount = -1; @@ -174,13 +174,13 @@ public class ImapFolder { try { final String command = ImapConstants.UID_SEARCH + " " + searchCriteria; final String[] result = getSearchUids(mConnection.executeSimpleCommand(command)); - LogUtils.d(TAG, "searchForUids '" + searchCriteria + "' results: " + result.length); + VvmLog.d(TAG, "searchForUids '" + searchCriteria + "' results: " + result.length); return result; } catch (ImapException me) { - LogUtils.d(TAG, "ImapException in search: " + searchCriteria, me); + VvmLog.d(TAG, "ImapException in search: " + searchCriteria, me); return Utility.EMPTY_STRINGS; // Not found } catch (IOException ioe) { - LogUtils.d(TAG, "IOException in search: " + searchCriteria, ioe); + VvmLog.d(TAG, "IOException in search: " + searchCriteria, ioe); mStore.getImapHelper().handleEvent(OmtpEvents.DATA_GENERIC_IMAP_IOE); throw ioExceptionHandler(mConnection, ioe); } @@ -199,7 +199,7 @@ public class ImapFolder { return new ImapMessage(uid, this); } } - LogUtils.e(TAG, "UID " + uid + " not found on server"); + VvmLog.e(TAG, "UID " + uid + " not found on server"); return null; } @@ -235,7 +235,7 @@ public class ImapFolder { try { fetchInternal(messages, fp, listener); } catch (RuntimeException e) { // Probably a parser error. - LogUtils.w(TAG, "Exception detected: " + e.getMessage()); + VvmLog.w(TAG, "Exception detected: " + e.getMessage()); throw e; } } @@ -346,7 +346,11 @@ public class ImapFolder { message.setInternalDate(internalDate); message.setSize(size); - message.parse(Utility.streamFromAsciiString(header)); + try { + message.parse(Utility.streamFromAsciiString(header)); + } catch (Exception e) { + VvmLog.e(TAG, "Error parsing header %s", e); + } } if (fp.contains(FetchProfile.Item.STRUCTURE)) { ImapList bs = fetchList.getKeyedListOrEmpty(ImapConstants.BODYSTRUCTURE); @@ -354,7 +358,7 @@ public class ImapFolder { try { parseBodyStructure(bs, message, ImapConstants.TEXT); } catch (MessagingException e) { - LogUtils.v(TAG, e, "Error handling message"); + VvmLog.v(TAG, "Error handling message", e); message.setBody(null); } } @@ -365,11 +369,15 @@ public class ImapFolder { // TODO Should we accept "RFC822" as well?? ImapString body = fetchList.getKeyedStringOrEmpty("BODY[]", true); InputStream bodyStream = body.getAsStream(); - message.parse(bodyStream); + try { + message.parse(bodyStream); + } catch (Exception e) { + VvmLog.e(TAG, "Error parsing body %s", e); + } } if (fetchPart != null) { InputStream bodyStream = fetchList.getKeyedStringOrEmpty("BODY[", true).getAsStream(); - String encodings[] = fetchPart.getHeader(MimeHeader.HEADER_CONTENT_TRANSFER_ENCODING); + String[] encodings = fetchPart.getHeader(MimeHeader.HEADER_CONTENT_TRANSFER_ENCODING); String contentTransferEncoding = null; if (encodings != null && encodings.length > 0) { @@ -397,7 +405,7 @@ public class ImapFolder { // from here. This blanket catch-all is because we're not sure what to // do if we don't have a contentTransferEncoding, and we don't have // time to figure out what exceptions might be thrown. - LogUtils.e(TAG, "Error fetching body %s", e); + VvmLog.e(TAG, "Error fetching body %s", e); } } @@ -782,7 +790,7 @@ public class ImapFolder { } private MessagingException ioExceptionHandler(ImapConnection connection, IOException ioe) { - LogUtils.d(TAG, "IO Exception detected: ", ioe); + VvmLog.d(TAG, "IO Exception detected: ", ioe); connection.close(); if (connection == mConnection) { mConnection = null; // To prevent close() from returning the connection to the pool. diff --git a/java/com/android/voicemail/impl/mail/store/ImapStore.java b/java/com/android/voicemail/impl/mail/store/ImapStore.java index cadbe593f..838bae257 100644 --- a/java/com/android/voicemail/impl/mail/store/ImapStore.java +++ b/java/com/android/voicemail/impl/mail/store/ImapStore.java @@ -25,6 +25,7 @@ import com.android.voicemail.impl.mail.MessagingException; import com.android.voicemail.impl.mail.internet.MimeMessage; import java.io.IOException; import java.io.InputStream; +import org.apache.james.mime4j.MimeException; public class ImapStore { /** @@ -112,7 +113,7 @@ public class ImapStore { } @Override - public void parse(InputStream in) throws IOException, MessagingException { + public void parse(InputStream in) throws IOException, MessagingException, MimeException { super.parse(in); } -- cgit v1.2.3