From 51c0c14cecdad88db9a5ee74d886b30174a5e17e Mon Sep 17 00:00:00 2001 From: Bennet Becker Date: Wed, 20 Mar 2024 16:02:59 +0100 Subject: [PATCH] fix attachment template if no password is set --- attachment_tmpl.html | 9 ++------ attachment_tmpl_pass.html | 45 +++++++++++++++++++++++++++++++++++++++ hooks.php | 19 ++++++++--------- 3 files changed, 56 insertions(+), 17 deletions(-) create mode 100644 attachment_tmpl_pass.html diff --git a/attachment_tmpl.html b/attachment_tmpl.html index 874c15e..fb0e1ab 100644 --- a/attachment_tmpl.html +++ b/attachment_tmpl.html @@ -9,8 +9,8 @@

The file %FILENAME% was attached as a Filelink. It can be downloaded from the link below.

%FILENAME% - Mime Icon - Paperclip Icon
+ Mime Icon + Paperclip Icon
Size: %FILESIZE%
@@ -20,11 +20,6 @@ Checksum: %CHECKSUM%
- %BEGINPASSWORD% - - Password: %PASSWORD%
-
- %ENDPASSWORD% Available until: %VALIDUNTIL%, after which the download link will expire
diff --git a/attachment_tmpl_pass.html b/attachment_tmpl_pass.html new file mode 100644 index 0000000..186aaaf --- /dev/null +++ b/attachment_tmpl_pass.html @@ -0,0 +1,45 @@ + + + + %FILENAME% - Filelink Attachment + + + +
+

The file %FILENAME% was attached as a Filelink. It can be downloaded from the link below.

+
+ %FILENAME% + Mime Icon + Paperclip Icon
+ + Size: %FILESIZE%
+
+ + Link: %FILEURL%
+
+ + Checksum: %CHECKSUM%
+
+ + Password: %PASSWORD%
+
+ + Available until: %VALIDUNTIL%, after which the download link will expire
+
+
+
+
+

+ Attachments hosted on %SERVERURL% and subject to the server provider's terms of service and privacy policy. + Beyond the attachment becoming unavailable after the expiration date, the sender may delete the attachment + at any point; download and save the file to retain a local copy. + Be careful who's attachments you trust, especially with executables and office documents. +

+
+
+

Generated with nextcloud_attachments for Roundcube by Bennet B.

+

Icons: Ubuntu Yaru (CC BY-SA 4.0) and Material Icons (Apache License 2.0).

+
+
+ + diff --git a/hooks.php b/hooks.php index f81e45e..a289688 100644 --- a/hooks.php +++ b/hooks.php @@ -562,8 +562,15 @@ public function upload(array $data): array return ["status" => false, "abort" => true]; } - //fill out template attachment HTML - $tmpl = file_get_contents(dirname(__FILE__) . "/attachment_tmpl.html"); + $tmpl = ""; + + if (isset($form_params["password"])) { + //fill out template attachment HTML with Password + $tmpl = file_get_contents(dirname(__FILE__) . "/attachment_tmpl_pass.html"); + } else { + //fill out template attachment HTML + $tmpl = file_get_contents(dirname(__FILE__) . "/attachment_tmpl.html"); + } $fs = filesize($data["path"]); $u = ["", "k", "M", "G", "T"]; @@ -582,14 +589,8 @@ public function upload(array $data): array $tmpl = str_replace("%ICONBLOB%", base64_encode($mime_icon), $tmpl); $tmpl = str_replace("%CHECKSUM%", strtoupper($checksum) . " " . hash_file($checksum, $data["path"]), $tmpl); - $icon_rows = 5; if (isset($form_params["password"])){ $tmpl = str_replace("%PASSWORD%", $form_params["password"], $tmpl); - $tmpl = str_replace("%BEGINPASSWORD%", "", $tmpl); - $tmpl = str_replace("%ENDPASSWORD%", "", $tmpl); - $icon_rows++; - } else { - $tmpl = preg_replace("/%BEGINPASSWORD%.*?%ENDPASSWORD%/", "", $tmpl); } if (isset($form_params["expireDate"]) && isset($expire_date)){ @@ -598,8 +599,6 @@ public function upload(array $data): array $tmpl = str_replace("%VALIDUNTIL%", "deletion", $tmpl); } - $tmpl = str_replace("%ICONSPAN%", $icon_rows, $tmpl); - // Minimize HTML // https://stackoverflow.com/a/6225706 $search = array(