Fix search parsing

b/17231624
SearchParser delegates parsing of email contents to the
EmailSyncParser. Whenever it encounters a <Properties> tag,
it pushes that tag onto the EmailSyncParser, and then has
it parse and get message contents. It will keep doing this
until it encounters a </Properties> tag.
However, this means that that the </Properties> tag is no
longer in the input stream. The parent parser (SearchParser)
won't see it, so it won't remove it from its internal stack.
We must manually pop that from the stack or the parser is in
a confused state.

Change-Id: Ia3352fc16f8281d8fc597048df5e105ca7e6ba49
diff --git a/src/com/android/exchange/adapter/Parser.java b/src/com/android/exchange/adapter/Parser.java
index 7c57f17..c4c9218 100644
--- a/src/com/android/exchange/adapter/Parser.java
+++ b/src/com/android/exchange/adapter/Parser.java
@@ -420,7 +420,7 @@
         push(id);
     }
 
-    private void pop() {
+    protected void pop() {
         // Retrieve the now-current startTag from our stack
         startTag = startTagArray.removeFirst();
         log("</" + startTag + '>');
diff --git a/src/com/android/exchange/adapter/SearchParser.java b/src/com/android/exchange/adapter/SearchParser.java
index 7a65370..8b7bc85 100644
--- a/src/com/android/exchange/adapter/SearchParser.java
+++ b/src/com/android/exchange/adapter/SearchParser.java
@@ -114,7 +114,6 @@
 
     private boolean parseResult(EmailSyncParser parser,
             ArrayList<ContentProviderOperation> ops) throws IOException {
-        // Get an email sync parser for our incoming message data
         boolean res = false;
         Message msg = new Message();
         while (nextTag(Tags.SEARCH_RESULT) != END) {
@@ -128,7 +127,15 @@
                 msg.mAccountKey = mAccount.mId;
                 msg.mMailboxKey = mMailbox.mId;
                 msg.mFlagLoaded = Message.FLAG_LOADED_COMPLETE;
+                // Delegate parsing of the properties to the EmailSyncParser.
+
+                // We push a new <Properties> tag onto the EmailSyncParser. It will parse
+                // until it consumes the </Properties>
                 parser.pushTag(tag);
+                // Since the EmailSyncParser is responsible for consuming the </Properties>
+                // tag, we need to remove it from our stack or it will be double counted.
+                pop();
+
                 parser.addData(msg, tag);
                 if (msg.mHtml != null) {
                     msg.mHtml = TextUtilities.highlightTermsInHtml(msg.mHtml, mQuery);