0.9.6claws31
authorChristoph Hohmann <reboot@gmx.ch>
Wed, 15 Oct 2003 12:33:08 +0000 (12:33 +0000)
committerChristoph Hohmann <reboot@gmx.ch>
Wed, 15 Oct 2003 12:33:08 +0000 (12:33 +0000)
* src/procmime.[ch]
        fix procmime_get_text_content() and
        procmime_get_first_text_content()

ChangeLog.claws
configure.ac
src/procmime.c
src/procmime.h

index dd88ef2..44a05ef 100644 (file)
@@ -1,3 +1,9 @@
+2003-10-15 [christoph]  0.9.6claws31
+
+       * src/procmime.[ch]
+               fix procmime_get_text_content() and
+               procmime_get_first_text_content()
+
 2003-10-15 [christoph] 0.9.6claws30
 
        * src/plugins/spamassassin/spamassassin_gtk.c
index 7fb566a..28fdcfd 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=9
 MICRO_VERSION=6
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=30
+EXTRA_VERSION=31
 if test $EXTRA_VERSION -eq 0; then
     VERSION=${MAJOR_VERSION}.${MINOR_VERSION}.${MICRO_VERSION}claws
 else
index a322a01..3271d66 100644 (file)
@@ -440,11 +440,8 @@ void renderer_write_config(void)
        }
 }
 
-FILE *procmime_get_text_content(MimeInfo *mimeinfo, FILE *infp)
+FILE *procmime_get_text_content(MimeInfo *mimeinfo)
 {
-       return NULL;
-
-#if 0  /* FIXME */
        FILE *tmpfp, *outfp;
        gchar *src_codeset;
        gboolean conv_fail = FALSE;
@@ -452,28 +449,32 @@ FILE *procmime_get_text_content(MimeInfo *mimeinfo, FILE *infp)
        gchar *str;
        struct ContentRenderer * renderer;
        GList * cur;
-
+       gchar *tmpfile, *content_type;
+    
        g_return_val_if_fail(mimeinfo != NULL, NULL);
-       g_return_val_if_fail(infp != NULL, NULL);
-       g_return_val_if_fail(mimeinfo->mime_type == MIME_TEXT ||
-                            mimeinfo->mime_type == MIME_TEXT_HTML ||
-                            mimeinfo->mime_type == MIME_TEXT_ENRICHED, NULL);
 
-       if (fseek(infp, mimeinfo->fpos, SEEK_SET) < 0) {
-               perror("fseek");
+       if (!procmime_decode_content(mimeinfo))
                return NULL;
-       }
 
-       while (fgets(buf, sizeof(buf), infp) != NULL)
-               if (buf[0] == '\r' || buf[0] == '\n') break;
+       tmpfile = procmime_get_tmp_file_name(mimeinfo);
+       if (tmpfile == NULL)
+               return NULL;
 
-       tmpfp = procmime_decode_content(NULL, infp, mimeinfo);
-       if (!tmpfp)
+       if (procmime_get_part(tmpfile, mimeinfo) < 0) {
+               g_free(tmpfile);
                return NULL;
+       }
+
+       tmpfp = fopen(tmpfile, "rb");
+       if (tmpfp == NULL) {
+               g_free(tmpfile);
+               return NULL;
+       }
 
        if ((outfp = my_tmpfile()) == NULL) {
                perror("tmpfile");
                fclose(tmpfp);
+               g_free(tmpfile);
                return NULL;
        }
 
@@ -482,15 +483,18 @@ FILE *procmime_get_text_content(MimeInfo *mimeinfo, FILE *infp)
 
        renderer = NULL;
 
+       content_type = g_strdup_printf("%s/%s", procmime_get_type_str(mimeinfo->type),
+               mimeinfo->subtype);
        for(cur = renderer_list ; cur != NULL ; cur = cur->next) {
                struct ContentRenderer * cr;
+
                cr = cur->data;
-               if (g_strcasecmp(cr->content_type,
-                                mimeinfo->content_type) == 0) {
+               if (g_strcasecmp(cr->content_type, content_type) == 0) {
                        renderer = cr;
                        break;
                }
        }
+       g_free(content_type);
 
        if (renderer != NULL) {
                FILE * p;
@@ -512,18 +516,7 @@ FILE *procmime_get_text_content(MimeInfo *mimeinfo, FILE *infp)
                }
                
                dup2(oldout, 1);
-       } else if (mimeinfo->mime_type == MIME_TEXT) {
-               while (fgets(buf, sizeof(buf), tmpfp) != NULL) {
-                       str = conv_codeset_strdup(buf, src_codeset, NULL);
-                       if (str) {
-                               fputs(str, outfp);
-                               g_free(str);
-                       } else {
-                               conv_fail = TRUE;
-                               fputs(buf, outfp);
-                       }
-               }
-       } else if (mimeinfo->mime_type == MIME_TEXT_HTML) {
+       } else if (mimeinfo->type == MIMETYPE_TEXT && !g_strcasecmp(mimeinfo->subtype, "html")) {
                HTMLParser *parser;
                CodeConverter *conv;
 
@@ -534,7 +527,7 @@ FILE *procmime_get_text_content(MimeInfo *mimeinfo, FILE *infp)
                }
                html_parser_destroy(parser);
                conv_code_converter_destroy(conv);
-       } else if (mimeinfo->mime_type == MIME_TEXT_ENRICHED) {
+       } else if (mimeinfo->type == MIMETYPE_TEXT && !g_strcasecmp(mimeinfo->subtype, "enriched")) {
                ERTFParser *parser;
                CodeConverter *conv;
 
@@ -545,6 +538,17 @@ FILE *procmime_get_text_content(MimeInfo *mimeinfo, FILE *infp)
                }
                ertf_parser_destroy(parser);
                conv_code_converter_destroy(conv);
+       } else if (mimeinfo->type == MIMETYPE_TEXT) {
+               while (fgets(buf, sizeof(buf), tmpfp) != NULL) {
+                       str = conv_codeset_strdup(buf, src_codeset, NULL);
+                       if (str) {
+                               fputs(str, outfp);
+                               g_free(str);
+                       } else {
+                               conv_fail = TRUE;
+                               fputs(buf, outfp);
+                       }
+               }
        }
 
        if (conv_fail)
@@ -552,19 +556,17 @@ FILE *procmime_get_text_content(MimeInfo *mimeinfo, FILE *infp)
 
        fclose(tmpfp);
        rewind(outfp);
+       unlink(tmpfile);
+       g_free(tmpfile);
 
        return outfp;
-#endif
 }
 
 /* search the first text part of (multipart) MIME message,
    decode, convert it and output to outfp. */
 FILE *procmime_get_first_text_content(MsgInfo *msginfo)
 {
-       return NULL;
-
-#if 0  /* FIXME */
-       FILE *infp, *outfp = NULL;
+       FILE *outfp = NULL;
        MimeInfo *mimeinfo, *partinfo;
 
        g_return_val_if_fail(msginfo != NULL, NULL);
@@ -572,30 +574,16 @@ FILE *procmime_get_first_text_content(MsgInfo *msginfo)
        mimeinfo = procmime_scan_message(msginfo);
        if (!mimeinfo) return NULL;
 
-       if ((infp = procmsg_open_message(msginfo)) == NULL) {
-               procmime_mimeinfo_free_all(mimeinfo);
-               return NULL;
-       }
-
        partinfo = mimeinfo;
-       while (partinfo && partinfo->mime_type != MIME_TEXT)
+       while (partinfo && partinfo->type != MIMETYPE_TEXT)
                partinfo = procmime_mimeinfo_next(partinfo);
-       if (!partinfo) {
-               partinfo = mimeinfo;
-               while (partinfo && partinfo->mime_type != MIME_TEXT_HTML &&
-                               partinfo->mime_type != MIME_TEXT_ENRICHED)
-                       partinfo = procmime_mimeinfo_next(partinfo);
-       }
-       
 
        if (partinfo)
-               outfp = procmime_get_text_content(partinfo, infp);
+               outfp = procmime_get_text_content(partinfo);
 
-       fclose(infp);
        procmime_mimeinfo_free_all(mimeinfo);
 
        return outfp;
-#endif
 }
 
 gboolean procmime_find_string_part(MimeInfo *mimeinfo, const gchar *filename,
index ab1b2ee..ec96544 100644 (file)
@@ -163,8 +163,7 @@ MimeInfo *procmime_scan_mime_header (FILE           *fp);
 gboolean procmime_decode_content       (MimeInfo       *mimeinfo);
 gint procmime_get_part                 (const gchar    *outfile,
                                         MimeInfo       *mimeinfo);
-FILE *procmime_get_text_content                (MimeInfo       *mimeinfo,
-                                        FILE           *infp);
+FILE *procmime_get_text_content                (MimeInfo       *mimeinfo);
 FILE *procmime_get_first_text_content  (MsgInfo        *msginfo);
 
 gboolean procmime_find_string_part     (MimeInfo       *mimeinfo,