0.9.6claws26
authorChristoph Hohmann <reboot@gmx.ch>
Tue, 14 Oct 2003 20:44:29 +0000 (20:44 +0000)
committerChristoph Hohmann <reboot@gmx.ch>
Tue, 14 Oct 2003 20:44:29 +0000 (20:44 +0000)
* src/compose.c
* src/mimeview.c
* src/procmime.[ch]
* src/rfc2015.c
* src/textview.c
* src/plugins/clamav/clamav_plugin.c
        use GNode to create the mime tree (some changes to functions
        that traverse the tree are just quick and dirty. Maybe we
        can find better solutions with g_node_*-functions)

ChangeLog.claws
configure.ac
src/compose.c
src/mimeview.c
src/plugins/clamav/clamav_plugin.c
src/procmime.c
src/procmime.h
src/rfc2015.c
src/textview.c

index 0fbca39e3d8651f5454532968575c608e3b8b793..df6f23f384afcef6953a0045510fa46444ed38de 100644 (file)
@@ -1,4 +1,17 @@
+2003-10-14 [christoph] 0.9.6claws26
+
+       * src/compose.c
+       * src/mimeview.c
+       * src/procmime.[ch]
+       * src/rfc2015.c
+       * src/textview.c
+       * src/plugins/clamav/clamav_plugin.c
+               use GNode to create the mime tree (some changes to functions
+               that traverse the tree are just quick and dirty. Maybe we
+               can find better solutions with g_node_*-functions)
+
 2003-10-14 [luke]      0.9.6claws25
+
        * src/mimeview.c
                fix a navigation bug (stupid typo of mine)
 
index 41493ce6548fbb9ab073edb9cb1136884c93c2b5..cbf194ae11671afcc53bab44c2078384d7d21c15 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=9
 MICRO_VERSION=6
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=25
+EXTRA_VERSION=26
 if test $EXTRA_VERSION -eq 0; then
     VERSION=${MAJOR_VERSION}.${MINOR_VERSION}.${MICRO_VERSION}claws
 else
index 6166aecf073ec7fc0c0b4af1de79012a87aaa6f7..d21118c36c7f34cf7b55863d46c6d9ee008d5ecc 100644 (file)
@@ -2171,8 +2171,8 @@ static void compose_attach_append(Compose *compose, const gchar *file,
        ((info->type == MIMETYPE_TEXT) || \
         (info->type == MIMETYPE_MULTIPART && info->subtype && \
          !strcasecmp(info->subtype, "alternative") && \
-         (info->children && \
-          (info->children->type == MIMETYPE_TEXT))))
+         (info->node->children && \
+          (((MimeInfo *) info->node->children->data)->type == MIMETYPE_TEXT))))
 
 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
 {
@@ -2185,25 +2185,25 @@ static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
        if (!mimeinfo) return;
 
        /* skip first text (presumably message body) */
-       child = mimeinfo->children;
+       child = (MimeInfo *) mimeinfo->node->children->data;
        if (!child || IS_FIRST_PART_TEXT(mimeinfo)) {
                procmime_mimeinfo_free_all(mimeinfo);
                return;
        }
 
        if (IS_FIRST_PART_TEXT(child))
-               child = child->next;
+               child = (MimeInfo *) child->node->next;
 
        infile = procmsg_get_message_file_path(msginfo);
 
        while (child != NULL) {
-               if (child->children || child->type == MIMETYPE_MULTIPART) {
+               if (child->node->children || child->type == MIMETYPE_MULTIPART) {
                        child = procmime_mimeinfo_next(child);
                        continue;
                }
-               if (child->parent && child->parent->parent
-               && (child->parent->parent->type == MIMETYPE_MULTIPART)
-               && !strcasecmp(child->parent->parent->subtype, "signed")
+               if (child->node->parent && child->node->parent->parent
+               && (((MimeInfo *) child->node->parent->parent->data)->type == MIMETYPE_MULTIPART)
+               && !strcasecmp(((MimeInfo *) child->node->parent->parent->data)->subtype, "signed")
                && child->type == MIMETYPE_TEXT) {
                        /* this is the main text part of a signed message */
                        child = procmime_mimeinfo_next(child);
@@ -2224,7 +2224,7 @@ static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
                        g_free(content_type);
                }
 
-               child = child->next;
+               child = child->node->next != NULL ? (MimeInfo *) child->node->next->data : NULL;
        }
 
        g_free(infile);
index 8d6d465a227489ebd3d8196d0787b4c871544292..24e9cb1c4d7cb23f540d96c22bde928d5d8a5d9d 100644 (file)
@@ -390,9 +390,9 @@ static void mimeview_set_multipart_tree(MimeView *mimeview,
        while (mimeinfo != NULL) {
                node = mimeview_append_part(mimeview, mimeinfo, parent);
 
-               if (mimeinfo->children)
-                       mimeview_set_multipart_tree(mimeview, mimeinfo->children, node);
-               mimeinfo = mimeinfo->next;
+               if (mimeinfo->node->children)
+                       mimeview_set_multipart_tree(mimeview, (MimeInfo *) mimeinfo->node->children->data, node);
+               mimeinfo = mimeinfo->node->next != NULL ? (MimeInfo *) mimeinfo->node->next->data : NULL;
        }
 }
 
@@ -892,8 +892,9 @@ static void mimeview_save_all(MimeView *mimeview)
        }
 
        /* return to first children */
-       if (!partinfo->parent->children) return;  /* multipart container? */
-       attachment = partinfo->parent->children->next;
+       if (partinfo->node->parent->children == NULL) return;  /* multipart container? */
+       attachment = partinfo->node->parent->children->next != NULL ?
+           (MimeInfo *) partinfo->node->parent->children->next->data : NULL;
        /* for each attachment, extract it in the selected dir. */
        while (attachment != NULL) {
                static guint subst_cnt = 1;
@@ -926,7 +927,7 @@ static void mimeview_save_all(MimeView *mimeview)
 
                if ((G_ALERTDEFAULT != aval) || (procmime_get_part(buf, attachment) < 0))
                        alertpanel_error(_("Can't save the part of multipart message."));
-               attachment = attachment->next;
+               attachment = attachment->node->next != NULL ? (MimeInfo *) attachment->node->next->data : NULL;
        }
 }
 
@@ -1476,9 +1477,9 @@ static void icon_list_create(MimeView *mimeview, MimeInfo *mimeinfo)
        while (mimeinfo != NULL) {
                if (mimeinfo->type != MIMETYPE_MULTIPART)
                        icon_list_append_icon(mimeview, mimeinfo);
-               if (mimeinfo->children != NULL)
-                       icon_list_create(mimeview, mimeinfo->children);
-               mimeinfo = mimeinfo->next;
+               if (mimeinfo->node->children != NULL)
+                       icon_list_create(mimeview, (MimeInfo *) mimeinfo->node->children->data);
+               mimeinfo = mimeinfo->node->next != NULL ? (MimeInfo *) mimeinfo->node->next->data : NULL;
        }
        gtk_widget_size_request(mimeview->icon_vbox, &size);
        width = size.width + 4;
index d3fcf9ab2b232809fa6e84705aab270cb9e9122f..4d242c7130c194c19af4eae79fe997ed64964b9c 100644 (file)
@@ -59,22 +59,53 @@ static PrefParam param[] = {
        {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
 };
 
+struct scan_parameters {
+       gboolean is_infected;
+
+       struct cl_node *root;
+       struct cl_limits limits;
+       gboolean scan_archive;
+};
+
+static gboolean scan_func(GNode *node, gpointer data)
+{
+       struct scan_parameters *params = (struct scan_parameters *) data;
+       MimeInfo *mimeinfo = (MimeInfo *) node->data;
+       gchar *outfile;
+       int ret;
+       unsigned long int size;
+       char *virname;
+
+       outfile = procmime_get_tmp_file_name(mimeinfo);
+       if (procmime_get_part(outfile, mimeinfo) < 0)
+               g_warning("Can't get the part of multipart message.");
+       else {
+               debug_print("Scanning %s\n", outfile);
+               if ((ret = cl_scanfile(outfile, &virname, &size, params->root, 
+                                     &params->limits, params->scan_archive)) == CL_VIRUS) {
+                       params->is_infected = TRUE;
+                       debug_print("Detected %s virus.\n", virname); 
+               } else {
+                       debug_print("No virus detected.\n");
+                       if (ret != CL_CLEAN)
+                               debug_print("Error: %s\n", cl_perror(ret));
+               }
+
+               unlink(outfile);
+       }
+
+       return params->is_infected;
+}
+
 static gboolean mail_filtering_hook(gpointer source, gpointer data)
 {
        MailFilteringData *mail_filtering_data = (MailFilteringData *) source;
        MsgInfo *msginfo = mail_filtering_data->msginfo;
        gboolean is_infected = FALSE;
        MimeInfo *mimeinfo;
-       MimeInfo *child;
-       gchar *infile;
-       gchar *outfile;
-       gint scan_archive = 0;
 
        int ret, no;
-       unsigned long int size;
-       char *virname;
-       struct cl_node *root = NULL;
-       struct cl_limits limits;
+       struct scan_parameters params;
 
        if (!config.clamav_enable)
                return FALSE;
@@ -82,62 +113,26 @@ static gboolean mail_filtering_hook(gpointer source, gpointer data)
        mimeinfo = procmime_scan_message(msginfo);
        if (!mimeinfo) return FALSE;
 
-       child = mimeinfo->children;
-       if (!child) {
-               procmime_mimeinfo_free_all(mimeinfo);
-               return FALSE;
-       }
-
        debug_print("Scanning message %d for viruses\n", msginfo->msgnum);
 
-       infile = procmsg_get_message_file_path(msginfo);
+       params.root = NULL;
+
+       params.limits.maxfiles = 1000; /* max files */
+       params.limits.maxfilesize = config.clamav_max_size * 1048576; /* maximum archived file size */
+       params.limits.maxreclevel = 8; /* maximum recursion level */
+
+       if (config.clamav_enable_arc)
+               params.scan_archive = TRUE;
 
-       if((ret = cl_loaddbdir(cl_retdbdir(), &root, &no))) {
+       if((ret = cl_loaddbdir(cl_retdbdir(), &params.root, &no))) {
                debug_print("cl_loaddbdir: %s\n", cl_perror(ret));
                exit(2);
        }
-
        debug_print("Database loaded (containing in total %d signatures)\n", no);
 
-       cl_buildtrie(root);
+       cl_buildtrie(params.root);
 
-       limits.maxfiles = 1000; /* max files */
-       limits.maxfilesize = config.clamav_max_size * 1048576; /* maximum archived file size */
-       limits.maxreclevel = 8; /* maximum recursion level */
-
-       if (config.clamav_enable_arc)
-               scan_archive = TRUE;
-
-       while (child != NULL) {
-               if(child->parent && child->parent->parent
-               && (child->parent->parent->type == MIMETYPE_MULTIPART)
-               && !strcasecmp(child->parent->parent->subtype, "signed")
-               && child->type == MIMETYPE_TEXT) {
-                       /* this is the main text part of a signed message */
-                       child = procmime_mimeinfo_next(child);
-                       continue;
-               }
-               outfile = procmime_get_tmp_file_name(child);
-               if (procmime_get_part(outfile, child) < 0)
-                       g_warning("Can't get the part of multipart message.");
-               else {
-                       debug_print("Scanning %s\n", outfile);
-                       if ((ret = cl_scanfile(outfile, &virname, &size, root, 
-                                             &limits, scan_archive)) == CL_VIRUS) {
-                               is_infected = TRUE;
-                               debug_print("Detected %s virus.\n", virname); 
-                       } else {
-                               debug_print("No virus detected.\n");
-                               if (ret != CL_CLEAN)
-                                       debug_print("Error: %s\n", cl_perror(ret));
-                       }
-
-                       unlink(outfile);
-
-                       if (is_infected) break;
-                       child = child->next;
-               }
-       }
+       g_node_traverse(mimeinfo->node, G_PRE_ORDER, G_TRAVERSE_ALL, -1, scan_func, &params);
 
        if (is_infected) {
                if (config.clamav_recv_infected) {
@@ -155,11 +150,10 @@ static gboolean mail_filtering_hook(gpointer source, gpointer data)
                }
        }
        
-       cl_freetrie(root);
-       g_free(infile);
+       cl_freetrie(params.root);
        procmime_mimeinfo_free_all(mimeinfo);
        
-       return is_infected;
+       return params.is_infected;
 }
 
 ClamAvConfig *clamav_get_config(void)
index d827eefc0b6d54a968544db136b9905f9f3fbbc9..a322a019ebfc45a33c562b8e62f5afc4cca6d19d 100644 (file)
@@ -58,6 +58,7 @@ MimeInfo *procmime_mimeinfo_new(void)
        mimeinfo->encoding_type = ENC_UNKNOWN;
 
        mimeinfo->parameters = g_hash_table_new(g_str_hash, g_str_equal);
+       mimeinfo->node       = g_node_new(mimeinfo);
 
        return mimeinfo;
 }
@@ -70,11 +71,9 @@ static gboolean procmime_mimeinfo_parameters_destroy(gpointer key, gpointer valu
        return TRUE;
 }
 
-void procmime_mimeinfo_free_all(MimeInfo *mimeinfo)
+static gboolean free_func(GNode *node, gpointer data)
 {
-       MimeInfo *next;
-
-       g_return_if_fail(mimeinfo);
+       MimeInfo *mimeinfo = (MimeInfo *) node->data;
 
        g_free(mimeinfo->encoding);
        g_free(mimeinfo->charset);
@@ -84,8 +83,6 @@ void procmime_mimeinfo_free_all(MimeInfo *mimeinfo)
                unlink(mimeinfo->filename);
        g_free(mimeinfo->filename);
 
-       if (mimeinfo->children != NULL)
-               procmime_mimeinfo_free_all(mimeinfo->children);
        g_free(mimeinfo->subtype);
        g_free(mimeinfo->description);
        g_free(mimeinfo->id);
@@ -96,11 +93,24 @@ void procmime_mimeinfo_free_all(MimeInfo *mimeinfo)
        if (mimeinfo->privacy)
                privacy_free_privacydata(mimeinfo->privacy);
 
-       next = mimeinfo->next;
        g_free(mimeinfo);
-       mimeinfo = next;
+
+       return FALSE;
 }
 
+void procmime_mimeinfo_free_all(MimeInfo *mimeinfo)
+{
+       GNode *node;
+
+       g_return_if_fail(mimeinfo);
+
+       node = mimeinfo->node;
+       g_node_traverse(node, G_IN_ORDER, G_TRAVERSE_ALL, -1, free_func, NULL);
+
+       g_node_destroy(node);
+}
+
+#if 0 /* UNUSED */
 MimeInfo *procmime_mimeinfo_insert(MimeInfo *parent, MimeInfo *mimeinfo)
 {
        MimeInfo *child = parent->children;
@@ -145,31 +155,30 @@ void procmime_mimeinfo_replace(MimeInfo *old, MimeInfo *new)
                child = new;
        }
 }
+#endif
+
+MimeInfo *procmime_mimeinfo_parent(MimeInfo *mimeinfo)
+{
+       g_return_val_if_fail(mimeinfo != NULL, NULL);
+
+       if (mimeinfo->node->parent == NULL)
+               return NULL;
+       return (MimeInfo *) mimeinfo->node->parent->data;
+}
 
 MimeInfo *procmime_mimeinfo_next(MimeInfo *mimeinfo)
 {
        if (!mimeinfo) return NULL;
 
-       if (mimeinfo->children)
-               return mimeinfo->children;
-       if (mimeinfo->next)
-               return mimeinfo->next;
+       if (mimeinfo->node->children)
+               return (MimeInfo *) mimeinfo->node->children->data;
+       if (mimeinfo->node->next)
+               return (MimeInfo *) mimeinfo->node->next->data;
 
-       if (mimeinfo->main) {
-               mimeinfo = mimeinfo->main;
-               if (mimeinfo->next)
-                       return mimeinfo->next;
-       }
-
-       for (mimeinfo = mimeinfo->parent; mimeinfo != NULL;
-            mimeinfo = mimeinfo->parent) {
-               if (mimeinfo->next)
-                       return mimeinfo->next;
-               if (mimeinfo->main) {
-                       mimeinfo = mimeinfo->main;
-                       if (mimeinfo->next)
-                               return mimeinfo->next;
-               }
+       for (mimeinfo = (MimeInfo *) mimeinfo->node->parent->data; mimeinfo != NULL;
+            mimeinfo = (MimeInfo *) mimeinfo->node->parent->data) {
+               if (mimeinfo->node->next)
+                       return (MimeInfo *) mimeinfo->node->next->data;
        }
 
        return NULL;
@@ -946,15 +955,15 @@ const gchar *procmime_get_type_str(MimeMediaType type)
        return NULL;
 }
 
-MimeInfo *procmime_parse_mimepart(MimeInfo *parent,
-                                 gchar *content_type,
-                                 gchar *content_encoding,
-                                 gchar *content_description,
-                                 gchar *content_id,
-                                 FILE *fp,
-                                 const gchar *filename,
-                                 guint offset,
-                                 guint length);
+void procmime_parse_mimepart(MimeInfo *parent,
+                            gchar *content_type,
+                            gchar *content_encoding,
+                            gchar *content_description,
+                            gchar *content_id,
+                            FILE *fp,
+                            const gchar *filename,
+                            guint offset,
+                            guint length);
 
 void procmime_parse_message_rfc822(MimeInfo *mimeinfo, FILE *fp)
 {
@@ -972,11 +981,11 @@ void procmime_parse_message_rfc822(MimeInfo *mimeinfo, FILE *fp)
        procheader_get_header_fields(fp, hentry);
        content_start = ftell(fp);
 
-       mimeinfo->children = procmime_parse_mimepart(mimeinfo,
-                                                    hentry[0].body, hentry[1].body,
-                                                    hentry[2].body, hentry[3].body, 
-                                                    fp, mimeinfo->filename, content_start,
-                                                    mimeinfo->length - (content_start - mimeinfo->offset));
+       procmime_parse_mimepart(mimeinfo,
+                               hentry[0].body, hentry[1].body,
+                               hentry[2].body, hentry[3].body, 
+                               fp, mimeinfo->filename, content_start,
+                               mimeinfo->length - (content_start - mimeinfo->offset));
        for (i = 0; i < 4; i++) {
                g_free(hentry[i].body);
                hentry[i].body = NULL;
@@ -997,7 +1006,6 @@ void procmime_parse_multipart(MimeInfo *mimeinfo, FILE *fp)
        gchar *boundary;
        gint boundary_len = 0, lastoffset = -1, i;
        gchar buf[BUFFSIZE];
-       MimeInfo *lastmimeinfo = NULL;
 
        boundary = g_hash_table_lookup(mimeinfo->parameters, "boundary");
        if(!boundary)
@@ -1011,19 +1019,11 @@ void procmime_parse_multipart(MimeInfo *mimeinfo, FILE *fp)
 
                if (IS_BOUNDARY(buf, boundary, boundary_len)) {
                        if(lastoffset != -1) {
-                               MimeInfo *newmimeinfo = NULL;
-
-                               newmimeinfo = procmime_parse_mimepart(mimeinfo,
-                                                                     hentry[0].body, hentry[1].body,
-                                                                     hentry[2].body, hentry[3].body, 
-                                                                     fp, mimeinfo->filename, lastoffset,
-                                                                     (ftell(fp) - strlen(buf)) - lastoffset);
-                                                                     
-                               if (lastmimeinfo == NULL)
-                                       mimeinfo->children = newmimeinfo;
-                               else
-                                       lastmimeinfo->next = newmimeinfo;
-                               lastmimeinfo = newmimeinfo;
+                               procmime_parse_mimepart(mimeinfo,
+                                                       hentry[0].body, hentry[1].body,
+                                                       hentry[2].body, hentry[3].body, 
+                                                       fp, mimeinfo->filename, lastoffset,
+                                                       (ftell(fp) - strlen(buf)) - lastoffset);
                        }
                        
                        if (buf[2 + boundary_len]     == '-' &&
@@ -1100,24 +1100,25 @@ static void procmime_parse_content_encoding(const gchar *content_encoding, MimeI
        return;
 }
 
-MimeInfo *procmime_parse_mimepart(MimeInfo *parent,
-                                 gchar *content_type,
-                                 gchar *content_encoding,
-                                 gchar *content_description,
-                                 gchar *content_id,
-                                 FILE *fp,
-                                 const gchar *filename,
-                                 guint offset,
-                                 guint length)
+void procmime_parse_mimepart(MimeInfo *parent,
+                            gchar *content_type,
+                            gchar *content_encoding,
+                            gchar *content_description,
+                            gchar *content_id,
+                            FILE *fp,
+                            const gchar *filename,
+                            guint offset,
+                            guint length)
 {
        MimeInfo *mimeinfo;
        guint oldpos;
 
-       g_return_val_if_fail(fp != NULL, NULL);
+       g_return_if_fail(fp != NULL);
 
        /* Create MimeInfo */
        mimeinfo = procmime_mimeinfo_new();
-       mimeinfo->parent = parent;
+       if (parent != NULL)
+               g_node_append(parent->node, mimeinfo->node);
        mimeinfo->filename = g_strdup(filename);
        mimeinfo->offset = offset;
        mimeinfo->length = length;
@@ -1163,8 +1164,6 @@ MimeInfo *procmime_parse_mimepart(MimeInfo *parent,
                        break;
        }
        fseek(fp, oldpos, SEEK_SET);
-
-       return mimeinfo;
 }
 
 static gchar *typenames[] = {
@@ -1178,18 +1177,22 @@ static gchar *typenames[] = {
     "unknown",
 };
 
-static void output_mime_structure(MimeInfo *mimeinfo, int indent)
+static gboolean output_func(GNode *node, gpointer data)
 {
-       int i;
-       
-       for(i = 0; i < indent; i++)
-               printf(" ");
+       guint i, depth;
+       MimeInfo *mimeinfo = (MimeInfo *) node->data;
+
+       depth = g_node_depth(node);
+       for(i = 0; i < depth; i++)
+               printf("    ");
        printf("%s/%s (offset:%d length:%d encoding: %d)\n", typenames[mimeinfo->type], mimeinfo->subtype, mimeinfo->offset, mimeinfo->length, mimeinfo->encoding_type);
 
-       if(mimeinfo->children)
-               output_mime_structure(mimeinfo->children, indent + 4);
-       if(mimeinfo->next)
-               output_mime_structure(mimeinfo->next, indent);
+       return FALSE;
+}
+
+static void output_mime_structure(MimeInfo *mimeinfo, int indent)
+{
+       g_node_traverse(mimeinfo->node, G_PRE_ORDER, G_TRAVERSE_ALL, -1, output_func, NULL);
 }
 
 MimeInfo *procmime_scan_fp(FILE *fp, const gchar *filename)
@@ -1201,7 +1204,14 @@ MimeInfo *procmime_scan_fp(FILE *fp, const gchar *filename)
        fstat(fileno(fp), &stat);
        offset = ftell(fp);
 
-       mimeinfo = procmime_parse_mimepart(NULL, "message/rfc822", "binary", NULL, NULL, fp, filename, offset, stat.st_size - offset);
+       mimeinfo = procmime_mimeinfo_new();
+       mimeinfo->type = MIMETYPE_MESSAGE;
+       mimeinfo->subtype = g_strdup("rfc822");
+       mimeinfo->filename = g_strdup(filename);
+       mimeinfo->offset = offset;
+       mimeinfo->length = stat.st_size - offset;
+
+       procmime_parse_message_rfc822(mimeinfo, fp);
        output_mime_structure(mimeinfo, 0);
 
        return mimeinfo;
index e121b82bc41e76193c736bbeaf25a8f8d6d380c7..ab1b2ee3a2a0ca87cca4550bb90c84427cd4fdc8 100644 (file)
@@ -97,17 +97,11 @@ struct _MimeInfo
 
        gchar *content_disposition;
 
-       MimeInfo *main;
-
-       gint level;
-
        /* Internal data */
        gchar *filename;
        gboolean tmpfile;
 
-       MimeInfo *next;
-       MimeInfo *parent;
-       MimeInfo *children;
+       GNode *node;
 
        /* --- NEW MIME STUFF --- */
        /* Content-Type */
@@ -145,6 +139,7 @@ MimeInfo *procmime_mimeinfo_insert  (MimeInfo       *parent,
 void procmime_mimeinfo_replace         (MimeInfo       *old_mimeinfo,
                                         MimeInfo       *new_mimeinfo);
 
+MimeInfo *procmime_mimeinfo_parent     (MimeInfo       *mimeinfo);
 MimeInfo *procmime_mimeinfo_next       (MimeInfo       *mimeinfo);
 
 MimeInfo *procmime_scan_message                (MsgInfo        *msginfo);
index a0cc91e5ed2497483623065c76eb5d491ffdb867..120fc27d9e9883ec6f769a35cc5d6af06cebbd4d 100644 (file)
@@ -524,6 +524,7 @@ leave:
     return plain;
 }
 
+#if 0 /* UNUSED */
 MimeInfo * rfc2015_find_signature (MimeInfo *mimeinfo)
 {
     MimeInfo *partinfo;
@@ -570,6 +571,7 @@ void rfc2015_check_signature (MimeInfo *mimeinfo, FILE *fp)
 
     check_signature (mimeinfo, partinfo, fp);
 }
+#endif
 
 int rfc2015_is_encrypted (MimeInfo *mimeinfo)
 {
@@ -1472,7 +1474,7 @@ static gboolean rfc2015_is_signed(MimeInfo *mimeinfo)
        g_return_val_if_fail(mimeinfo != NULL, FALSE);
        
        /* check parent */
-       parent = mimeinfo->parent;
+       parent = procmime_mimeinfo_parent(mimeinfo);
        if (parent == NULL)
                return FALSE;
        if ((parent->type != MIMETYPE_MULTIPART) ||
@@ -1483,11 +1485,12 @@ static gboolean rfc2015_is_signed(MimeInfo *mimeinfo)
                return FALSE;
 
        /* check if mimeinfo is the first child */
-       if (parent->children != mimeinfo)
+       if (parent->node->children->data != mimeinfo)
                return FALSE;
 
        /* check signature */
-       signature = parent->children->next;
+       signature = parent->node->children->next != NULL ? 
+           (MimeInfo *) parent->node->children->next->data : NULL;
        if (signature == NULL)
                return FALSE;
        if ((signature->type != MIMETYPE_APPLICATION) ||
index 06dcb4a93cf02bb860408112c3d47c26b49a0aa4..b0d7d6f3f36e4b50263955e5555bb555642a0e86 100644 (file)
@@ -131,14 +131,11 @@ static void textview_show_ertf            (TextView       *textview,
                                         FILE           *fp,
                                         CodeConverter  *conv);
 static void textview_add_part          (TextView       *textview,
-                                        MimeInfo       *mimeinfo,
-                                        FILE           *fp);
+                                        MimeInfo       *mimeinfo);
 static void textview_add_parts         (TextView       *textview,
-                                        MimeInfo       *mimeinfo,
-                                        FILE           *fp);
+                                        MimeInfo       *mimeinfo);
 static void textview_write_body                (TextView       *textview,
                                         MimeInfo       *mimeinfo,
-                                        FILE           *fp,
                                         const gchar    *charset);
 static void textview_show_html         (TextView       *textview,
                                         FILE           *fp,
@@ -349,7 +346,7 @@ void textview_show_message(TextView *textview, MimeInfo *mimeinfo,
                textview->body_pos = gtk_stext_get_length(text);
        }
 */
-       textview_add_parts(textview, mimeinfo, fp);
+       textview_add_parts(textview, mimeinfo);
 
        gtk_stext_thaw(text);
 
@@ -367,7 +364,7 @@ void textview_show_part(TextView *textview, MimeInfo *mimeinfo, FILE *fp)
        if ((mimeinfo->type == MIMETYPE_MULTIPART) ||
            ((mimeinfo->type == MIMETYPE_MESSAGE) && !g_strcasecmp(mimeinfo->subtype, "rfc822"))) {
                textview_clear(textview);
-               textview_add_parts(textview, mimeinfo, fp);
+               textview_add_parts(textview, mimeinfo);
                return;
        }
 
@@ -400,14 +397,14 @@ void textview_show_part(TextView *textview, MimeInfo *mimeinfo, FILE *fp)
        }
 */
        if (mimeinfo->type == MIMETYPE_MULTIPART)
-               textview_add_parts(textview, mimeinfo, fp);
+               textview_add_parts(textview, mimeinfo);
        else
-               textview_write_body(textview, mimeinfo, fp, charset);
+               textview_write_body(textview, mimeinfo, charset);
 
        gtk_stext_thaw(text);
 }
 
-static void textview_add_part(TextView *textview, MimeInfo *mimeinfo, FILE *fp)
+static void textview_add_part(TextView *textview, MimeInfo *mimeinfo)
 {
        GtkSText *text = GTK_STEXT(textview->text);
        gchar buf[BUFFSIZE];
@@ -415,16 +412,14 @@ static void textview_add_part(TextView *textview, MimeInfo *mimeinfo, FILE *fp)
        GPtrArray *headers = NULL;
 
        g_return_if_fail(mimeinfo != NULL);
-       g_return_if_fail(fp != NULL);
 
        if (mimeinfo->type == MIMETYPE_MULTIPART) return;
 
-       if (fseek(fp, mimeinfo->offset, SEEK_SET) < 0) {
-               perror("fseek");
-               return;
-       }
-
        if ((mimeinfo->type == MIMETYPE_MESSAGE) && !g_strcasecmp(mimeinfo->subtype, "rfc822")) {
+               FILE *fp;
+
+               fp = fopen(mimeinfo->filename, "rb");
+               fseek(fp, mimeinfo->offset, SEEK_SET);
                headers = textview_scan_header(textview, fp);
                if (headers) {
                        gtk_stext_freeze(text);
@@ -434,6 +429,7 @@ static void textview_add_part(TextView *textview, MimeInfo *mimeinfo, FILE *fp)
                        procheader_header_array_destroy(headers);
                        gtk_stext_thaw(text);
                }
+               fclose(fp);
                return;
        }
 
@@ -452,11 +448,7 @@ static void textview_add_part(TextView *textview, MimeInfo *mimeinfo, FILE *fp)
        if (mimeinfo->type != MIMETYPE_TEXT) {
                gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
        } else {
-               if (!mimeinfo->main &&
-                   mimeinfo->parent &&
-                   mimeinfo->parent->children != mimeinfo)
-                       gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
-               else if (prefs_common.display_header && (gtk_stext_get_length(text) > 0))
+               if (prefs_common.display_header && (gtk_stext_get_length(text) > 0))
                        gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
                if (textview->messageview->forced_charset)
                        charset = textview->messageview->forced_charset;
@@ -464,33 +456,29 @@ static void textview_add_part(TextView *textview, MimeInfo *mimeinfo, FILE *fp)
                        charset = prefs_common.force_charset;
                else if (mimeinfo->charset)
                        charset = mimeinfo->charset;
-               textview_write_body(textview, mimeinfo, fp, charset);
+               textview_write_body(textview, mimeinfo, charset);
        }
 
        gtk_stext_thaw(text);
 }
 
-static void textview_add_parts_func(TextView *textview, MimeInfo *mimeinfo, FILE *fp)
+static gboolean add_parts_func(GNode *node, gpointer data)
 {
-       g_return_if_fail(mimeinfo != NULL);
-       g_return_if_fail(fp != NULL);
+       MimeInfo *mimeinfo = (MimeInfo *) node->data;
+       TextView *textview = (TextView *) data;
 
-       while (mimeinfo) {
-               textview_add_part(textview, mimeinfo, fp);
-               if(mimeinfo->children)
-                       textview_add_parts_func(textview, mimeinfo->children, fp);
-               mimeinfo = mimeinfo->next;
-       }
+       g_return_val_if_fail(mimeinfo != NULL, FALSE);
+
+       textview_add_part(textview, mimeinfo);
+
+       return FALSE;
 }
 
-static void textview_add_parts(TextView *textview, MimeInfo *mimeinfo, FILE *fp)
+static void textview_add_parts(TextView *textview, MimeInfo *mimeinfo)
 {
        g_return_if_fail(mimeinfo != NULL);
-       g_return_if_fail(fp != NULL);
 
-       textview_add_part(textview, mimeinfo, fp);
-       if(mimeinfo->children)
-               textview_add_parts_func(textview, mimeinfo->children, fp);
+       g_node_traverse(mimeinfo->node, G_PRE_ORDER, G_TRAVERSE_ALL, -1, add_parts_func, textview);
 }
 
 #define TEXT_INSERT(str) \
@@ -526,7 +514,7 @@ void textview_show_mime_part(TextView *textview, MimeInfo *partinfo)
 #undef TEXT_INSERT
 
 static void textview_write_body(TextView *textview, MimeInfo *mimeinfo,
-                               FILE *fp, const gchar *charset)
+                               const gchar *charset)
 {
        FILE *tmpfp;
        gchar buf[BUFFSIZE];
@@ -541,7 +529,6 @@ static void textview_write_body(TextView *textview, MimeInfo *mimeinfo,
           mimeinfo->encoding_type != ENC_8BIT)
                procmime_decode_content(mimeinfo);
 
-
        if (!g_strcasecmp(mimeinfo->subtype, "html")) {
                gchar *filename;