diff --git a/src/com/android/email/provider/EmailContent.java b/src/com/android/email/provider/EmailContent.java index 9f0be5e6b..f9b633622 100644 --- a/src/com/android/email/provider/EmailContent.java +++ b/src/com/android/email/provider/EmailContent.java @@ -1945,6 +1945,16 @@ public abstract class EmailContent { AttachmentColumns.ACCOUNT_KEY }; + // All attachments with an empty URI, regardless of mailbox + public static final String EMPTY_URI_SELECTION = + AttachmentColumns.CONTENT_URI + " isnull AND " + Attachment.FLAGS + "=0"; + // Attachments with an empty URI that are in an inbox + public static final String EMPTY_URI_INBOX_SELECTION = + EMPTY_URI_SELECTION + " AND " + AttachmentColumns.MESSAGE_KEY + " IN (" + + "SELECT " + MessageColumns.ID + " FROM " + Message.TABLE_NAME + + " WHERE " + Message.INBOX_SELECTION + + ")"; + // Bits used in mFlags // Instruct Rfc822Output to 1) not use Content-Disposition and 2) use multipart/alternative // with this attachment. This is only valid if there is one and only one attachment and diff --git a/src/com/android/email/service/AttachmentDownloadService.java b/src/com/android/email/service/AttachmentDownloadService.java index 0f4f2caa3..d78fadfd1 100644 --- a/src/com/android/email/service/AttachmentDownloadService.java +++ b/src/com/android/email/service/AttachmentDownloadService.java @@ -332,7 +332,7 @@ public class AttachmentDownloadService extends Service implements Runnable { Uri lookupUri = EmailContent.uriWithLimit(Attachment.CONTENT_URI, MAX_ATTACHMENTS_TO_CHECK); Cursor c = mContext.getContentResolver().query(lookupUri, AttachmentInfo.PROJECTION, - AttachmentColumns.CONTENT_URI + " isnull AND " + Attachment.FLAGS + "=0", + EmailContent.Attachment.EMPTY_URI_INBOX_SELECTION, null, Attachment.RECORD_ID + " DESC"); File cacheDir = mContext.getCacheDir(); try { diff --git a/tests/src/com/android/email/provider/AttachmentProviderTests.java b/tests/src/com/android/email/provider/AttachmentProviderTests.java index 66cad9617..7a2cf43db 100644 --- a/tests/src/com/android/email/provider/AttachmentProviderTests.java +++ b/tests/src/com/android/email/provider/AttachmentProviderTests.java @@ -16,6 +16,7 @@ package com.android.email.provider; +import com.android.email.AttachmentInfo; import com.android.email.R; import com.android.email.mail.MessagingException; import com.android.email.mail.store.LocalStore; @@ -186,6 +187,88 @@ public class AttachmentProviderTests extends ProviderTestCase2