summaryrefslogtreecommitdiffstats
path: root/provider_src/com
diff options
context:
space:
mode:
authorTony Mantler <nicoya@google.com>2014-10-01 13:27:01 -0700
committerTony Mantler <nicoya@google.com>2014-10-01 14:02:17 -0700
commitb62067e3c3ec01559568705df4908fe7f2860af9 (patch)
tree3a6d4a5c9e8c6a8a12111e9da72d4b03a2495e09 /provider_src/com
parent69ba565b62874d4957c28749494bef173490b0c1 (diff)
downloadandroid_packages_apps_Email-b62067e3c3ec01559568705df4908fe7f2860af9.tar.gz
android_packages_apps_Email-b62067e3c3ec01559568705df4908fe7f2860af9.tar.bz2
android_packages_apps_Email-b62067e3c3ec01559568705df4908fe7f2860af9.zip
Make sure old body files don't contaminate new messages
If we have an error writing an old body file and overwrite the same ID, we might end up in a situation where we have HTML from one message and Text from another. Clean up the body files before insert to avoid this. b/17720266 Change-Id: I2fb18fa24c6f3bc01e7c877e2f3bfccee6a34015
Diffstat (limited to 'provider_src/com')
-rw-r--r--provider_src/com/android/email/provider/EmailProvider.java20
1 files changed, 12 insertions, 8 deletions
diff --git a/provider_src/com/android/email/provider/EmailProvider.java b/provider_src/com/android/email/provider/EmailProvider.java
index b643c528a..58565dd9a 100644
--- a/provider_src/com/android/email/provider/EmailProvider.java
+++ b/provider_src/com/android/email/provider/EmailProvider.java
@@ -758,12 +758,9 @@ public class EmailProvider extends ContentProvider
if (messageDeletion) {
if (match == MESSAGE_ID) {
// Delete the Body record associated with the deleted message
- final ContentValues emptyValues = new ContentValues(2);
- emptyValues.putNull(BodyColumns.HTML_CONTENT);
- emptyValues.putNull(BodyColumns.TEXT_CONTENT);
final long messageId = Long.valueOf(id);
try {
- writeBodyFiles(context, messageId, emptyValues);
+ deleteBodyFiles(context, messageId);
} catch (final IllegalStateException e) {
LogUtils.v(LogUtils.TAG, e, "Exception while deleting bodies");
}
@@ -772,13 +769,10 @@ public class EmailProvider extends ContentProvider
// Delete any orphaned Body records
final Cursor orphans = db.rawQuery(ORPHAN_BODY_MESSAGE_ID_SELECT, null);
try {
- final ContentValues emptyValues = new ContentValues(2);
- emptyValues.putNull(BodyColumns.HTML_CONTENT);
- emptyValues.putNull(BodyColumns.TEXT_CONTENT);
while (orphans.moveToNext()) {
final long messageId = orphans.getLong(0);
try {
- writeBodyFiles(context, messageId, emptyValues);
+ deleteBodyFiles(context, messageId);
} catch (final IllegalStateException e) {
LogUtils.v(LogUtils.TAG, e, "Exception while deleting bodies");
}
@@ -908,6 +902,8 @@ public class EmailProvider extends ContentProvider
"Cannot insert body without MESSAGE_KEY");
}
final long messageId = values.getAsLong(BodyColumns.MESSAGE_KEY);
+ // Ensure that no pre-existing body files contaminate the message
+ deleteBodyFiles(context, messageId);
writeBodyFiles(getContext(), messageId, values);
break;
// NOTE: It is NOT legal for production code to insert directly into UPDATED_MESSAGE
@@ -2220,6 +2216,14 @@ public class EmailProvider extends ContentProvider
return result;
}
+ private static void deleteBodyFiles(final Context c, final long messageId)
+ throws IllegalStateException {
+ final ContentValues emptyValues = new ContentValues(2);
+ emptyValues.putNull(BodyColumns.HTML_CONTENT);
+ emptyValues.putNull(BodyColumns.TEXT_CONTENT);
+ writeBodyFiles(c, messageId, emptyValues);
+ }
+
/**
* Writes message bodies to disk, read from a set of ContentValues
*