From 889ab2284890fda1c46cfe79a39cdb25711da107 Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 11 Mar 2022 13:04:28 +0100 Subject: [PATCH] Prevent download/save of sub attachments --- .../eu/faircode/email/AdapterMessage.java | 36 ++++++---- .../java/eu/faircode/email/FragmentBase.java | 65 ++++++++++--------- 2 files changed, 55 insertions(+), 46 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/AdapterMessage.java b/app/src/main/java/eu/faircode/email/AdapterMessage.java index 63ddb0c699..05170da506 100644 --- a/app/src/main/java/eu/faircode/email/AdapterMessage.java +++ b/app/src/main/java/eu/faircode/email/AdapterMessage.java @@ -3062,28 +3062,36 @@ public class AdapterMessage extends RecyclerView.Adapter 1 && suitable ? View.VISIBLE : View.GONE); + ibSaveAttachments.setVisibility(available > 1 && unavailable == 0 ? View.VISIBLE : View.GONE); + ibDownloadAttachments.setVisibility(downloadable > 1 && suitable ? View.VISIBLE : View.GONE); tvNoInternetAttachments.setVisibility(downloading && !suitable ? View.VISIBLE : View.GONE); cbInline.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { diff --git a/app/src/main/java/eu/faircode/email/FragmentBase.java b/app/src/main/java/eu/faircode/email/FragmentBase.java index 3f24f3d0d5..249d2817dd 100644 --- a/app/src/main/java/eu/faircode/email/FragmentBase.java +++ b/app/src/main/java/eu/faircode/email/FragmentBase.java @@ -573,41 +573,42 @@ public class FragmentBase extends Fragment { DB db = DB.getInstance(context); DocumentFile tree = DocumentFile.fromTreeUri(context, uri); List attachments = db.attachment().getAttachments(id); - for (EntityAttachment attachment : attachments) { - File file = attachment.getFile(context); - - String name = Helper.sanitizeFilename(attachment.name); - if (TextUtils.isEmpty(name)) - name = Long.toString(attachment.id); - DocumentFile document = tree.createFile(attachment.getMimeType(), name); - if (document == null) - throw new FileNotFoundException("Could not save " + uri + ":" + name); - - OutputStream os = null; - InputStream is = null; - try { - os = context.getContentResolver().openOutputStream(document.getUri()); - is = new FileInputStream(file); - - byte[] buffer = new byte[Helper.BUFFER_SIZE]; - int read; - while ((read = is.read(buffer)) != -1) - os.write(buffer, 0, read); - } finally { - try { - if (os != null) - os.close(); - } catch (Throwable ex) { - Log.w(ex); - } + for (EntityAttachment attachment : attachments) + if (attachment.subsequence == null) { + File file = attachment.getFile(context); + + String name = Helper.sanitizeFilename(attachment.name); + if (TextUtils.isEmpty(name)) + name = Long.toString(attachment.id); + DocumentFile document = tree.createFile(attachment.getMimeType(), name); + if (document == null) + throw new FileNotFoundException("Could not save " + uri + ":" + name); + + OutputStream os = null; + InputStream is = null; try { - if (is != null) - is.close(); - } catch (Throwable ex) { - Log.w(ex); + os = context.getContentResolver().openOutputStream(document.getUri()); + is = new FileInputStream(file); + + byte[] buffer = new byte[Helper.BUFFER_SIZE]; + int read; + while ((read = is.read(buffer)) != -1) + os.write(buffer, 0, read); + } finally { + try { + if (os != null) + os.close(); + } catch (Throwable ex) { + Log.w(ex); + } + try { + if (is != null) + is.close(); + } catch (Throwable ex) { + Log.w(ex); + } } } - } return null; }