Differentiate between external and embedded images

This commit is contained in:
M66B 2018-11-29 13:15:41 +01:00
parent c6beb1b902
commit fe77429da5
5 changed files with 54 additions and 35 deletions

18
FAQ.md
View File

@ -353,15 +353,21 @@ Yes, you can translate the texts of FairEmail in your own language [here](https:
Registration is free.
<a name="faq27"></a>
**(27) ~~Why are images shown without tapping 'Show images' ?~~**
**(27) How can I differentiate external and embedded images?**
~~There are two types of images:~~
External image:
* ~~Images embedded into a message~~
* ~~Images stored on a remote server~~
![External image](https://raw.githubusercontent.com/google/material-design-icons/master/image/1x_web/ic_image_black_48dp.png)
~~Embedded images, also visible as an attachment, are always shown, but images stored on a remote server need to be downloaded by tapping *Show images*.~~
~~Note that downloading images from a remote server can be used to record you did see a message, which you likely don't want if the message is spam or malicious.~~
Embedded image:
![Embedded image](https://raw.githubusercontent.com/google/material-design-icons/master/image/1x_web/ic_photo_library_black_48dp.png)
Broken image:
![Broken image](https://raw.githubusercontent.com/google/material-design-icons/master/image/1x_web/ic_broken_image_black_48dp.png)
Note that downloading external images from a remote server can be used to record you did see a message, which you likely don't want if the message is spam or malicious.
<a name="faq28"></a>
**(28) How can I manage status bar notifications?**

View File

@ -724,29 +724,34 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
@Override
public Drawable getDrawable(String source) {
float scale = context.getResources().getDisplayMetrics().density;
int px = (int) (48 * scale + 0.5f);
int px = Math.round(48 * scale);
if (TextUtils.isEmpty(source)) {
Drawable d = context.getResources().getDrawable(R.drawable.baseline_broken_image_24, context.getTheme());
d.setBounds(0, 0, px / 2, px / 2);
return d;
}
boolean embedded = (source.startsWith("cid") && source.split(":").length > 1);
if (properties.showImages(message.id)) {
// Embedded images
if (source != null && source.startsWith("cid")) {
String[] cids = source.split(":");
if (cids.length > 1) {
String cid = "<" + cids[1] + ">";
EntityAttachment attachment = DB.getInstance(context).attachment().getAttachment(message.id, cid);
if (attachment == null || !attachment.available) {
Drawable d = context.getResources().getDrawable(R.drawable.baseline_warning_24, context.getTheme());
d.setBounds(0, 0, px, px);
return d;
} else {
File file = EntityAttachment.getFile(context, attachment.id);
Drawable d = Drawable.createFromPath(file.getAbsolutePath());
if (d == null) {
d = context.getResources().getDrawable(R.drawable.baseline_warning_24, context.getTheme());
d.setBounds(0, 0, px, px);
} else
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
return d;
}
if (embedded) {
String cid = "<" + source.split(":")[1] + ">";
EntityAttachment attachment = DB.getInstance(context).attachment().getAttachment(message.id, cid);
if (attachment == null || !attachment.available) {
Drawable d = context.getResources().getDrawable(R.drawable.baseline_photo_library_24, context.getTheme());
d.setBounds(0, 0, px, px);
return d;
} else {
File file = EntityAttachment.getFile(context, attachment.id);
Drawable d = Drawable.createFromPath(file.getAbsolutePath());
if (d == null) {
d = context.getResources().getDrawable(R.drawable.baseline_broken_image_24, context.getTheme());
d.setBounds(0, 0, px / 2, px / 2);
} else
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
return d;
}
}
@ -767,9 +772,6 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
InputStream is = null;
FileOutputStream os = null;
try {
if (source == null)
throw new IllegalArgumentException("Html.ImageGetter.getDrawable(source == null)");
// Create unique file name
File file = new File(dir, message.id + "_" + source.hashCode());
@ -800,8 +802,8 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
} catch (Throwable ex) {
// Show warning icon
Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
Drawable d = context.getResources().getDrawable(R.drawable.baseline_warning_24, context.getTheme());
d.setBounds(0, 0, px, px);
Drawable d = context.getResources().getDrawable(R.drawable.baseline_broken_image_24, context.getTheme());
d.setBounds(0, 0, px / 2, px / 2);
return d;
} finally {
// Close streams
@ -822,7 +824,8 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
}
} else {
// Show placeholder icon
Drawable d = context.getResources().getDrawable(R.drawable.baseline_image_24, context.getTheme());
int resid = (embedded ? R.drawable.baseline_photo_library_24 : R.drawable.baseline_image_24);
Drawable d = context.getResources().getDrawable(resid, context.getTheme());
d.setBounds(0, 0, px, px);
return d;
}

View File

@ -1705,8 +1705,8 @@ public class FragmentCompose extends FragmentEx {
}
float scale = getContext().getResources().getDisplayMetrics().density;
int px = (int) (24 * scale + 0.5f);
Drawable d = getContext().getResources().getDrawable(R.drawable.baseline_warning_24, getContext().getTheme());
int px = Math.round(12 * scale);
Drawable d = getContext().getResources().getDrawable(R.drawable.baseline_broken_image_24, getContext().getTheme());
d.setBounds(0, 0, px, px);
return d;
}

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M21,5v6.59l-3,-3.01 -4,4.01 -4,-4 -4,4 -3,-3.01L3,5c0,-1.1 0.9,-2 2,-2h14c1.1,0 2,0.9 2,2zM18,11.42l3,3.01L21,19c0,1.1 -0.9,2 -2,2L5,21c-1.1,0 -2,-0.9 -2,-2v-6.58l3,2.99 4,-4 4,4 4,-3.99z"/>
</vector>

View File

@ -6,5 +6,5 @@
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M1,21h22L12,2 1,21zM13,18h-2v-2h2v2zM13,14h-2v-4h2v4z"/>
android:pathData="M22,16L22,4c0,-1.1 -0.9,-2 -2,-2L8,2c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2zM11,12l2.03,2.71L16,11l4,5L8,16l3,-4zM2,6v14c0,1.1 0.9,2 2,2h14v-2L4,20L4,6L2,6z"/>
</vector>