talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

commit d92dfd13745aac59923d8ff88e89057d966295b5
parent b9c9f6396734350b659f1fadd46a238d38ae8ea7
Author: Paul <paul@claws-mail.org>
Date:   Wed, 14 Aug 2024 16:56:02 +0100

implement RFE 4706, 'add config option for chmod of saved attachments'

Diffstat:
Msrc/common/file-utils.c | 16+++++++++++++++-
Msrc/common/file-utils.h | 5++++-
Msrc/mimeview.c | 5+++++
Msrc/prefs_common.c | 4++++
Msrc/prefs_common.h | 1+
Msrc/prefs_folder_item.c | 20++------------------
Msrc/prefs_other.c | 37+++++++++++++++++++++++++++++++++++++
7 files changed, 68 insertions(+), 20 deletions(-)

diff --git a/src/common/file-utils.c b/src/common/file-utils.c @@ -1,6 +1,6 @@ /* * Claws Mail -- a GTK based, lightweight, and fast e-mail client - * Copyright (C) 1999-2018 Colin Leroy and the Claws Mail team + * Copyright (C) 1999-2024 the Claws Mail team and Colin Leroy * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -870,3 +870,17 @@ FILE *str_open_as_stream(const gchar *str) rewind(fp); return fp; } + +gint prefs_chmod_mode(gchar *chmod_pref) +{ + gint newmode = 0; + gchar *tmp; + + if (chmod_pref) { + newmode = strtol(chmod_pref, &tmp, 8); + if (!(*(chmod_pref) && !(*tmp))) + newmode = 0; + } + + return newmode; +} diff --git a/src/common/file-utils.h b/src/common/file-utils.h @@ -1,6 +1,6 @@ /* * Claws Mail -- a GTK based, lightweight, and fast e-mail client - * Copyright (C) 1999-2018 Colin Leroy and the Claws Mail team + * Copyright (C) 1999-2024 the Claws Mail team and Colin Leroy * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -100,4 +100,7 @@ gint str_write_to_file (const gchar *str, const gchar *file, gboolean safe); +gint prefs_chmod_mode (gchar *chmod_pref); + + #endif diff --git a/src/mimeview.c b/src/mimeview.c @@ -1839,6 +1839,11 @@ static gint mimeview_write_part(const gchar *filename, return 0; } + if (prefs_common.attach_save_chmod) { + if (chmod(filename, prefs_common.attach_save_chmod) < 0) + FILE_OP_ERROR(filename, "chmod"); + } + return 1; } diff --git a/src/prefs_common.c b/src/prefs_common.c @@ -110,6 +110,8 @@ static PrefParam param_os_specific[] = { /* Message */ {"attach_save_directory", NULL, &prefs_common.attach_save_dir, P_STRING, NULL, NULL, NULL}, + {"attach_save_chmod", "", + &prefs_common.attach_save_chmod, P_INT, NULL, NULL, NULL}, {"attach_load_directory", NULL, &prefs_common.attach_load_dir, P_STRING, NULL, NULL, NULL}, @@ -804,6 +806,8 @@ static PrefParam param[] = { NULL, NULL, NULL}, {"attach_save_directory", NULL, &SPECIFIC_PREFS.attach_save_dir, P_STRING, NULL, NULL, NULL}, + {"attach_save_chmod", "", + &SPECIFIC_PREFS.attach_save_chmod, P_INT, NULL, NULL, NULL}, {"attach_load_directory", NULL, &SPECIFIC_PREFS.attach_load_dir, P_STRING, NULL, NULL, NULL}, diff --git a/src/prefs_common.h b/src/prefs_common.h @@ -380,6 +380,7 @@ struct _PrefsCommon gchar *mime_textviewer; gchar *mime_open_cmd; gchar *attach_save_dir; + gint attach_save_chmod; gchar *attach_load_dir; GList *mime_open_cmd_history; diff --git a/src/prefs_folder_item.c b/src/prefs_folder_item.c @@ -48,6 +48,7 @@ #include "quote_fmt.h" #include "combobox.h" #include "stock_pixmap.h" +#include "file-utils.h" #if USE_ENCHANT #include "gtkaspell.h" @@ -193,8 +194,6 @@ static gboolean general_save_recurse_func(GNode *node, gpointer data); static gboolean compose_save_recurse_func(GNode *node, gpointer data); static gboolean templates_save_recurse_func(GNode *node, gpointer data); -static gint prefs_folder_item_chmod_mode (gchar *folder_chmod); - static void clean_cache_cb(GtkWidget *widget, gpointer data); static void folder_regexp_test_cb(GtkWidget *widget, gpointer data); static void folder_regexp_set_subject_example_cb(GtkWidget *widget, gpointer data); @@ -746,7 +745,7 @@ static void general_save_folder_prefs(FolderItem *folder, FolderItemGeneralPage prefs->enable_folder_chmod = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_folder_chmod)); buf = gtk_editable_get_chars(GTK_EDITABLE(page->entry_folder_chmod), 0, -1); - prefs->folder_chmod = prefs_folder_item_chmod_mode(buf); + prefs->folder_chmod = prefs_chmod_mode(buf); g_free(buf); } @@ -1799,21 +1798,6 @@ static void prefs_folder_item_templates_save_func(PrefsPage *page_) } -static gint prefs_folder_item_chmod_mode(gchar *folder_chmod) -{ - gint newmode = 0; - gchar *tmp; - - if (folder_chmod) { - newmode = strtol(folder_chmod, &tmp, 8); - if (!(*(folder_chmod) && !(*tmp))) - newmode = 0; - } - - return newmode; -} - - static void clean_cache_cb(GtkWidget *widget, gpointer data) { FolderItemGeneralPage *page = (FolderItemGeneralPage *) data; diff --git a/src/prefs_other.c b/src/prefs_other.c @@ -47,6 +47,8 @@ #include "imap-thread.h" #endif +#include "file-utils.h" + typedef struct _OtherPage { PrefsPage page; @@ -65,6 +67,7 @@ typedef struct _OtherPage GtkWidget *checkbtn_askonfilter; GtkWidget *checkbtn_use_shred; GtkWidget *checkbtn_real_time_sync; + GtkWidget *entry_attach_save_chmod; GtkWidget *flush_metadata_faster_radiobtn; GtkWidget *flush_metadata_safer_radiobtn; GtkWidget *checkbtn_transhdr; @@ -370,6 +373,8 @@ static void prefs_other_create_widget(PrefsPage *_page, GtkWindow *window, GtkWidget *checkbtn_askonfilter; GtkWidget *checkbtn_use_shred; GtkWidget *checkbtn_real_time_sync; + GtkWidget *label_attach_save_chmod; + GtkWidget *entry_attach_save_chmod; GtkWidget *frame_metadata; GtkWidget *vbox_metadata; @@ -510,6 +515,32 @@ static void prefs_other_create_widget(PrefsPage *_page, GtkWindow *window, PACK_CHECK_BUTTON (vbox2, checkbtn_real_time_sync, _("Synchronise offline folders as soon as possible")); + + hbox1 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8); + gtk_widget_show(hbox1); + gtk_box_pack_start(GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0); + + label_attach_save_chmod = gtk_label_new (_("Save attachments with chmod")); + gtk_widget_show(label_attach_save_chmod); + gtk_box_pack_start(GTK_BOX (hbox1), label_attach_save_chmod, FALSE, FALSE, 0); + + entry_attach_save_chmod = gtk_entry_new(); + gtk_entry_set_width_chars(GTK_ENTRY(entry_attach_save_chmod), 5); + gtk_widget_set_tooltip_text(entry_attach_save_chmod, + _("By default attachments are saved with chmod value 600: " + "readable and writeable by the user only. If this is too " + "restrictive for you, set a chmod value here, otherwise leave " + "blank to use the default.")); + gtk_widget_show(entry_attach_save_chmod); + gtk_box_pack_start(GTK_BOX(hbox1), entry_attach_save_chmod, FALSE, FALSE, 0); + if (prefs_common.attach_save_chmod) { + gchar *buf; + + buf = g_strdup_printf("%o", prefs_common.attach_save_chmod); + gtk_entry_set_text(GTK_ENTRY(entry_attach_save_chmod), buf); + g_free(buf); + } + #ifndef PASSWORD_CRYPTO_OLD vbox_passphrase = gtkut_get_options_frame(vbox1, &frame_passphrase, _("Primary passphrase")); @@ -580,6 +611,7 @@ static void prefs_other_create_widget(PrefsPage *_page, GtkWindow *window, prefs_other->checkbtn_askonfilter = checkbtn_askonfilter; prefs_other->checkbtn_use_shred = checkbtn_use_shred; prefs_other->checkbtn_real_time_sync = checkbtn_real_time_sync; + prefs_other->entry_attach_save_chmod = entry_attach_save_chmod; prefs_other->flush_metadata_safer_radiobtn = flush_metadata_safer_radiobtn; prefs_other->flush_metadata_faster_radiobtn = flush_metadata_faster_radiobtn; #ifndef PASSWORD_CRYPTO_OLD @@ -593,6 +625,7 @@ static void prefs_other_save(PrefsPage *_page) OtherPage *page = (OtherPage *) _page; GtkSettings *settings = gtk_settings_get_default(); gboolean gtk_enable_accels; + gchar *buf; prefs_common.add_address_by_click = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(page->checkbtn_addaddrbyclick)); @@ -624,6 +657,10 @@ static void prefs_other_save(PrefsPage *_page) gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(page->checkbtn_real_time_sync)); + buf = gtk_editable_get_chars(GTK_EDITABLE(page->entry_attach_save_chmod), 0, -1); + prefs_common.attach_save_chmod = prefs_chmod_mode(buf); + g_free(buf); + prefs_keybind_preset_changed(GTK_COMBO_BOX(page->keys_preset_combo)); #ifndef PASSWORD_CRYPTO_OLD