From fe9db1783117a4942efbc71da8a1538ec25bf33d Mon Sep 17 00:00:00 2001 From: Marc Blank Date: Wed, 26 Jan 2011 15:02:13 -0800 Subject: [PATCH] Show smart forward attachments in MessageCompose Bug: 3367188 Change-Id: I59dae9781be59eebe3a68769138e8253a24455e6 --- .../email/activity/MessageCompose.java | 23 +++++++++++-------- .../email/mail/transport/Rfc822Output.java | 5 +++- .../android/email/provider/EmailContent.java | 4 +++- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/com/android/email/activity/MessageCompose.java b/src/com/android/email/activity/MessageCompose.java index dd55204dd..d0493d667 100644 --- a/src/com/android/email/activity/MessageCompose.java +++ b/src/com/android/email/activity/MessageCompose.java @@ -680,14 +680,6 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus mLoadAttachmentsTask = new AsyncTask() { @Override protected Attachment[] doInBackground(Long... messageIds) { - // TODO: When we finally allow the user to change the sending account, - // we'll need a test to check whether the sending account is - // the message's account - boolean smartForward = - (account.mFlags & Account.FLAGS_SUPPORTS_SMART_FORWARD) != 0; - if (smartForward && !draft) { - return null; - } return Attachment.restoreAttachmentsWithMessageId(MessageCompose.this, messageIds[0]); } @@ -696,8 +688,14 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus if (attachments == null) { return; } + boolean smartForward = + (account.mFlags & Account.FLAGS_SUPPORTS_SMART_FORWARD) != 0; + for (Attachment attachment : attachments) { - addAttachment(attachment, true); + if (smartForward && !draft) { + attachment.mFlags |= Attachment.FLAG_SMART_FORWARD; + } + addAttachment(attachment, !smartForward); } } }.execute(message.mId); @@ -931,7 +929,9 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus // For any unloaded attachment, set the flag saying we need it loaded boolean hasUnloadedAttachments = false; for (Attachment attachment : attachments) { - if (attachment.mContentUri == null) { + + if (attachment.mContentUri == null && + ((attachment.mFlags & Attachment.FLAG_SMART_FORWARD) != 0)) { attachment.mFlags |= Attachment.FLAG_DOWNLOAD_FORWARD; hasUnloadedAttachments = true; if (Email.DEBUG){ @@ -939,6 +939,8 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus "Requesting download of attachment #" + attachment.mId); } } + // Make sure the UI version of the attachment has the now-correct id; we will + // use the id again when coming back from picking new attachments if (!attachment.isSaved()) { // this attachment is new so save it to DB. attachment.mMessageKey = mDraft.mId; @@ -949,6 +951,7 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus // the attachments will be independent of the original message in the // database; however, we still need the message on the server in order // to retrieve unloaded attachments + attachment.mMessageKey = mDraft.mId; ContentValues cv = attachment.toContentValues(); cv.put(Attachment.FLAGS, attachment.mFlags); cv.put(Attachment.MESSAGE_KEY, mDraft.mId); diff --git a/src/com/android/email/mail/transport/Rfc822Output.java b/src/com/android/email/mail/transport/Rfc822Output.java index aa95d89ce..22974edd8 100644 --- a/src/com/android/email/mail/transport/Rfc822Output.java +++ b/src/com/android/email/mail/transport/Rfc822Output.java @@ -59,6 +59,9 @@ public class Rfc822Output { private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", Locale.US); + private static final String WHERE_NOT_SMART_FORWARD = "(" + Attachment.FLAGS + "&" + + Attachment.FLAG_SMART_FORWARD + ")=0"; + /*package*/ static String buildBodyText(Context context, Message message, boolean appendQuotedText) { Body body = Body.restoreBodyWithMessageId(context, message.mId); @@ -151,7 +154,7 @@ public class Rfc822Output { Uri uri = ContentUris.withAppendedId(Attachment.MESSAGE_ID_URI, messageId); Cursor attachmentsCursor = context.getContentResolver().query(uri, - Attachment.CONTENT_PROJECTION, null, null, null); + Attachment.CONTENT_PROJECTION, WHERE_NOT_SMART_FORWARD, null, null); try { int attachmentCount = attachmentsCursor.getCount(); diff --git a/src/com/android/email/provider/EmailContent.java b/src/com/android/email/provider/EmailContent.java index 9c3a0de82..0672c66be 100644 --- a/src/com/android/email/provider/EmailContent.java +++ b/src/com/android/email/provider/EmailContent.java @@ -1976,7 +1976,9 @@ public abstract class EmailContent { public static final int FLAG_DOWNLOAD_FORWARD = 1<<2; // Indicates that the attachment download failed in a non-recoverable manner public static final int FLAG_DOWNLOAD_FAILED = 1<<3; - + // Allow "room" for some additional download-related flags here + // Indicates that the attachment will be smart-forwarded + public static final int FLAG_SMART_FORWARD = 1<<8; /** * no public constructor since this is a utility class */