Modified webpage: now tinymail repository is in gitorious.
[modest] / src / widgets / modest-header-view-render.c
index a7a242a..455c94e 100644 (file)
@@ -48,6 +48,8 @@
 #define SMALL_ICON_SIZE MODEST_ICON_SIZE_SMALL
 #endif
 
+#define MODEST_HEADER_VIEW_MAX_TEXT_LENGTH 128
+
 static const gchar *
 get_status_string (ModestTnySendQueueStatus status)
 {
@@ -71,7 +73,7 @@ get_status_string (ModestTnySendQueueStatus status)
 }
 
 static GdkPixbuf*
-get_pixbuf_for_flag (TnyHeaderFlags flag)
+get_pixbuf_for_flag (TnyHeaderFlags flag, gboolean is_calendar)
 {
        /* optimization */
        static GdkPixbuf *deleted_pixbuf          = NULL;
@@ -80,6 +82,14 @@ get_pixbuf_for_flag (TnyHeaderFlags flag)
        static GdkPixbuf *attachments_pixbuf      = NULL;
        static GdkPixbuf *high_pixbuf             = NULL;
        static GdkPixbuf *low_pixbuf             = NULL;
+       static GdkPixbuf *calendar_pixbuf             = NULL;
+
+       if (is_calendar) {
+               if (G_UNLIKELY(!calendar_pixbuf))
+                       calendar_pixbuf = modest_platform_get_icon (MODEST_HEADER_ICON_CALENDAR,
+                                                                   SMALL_ICON_SIZE);
+               return calendar_pixbuf;
+       }
        
        switch (flag) {
        case TNY_HEADER_FLAG_DELETED:
@@ -127,14 +137,33 @@ set_common_flags (GtkCellRenderer *renderer, TnyHeaderFlags flags)
 }
 
 static void
-set_cell_text (GtkCellRenderer *renderer, 
-              const gchar *text, 
+set_cell_text (GtkCellRenderer *renderer,
+              const gchar *text,
               TnyHeaderFlags flags)
 {
        gboolean strikethrough;
        gboolean bold_is_active_color;
        GdkColor *color = NULL;
        PangoWeight weight;
+       gchar *newtext = NULL;
+
+       /* We have to limit the size of the text. Otherwise Pango
+          could cause freezes trying to render too large texts. This
+          prevents DoS attacks with specially malformed emails */
+       if (g_utf8_validate(text, -1, NULL)) {
+               if (g_utf8_strlen (text, -1) > MODEST_HEADER_VIEW_MAX_TEXT_LENGTH) {
+                       /* UTF-8 bytes are 4 bytes length in the worst case */
+                       newtext = g_malloc0 (MODEST_HEADER_VIEW_MAX_TEXT_LENGTH * 4);
+                       g_utf8_strncpy (newtext, text, MODEST_HEADER_VIEW_MAX_TEXT_LENGTH);
+                       text = newtext;
+               }
+       } else {
+               if (strlen (text) > MODEST_HEADER_VIEW_MAX_TEXT_LENGTH) {
+                       newtext = g_malloc0 (MODEST_HEADER_VIEW_MAX_TEXT_LENGTH);
+                       strncpy (newtext, text, MODEST_HEADER_VIEW_MAX_TEXT_LENGTH);
+                       text = newtext;
+               }
+       }
 
        bold_is_active_color = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (renderer), BOLD_IS_ACTIVE_COLOR));
        if (bold_is_active_color) {
@@ -165,6 +194,10 @@ set_cell_text (GtkCellRenderer *renderer,
                                      NULL);
                }
        }
+
+       if (newtext)
+               g_free (newtext);
+
        g_object_thaw_notify (G_OBJECT (renderer));
 }
 
@@ -179,7 +212,7 @@ _modest_header_view_attach_cell_data (GtkTreeViewColumn *column, GtkCellRenderer
 
        if (flags & TNY_HEADER_FLAG_ATTACHMENTS)
                g_object_set (G_OBJECT (renderer), "pixbuf",
-                             get_pixbuf_for_flag (TNY_HEADER_FLAG_ATTACHMENTS),
+                             get_pixbuf_for_flag (TNY_HEADER_FLAG_ATTACHMENTS, FALSE),
                              NULL);
 }
 
@@ -271,6 +304,7 @@ _modest_header_view_compact_header_cell_data  (GtkTreeViewColumn *column,  GtkCe
                *recipient_box, *subject_box = NULL;
        TnyHeader *msg_header = NULL;
        TnyHeaderFlags prio = 0;
+       gboolean is_calendar = FALSE;
 
 #ifdef MAEMO_CHANGES
 #ifdef HAVE_GTK_TREE_VIEW_COLUMN_GET_CELL_DATA_HINT
@@ -321,16 +355,19 @@ _modest_header_view_compact_header_cell_data  (GtkTreeViewColumn *column,  GtkCe
        /* FIXME: we might gain something by doing all the g_object_set's at once */
        if (flags & TNY_HEADER_FLAG_ATTACHMENTS)
                g_object_set (G_OBJECT (attach_cell), "pixbuf",
-                             get_pixbuf_for_flag (TNY_HEADER_FLAG_ATTACHMENTS),
+                             get_pixbuf_for_flag (TNY_HEADER_FLAG_ATTACHMENTS, FALSE),
                              NULL);
        else
                g_object_set (G_OBJECT (attach_cell), "pixbuf",
                              NULL, NULL);
 
-       if (msg_header)
+       is_calendar = tny_header_get_user_flag (msg_header, "calendar");
+       if (msg_header) {
                prio = tny_header_get_priority (msg_header);
+       }
+       
        g_object_set (G_OBJECT (priority_cell), "pixbuf",
-                     get_pixbuf_for_flag (prio), 
+                     get_pixbuf_for_flag (prio, is_calendar),
                      NULL);
 
        set_cell_text (subject_cell, (subject && subject[0] != 0)?subject:_("mail_va_no_subject"),