talons

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

commit 4e10965ee27426d10f74a2cae062e06e69073958
parent f9fa10468c97f9498ece9bca5796cfa7b100499b
Author: Michael Rasmussen <mir@datanom.net>
Date:   Sat, 25 Dec 2021 23:08:38 +0100

Warn when user tries to paste more text into compose window than the defined max size in common/utils.h

Signed-off-by: Michael Rasmussen <mir@datanom.net>

Diffstat:
Msrc/compose.c | 24++++++++++++++++++++++--
1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/src/compose.c b/src/compose.c @@ -10896,6 +10896,20 @@ static void entry_copy_clipboard(GtkWidget *entry) gtk_clipboard_get(GDK_SELECTION_CLIPBOARD)); } +static void text_to_big_alert(Compose *compose, glong size) { + GtkDialogFlags flags = GTK_DIALOG_DESTROY_WITH_PARENT; + GtkMessageDialog* dialog = gtk_message_dialog_new( + GTK_WINDOW(compose->window), + flags, + GTK_MESSAGE_INFO, + GTK_BUTTONS_OK, + _("Number of pages '%d' exceeds limit '%d' for paste. Attach as file instead"), + (size / 1800), + (MAX_ALLOCA_MEM_SIZE / 1800)); + gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(GTK_WIDGET(dialog)); +} + static void entry_paste_clipboard(Compose *compose, GtkWidget *entry, gboolean wrap, GdkAtom clip, GtkTextIter *insert_place) { @@ -10908,8 +10922,14 @@ static void entry_paste_clipboard(Compose *compose, GtkWidget *entry, if (contents == NULL) return; - - /* we shouldn't delete the selection when middle-click-pasting, or we + + glong len = g_utf8_strlen(contents, -1); + if (len > MAX_ALLOCA_MEM_SIZE) { + text_to_big_alert(compose, len); + return; + } + + /* we shouldn't delete the selection when middle-click-pasting, or we * can't mid-click-paste our own selection */ if (clip != GDK_SELECTION_PRIMARY) { undo_paste_clipboard(GTK_TEXT_VIEW(compose->text), compose->undostruct);