Skip to content

Commit

Permalink
Merge pull request cypht-org#1087 from Baraka24/disable_delete_attach…
Browse files Browse the repository at this point in the history
…ment_setting

[ENH]Add a way to be able to deactivate 'delete attachment'
  • Loading branch information
Shadow243 authored Jul 31, 2024
2 parents b75662d + 0f7995b commit 038a0da
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 13 deletions.
16 changes: 16 additions & 0 deletions modules/core/handler_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions modules/core/output_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<span class="tooltip_restore" restore_aria_label="Restore default value"><i class="bi bi-arrow-repeat refresh_list reset_default_value_checkbox"></i></span>';
}
return '<tr class="general_setting"><td><label class="form-check-label" for="allow_delete_attachment">'.$this->trans('Allow delete attachment').'</label></td>'.
'<td><input class="form-check-input" type="checkbox" '.$checked.' value="1" id="allow_delete_attachment" name="allow_delete_attachment" />'.$reset.'</td></tr>';
}
}

/**
* Starts the Flagged section on the settings page
* @subpackage core/output
Expand Down
2 changes: 2 additions & 0 deletions modules/core/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -293,6 +294,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,
Expand Down
24 changes: 11 additions & 13 deletions modules/imap/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -471,11 +471,8 @@ function format_msg_part_row($id, $vals, $output_mod, $level, $part, $dl_args, $
}
$res .= '</td><td class="part_desc">'.$output_mod->html_safe(decode_fld($desc)).'</td>';
$res .= '<td class="download_link"><a href="?'.$dl_args.'&amp;imap_msg_part='.$output_mod->html_safe($id).'">'.$output_mod->trans('Download').'</a></td>';
if ($lc_type == "textplain" || $lc_type == "multipartmixed") {
$res .= '<td class="download_link"><a href="?'.$dl_args.'&amp;imap_msg_part='.$output_mod->html_safe($id).'"></a></td>';
}
}
if (isset($vals['file_attributes']['attachment'])) {
if ($output_mod->get('allow_delete_attachment') && isset($vals['file_attributes']['attachment'])) {
$res .= '<td><a href="?'.$at_args.'&amp;imap_msg_part='.$output_mod->html_safe($id).'" class="remove_attachment">'.$output_mod->trans('Remove').'</a></td>';
}
$res .= '</tr>';
Expand Down Expand Up @@ -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) {
Expand All @@ -636,14 +633,15 @@ function format_attachment ($struct, $output_mod, $part, $dl_args) {

$res .= '<tr><td class="part_desc" colspan="4">'.$output_mod->html_safe(decode_fld($desc)).'</td>';
$res .= '</td><td class="part_size">'.$output_mod->html_safe($size).'</td>';
/* $res .= '</td><td class="part_encoding">'.(isset($vals['encoding']) ? $output_mod->html_safe(strtolower($vals['encoding'])) : '').
'</td><td class="part_charset">'.(isset($vals['attributes']['charset']) && trim($vals['attributes']['charset']) ? $output_mod->html_safe(strtolower($vals['attributes']['charset'])) : ''); */

$res .= '<td class="download_link"><a href="?'.$dl_args.'&amp;imap_msg_part='.$output_mod->html_safe($id).'">'.$output_mod->trans('Download').'</a></td></tr>';
$res .= '<td class="download_link"><a href="?'.$dl_args.'&amp;imap_msg_part='.$output_mod->html_safe($id).'">'.$output_mod->trans('Download').'</a></td>';
if ($output_mod->get('allow_delete_attachment') && isset($vals['file_attributes']['attachment'])) {
$res .= '<td><a href="?'.$at_args.'&amp;imap_msg_part='.$output_mod->html_safe($id).'" class="remove_attachment">'.$output_mod->trans('Remove').'</a></td></tr>';
}
}

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;
}
}
Expand Down
1 change: 1 addition & 0 deletions modules/imap/handler_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions modules/smtp/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
add_output('settings', 'attachment_setting', true, 'smtp', 'compose_type_setting', 'after');

add_output('settings', 'enable_attachment_reminder_setting', true, 'smtp', 'attachment_setting', 'after');
add_output('settings', 'delete_attachment_setting', true, 'smtp', 'enable_attachment_reminder_setting', 'after');
add_handler('settings', 'process_enable_attachment_reminder_setting', true, 'smtp', 'save_user_settings', 'before');

/* ajax server setup callback data */
Expand Down

0 comments on commit 038a0da

Please sign in to comment.