2005-03-04 [paul] 1.0.1cvs21
[claws.git] / src / procmime.c
index b035ab29a17f7e1a8d7ae97eff7a03ed5d60ac28..0cc98441638f557f1b4eb5cf8d55cee0a76d6486 100644 (file)
@@ -228,9 +228,14 @@ MimeInfo *procmime_scan_message(MsgInfo *msginfo)
        gchar *filename;
        MimeInfo *mimeinfo;
 
-       filename = procmsg_get_message_file(msginfo);
-       if (!filename)
+       filename = procmsg_get_message_file_path(msginfo);
+       if (!filename || !is_file_exist(filename)) {
+               g_free(filename);
+               filename = procmsg_get_message_file(msginfo);
+       }
+       if (!filename || !is_file_exist(filename)) 
                return NULL;
+
        if (msginfo->folder->stype != F_QUEUE && 
            msginfo->folder->stype != F_DRAFT)
                mimeinfo = procmime_scan_file(filename);
@@ -428,16 +433,27 @@ gboolean procmime_encode_content(MimeInfo *mimeinfo, EncodingType encoding)
 
                if (mimeinfo->type == MIMETYPE_TEXT ||
                    mimeinfo->type == MIMETYPE_MESSAGE) {
-                       tmp_file = get_tmp_file();
-                       if (canonicalize_file(mimeinfo->data.filename, tmp_file) < 0) {
-                               g_free(tmp_file);
-                               fclose(infp);
-                       }
-                       if ((tmp_fp = fopen(tmp_file, "rb")) == NULL) {
-                               FILE_OP_ERROR(tmp_file, "fopen");
-                               unlink(tmp_file);
-                               g_free(tmp_file);
+                       if (mimeinfo->content == MIMECONTENT_FILE) {
+                               tmp_file = get_tmp_file();
+                               if (canonicalize_file(mimeinfo->data.filename, tmp_file) < 0) {
+                                       g_free(tmp_file);
+                                       fclose(infp);
+                                       return FALSE;
+                               }
+                               if ((tmp_fp = fopen(tmp_file, "rb")) == NULL) {
+                                       FILE_OP_ERROR(tmp_file, "fopen");
+                                       unlink(tmp_file);
+                                       g_free(tmp_file);
+                                       fclose(infp);
+                                       return FALSE;
+                               }
+                       } else {
+                               gchar *out = canonicalize_str(mimeinfo->data.mem);
                                fclose(infp);
+                               tmp_fp = infp = str_open_as_stream(out);
+                               g_free(out);
+                               if (infp == NULL)
+                                       return FALSE;
                        }
                }
 
@@ -458,13 +474,22 @@ gboolean procmime_encode_content(MimeInfo *mimeinfo, EncodingType encoding)
                        fclose(tmp_fp);
                        unlink(tmp_file);
                        g_free(tmp_file);
-               }
+               } 
        } else if (encoding == ENC_QUOTED_PRINTABLE) {
                gchar inbuf[BUFFSIZE], outbuf[BUFFSIZE * 4];
 
                while (fgets(inbuf, sizeof(inbuf), infp) != NULL) {
                        qp_encode_line(outbuf, inbuf);
-                       fputs(outbuf, outfp);
+
+                       if (!strncmp("From ", outbuf, sizeof("From ")-1)) {
+                               gchar *tmpbuf = outbuf;
+                               
+                               tmpbuf += sizeof("From ")-1;
+                               
+                               fputs("=46rom ", outfp);
+                               fputs(tmpbuf, outfp);
+                       } else 
+                               fputs(outbuf, outfp);
                }
        } else {
                gchar buf[BUFFSIZE];
@@ -1198,6 +1223,7 @@ void procmime_parse_message_rfc822(MimeInfo *mimeinfo)
                                {NULL,             NULL, FALSE}};
        guint content_start, i;
        FILE *fp;
+       gchar buf[BUFFSIZE];
        gint mime_major, mime_minor;
 
        procmime_decode_content(mimeinfo);
@@ -1210,11 +1236,14 @@ void procmime_parse_message_rfc822(MimeInfo *mimeinfo)
        fseek(fp, mimeinfo->offset, SEEK_SET);
        procheader_get_header_fields(fp, hentry);
        if (hentry[0].body != NULL)
-               conv_unmime_header_overwrite(hentry[0].body);
+               conv_unmime_header(buf, sizeof(buf), hentry[0].body,
+                                  NULL);
        if (hentry[2].body != NULL)
-               conv_unmime_header_overwrite(hentry[2].body);
+               conv_unmime_header(buf, sizeof(buf), hentry[2].body,
+                                  NULL);
        if (hentry[4].body != NULL)
-               conv_unmime_header_overwrite(hentry[4].body);
+               conv_unmime_header(buf, sizeof(buf), hentry[4].body,
+                                  NULL);
        content_start = ftell(fp);
        fclose(fp);
 
@@ -1231,6 +1260,7 @@ void procmime_parse_message_rfc822(MimeInfo *mimeinfo)
                MimeInfo *subinfo;
 
                subinfo = procmime_mimeinfo_new();
+               subinfo->content = MIMECONTENT_FILE;
                subinfo->encoding_type = ENC_UNKNOWN;
                subinfo->type = MIMETYPE_TEXT;
                subinfo->subtype = g_strdup("plain");
@@ -1301,11 +1331,14 @@ void procmime_parse_multipart(MimeInfo *mimeinfo)
                        }
                        procheader_get_header_fields(fp, hentry);
                        if (hentry[0].body != NULL)
-                               conv_unmime_header_overwrite(hentry[0].body);
+                               conv_unmime_header(buf, sizeof(buf), hentry[0].body,
+                               NULL);
                        if (hentry[2].body != NULL)
-                               conv_unmime_header_overwrite(hentry[2].body);
+                               conv_unmime_header(buf, sizeof(buf), hentry[2].body,
+                               NULL);
                        if (hentry[4].body != NULL)
-                               conv_unmime_header_overwrite(hentry[4].body);
+                               conv_unmime_header(buf, sizeof(buf), hentry[4].body,
+                               NULL);
                        lastoffset = ftell(fp);
                }
        }