[balsa/64-save-empty-attachment: 2/2] balsa-mime-widget-callbacks: Warn about empty part




commit 95743c5ec3f83067feb1dbd41c8944ea819b8b8e
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Mon Jan 17 17:22:16 2022 -0500

    balsa-mime-widget-callbacks: Warn about empty part
    
    Do not try to save an empty attachment.

 src/balsa-mime-widget-callbacks.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
---
diff --git a/src/balsa-mime-widget-callbacks.c b/src/balsa-mime-widget-callbacks.c
index 895e5a844..444450a5f 100644
--- a/src/balsa-mime-widget-callbacks.c
+++ b/src/balsa-mime-widget-callbacks.c
@@ -67,6 +67,7 @@ balsa_mime_widget_ctx_menu_save(GtkWidget * parent_widget,
                                LibBalsaMessageBody * mime_body)
 {
     gchar *cont_type, *title;
+    gint64 length;
     GtkWidget *save_dialog;
     gchar *file_uri;
     LibbalsaVfs *save_file;
@@ -76,6 +77,26 @@ balsa_mime_widget_ctx_menu_save(GtkWidget * parent_widget,
     g_return_if_fail(mime_body != NULL);
 
     cont_type = libbalsa_message_body_get_mime_type(mime_body);
+
+    length = libbalsa_message_body_length(mime_body, &err);
+
+    if (err != NULL) {
+        balsa_information(LIBBALSA_INFORMATION_ERROR,
+                          _("Could not access %s MIME Part: %s"), cont_type, err->message);
+        g_error_free(err);
+        g_free(cont_type);
+
+        return;
+    }
+
+    if (length == 0) {
+        balsa_information(LIBBALSA_INFORMATION_WARNING,
+                          _("Empty %s MIME Part was not saved"), cont_type);
+        g_free(cont_type);
+
+        return;
+    }
+
     title = g_strdup_printf(_("Save %s MIME Part"), cont_type);
 
     save_dialog =


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]