[evolution-data-server/wip/camel-more-gobject] Remove unused CamelMessageContentInfo build from CamelFolderSummary



commit b1914bb8b6874d6b8d7564683fbd511fde559438
Author: Milan Crha <mcrha redhat com>
Date:   Tue Sep 13 16:49:04 2016 +0200

    Remove unused CamelMessageContentInfo build from CamelFolderSummary

 camel/camel-folder-summary.c                |  524 ++-------------------------
 camel/camel-folder-summary.h                |   57 +---
 camel/camel-mime-part-utils.c               |  128 +++++++
 camel/camel-mime-part-utils.h               |   33 ++
 camel/providers/imapx/camel-imapx-summary.c |    2 -
 camel/providers/local/camel-local-summary.c |    1 -
 camel/providers/nntp/camel-nntp-summary.c   |    2 -
 7 files changed, 184 insertions(+), 563 deletions(-)
---
diff --git a/camel/camel-folder-summary.c b/camel/camel-folder-summary.c
index 03fcae6..fe4f80d 100644
--- a/camel/camel-folder-summary.c
+++ b/camel/camel-folder-summary.c
@@ -91,8 +91,6 @@ struct _CamelFolderSummaryPrivate {
        guint32 junk_not_deleted_count;
        guint32 visible_count;
 
-       gboolean build_content; /* do we try and parse/index the content, or not? */
-
        GHashTable *uids; /* uids of all known message infos; the 'value' are used flags for the message info 
*/
        GHashTable *loaded_infos; /* uid->CamelMessageInfo *, those currently in memory */
 
@@ -117,25 +115,18 @@ struct _node {
 
 static void cfs_schedule_info_release_timer (CamelFolderSummary *summary);
 
-static struct _node *my_list_append (struct _node **list, struct _node *n);
-static gint my_list_size (struct _node **list);
+static void summary_traverse_content_with_parser (CamelFolderSummary *summary, CamelMessageInfo *msginfo, 
CamelMimeParser *mp);
+static void summary_traverse_content_with_part (CamelFolderSummary *summary, CamelMessageInfo *msginfo, 
CamelMimePart *object);
 
 static CamelMessageInfo * message_info_new_from_header (CamelFolderSummary *, struct _camel_header_raw *);
 static CamelMessageInfo * message_info_new_from_parser (CamelFolderSummary *, CamelMimeParser *);
 static CamelMessageInfo * message_info_new_from_message (CamelFolderSummary *summary, CamelMimeMessage *msg);
 
-static CamelMessageContentInfo * content_info_new_from_header (CamelFolderSummary *, struct 
_camel_header_raw *);
-static CamelMessageContentInfo * content_info_new_from_parser (CamelFolderSummary *, CamelMimeParser *);
-static CamelMessageContentInfo * content_info_new_from_message (CamelFolderSummary *summary, CamelMimePart 
*mp);
-
 static gint save_message_infos_to_db (CamelFolderSummary *summary, GError **error);
 static gint camel_read_mir_callback (gpointer  ref, gint ncol, gchar ** cols, gchar ** name);
 
 static gchar *next_uid_string (CamelFolderSummary *summary);
 
-static CamelMessageContentInfo * summary_build_content_info (CamelFolderSummary *summary, CamelMessageInfo 
*msginfo, CamelMimeParser *mp);
-static CamelMessageContentInfo * summary_build_content_info_message (CamelFolderSummary *summary, 
CamelMessageInfo *msginfo, CamelMimePart *object);
-
 static CamelMessageInfo * message_info_from_uid (CamelFolderSummary *summary, const gchar *uid);
 
 enum {
@@ -146,8 +137,7 @@ enum {
        PROP_DELETED_COUNT,
        PROP_JUNK_COUNT,
        PROP_JUNK_NOT_DELETED_COUNT,
-       PROP_VISIBLE_COUNT,
-       PROP_BUILD_CONTENT
+       PROP_VISIBLE_COUNT
 };
 
 G_DEFINE_TYPE (CamelFolderSummary, camel_folder_summary, G_TYPE_OBJECT)
@@ -265,12 +255,6 @@ folder_summary_set_property (GObject *object,
                                CAMEL_FOLDER_SUMMARY (object),
                                CAMEL_FOLDER (g_value_get_object (value)));
                        return;
-
-               case PROP_BUILD_CONTENT:
-                       camel_folder_summary_set_build_content (
-                               CAMEL_FOLDER_SUMMARY (object),
-                               g_value_get_boolean (value));
-                       return;
        }
 
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -331,13 +315,6 @@ folder_summary_get_property (GObject *object,
                                camel_folder_summary_get_visible_count (
                                CAMEL_FOLDER_SUMMARY (object)));
                        return;
-
-               case PROP_BUILD_CONTENT:
-                       g_value_set_boolean (
-                               value,
-                               camel_folder_summary_get_build_content (
-                               CAMEL_FOLDER_SUMMARY (object)));
-                       return;
        }
 
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -530,123 +507,6 @@ summary_header_to_db (CamelFolderSummary *summary,
        return record;
 }
 
-static CamelMessageContentInfo *
-content_info_from_db (CamelFolderSummary *summary,
-                      CamelMIRecord *record)
-{
-       CamelMessageContentInfo *ci;
-       gchar *type, *subtype;
-       guint32 count, i;
-       CamelContentType *ct;
-       gchar *part = record->cinfo;
-
-       io (printf ("Loading content info from db\n"));
-
-       if (!part)
-               return NULL;
-
-       ci = camel_folder_summary_content_info_new (summary);
-       if (*part == ' ') part++; /* Move off the space in the record */
-
-       type = camel_util_bdata_get_string (&part, NULL);
-       subtype = camel_util_bdata_get_string (&part, NULL);
-       ct = camel_content_type_new (type, subtype);
-       g_free (type);          /* can this be removed? */
-       g_free (subtype);
-       count = camel_util_bdata_get_number (&part, 0);
-
-       for (i = 0; i < count; i++) {
-               gchar *name, *value;
-               name = camel_util_bdata_get_string (&part, NULL);
-               value = camel_util_bdata_get_string (&part, NULL);
-
-               camel_content_type_set_param (ct, name, value);
-               /* TODO: do this so we dont have to double alloc/free */
-               g_free (name);
-               g_free (value);
-       }
-       ci->type = ct;
-
-       /* FIXME[disk-summary] move all these to camel pstring */
-       ci->id = camel_util_bdata_get_string (&part, NULL);
-       ci->description = camel_util_bdata_get_string (&part, NULL);
-       ci->encoding = camel_util_bdata_get_string (&part, NULL);
-       ci->size = camel_util_bdata_get_number (&part, 0);
-
-       record->cinfo = part; /* Keep moving the cursor in the record */
-
-       ci->childs = NULL;
-
-       return ci;
-}
-
-static gboolean
-content_info_to_db (CamelFolderSummary *summary,
-                    CamelMessageContentInfo *ci,
-                    CamelMIRecord *record)
-{
-       CamelContentType *ct;
-       struct _camel_header_param *hp;
-       GString *str = g_string_new (NULL);
-       gchar *oldr;
-
-       io (printf ("Saving content info to db\n"));
-
-       ct = ci->type;
-       if (ct) {
-               if (ct->type)
-                       g_string_append_printf (str, " %d-%s", (gint) strlen (ct->type), ct->type);
-               else
-                       g_string_append_printf (str, " 0-");
-               if (ct->subtype)
-                       g_string_append_printf (str, " %d-%s", (gint) strlen (ct->subtype), ct->subtype);
-               else
-                       g_string_append_printf (str, " 0-");
-               g_string_append_printf (str, " %d", my_list_size ((struct _node **) &ct->params));
-               hp = ct->params;
-               while (hp) {
-                       if (hp->name)
-                               g_string_append_printf (str, " %d-%s", (gint) strlen (hp->name), hp->name);
-                       else
-                               g_string_append_printf (str, " 0-");
-                       if (hp->value)
-                               g_string_append_printf (str, " %d-%s", (gint) strlen (hp->value), hp->value);
-                       else
-                               g_string_append_printf (str, " 0-");
-                       hp = hp->next;
-               }
-       } else {
-               g_string_append_printf (str, " %d-", 0);
-               g_string_append_printf (str, " %d-", 0);
-               g_string_append_printf (str, " %d", 0);
-       }
-
-       if (ci->id)
-               g_string_append_printf (str, " %d-%s", (gint) strlen (ci->id), ci->id);
-       else
-               g_string_append_printf (str, " 0-");
-       if (ci->description)
-               g_string_append_printf (str, " %d-%s", (gint) strlen (ci->description), ci->description);
-       else
-               g_string_append_printf (str, " 0-");
-       if (ci->encoding)
-               g_string_append_printf (str, " %d-%s", (gint) strlen (ci->encoding), ci->encoding);
-       else
-               g_string_append_printf (str, " 0-");
-       g_string_append_printf (str, " %u", ci->size);
-
-       if (record->cinfo) {
-               oldr = record->cinfo;
-               record->cinfo = g_strconcat (oldr, str->str, NULL);
-               g_free (oldr); g_string_free (str, TRUE);
-       } else {
-               record->cinfo = str->str;
-               g_string_free (str, FALSE);
-       }
-
-       return TRUE;
-}
-
 /**
  * camel_folder_summary_replace_flags:
  * @summary: a #CamelFolderSummary
@@ -750,18 +610,12 @@ camel_folder_summary_class_init (CamelFolderSummaryClass *class)
 
        class->summary_header_from_db = summary_header_from_db;
        class->summary_header_to_db = summary_header_to_db;
-       class->content_info_from_db = content_info_from_db;
-       class->content_info_to_db = content_info_to_db;
 
        class->message_info_new_from_header = message_info_new_from_header;
        class->message_info_new_from_parser = message_info_new_from_parser;
        class->message_info_new_from_message = message_info_new_from_message;
        class->message_info_from_uid = message_info_from_uid;
 
-       class->content_info_new_from_header = content_info_new_from_header;
-       class->content_info_new_from_parser = content_info_new_from_parser;
-       class->content_info_new_from_message = content_info_new_from_message;
-
        class->next_uid_string = next_uid_string;
 
        /**
@@ -869,21 +723,6 @@ camel_folder_summary_class_init (CamelFolderSummaryClass *class)
                        "How many visible (not deleted and not junk) infos is saved in a summary",
                        0,  G_MAXUINT32,
                        0, G_PARAM_READABLE));
-
-       /**
-        * CamelFolderSummary:build-content
-        *
-        * Whether to build CamelMessageInfo.content.
-        **/
-       g_object_class_install_property (
-               object_class,
-               PROP_BUILD_CONTENT,
-               g_param_spec_boolean (
-                       "build-content",
-                       "Build content",
-                       "Whether to build CamelMessageInfo.content",
-                       FALSE,
-                       G_PARAM_READWRITE));
 }
 
 static void
@@ -1042,8 +881,6 @@ camel_folder_summary_get_visible_count (CamelFolderSummary *summary)
  *
  * Set the index used to index body content.  If the index is %NULL, or
  * not set (the default), no indexing of body content will take place.
- *
- * Unlike earlier behaviour, build_content need not be set to perform indexing.
  **/
 void
 camel_folder_summary_set_index (CamelFolderSummary *summary,
@@ -1077,45 +914,6 @@ camel_folder_summary_get_index (CamelFolderSummary *summary)
 }
 
 /**
- * camel_folder_summary_set_build_content:
- * @summary: a #CamelFolderSummary object
- * @state: to build or not to build the content
- *
- * Set a flag to tell the summary to build the content info summary
- * (#CamelMessageInfo.content).  The default is not to build content
- * info summaries.
- **/
-void
-camel_folder_summary_set_build_content (CamelFolderSummary *summary,
-                                        gboolean state)
-{
-       g_return_if_fail (CAMEL_IS_FOLDER_SUMMARY (summary));
-
-       if (summary->priv->build_content == state)
-               return;
-
-       summary->priv->build_content = state;
-
-       g_object_notify (G_OBJECT (summary), "build-content");
-}
-
-/**
- * camel_folder_summary_get_build_content:
- * @summary: a #CamelFolderSummary object
- *
- * Returns: Whether to build #CamelMessageInfo.content.
- *
- * Since: 3.4
- **/
-gboolean
-camel_folder_summary_get_build_content (CamelFolderSummary *summary)
-{
-       g_return_val_if_fail (CAMEL_IS_FOLDER_SUMMARY (summary), FALSE);
-
-       return summary->priv->build_content;
-}
-
-/**
  * camel_folder_summary_next_uid:
  * @summary: a #CamelFolderSummary object
  *
@@ -1510,39 +1308,6 @@ camel_folder_summary_get_info_flags (CamelFolderSummary *summary,
        return GPOINTER_TO_UINT (ptr_flags);
 }
 
-static CamelMessageContentInfo *
-perform_content_info_load_from_db (CamelFolderSummary *summary,
-                                   CamelMIRecord *mir)
-{
-       gint i;
-       guint32 count;
-       CamelMessageContentInfo *ci, *pci;
-       gchar *part;
-
-       ci = CAMEL_FOLDER_SUMMARY_GET_CLASS (summary)->content_info_from_db (summary, mir);
-       if (ci == NULL)
-               return NULL;
-       part = mir->cinfo;
-       if (!part)
-               return ci;
-       if (*part == ' ') part++;
-       count = camel_util_bdata_get_number (&part, 0);
-
-       mir->cinfo = part;
-       for (i = 0; i < count; i++) {
-               pci = perform_content_info_load_from_db (summary, mir);
-               if (pci ) {
-                       my_list_append ((struct _node **) &ci->childs, (struct _node *) pci);
-                       pci->parent = ci;
-               } else {
-                       d (fprintf (stderr, "Summary file format messed up?"));
-                       camel_folder_summary_content_info_free (summary, ci);
-                       return NULL;
-               }
-       }
-       return ci;
-}
-
 static void
 gather_dirty_or_flagged_uids (gpointer key,
                              gpointer value,
@@ -2035,23 +1800,6 @@ camel_read_mir_callback (gpointer ref,
        info = camel_message_info_new (summary);
        bdata_ptr = mir->bdata;
        if (camel_message_info_load (info, mir, &bdata_ptr)) {
-               if (summary->priv->build_content) {
-                       gchar *tmp;
-                       tmp = mir->cinfo;
-                       /* FIXME: this should be done differently, how i don't know */
-                       /* #warning Possibly remove the content info code */
-                       /*((CamelMessageInfoBase *) info)->content = perform_content_info_load_from_db 
(summary, mir);
-                       if (((CamelMessageInfoBase *) info)->content == NULL) {
-                               g_clear_object (&info);
-                       }
-                       mir->cinfo = tmp;
-
-                       if (!info) {
-                               camel_db_camel_mir_free (mir);
-                               return -1;
-                       }*/
-               }
-
                /* Just now we are reading from the DB, it can't be dirty. */
                camel_message_info_set_dirty (info, FALSE);
                if (data->add)
@@ -2070,32 +1818,6 @@ camel_read_mir_callback (gpointer ref,
        return ret;
 }
 
-/* saves the content descriptions, recursively */
-static gboolean
-perform_content_info_save_to_db (CamelFolderSummary *summary,
-                                 CamelMessageContentInfo *ci,
-                                 CamelMIRecord *record)
-{
-       CamelMessageContentInfo *part;
-       gchar *oldr;
-
-       if (!CAMEL_FOLDER_SUMMARY_GET_CLASS (summary)->content_info_to_db (summary, ci, record))
-               return FALSE;
-
-       oldr = record->cinfo;
-       record->cinfo = g_strdup_printf ("%s %d", oldr, my_list_size ((struct _node **) &ci->childs));
-       g_free (oldr);
-
-       part = ci->childs;
-       while (part) {
-               if (perform_content_info_save_to_db (summary, part, record) == -1)
-                       return FALSE;
-               part = part->next;
-       }
-
-       return TRUE;
-}
-
 static void
 save_to_db_cb (gpointer key,
                gpointer value,
@@ -2141,17 +1863,6 @@ save_to_db_cb (gpointer key,
        mir->bdata = g_string_free (bdata_str, FALSE);
        bdata_str = NULL;
 
-       if (summary->priv->build_content) {
-               /* #warning Possibly remove the mi::content info */
-               /*if (!perform_content_info_save_to_db (summary, ((CamelMessageInfoBase *) mi)->content, 
mir)) {
-                       g_warning ("unable to save mir+cinfo for uid: %s\n", camel_message_info_get_uid (mi));
-                       camel_db_camel_mir_free (mir);
-                       g_clear_object (&summary);
-                       / * FIXME: Add exception here * /
-                       return;
-               }*/
-       }
-
        if (camel_db_write_message_info_record (cdb, full_name, mir, error) != 0) {
                camel_db_camel_mir_free (mir);
                g_clear_object (&summary);
@@ -2598,6 +2309,9 @@ camel_folder_summary_info_new_from_parser (CamelFolderSummary *summary,
                        camel_mime_filter_index_set_name (CAMEL_MIME_FILTER_INDEX (p->filter_index), name);
                }
 
+               /* always scan the content info, even if we dont save it */
+               summary_traverse_content_with_parser (summary, info, mp);
+
                if (name && p->index) {
                        camel_index_write_name (p->index, name);
                        g_object_unref (name);
@@ -2655,6 +2369,8 @@ camel_folder_summary_info_new_from_message (CamelFolderSummary *summary,
                }
        }
 
+       summary_traverse_content_with_part (summary, info, (CamelMimePart *) msg);
+
        if (name) {
                camel_index_write_name (p->index, name);
                g_object_unref (name);
@@ -2668,36 +2384,6 @@ camel_folder_summary_info_new_from_message (CamelFolderSummary *summary,
 }
 
 /**
- * camel_folder_summary_content_info_free:
- * @summary: a #CamelFolderSummary object
- * @ci: a #CamelMessageContentInfo
- *
- * Free the content info @ci, and all associated memory.
- **/
-void
-camel_folder_summary_content_info_free (CamelFolderSummary *summary,
-                                        CamelMessageContentInfo *ci)
-{
-       CamelMessageContentInfo *pw, *pn;
-
-       g_return_if_fail (ci != NULL);
-
-       pw = ci->childs;
-
-       camel_content_type_unref (ci->type);
-       g_free (ci->id);
-       g_free (ci->description);
-       g_free (ci->encoding);
-       g_slice_free1 (sizeof (CamelMessageContentInfo), ci);
-
-       while (pw) {
-               pn = pw->next;
-               camel_folder_summary_content_info_free (summary, pw);
-               pw = pn;
-       }
-}
-
-/**
  * camel_folder_summary_touch:
  * @summary: a #CamelFolderSummary object
  *
@@ -2909,36 +2595,6 @@ camel_folder_summary_remove_uids (CamelFolderSummary *summary,
        return res;
 }
 
-static struct _node *
-my_list_append (struct _node **list,
-                struct _node *n)
-{
-       struct _node *ln = *list;
-       n->next = NULL;
-
-       if (!ln) {
-               *list = n;
-               return n;
-       }
-
-       while (ln->next)
-               ln = ln->next;
-       ln->next = n;
-       return n;
-}
-
-static gint
-my_list_size (struct _node **list)
-{
-       gint len = 0;
-       struct _node *ln = (struct _node *) list;
-       while (ln->next) {
-               ln = ln->next;
-               len++;
-       }
-       return len;
-}
-
 /* are these even useful for anything??? */
 static CamelMessageInfo *
 message_info_new_from_parser (CamelFolderSummary *summary,
@@ -2961,31 +2617,6 @@ message_info_new_from_parser (CamelFolderSummary *summary,
        return mi;
 }
 
-static CamelMessageContentInfo *
-content_info_new_from_parser (CamelFolderSummary *summary,
-                              CamelMimeParser *mp)
-{
-       CamelMessageContentInfo *ci = NULL;
-
-       switch (camel_mime_parser_state (mp)) {
-       case CAMEL_MIME_PARSER_STATE_HEADER:
-       case CAMEL_MIME_PARSER_STATE_MESSAGE:
-       case CAMEL_MIME_PARSER_STATE_MULTIPART:
-               ci = CAMEL_FOLDER_SUMMARY_GET_CLASS (summary)->content_info_new_from_header (summary, 
camel_mime_parser_headers_raw (mp));
-               if (ci) {
-                       if (ci->type)
-                               camel_content_type_unref (ci->type);
-                       ci->type = camel_mime_parser_content_type (mp);
-                       camel_content_type_ref (ci->type);
-               }
-               break;
-       default:
-               g_error ("Invalid parser state");
-       }
-
-       return ci;
-}
-
 static CamelMessageInfo *
 message_info_new_from_message (CamelFolderSummary *summary,
                                CamelMimeMessage *msg)
@@ -2993,17 +2624,6 @@ message_info_new_from_message (CamelFolderSummary *summary,
        return CAMEL_FOLDER_SUMMARY_GET_CLASS (summary)->message_info_new_from_header (summary, 
((CamelMimePart *) msg)->headers);
 }
 
-static CamelMessageContentInfo *
-content_info_new_from_message (CamelFolderSummary *summary,
-                               CamelMimePart *mp)
-{
-       CamelMessageContentInfo *ci;
-
-       ci = CAMEL_FOLDER_SUMMARY_GET_CLASS (summary)->content_info_new_from_header (summary, mp->headers);
-
-       return ci;
-}
-
 static gchar *
 summary_format_address (struct _camel_header_raw *h,
                         const gchar *name,
@@ -3051,23 +2671,6 @@ summary_format_string (struct _camel_header_raw *h,
        return str;
 }
 
-/**
- * camel_folder_summary_content_info_new:
- * @summary: a #CamelFolderSummary object
- *
- * Allocate a new #CamelMessageContentInfo, suitable for adding
- * to this summary.
- *
- * Returns: a newly allocated #CamelMessageContentInfo
- **/
-CamelMessageContentInfo *
-camel_folder_summary_content_info_new (CamelFolderSummary *summary)
-{
-       g_return_val_if_fail (CAMEL_IS_FOLDER_SUMMARY (summary), NULL);
-
-       return g_slice_alloc0 (sizeof (CamelMessageContentInfo));
-}
-
 static CamelMessageInfo *
 message_info_new_from_header (CamelFolderSummary *summary,
                               struct _camel_header_raw *h)
@@ -3198,24 +2801,6 @@ message_info_new_from_header (CamelFolderSummary *summary,
        return mi;
 }
 
-static CamelMessageContentInfo *
-content_info_new_from_header (CamelFolderSummary *summary,
-                              struct _camel_header_raw *h)
-{
-       CamelMessageContentInfo *ci;
-       const gchar *charset;
-
-       ci = camel_folder_summary_content_info_new (summary);
-
-       charset = camel_iconv_locale_charset ();
-       ci->id = camel_header_msgid_decode (camel_header_raw_find (&h, "content-id", NULL));
-       ci->description = camel_header_decode_string (camel_header_raw_find (&h, "content-description", 
NULL), charset);
-       ci->encoding = camel_content_transfer_encoding_decode (camel_header_raw_find (&h, 
"content-transfer-encoding", NULL));
-       ci->type = camel_content_type_decode (camel_header_raw_find (&h, "content-type", NULL));
-
-       return ci;
-}
-
 static gchar *
 next_uid_string (CamelFolderSummary *summary)
 {
@@ -3229,30 +2814,25 @@ next_uid_string (CamelFolderSummary *summary)
 */
 
 /* must have filter_lock before calling this function */
-static CamelMessageContentInfo *
-summary_build_content_info (CamelFolderSummary *summary,
-                            CamelMessageInfo *msginfo,
-                            CamelMimeParser *mp)
+static void
+summary_traverse_content_with_parser (CamelFolderSummary *summary,
+                                     CamelMessageInfo *msginfo,
+                                     CamelMimeParser *mp)
 {
        gint state;
        gsize len;
        gchar *buffer;
-       CamelMessageContentInfo *info = NULL;
        CamelContentType *ct;
        gint enc_id = -1, chr_id = -1, html_id = -1, idx_id = -1;
        CamelFolderSummaryPrivate *p = summary->priv;
        CamelMimeFilter *mfc;
-       CamelMessageContentInfo *part;
        const gchar *calendar_header;
 
-       d (printf ("building content info\n"));
+       d (printf ("traversing content\n"));
 
        /* start of this part */
        state = camel_mime_parser_step (mp, &buffer, &len);
 
-       if (summary->priv->build_content)
-               info = CAMEL_FOLDER_SUMMARY_GET_CLASS (summary)->content_info_new_from_parser (summary, mp);
-
        switch (state) {
        case CAMEL_MIME_PARSER_STATE_HEADER:
                /* check content type for indexing, then read body */
@@ -3368,11 +2948,7 @@ summary_build_content_info (CamelFolderSummary *summary,
 
                while (camel_mime_parser_step (mp, &buffer, &len) != CAMEL_MIME_PARSER_STATE_MULTIPART_END) {
                        camel_mime_parser_unstep (mp);
-                       part = summary_build_content_info (summary, msginfo, mp);
-                       if (part) {
-                               part->parent = info;
-                               my_list_append ((struct _node **) &info->childs, (struct _node *) part);
-                       }
+                       summary_traverse_content_with_parser (summary, msginfo, mp);
                }
                break;
        case CAMEL_MIME_PARSER_STATE_MESSAGE:
@@ -3380,11 +2956,7 @@ summary_build_content_info (CamelFolderSummary *summary,
                /* update attachments flag as we go */
                camel_message_info_set_flags (msginfo, CAMEL_MESSAGE_ATTACHMENTS, CAMEL_MESSAGE_ATTACHMENTS);
 
-               part = summary_build_content_info (summary, msginfo, mp);
-               if (part) {
-                       part->parent = info;
-                       my_list_append ((struct _node **) &info->childs, (struct _node *) part);
-               }
+               summary_traverse_content_with_parser (summary, msginfo, mp);
                state = camel_mime_parser_step (mp, &buffer, &len);
                if (state != CAMEL_MIME_PARSER_STATE_MESSAGE_END) {
                        g_error ("Bad parser state: Expecing MESSAGE_END or MESSAGE_EOF, got: %d", state);
@@ -3393,33 +2965,27 @@ summary_build_content_info (CamelFolderSummary *summary,
                break;
        }
 
-       d (printf ("finished building content info\n"));
-
-       return info;
+       d (printf ("finished traversion content info\n"));
 }
 
 /* build the content-info, from a message */
 /* this needs the filter lock since it uses filters to perform indexing */
-static CamelMessageContentInfo *
-summary_build_content_info_message (CamelFolderSummary *summary,
+static void
+summary_traverse_content_with_part (CamelFolderSummary *summary,
                                     CamelMessageInfo *msginfo,
                                     CamelMimePart *object)
 {
        CamelDataWrapper *containee;
        gint parts, i;
        CamelFolderSummaryPrivate *p = summary->priv;
-       CamelMessageContentInfo *info = NULL, *child;
        CamelContentType *ct;
        const struct _camel_header_raw *header;
        gboolean is_calendar = FALSE, is_note = FALSE;
 
-       if (summary->priv->build_content)
-               info = CAMEL_FOLDER_SUMMARY_GET_CLASS (summary)->content_info_new_from_message (summary, 
object);
-
        containee = camel_medium_get_content (CAMEL_MEDIUM (object));
 
        if (containee == NULL)
-               return info;
+               return;
 
        /* TODO: I find it odd that get_part and get_content do not
         * add a reference, probably need fixing for multithreading */
@@ -3475,20 +3041,12 @@ summary_build_content_info_message (CamelFolderSummary *summary,
 
                for (i = 0; i < parts; i++) {
                        CamelMimePart *part = camel_multipart_get_part (CAMEL_MULTIPART (containee), i);
-                       g_return_val_if_fail (part, info);
-                       child = summary_build_content_info_message (summary, msginfo, part);
-                       if (child) {
-                               child->parent = info;
-                               my_list_append ((struct _node **) &info->childs, (struct _node *) child);
-                       }
+                       g_return_if_fail (part);
+                       summary_traverse_content_with_part (summary, msginfo, part);
                }
        } else if (CAMEL_IS_MIME_MESSAGE (containee)) {
                /* for messages we only look at its contents */
-               child = summary_build_content_info_message (summary, msginfo, (CamelMimePart *) containee);
-               if (child) {
-                       child->parent = info;
-                       my_list_append ((struct _node **) &info->childs, (struct _node *) child);
-               }
+               summary_traverse_content_with_part (summary, msginfo, (CamelMimePart *) containee);
        } else if (p->filter_stream
                   && camel_content_type_is (ct, "text", "*")) {
                gint html_id = -1, idx_id = -1;
@@ -3517,8 +3075,6 @@ summary_build_content_info_message (CamelFolderSummary *summary,
                camel_stream_filter_remove (
                        CAMEL_STREAM_FILTER (p->filter_stream), html_id);
        }
-
-       return info;
 }
 
 static struct flag_names_t {
@@ -3595,42 +3151,6 @@ camel_message_info_new_from_header (CamelFolderSummary *summary,
                return message_info_new_from_header (NULL, header);
 }
 
-void
-camel_content_info_dump (CamelMessageContentInfo *ci,
-                         gint depth)
-{
-       gchar *p;
-
-       p = alloca (depth * 4 + 1);
-       memset (p, ' ', depth * 4);
-       p[depth * 4] = 0;
-
-       if (ci == NULL) {
-               printf ("%s<empty>\n", p);
-               return;
-       }
-
-       if (ci->type)
-               printf (
-                       "%scontent-type: %s/%s\n",
-                       p, ci->type->type ? ci->type->type : "(null)",
-                       ci->type->subtype ? ci->type->subtype : "(null)");
-       else
-               printf ("%scontent-type: <unset>\n", p);
-       printf (
-               "%scontent-transfer-encoding: %s\n",
-               p, ci->encoding ? ci->encoding : "(null)");
-       printf (
-               "%scontent-description: %s\n",
-               p, ci->description ? ci->description : "(null)");
-       printf ("%ssize: %lu\n", p, (gulong) ci->size);
-       ci = ci->childs;
-       while (ci) {
-               camel_content_info_dump (ci, depth + 1);
-               ci = ci->next;
-       }
-}
-
 /**
  * camel_folder_summary_lock:
  * @summary: a #CamelFolderSummary
diff --git a/camel/camel-folder-summary.h b/camel/camel-folder-summary.h
index 62fcd9a..0e8346e 100644
--- a/camel/camel-folder-summary.h
+++ b/camel/camel-folder-summary.h
@@ -60,23 +60,6 @@ typedef struct _CamelFolderSummary CamelFolderSummary;
 typedef struct _CamelFolderSummaryClass CamelFolderSummaryClass;
 typedef struct _CamelFolderSummaryPrivate CamelFolderSummaryPrivate;
 
-typedef struct _CamelMessageContentInfo CamelMessageContentInfo;
-
-/* A tree of message content info structures
- * describe the content structure of the message (if it has any) */
-struct _CamelMessageContentInfo {
-       CamelMessageContentInfo *next;
-
-       CamelMessageContentInfo *childs;
-       CamelMessageContentInfo *parent;
-
-       CamelContentType *type;
-       gchar *id;
-       gchar *description;
-       gchar *encoding;                /* this should be an enum?? */
-       guint32 size;
-};
-
 /**
  * CamelFolderSummaryFlags:
  * @CAMEL_FOLDER_SUMMARY_DIRTY:
@@ -123,16 +106,7 @@ struct _CamelFolderSummaryClass {
                                        (CamelFolderSummary *summary,
                                         GError **error);
 
-       CamelMessageContentInfo *
-                       (*content_info_from_db)
-                                       (CamelFolderSummary *summary,
-                                        struct _CamelMIRecord *mir);
-       gboolean        (*content_info_to_db)
-                                       (CamelFolderSummary *summary,
-                                        CamelMessageContentInfo *info,
-                                        struct _CamelMIRecord *mir);
-
-       /* create/save/load an individual message info */
+       /* create an individual message info */
        CamelMessageInfo *
                        (*message_info_new_from_header)
                                        (CamelFolderSummary *summary,
@@ -146,19 +120,6 @@ struct _CamelFolderSummaryClass {
                                        (CamelFolderSummary *summary,
                                         CamelMimeMessage *message);
 
-       /* save/load individual content info's */
-       CamelMessageContentInfo *
-                       (*content_info_new_from_header)
-                                       (CamelFolderSummary *summary,
-                                        struct _camel_header_raw *header);
-       CamelMessageContentInfo *
-                       (*content_info_new_from_parser)
-                                       (CamelFolderSummary *summary,
-                                        CamelMimeParser *parser);
-       CamelMessageContentInfo *
-                       (*content_info_new_from_message)
-                                       (CamelFolderSummary *summary,
-                                        CamelMimePart *mime_part);
        CamelMessageInfo *
                        (*message_info_from_uid)
                                        (CamelFolderSummary *summary,
@@ -195,11 +156,6 @@ guint32            camel_folder_summary_get_visible_count
 void           camel_folder_summary_set_index  (CamelFolderSummary *summary,
                                                 CamelIndex *index);
 CamelIndex *   camel_folder_summary_get_index  (CamelFolderSummary *summary);
-void           camel_folder_summary_set_build_content
-                                               (CamelFolderSummary *summary,
-                                                gboolean state);
-gboolean       camel_folder_summary_get_build_content
-                                               (CamelFolderSummary *summary);
 guint32                camel_folder_summary_next_uid   (CamelFolderSummary *summary);
 void           camel_folder_summary_set_next_uid
                                                (CamelFolderSummary *summary,
@@ -243,13 +199,6 @@ CamelMessageInfo *
                                                (CamelFolderSummary *summary,
                                                 CamelMimeMessage *message);
 
-CamelMessageContentInfo *
-               camel_folder_summary_content_info_new
-                                               (CamelFolderSummary *summary);
-void           camel_folder_summary_content_info_free
-                                               (CamelFolderSummary *summary,
-                                                CamelMessageContentInfo *ci);
-
 /* add a new raw summary item */
 void           camel_folder_summary_add        (CamelFolderSummary *summary,
                                                 CamelMessageInfo *info);
@@ -319,10 +268,6 @@ CamelMessageInfo *
                camel_message_info_new_from_header
                                                (CamelFolderSummary *summary,
                                                 struct _camel_header_raw *header);
-/* debugging functions */
-void           camel_content_info_dump         (CamelMessageContentInfo *ci,
-                                                gint depth);
-
 G_END_DECLS
 
 #endif /* CAMEL_FOLDER_SUMMARY_H */
diff --git a/camel/camel-mime-part-utils.c b/camel/camel-mime-part-utils.c
index 6ee8e11..0975f71 100644
--- a/camel/camel-mime-part-utils.c
+++ b/camel/camel-mime-part-utils.c
@@ -32,6 +32,7 @@
 
 #include "camel-charset-map.h"
 #include "camel-html-parser.h"
+#include "camel-iconv.h"
 #include "camel-mime-filter-basic.h"
 #include "camel-mime-filter-charset.h"
 #include "camel-mime-filter-crlf.h"
@@ -151,3 +152,130 @@ camel_mime_part_construct_content_from_parser (CamelMimePart *dw,
 
        return success;
 }
+
+
+/**
+ * camel_message_content_info_new:
+ *
+ * Allocate a new #CamelMessageContentInfo.
+ *
+ * Returns: a newly allocated #CamelMessageContentInfo
+ **/
+CamelMessageContentInfo *
+camel_message_content_info_new (void)
+{
+       return g_slice_alloc0 (sizeof (CamelMessageContentInfo));
+}
+
+/**
+ * camel_message_content_info_free:
+ * @ci: a #CamelMessageContentInfo
+ *
+ * Recursively frees the content info @ci, and all associated memory.
+ **/
+void
+camel_message_content_info_free (CamelMessageContentInfo *ci)
+{
+       CamelMessageContentInfo *pw, *pn;
+
+       pw = ci->childs;
+
+       camel_content_type_unref (ci->type);
+       g_free (ci->id);
+       g_free (ci->description);
+       g_free (ci->encoding);
+       g_slice_free1 (sizeof (CamelMessageContentInfo), ci);
+
+       while (pw) {
+               pn = pw->next;
+               camel_message_content_info_free (pw);
+               pw = pn;
+       }
+}
+
+CamelMessageContentInfo *
+camel_message_content_info_new_from_parser (CamelMimeParser *mp)
+{
+       CamelMessageContentInfo *ci = NULL;
+
+       g_return_val_if_fail (CAMEL_IS_MIME_PARSER (mp), NULL);
+
+       switch (camel_mime_parser_state (mp)) {
+       case CAMEL_MIME_PARSER_STATE_HEADER:
+       case CAMEL_MIME_PARSER_STATE_MESSAGE:
+       case CAMEL_MIME_PARSER_STATE_MULTIPART:
+               ci = camel_message_content_info_new_from_header (camel_mime_parser_headers_raw (mp));
+               if (ci) {
+                       if (ci->type)
+                               camel_content_type_unref (ci->type);
+                       ci->type = camel_mime_parser_content_type (mp);
+                       camel_content_type_ref (ci->type);
+               }
+               break;
+       default:
+               g_error ("Invalid parser state");
+       }
+
+       return ci;
+}
+
+CamelMessageContentInfo *
+camel_message_content_info_new_from_message (CamelMimePart *mp)
+{
+       g_return_val_if_fail (CAMEL_IS_MIME_PART (mp), NULL);
+
+       return camel_message_content_info_new_from_header (mp->headers);
+}
+
+CamelMessageContentInfo *
+camel_message_content_info_new_from_header (struct _camel_header_raw *h)
+{
+       CamelMessageContentInfo *ci;
+       const gchar *charset;
+
+       ci = camel_message_content_info_new ();
+
+       charset = camel_iconv_locale_charset ();
+       ci->id = camel_header_msgid_decode (camel_header_raw_find (&h, "content-id", NULL));
+       ci->description = camel_header_decode_string (camel_header_raw_find (&h, "content-description", 
NULL), charset);
+       ci->encoding = camel_content_transfer_encoding_decode (camel_header_raw_find (&h, 
"content-transfer-encoding", NULL));
+       ci->type = camel_content_type_decode (camel_header_raw_find (&h, "content-type", NULL));
+
+       return ci;
+}
+
+void
+camel_message_content_info_dump (CamelMessageContentInfo *ci,
+                                gint depth)
+{
+       gchar *p;
+
+       p = alloca (depth * 4 + 1);
+       memset (p, ' ', depth * 4);
+       p[depth * 4] = 0;
+
+       if (ci == NULL) {
+               printf ("%s<empty>\n", p);
+               return;
+       }
+
+       if (ci->type)
+               printf (
+                       "%scontent-type: %s/%s\n",
+                       p, ci->type->type ? ci->type->type : "(null)",
+                       ci->type->subtype ? ci->type->subtype : "(null)");
+       else
+               printf ("%scontent-type: <unset>\n", p);
+       printf (
+               "%scontent-transfer-encoding: %s\n",
+               p, ci->encoding ? ci->encoding : "(null)");
+       printf (
+               "%scontent-description: %s\n",
+               p, ci->description ? ci->description : "(null)");
+       printf ("%ssize: %lu\n", p, (gulong) ci->size);
+       ci = ci->childs;
+       while (ci) {
+               camel_message_content_info_dump (ci, depth + 1);
+               ci = ci->next;
+       }
+}
diff --git a/camel/camel-mime-part-utils.h b/camel/camel-mime-part-utils.h
index b5e9580..0147ac5 100644
--- a/camel/camel-mime-part-utils.h
+++ b/camel/camel-mime-part-utils.h
@@ -36,6 +36,39 @@ gboolean     camel_mime_part_construct_content_from_parser
                                                 GCancellable *cancellable,
                                                 GError **error);
 
+typedef struct _CamelMessageContentInfo CamelMessageContentInfo;
+
+/* A tree of message content info structures
+ * describe the content structure of the message (if it has any) */
+struct _CamelMessageContentInfo {
+       CamelMessageContentInfo *next;
+
+       CamelMessageContentInfo *childs;
+       CamelMessageContentInfo *parent;
+
+       CamelContentType *type;
+       gchar *id;
+       gchar *description;
+       gchar *encoding;
+       guint32 size;
+};
+
+CamelMessageContentInfo *
+               camel_message_content_info_new  (void);
+void           camel_message_content_info_free (CamelMessageContentInfo *content_info);
+CamelMessageContentInfo *
+               camel_message_content_info_new_from_header
+                                               (struct _camel_header_raw *header);
+CamelMessageContentInfo *
+               camel_message_content_info_new_from_parser
+                                               (CamelMimeParser *parser);
+CamelMessageContentInfo *
+               camel_message_content_info_new_from_message
+                                               (CamelMimePart *mime_part);
+/* debugging functions */
+void           camel_message_content_info_dump (CamelMessageContentInfo *ci,
+                                                gint depth);
+
 G_END_DECLS
 
 #endif /*  CAMEL_MIME_PART_UTILS_H  */
diff --git a/camel/providers/imapx/camel-imapx-summary.c b/camel/providers/imapx/camel-imapx-summary.c
index f348c30..92e8b95 100644
--- a/camel/providers/imapx/camel-imapx-summary.c
+++ b/camel/providers/imapx/camel-imapx-summary.c
@@ -176,8 +176,6 @@ camel_imapx_summary_new (CamelFolder *folder)
                summary->collate = "imapx_uid_sort";
        }
 
-       camel_folder_summary_set_build_content (summary, TRUE);
-
        if (!camel_folder_summary_load_from_db (summary, &local_error)) {
                /* FIXME: Isn't this dangerous ? We clear the summary
                if it cannot be loaded, for some random reason.
diff --git a/camel/providers/local/camel-local-summary.c b/camel/providers/local/camel-local-summary.c
index f80f181..db81d0d 100644
--- a/camel/providers/local/camel-local-summary.c
+++ b/camel/providers/local/camel-local-summary.c
@@ -148,7 +148,6 @@ camel_local_summary_construct (CamelLocalSummary *new,
                                const gchar *local_name,
                                CamelIndex *index)
 {
-       camel_folder_summary_set_build_content (CAMEL_FOLDER_SUMMARY (new), FALSE);
        new->folder_path = g_strdup (local_name);
        new->index = index;
        if (index)
diff --git a/camel/providers/nntp/camel-nntp-summary.c b/camel/providers/nntp/camel-nntp-summary.c
index 563059c..acb75bc 100644
--- a/camel/providers/nntp/camel-nntp-summary.c
+++ b/camel/providers/nntp/camel-nntp-summary.c
@@ -90,8 +90,6 @@ camel_nntp_summary_new (CamelFolder *folder)
 
        cns = g_object_new (CAMEL_TYPE_NNTP_SUMMARY, "folder", folder, NULL);
 
-       camel_folder_summary_set_build_content ((CamelFolderSummary *) cns, FALSE);
-
        return cns;
 }
 


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