Printing: only print as plain text if the part is of type text;
authorColin Leroy <colin@colino.net>
Sat, 9 Nov 2019 22:13:33 +0000 (23:13 +0100)
committerColin Leroy <colin@colino.net>
Sat, 9 Nov 2019 22:13:33 +0000 (23:13 +0100)
fix a segfault with default info icon when trying to print a non-text
part.

src/messageview.c
src/printing.c

index b4fc183..3a6184f 100644 (file)
@@ -2181,9 +2181,17 @@ static void print_mimeview(MimeView *mimeview, gint sel_start, gint sel_end, gin
                                viewer->print(viewer);
                                return;
                        } else {
-                               /* Force text rendering */
-                               mimeview_show_part_as_text(mimeview,
-                                                          mimeview_get_selected_part(mimeview));
+                               /* Force text rendering if possible */
+                               MimeInfo *mimepart;
+
+                               mimepart = mimeview_get_selected_part(mimeview);
+                               if (mimepart == NULL
+                               ||  (mimepart->type != MIMETYPE_TEXT && mimepart->type != MIMETYPE_MESSAGE)) {
+                                       alertpanel_warning(_("Cannot print: the message doesn't "
+                                                            "contain text."));
+                                       return;
+                               }
+                               mimeview_show_part_as_text(mimeview, mimepart);
                        }
                }
                if (sel_start != -1 && sel_end != -1) {
index ae3cd15..d0d3d97 100644 (file)
@@ -1122,16 +1122,18 @@ static void printing_textview_cb_draw_page(GtkPrintOperation *op, GtkPrintContex
                GdkPixbuf *pixbuf = gtk_image_get_pixbuf(print_data->avatar);
                gdouble startx, starty;
                
-               startx = gtk_print_context_get_width(context)/print_data->zoom;
+               if (pixbuf != NULL) {
+                       startx = gtk_print_context_get_width(context)/print_data->zoom;
                
-               startx -= ((double)gdk_pixbuf_get_width(pixbuf));
+                       startx -= ((double)gdk_pixbuf_get_width(pixbuf));
 
-               starty = start_pos;
+                       starty = start_pos;
 
-               surface = pixbuf_to_surface(pixbuf);
-               cairo_set_source_surface (cr, surface, startx, starty);
-               cairo_paint (cr);
-               cairo_surface_destroy (surface);
+                       surface = pixbuf_to_surface(pixbuf);
+                       cairo_set_source_surface (cr, surface, startx, starty);
+                       cairo_paint (cr);
+                       cairo_surface_destroy (surface);
+               }
        }
 
        pango_layout_iter_free(iter);