From 5075a516711d70e3ef8887c2973c5cb2f059a28c Mon Sep 17 00:00:00 2001 From: Baraka Kinywa Date: Sun, 28 Jul 2024 11:13:09 +0200 Subject: [PATCH 1/2] [ENH]Add a way to be able to deactivate 'delete attachment' --- modules/core/handler_modules.php | 16 ++++++++++++++++ modules/core/output_modules.php | 19 +++++++++++++++++++ modules/core/setup.php | 5 ++++- modules/imap/functions.php | 7 +++++-- modules/imap/handler_modules.php | 1 + 5 files changed, 45 insertions(+), 3 deletions(-) diff --git a/modules/core/handler_modules.php b/modules/core/handler_modules.php index 838062f6fe..8d4b36c2d1 100644 --- a/modules/core/handler_modules.php +++ b/modules/core/handler_modules.php @@ -342,6 +342,22 @@ function delete_disabled_callback($val) { } } +/** + * Process input from the disable delete attachment setting + * @subpackage core/handler + */ +class Hm_Handler_process_delete_attachment_setting extends Hm_Handler_Module { + /** + * Allowed vals are bool true/false + */ + public function process() { + function delete_attachment_callback($val) { + return $val; + } + process_site_setting('allow_delete_attachment', $this, 'delete_attachment_callback', true, true); + } +} + /** * Process input from the max per source setting for the Everything page in the settings page * @subpackage core/handler diff --git a/modules/core/output_modules.php b/modules/core/output_modules.php index e210637388..a035f087ee 100644 --- a/modules/core/output_modules.php +++ b/modules/core/output_modules.php @@ -857,6 +857,25 @@ protected function output() { } } +/** + * @subpackage core/output + */ +class Hm_Output_delete_attachment_setting extends Hm_Output_Module { + protected function output() { + $checked = ''; + $reset = ''; + $settings = $this->get('user_settings'); + if (array_key_exists('allow_delete_attachment', $settings) && $settings['allow_delete_attachment']) { + $checked = ' checked="checked"'; + } + else { + $reset = ''; + } + return ''. + ''.$reset.''; + } +} + /** * Starts the Flagged section on the settings page * @subpackage core/output diff --git a/modules/core/setup.php b/modules/core/setup.php index 4f73fb99da..4940ca58b4 100644 --- a/modules/core/setup.php +++ b/modules/core/setup.php @@ -56,6 +56,7 @@ add_handler('settings', 'process_drafts_source_max_setting', true, 'core', 'date', 'after'); add_handler('settings', 'process_hide_folder_icons', true, 'core', 'date', 'after'); add_handler('settings', 'process_delete_prompt_setting', true, 'core', 'date', 'after'); +add_handler('settings', 'process_delete_attachment_setting', true, 'core', 'date', 'after'); add_handler('settings', 'process_no_password_setting', true, 'core', 'date', 'after'); add_handler('settings', 'process_start_page_setting', true, 'core', 'date', 'after'); add_handler('settings', 'process_default_sort_order_setting', true, 'core', 'date', 'after'); @@ -75,7 +76,8 @@ add_output('settings', 'list_style_setting', true, 'core', 'mailto_handler_setting', 'after'); add_output('settings', 'msg_list_icons_setting', true, 'core', 'list_style_setting', 'before'); add_output('settings', 'delete_prompt_setting', true, 'core', 'list_style_setting', 'after'); -add_output('settings', 'no_password_setting', true, 'core', 'delete_prompt_setting', 'after'); +add_output('settings', 'delete_attachment_setting', true, 'core', 'delete_prompt_setting', 'after'); +add_output('settings', 'no_password_setting', true, 'core', 'delete_attachment_setting', 'after'); add_output('settings', 'start_page_setting', true, 'core', 'no_password_setting', 'after'); add_output('settings', 'default_sort_order_setting', true, 'core', 'start_page_setting', 'after'); add_output('settings', 'start_unread_settings', true, 'core', 'default_sort_order_setting', 'after'); @@ -293,6 +295,7 @@ 'list_style' => FILTER_DEFAULT, 'timezone' => FILTER_DEFAULT, 'disable_delete_prompt' => FILTER_VALIDATE_INT, + 'allow_delete_attachment' => FILTER_VALIDATE_INT, 'section_state' => FILTER_DEFAULT, 'section_class' => FILTER_DEFAULT, 'message_ids' => FILTER_DEFAULT, diff --git a/modules/imap/functions.php b/modules/imap/functions.php index c65c81e3d5..b31c00f689 100644 --- a/modules/imap/functions.php +++ b/modules/imap/functions.php @@ -475,7 +475,7 @@ function format_msg_part_row($id, $vals, $output_mod, $level, $part, $dl_args, $ $res .= ''; } } - if (isset($vals['file_attributes']['attachment'])) { + if ($output_mod->get('allow_delete_attachment') && isset($vals['file_attributes']['attachment'])) { $res .= ''.$output_mod->trans('Remove').''; } $res .= ''; @@ -639,7 +639,10 @@ function format_attachment ($struct, $output_mod, $part, $dl_args) { /* $res .= ''.(isset($vals['encoding']) ? $output_mod->html_safe(strtolower($vals['encoding'])) : ''). ''.(isset($vals['attributes']['charset']) && trim($vals['attributes']['charset']) ? $output_mod->html_safe(strtolower($vals['attributes']['charset'])) : ''); */ - $res .= ''.$output_mod->trans('Download').''; + $res .= ''.$output_mod->trans('Download').''; + if ($output_mod->get('allow_delete_attachment') && isset($vals['file_attributes']['attachment'])) { + $res .= ''.$output_mod->trans('Remove').''; + } } if(is_array($vals) && isset($vals['subs'])) { diff --git a/modules/imap/handler_modules.php b/modules/imap/handler_modules.php index b26fa69aa4..f71159bd82 100644 --- a/modules/imap/handler_modules.php +++ b/modules/imap/handler_modules.php @@ -1925,6 +1925,7 @@ public function process() { $this->out('imap_msg_part', "$part"); $this->out('use_message_part_icons', $this->user_config->get('msg_part_icons_setting', false)); $this->out('simple_msg_part_view', $this->user_config->get('simple_msg_parts_setting', true)); + $this->out('allow_delete_attachment', $this->user_config->get('allow_delete_attachment_setting', false)); if ($msg_struct_current) { $this->out('msg_struct_current', $msg_struct_current); } From d90cb90d9c29c1807b8b48ca285628ec889af805 Mon Sep 17 00:00:00 2001 From: Baraka Kinywa Date: Sun, 28 Jul 2024 11:13:09 +0200 Subject: [PATCH 2/2] [ENH]Add a way to be able to deactivate 'delete attachment' --- modules/core/handler_modules.php | 16 ++++++++++++++++ modules/core/output_modules.php | 19 +++++++++++++++++++ modules/core/setup.php | 5 ++++- modules/imap/functions.php | 24 +++++++++++------------- modules/imap/handler_modules.php | 1 + 5 files changed, 51 insertions(+), 14 deletions(-) diff --git a/modules/core/handler_modules.php b/modules/core/handler_modules.php index 838062f6fe..8d4b36c2d1 100644 --- a/modules/core/handler_modules.php +++ b/modules/core/handler_modules.php @@ -342,6 +342,22 @@ function delete_disabled_callback($val) { } } +/** + * Process input from the disable delete attachment setting + * @subpackage core/handler + */ +class Hm_Handler_process_delete_attachment_setting extends Hm_Handler_Module { + /** + * Allowed vals are bool true/false + */ + public function process() { + function delete_attachment_callback($val) { + return $val; + } + process_site_setting('allow_delete_attachment', $this, 'delete_attachment_callback', true, true); + } +} + /** * Process input from the max per source setting for the Everything page in the settings page * @subpackage core/handler diff --git a/modules/core/output_modules.php b/modules/core/output_modules.php index e210637388..a035f087ee 100644 --- a/modules/core/output_modules.php +++ b/modules/core/output_modules.php @@ -857,6 +857,25 @@ protected function output() { } } +/** + * @subpackage core/output + */ +class Hm_Output_delete_attachment_setting extends Hm_Output_Module { + protected function output() { + $checked = ''; + $reset = ''; + $settings = $this->get('user_settings'); + if (array_key_exists('allow_delete_attachment', $settings) && $settings['allow_delete_attachment']) { + $checked = ' checked="checked"'; + } + else { + $reset = ''; + } + return ''. + ''.$reset.''; + } +} + /** * Starts the Flagged section on the settings page * @subpackage core/output diff --git a/modules/core/setup.php b/modules/core/setup.php index 4f73fb99da..4940ca58b4 100644 --- a/modules/core/setup.php +++ b/modules/core/setup.php @@ -56,6 +56,7 @@ add_handler('settings', 'process_drafts_source_max_setting', true, 'core', 'date', 'after'); add_handler('settings', 'process_hide_folder_icons', true, 'core', 'date', 'after'); add_handler('settings', 'process_delete_prompt_setting', true, 'core', 'date', 'after'); +add_handler('settings', 'process_delete_attachment_setting', true, 'core', 'date', 'after'); add_handler('settings', 'process_no_password_setting', true, 'core', 'date', 'after'); add_handler('settings', 'process_start_page_setting', true, 'core', 'date', 'after'); add_handler('settings', 'process_default_sort_order_setting', true, 'core', 'date', 'after'); @@ -75,7 +76,8 @@ add_output('settings', 'list_style_setting', true, 'core', 'mailto_handler_setting', 'after'); add_output('settings', 'msg_list_icons_setting', true, 'core', 'list_style_setting', 'before'); add_output('settings', 'delete_prompt_setting', true, 'core', 'list_style_setting', 'after'); -add_output('settings', 'no_password_setting', true, 'core', 'delete_prompt_setting', 'after'); +add_output('settings', 'delete_attachment_setting', true, 'core', 'delete_prompt_setting', 'after'); +add_output('settings', 'no_password_setting', true, 'core', 'delete_attachment_setting', 'after'); add_output('settings', 'start_page_setting', true, 'core', 'no_password_setting', 'after'); add_output('settings', 'default_sort_order_setting', true, 'core', 'start_page_setting', 'after'); add_output('settings', 'start_unread_settings', true, 'core', 'default_sort_order_setting', 'after'); @@ -293,6 +295,7 @@ 'list_style' => FILTER_DEFAULT, 'timezone' => FILTER_DEFAULT, 'disable_delete_prompt' => FILTER_VALIDATE_INT, + 'allow_delete_attachment' => FILTER_VALIDATE_INT, 'section_state' => FILTER_DEFAULT, 'section_class' => FILTER_DEFAULT, 'message_ids' => FILTER_DEFAULT, diff --git a/modules/imap/functions.php b/modules/imap/functions.php index 9a91226d16..34242d599d 100644 --- a/modules/imap/functions.php +++ b/modules/imap/functions.php @@ -471,11 +471,8 @@ function format_msg_part_row($id, $vals, $output_mod, $level, $part, $dl_args, $ } $res .= ''.$output_mod->html_safe(decode_fld($desc)).''; $res .= ''.$output_mod->trans('Download').''; - if ($lc_type == "textplain" || $lc_type == "multipartmixed") { - $res .= ''; - } } - if (isset($vals['file_attributes']['attachment'])) { + if ($output_mod->get('allow_delete_attachment') && isset($vals['file_attributes']['attachment'])) { $res .= ''.$output_mod->trans('Remove').''; } $res .= ''; @@ -605,28 +602,28 @@ function format_msg_part_section($struct, $output_mod, $part, $dl_link, $at_link if(!$simple_view){ foreach ($struct as $id => $vals) { if (is_array($vals) && isset($vals['type'])) { - $row = format_msg_part_row($id, $vals, $output_mod, $level, $part, $dl_link, $use_icons, $simple_view, $mobile); + $row = format_msg_part_row($id, $vals, $output_mod, $level, $part, $dl_link, $at_link, $use_icons, $simple_view, $mobile); if (!$row) { $level--; } $res .= $row; if (isset($vals['subs'])) { - $res .= format_msg_part_section($vals['subs'], $output_mod, $part, $dl_link, ($level + 1)); + $res .= format_msg_part_section($vals['subs'], $output_mod, $part, $dl_link, $at_link, ($level + 1)); } } else { if (is_array($vals) && count($vals) == 1 && isset($vals['subs'])) { - $res .= format_msg_part_section($vals['subs'], $output_mod, $part, $dl_link, $level); + $res .= format_msg_part_section($vals['subs'], $output_mod, $part, $dl_link, $at_link, $level); } } } }else{ - $res = format_attachment($struct, $output_mod, $part, $dl_link); + $res = format_attachment($struct, $output_mod, $part, $dl_link, $at_link); } return $res; }} -function format_attachment ($struct, $output_mod, $part, $dl_args) { +function format_attachment($struct, $output_mod, $part, $dl_args, $at_args) { $res = ''; foreach ($struct as $id => $vals) { @@ -636,14 +633,15 @@ function format_attachment ($struct, $output_mod, $part, $dl_args) { $res .= ''.$output_mod->html_safe(decode_fld($desc)).''; $res .= ''.$output_mod->html_safe($size).''; - /* $res .= ''.(isset($vals['encoding']) ? $output_mod->html_safe(strtolower($vals['encoding'])) : ''). - ''.(isset($vals['attributes']['charset']) && trim($vals['attributes']['charset']) ? $output_mod->html_safe(strtolower($vals['attributes']['charset'])) : ''); */ - $res .= ''.$output_mod->trans('Download').''; + $res .= ''.$output_mod->trans('Download').''; + if ($output_mod->get('allow_delete_attachment') && isset($vals['file_attributes']['attachment'])) { + $res .= ''.$output_mod->trans('Remove').''; + } } if(is_array($vals) && isset($vals['subs'])) { - $sub_res = format_attachment($vals['subs'], $output_mod, $part, $dl_args); + $sub_res = format_attachment($vals['subs'], $output_mod, $part, $dl_args, $at_args); $res =$sub_res; } } diff --git a/modules/imap/handler_modules.php b/modules/imap/handler_modules.php index b26fa69aa4..f71159bd82 100644 --- a/modules/imap/handler_modules.php +++ b/modules/imap/handler_modules.php @@ -1925,6 +1925,7 @@ public function process() { $this->out('imap_msg_part', "$part"); $this->out('use_message_part_icons', $this->user_config->get('msg_part_icons_setting', false)); $this->out('simple_msg_part_view', $this->user_config->get('simple_msg_parts_setting', true)); + $this->out('allow_delete_attachment', $this->user_config->get('allow_delete_attachment_setting', false)); if ($msg_struct_current) { $this->out('msg_struct_current', $msg_struct_current); }