Merge "Gmail does not display inline attachments nor does it offer "Show pictures" within the EML viewer" into ub-mail-master
diff --git a/src/com/android/mail/browse/MessageFooterView.java b/src/com/android/mail/browse/MessageFooterView.java
index f904b82..24bc5f8 100644
--- a/src/com/android/mail/browse/MessageFooterView.java
+++ b/src/com/android/mail/browse/MessageFooterView.java
@@ -89,6 +89,12 @@
         MessageFooterView getViewForItem(MessageFooterItem item);
 
         int getUpdatedHeight(MessageFooterItem item);
+
+        /**
+         * @return <tt>true</tt> if this footer is contained within a SecureConversationViewFragment
+         * and cannot assume the content is <strong>not</strong> malicious
+         */
+        boolean isSecure();
     }
 
     public MessageFooterView(Context context) {
@@ -222,13 +228,15 @@
         final List<Attachment> barAttachments = new ArrayList<Attachment>(maxSize);
 
         for (Attachment attachment : attachments) {
-            if (attachment.isInlineAttachment()) {
-                // skip non-standard (aka inline) attachments
-                continue;
-            } else if (AttachmentTile.isTiledAttachment(attachment)) {
-                tiledAttachments.add(attachment);
-            } else {
-                barAttachments.add(attachment);
+            // attachments in secure views are displayed in the footer so the user may interact with
+            // them; for normal views there is no need to show inline attachments in the footer
+            // since users can interact with them in place
+            if (!attachment.isInlineAttachment() || mCallbacks.isSecure()) {
+                if (AttachmentTile.isTiledAttachment(attachment)) {
+                    tiledAttachments.add(attachment);
+                } else {
+                    barAttachments.add(attachment);
+                }
             }
         }
 
diff --git a/src/com/android/mail/browse/MessageHeaderView.java b/src/com/android/mail/browse/MessageHeaderView.java
index 8b6ef04..7330338 100644
--- a/src/com/android/mail/browse/MessageHeaderView.java
+++ b/src/com/android/mail/browse/MessageHeaderView.java
@@ -225,6 +225,12 @@
         String getMessageTransforms(Message msg);
 
         FragmentManager getFragmentManager();
+
+        /**
+         * @return <tt>true</tt> if this header is contained within a SecureConversationViewFragment
+         * and cannot assume the content is <strong>not</strong> malicious
+         */
+        boolean isSecure();
     }
 
     public MessageHeaderView(Context context) {
@@ -414,9 +420,21 @@
         mMessage = mMessageHeaderItem.getMessage();
 
         final Account account = getAccount();
-        final boolean alwaysShowImages = (account != null) &&
+        final boolean alwaysShowImagesForAccount = (account != null) &&
                 (account.settings.showImages == Settings.ShowImages.ALWAYS);
-        mShowImagePrompt = mMessage.shouldShowImagePrompt() && !alwaysShowImages;
+
+        final boolean alwaysShowImagesForMessage = mMessage.shouldShowImagePrompt();
+
+        if (!alwaysShowImagesForMessage) {
+            // we don't need the "Show picture" prompt if the user allows images for this message
+            mShowImagePrompt = false;
+        } else if (mCallbacks.isSecure()) {
+            // in a secure view we always display the "Show picture" prompt
+            mShowImagePrompt = true;
+        } else {
+            // otherwise honor the account setting for automatically showing pictures
+            mShowImagePrompt = !alwaysShowImagesForAccount;
+        }
 
         setExpanded(mMessageHeaderItem.isExpanded());
 
diff --git a/src/com/android/mail/providers/Message.java b/src/com/android/mail/providers/Message.java
index 29522e5..7fd3b41 100644
--- a/src/com/android/mail/providers/Message.java
+++ b/src/com/android/mail/providers/Message.java
@@ -468,7 +468,7 @@
         int partId = 0;
         for (final Part attachmentPart : attachments) {
             mAttachments.add(new Attachment(context, attachmentPart,
-                    emlFileUri, messageId, Integer.toString(partId++), false));
+                    emlFileUri, messageId, Integer.toString(partId++), false /* inline */));
         }
 
         // instantiating an Attachment for each viewable will cause it to be registered within the
@@ -477,7 +477,8 @@
             final String[] cids = viewablePart.getHeader(MimeHeader.HEADER_CONTENT_ID);
             if (cids != null && cids.length == 1) {
                 final String cid = REMOVE_OPTIONAL_BRACKETS.matcher(cids[0]).replaceAll("$1");
-                new Attachment(context, viewablePart, emlFileUri, messageId, cid, true);
+                mAttachments.add(new Attachment(context, viewablePart, emlFileUri, messageId, cid,
+                        true /* inline */));
             }
         }
 
diff --git a/src/com/android/mail/ui/ConversationViewFragment.java b/src/com/android/mail/ui/ConversationViewFragment.java
index 15a8739..3c679ed 100644
--- a/src/com/android/mail/ui/ConversationViewFragment.java
+++ b/src/com/android/mail/ui/ConversationViewFragment.java
@@ -1041,6 +1041,11 @@
         return (domId == null) ? null : mMessageTransforms.get(domId);
     }
 
+    @Override
+    public boolean isSecure() {
+        return false;
+    }
+
     // END message header callbacks
 
     @Override
diff --git a/src/com/android/mail/ui/SecureConversationViewController.java b/src/com/android/mail/ui/SecureConversationViewController.java
index 43d8f6d..1fed820 100644
--- a/src/com/android/mail/ui/SecureConversationViewController.java
+++ b/src/com/android/mail/ui/SecureConversationViewController.java
@@ -22,7 +22,6 @@
 import android.content.res.Resources;
 import android.graphics.Rect;
 import android.os.Bundle;
-import android.support.v4.text.BidiFormatter;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
@@ -294,6 +293,11 @@
     }
 
     @Override
+    public boolean isSecure() {
+        return true;
+    }
+
+    @Override
     public FragmentManager getFragmentManager() {
         return mCallbacks.getFragment().getFragmentManager();
     }