2005-09-14 [paul] 1.9.14cvs26
[claws.git] / src / procmime.c
index 96e94b66f9f6cdbcc5017b8cfd0c98ff53c19c86..d01dd2433d5f963e4758aca5cd6eb9dacad51b5c 100644 (file)
@@ -102,7 +102,7 @@ static gboolean free_func(GNode *node, gpointer data)
        switch (mimeinfo->content) {
        case MIMECONTENT_FILE:
                if (mimeinfo->tmp)
-                       unlink(mimeinfo->data.filename);
+                       g_unlink(mimeinfo->data.filename);
                g_free(mimeinfo->data.filename);
                break;
 
@@ -237,8 +237,8 @@ MimeInfo *procmime_scan_message(MsgInfo *msginfo)
        if (!filename || !is_file_exist(filename)) 
                return NULL;
 
-       if (msginfo->folder->stype != F_QUEUE && 
-           msginfo->folder->stype != F_DRAFT)
+       if (!folder_has_parent_of_type(msginfo->folder, F_QUEUE) &&
+           !folder_has_parent_of_type(msginfo->folder, F_DRAFT))
                mimeinfo = procmime_scan_file(filename);
        else
                mimeinfo = procmime_scan_queue_file(filename);
@@ -289,7 +289,7 @@ gboolean procmime_decode_content(MimeInfo *mimeinfo)
            encoding == ENC_BINARY)
                return TRUE;
 
-       infp = fopen(mimeinfo->data.filename, "rb");
+       infp = g_fopen(mimeinfo->data.filename, "rb");
        if (!infp) {
                perror("fopen");
                return FALSE;
@@ -308,7 +308,7 @@ gboolean procmime_decode_content(MimeInfo *mimeinfo)
                while ((ftell(infp) < readend) && (fgets(buf, sizeof(buf), infp) != NULL)) {
                        gint len;
                        len = qp_decode_line(buf);
-                       fwrite(buf, len, 1, outfp);
+                       fwrite(buf, 1, len, outfp);
                }
        } else if (encoding == ENC_BASE64) {
                gchar outbuf[BUFFSIZE];
@@ -387,7 +387,7 @@ gboolean procmime_decode_content(MimeInfo *mimeinfo)
 
        stat(tmpfilename, &statbuf);
        if (mimeinfo->tmp && (mimeinfo->data.filename != NULL))
-               unlink(mimeinfo->data.filename);
+               g_unlink(mimeinfo->data.filename);
        if (mimeinfo->data.filename != NULL)
                g_free(mimeinfo->data.filename);
        mimeinfo->data.filename = tmpfilename;
@@ -409,6 +409,9 @@ gboolean procmime_encode_content(MimeInfo *mimeinfo, EncodingType encoding)
        gchar *tmpfilename;
        struct stat statbuf;
 
+       if (mimeinfo->content == MIMECONTENT_EMPTY)
+               return TRUE;
+
        if (mimeinfo->encoding_type != ENC_UNKNOWN &&
            mimeinfo->encoding_type != ENC_BINARY &&
            mimeinfo->encoding_type != ENC_7BIT &&
@@ -423,7 +426,7 @@ gboolean procmime_encode_content(MimeInfo *mimeinfo, EncodingType encoding)
        }
 
        if (mimeinfo->content == MIMECONTENT_FILE) {
-               if ((infp = fopen(mimeinfo->data.filename, "rb")) == NULL) {
+               if ((infp = g_fopen(mimeinfo->data.filename, "rb")) == NULL) {
                        g_warning("Can't open file %s\n", mimeinfo->data.filename);
                        return FALSE;
                }
@@ -447,9 +450,9 @@ gboolean procmime_encode_content(MimeInfo *mimeinfo, EncodingType encoding)
                                        fclose(infp);
                                        return FALSE;
                                }
-                               if ((tmp_fp = fopen(tmp_file, "rb")) == NULL) {
+                               if ((tmp_fp = g_fopen(tmp_file, "rb")) == NULL) {
                                        FILE_OP_ERROR(tmp_file, "fopen");
-                                       unlink(tmp_file);
+                                       g_unlink(tmp_file);
                                        g_free(tmp_file);
                                        fclose(infp);
                                        return FALSE;
@@ -458,6 +461,7 @@ gboolean procmime_encode_content(MimeInfo *mimeinfo, EncodingType encoding)
                                gchar *out = canonicalize_str(mimeinfo->data.mem);
                                fclose(infp);
                                infp = str_open_as_stream(out);
+                               tmp_fp = infp;
                                g_free(out);
                                if (infp == NULL)
                                        return FALSE;
@@ -479,7 +483,7 @@ gboolean procmime_encode_content(MimeInfo *mimeinfo, EncodingType encoding)
 
                if (tmp_file) {
                        fclose(tmp_fp);
-                       unlink(tmp_file);
+                       g_unlink(tmp_file);
                        g_free(tmp_file);
                }
        } else if (encoding == ENC_QUOTED_PRINTABLE) {
@@ -512,7 +516,7 @@ gboolean procmime_encode_content(MimeInfo *mimeinfo, EncodingType encoding)
 
        if (mimeinfo->content == MIMECONTENT_FILE) {
                if (mimeinfo->tmp && (mimeinfo->data.filename != NULL))
-                       unlink(mimeinfo->data.filename);
+                       g_unlink(mimeinfo->data.filename);
                g_free(mimeinfo->data.filename);
        } else if (mimeinfo->content == MIMECONTENT_MEM) {
                if (mimeinfo->tmp && (mimeinfo->data.mem != NULL))
@@ -542,7 +546,7 @@ gint procmime_get_part(const gchar *outfile, MimeInfo *mimeinfo)
        if (mimeinfo->encoding_type != ENC_BINARY && !procmime_decode_content(mimeinfo))
                return -1;
 
-       if ((infp = fopen(mimeinfo->data.filename, "rb")) == NULL) {
+       if ((infp = g_fopen(mimeinfo->data.filename, "rb")) == NULL) {
                FILE_OP_ERROR(mimeinfo->data.filename, "fopen");
                return -1;
        }
@@ -551,7 +555,7 @@ gint procmime_get_part(const gchar *outfile, MimeInfo *mimeinfo)
                fclose(infp);
                return -1;
        }
-       if ((outfp = fopen(outfile, "wb")) == NULL) {
+       if ((outfp = g_fopen(outfile, "wb")) == NULL) {
                FILE_OP_ERROR(outfile, "fopen");
                fclose(infp);
                return -1;
@@ -567,7 +571,7 @@ gint procmime_get_part(const gchar *outfile, MimeInfo *mimeinfo)
        fclose(infp);
        if (fclose(outfp) == EOF) {
                FILE_OP_ERROR(outfile, "fclose");
-               unlink(outfile);
+               g_unlink(outfile);
                return -1;
        }
 
@@ -613,7 +617,7 @@ void renderer_read_config(void)
        renderer_list = NULL;
 
        rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, RENDERER_RC, NULL);
-       f = fopen(rcpath, "rb");
+       f = g_fopen(rcpath, "rb");
        g_free(rcpath);
        
        if (f == NULL)
@@ -693,7 +697,7 @@ FILE *procmime_get_text_content(MimeInfo *mimeinfo)
                return NULL;
        }
 
-       tmpfp = fopen(tmpfile, "rb");
+       tmpfp = g_fopen(tmpfile, "rb");
        if (tmpfp == NULL) {
                g_free(tmpfile);
                return NULL;
@@ -732,7 +736,7 @@ FILE *procmime_get_text_content(MimeInfo *mimeinfo)
                oldout = dup(1);
                
                dup2(fileno(outfp), 1);
-               
+
                p = popen(renderer->renderer, "w");
                if (p != NULL) {
                        size_t count;
@@ -786,7 +790,7 @@ FILE *procmime_get_text_content(MimeInfo *mimeinfo)
 
        fclose(tmpfp);
        rewind(outfp);
-       unlink(tmpfile);
+       g_unlink(tmpfile);
        g_free(tmpfile);
 
        return outfp;
@@ -805,8 +809,65 @@ FILE *procmime_get_first_text_content(MsgInfo *msginfo)
        if (!mimeinfo) return NULL;
 
        partinfo = mimeinfo;
-       while (partinfo && partinfo->type != MIMETYPE_TEXT)
+       while (partinfo && partinfo->type != MIMETYPE_TEXT) {
                partinfo = procmime_mimeinfo_next(partinfo);
+       }
+       if (partinfo)
+               outfp = procmime_get_text_content(partinfo);
+
+       procmime_mimeinfo_free_all(mimeinfo);
+
+       return outfp;
+}
+
+
+static gboolean find_encrypted_func(GNode *node, gpointer data)
+{
+       MimeInfo *mimeinfo = (MimeInfo *) node->data;
+       MimeInfo **encinfo = (MimeInfo **) data;
+       
+       if (privacy_mimeinfo_is_encrypted(mimeinfo)) {
+               *encinfo = mimeinfo;
+               return TRUE;
+       }
+       
+       return FALSE;
+}
+
+static MimeInfo *find_encrypted_part(MimeInfo *rootinfo)
+{
+       MimeInfo *encinfo = NULL;
+
+       g_node_traverse(rootinfo->node, G_IN_ORDER, G_TRAVERSE_ALL, -1,
+               find_encrypted_func, &encinfo);
+       
+       return encinfo;
+}
+
+/* search the first encrypted text part of (multipart) MIME message,
+   decode, convert it and output to outfp. */
+FILE *procmime_get_first_encrypted_text_content(MsgInfo *msginfo)
+{
+       FILE *outfp = NULL;
+       MimeInfo *mimeinfo, *partinfo, *encinfo;
+
+       g_return_val_if_fail(msginfo != NULL, NULL);
+
+       mimeinfo = procmime_scan_message(msginfo);
+       if (!mimeinfo) {
+               return NULL;
+       }
+
+       partinfo = mimeinfo;
+       if ((encinfo = find_encrypted_part(partinfo)) != NULL) {
+               debug_print("decrypting message part\n");
+               if (privacy_mimeinfo_decrypt(encinfo) < 0)
+                       return NULL;
+       }
+       partinfo = mimeinfo;
+       while (partinfo && partinfo->type != MIMETYPE_TEXT) {
+               partinfo = procmime_mimeinfo_next(partinfo);
+       }
 
        if (partinfo)
                outfp = procmime_get_text_content(partinfo);
@@ -816,6 +877,25 @@ FILE *procmime_get_first_text_content(MsgInfo *msginfo)
        return outfp;
 }
 
+gboolean procmime_msginfo_is_encrypted(MsgInfo *msginfo)
+{
+       MimeInfo *mimeinfo, *partinfo;
+       gboolean result = FALSE;
+
+       g_return_val_if_fail(msginfo != NULL, FALSE);
+
+       mimeinfo = procmime_scan_message(msginfo);
+       if (!mimeinfo) {
+               return FALSE;
+       }
+
+       partinfo = mimeinfo;
+       result = (find_encrypted_part(partinfo) != NULL);
+       procmime_mimeinfo_free_all(mimeinfo);
+
+       return result;
+}
+
 gboolean procmime_find_string_part(MimeInfo *mimeinfo, const gchar *filename,
                                   const gchar *str, StrFindFunc find_func)
 {
@@ -1012,17 +1092,23 @@ GList *procmime_get_mime_type_list(void)
        GList *list = NULL;
        FILE *fp;
        gchar buf[BUFFSIZE];
-       guchar *p;
+       gchar *p;
        gchar *delim;
        MimeType *mime_type;
+       gboolean fp_is_glob_file = TRUE;
 
        if (mime_type_list) 
                return mime_type_list;
-
-       if ((fp = fopen("/etc/mime.types", "rb")) == NULL) {
-               if ((fp = fopen(SYSCONFDIR "/mime.types", "rb")) == NULL) {
-                       FILE_OP_ERROR(SYSCONFDIR "/mime.types", "fopen");
-                       return NULL;
+       
+       if ((fp = g_fopen("/usr/share/mime/globs", "rb")) == NULL) {
+               fp_is_glob_file = FALSE;
+               if ((fp = g_fopen("/etc/mime.types", "rb")) == NULL) {
+                       if ((fp = g_fopen(SYSCONFDIR "/mime.types", "rb")) 
+                               == NULL) {
+                               FILE_OP_ERROR(SYSCONFDIR "/mime.types", 
+                                       "fopen");
+                               return NULL;
+                       }
                }
        }
 
@@ -1032,7 +1118,13 @@ GList *procmime_get_mime_type_list(void)
                g_strstrip(buf);
 
                p = buf;
-               while (*p && !isspace(*p)) p++;
+               
+               if (fp_is_glob_file) {
+                       while (*p && !g_ascii_isspace(*p) && (*p!=':')) p++;
+               } else {
+                       while (*p && !g_ascii_isspace(*p)) p++;
+               }
+
                if (*p) {
                        *p = '\0';
                        p++;
@@ -1045,7 +1137,12 @@ GList *procmime_get_mime_type_list(void)
                mime_type->type = g_strdup(buf);
                mime_type->sub_type = g_strdup(delim + 1);
 
-               while (*p && isspace(*p)) p++;
+               if (fp_is_glob_file) {
+                       while (*p && (g_ascii_isspace(*p)||(*p=='*')||(*p=='.'))) p++;
+               } else {
+                       while (*p && g_ascii_isspace(*p)) p++;
+               }
+
                if (*p)
                        mime_type->extension = g_strdup(p);
                else
@@ -1088,7 +1185,7 @@ EncodingType procmime_get_encoding_for_text_file(const gchar *file)
        size_t total_len = 0;
        gfloat octet_percentage;
 
-       if ((fp = fopen(file, "rb")) == NULL) {
+       if ((fp = g_fopen(file, "rb")) == NULL) {
                FILE_OP_ERROR(file, "fopen");
                return ENC_UNKNOWN;
        }
@@ -1235,12 +1332,11 @@ void procmime_parse_message_rfc822(MimeInfo *mimeinfo)
                                {NULL,             NULL, FALSE}};
        guint content_start, i;
        FILE *fp;
-       gint mime_major, mime_minor;
         gchar *tmp;
 
        procmime_decode_content(mimeinfo);
 
-       fp = fopen(mimeinfo->data.filename, "rb");
+       fp = g_fopen(mimeinfo->data.filename, "rb");
        if (fp == NULL) {
                FILE_OP_ERROR(mimeinfo->data.filename, "fopen");
                return;
@@ -1264,30 +1360,14 @@ void procmime_parse_message_rfc822(MimeInfo *mimeinfo)
         }                
        content_start = ftell(fp);
        fclose(fp);
-
-       if ((hentry[5].body != NULL) &&
-           (sscanf(hentry[5].body, "%d.%d", &mime_major, &mime_minor) == 2) &&
-           (mime_major == 1) && (mime_minor == 0)) {
-               procmime_parse_mimepart(mimeinfo,
-                                       hentry[0].body, hentry[1].body,
-                                       hentry[2].body, hentry[3].body, 
-                                       hentry[4].body, 
-                                       mimeinfo->data.filename, content_start,
-                                       mimeinfo->length - (content_start - mimeinfo->offset));
-       } else {
-               MimeInfo *subinfo;
-
-               subinfo = procmime_mimeinfo_new();
-               subinfo->content = MIMECONTENT_FILE;
-               subinfo->encoding_type = ENC_UNKNOWN;
-               subinfo->type = MIMETYPE_TEXT;
-               subinfo->subtype = g_strdup("plain");
-               subinfo->data.filename = g_strdup(mimeinfo->data.filename);
-               subinfo->offset = content_start;
-               subinfo->length = mimeinfo->length - (content_start - mimeinfo->offset);
-
-               g_node_append(mimeinfo->node, subinfo->node);
-       }
+       
+       procmime_parse_mimepart(mimeinfo,
+                               hentry[0].body, hentry[1].body,
+                               hentry[2].body, hentry[3].body,
+                               hentry[4].body,
+                               mimeinfo->data.filename, content_start,
+                               mimeinfo->length - (content_start - mimeinfo->offset));
+       
        for (i = 0; i < (sizeof hentry / sizeof hentry[0]); i++) {
                g_free(hentry[i].body);
                hentry[i].body = NULL;
@@ -1320,7 +1400,7 @@ void procmime_parse_multipart(MimeInfo *mimeinfo)
 
        procmime_decode_content(mimeinfo);
 
-       fp = fopen(mimeinfo->data.filename, "rb");
+       fp = g_fopen(mimeinfo->data.filename, "rb");
        if (fp == NULL) {
                FILE_OP_ERROR(mimeinfo->data.filename, "fopen");
                return;
@@ -1491,7 +1571,8 @@ static void parse_parameters(const gchar *parameters, GHashTable *table)
                gchar *charset, *lang, *oldvalue, *newvalue;
 
                attribute = (gchar *) cur->data;
-               if (!g_hash_table_lookup_extended(table, attribute, (gpointer *) &key, (gpointer *) &value))
+               if (!g_hash_table_lookup_extended(
+                       table, attribute, (gpointer *)(gchar *) &key, (gpointer *)(gchar *) &value))
                        continue;
 
                charset = value;
@@ -1534,7 +1615,7 @@ static void procmime_parse_content_type(const gchar *content_type, MimeInfo *mim
                                       "charset") == NULL)
                        g_hash_table_insert(mimeinfo->typeparameters,
                                            g_strdup("charset"),
-                                           g_strdup("us-ascii"));
+                                           g_strdup(conv_get_locale_charset_str()));
        } else {
                gchar *type, *subtype, *params;
 
@@ -1636,7 +1717,8 @@ int procmime_parse_mimepart(MimeInfo *parent,
                mimeinfo->subtype = g_strdup("plain");
                if (g_hash_table_lookup(mimeinfo->typeparameters,
                                       "charset") == NULL)
-                       g_hash_table_insert(mimeinfo->typeparameters, g_strdup("charset"), g_strdup("us-ascii"));
+                       g_hash_table_insert(mimeinfo->typeparameters, g_strdup("charset"), 
+                               g_strdup(conv_get_locale_charset_str()));
        }
 
        if (content_encoding != NULL) {
@@ -1752,7 +1834,7 @@ MimeInfo *procmime_scan_queue_file(const gchar *filename)
        g_return_val_if_fail(filename != NULL, NULL);
 
        /* Open file */
-       if ((fp = fopen(filename, "rb")) == NULL)
+       if ((fp = g_fopen(filename, "rb")) == NULL)
                return NULL;
        /* Skip queue header */
        while (fgets(buf, sizeof(buf), fp) != NULL)
@@ -1769,24 +1851,26 @@ typedef enum {
     ENC_AS_TOKEN,
     ENC_AS_QUOTED_STRING,
     ENC_AS_EXTENDED,
+    ENC_TO_ASCII,
 } EncodeAs;
 
 typedef struct _ParametersData {
        FILE *fp;
        guint len;
+       guint ascii_only;
 } ParametersData;
 
 static void write_parameters(gpointer key, gpointer value, gpointer user_data)
 {
        gchar *param = key;
-       gchar *val = value, *valpos;
+       gchar *val = value, *valpos, *tmp;
        ParametersData *pdata = (ParametersData *)user_data;
        GString *buf = g_string_new("");
 
        EncodeAs encas = ENC_AS_TOKEN;
 
        for (valpos = val; *valpos != 0; valpos++) {
-               if (!IS_ASCII(*valpos)) {
+               if (!IS_ASCII(*valpos) || *valpos == '"') {
                        encas = ENC_AS_EXTENDED;
                        break;
                }
@@ -1809,7 +1893,7 @@ static void write_parameters(gpointer key, gpointer value, gpointer user_data)
                case ';':
                case ':':
                case '\\':
-               case '"':
+               case '\'':
                case '/':
                case '[':
                case ']':
@@ -1819,12 +1903,26 @@ static void write_parameters(gpointer key, gpointer value, gpointer user_data)
                        continue;
                }
        }
+       
+       if (encas == ENC_AS_EXTENDED && pdata->ascii_only == TRUE) 
+               encas = ENC_TO_ASCII;
 
        switch (encas) {
        case ENC_AS_TOKEN:
                g_string_append_printf(buf, "%s=%s", param, val);
                break;
 
+       case ENC_TO_ASCII:
+               tmp = g_strdup(val);
+               g_strcanon(tmp, 
+                       " ()<>@,';:\\/[]?=.0123456789"
+                       "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+                       "abcdefghijklmnopqrstuvwxyz",
+                       '_');
+               g_string_append_printf(buf, "%s=\"%s\"", param, tmp);
+               g_free(tmp);
+               break;
+
        case ENC_AS_QUOTED_STRING:
                g_string_append_printf(buf, "%s=\"%s\"", param, val);
                break;
@@ -1845,7 +1943,7 @@ static void write_parameters(gpointer key, gpointer value, gpointer user_data)
                                g_string_append_printf(buf, "%%%s", hexstr);
                        }
                }
-               break;
+               break;          
        }
        
        if (buf->str && strlen(buf->str)) {
@@ -1867,6 +1965,7 @@ void procmime_write_mime_header(MimeInfo *mimeinfo, FILE *fp)
        debug_print("procmime_write_mime_header\n");
        
        pdata->fp = fp;
+       pdata->ascii_only = FALSE;
 
        for (type_table = mime_type_table; type_table->str != NULL; type_table++)
                if (mimeinfo->type == type_table->type) {
@@ -1874,6 +1973,7 @@ void procmime_write_mime_header(MimeInfo *mimeinfo, FILE *fp)
                                "Content-Type: %s/%s", type_table->str, mimeinfo->subtype);
                        fprintf(fp, "%s", buf);
                        pdata->len = strlen(buf);
+                       pdata->ascii_only = TRUE;
                        g_free(buf);
                        break;
                }
@@ -1906,6 +2006,8 @@ void procmime_write_mime_header(MimeInfo *mimeinfo, FILE *fp)
                g_free(buf);
 
                pdata->fp = fp;
+               pdata->ascii_only = FALSE;
+
                g_hash_table_foreach(mimeinfo->dispositionparameters, write_parameters, pdata);
                g_free(pdata);
                fprintf(fp, "\n");
@@ -1927,7 +2029,7 @@ gint procmime_write_message_rfc822(MimeInfo *mimeinfo, FILE *fp)
        /* write header */
        switch (mimeinfo->content) {
        case MIMECONTENT_FILE:
-               if ((infp = fopen(mimeinfo->data.filename, "rb")) == NULL) {
+               if ((infp = g_fopen(mimeinfo->data.filename, "rb")) == NULL) {
                        FILE_OP_ERROR(mimeinfo->data.filename, "fopen");
                        return -1;
                }
@@ -1953,7 +2055,10 @@ gint procmime_write_message_rfc822(MimeInfo *mimeinfo, FILE *fp)
                break;
 
        case MIMECONTENT_MEM:
-               fwrite(mimeinfo->data.mem, strlen(mimeinfo->data.mem), sizeof(gchar), fp);
+               fwrite(mimeinfo->data.mem, 
+                               sizeof(gchar), 
+                               strlen(mimeinfo->data.mem), 
+                               fp);
                break;
 
        default:
@@ -1984,7 +2089,7 @@ gint procmime_write_multipart(MimeInfo *mimeinfo, FILE *fp)
 
        switch (mimeinfo->content) {
        case MIMECONTENT_FILE:
-               if ((infp = fopen(mimeinfo->data.filename, "rb")) == NULL) {
+               if ((infp = g_fopen(mimeinfo->data.filename, "rb")) == NULL) {
                        FILE_OP_ERROR(mimeinfo->data.filename, "fopen");
                        return -1;
                }
@@ -2002,7 +2107,7 @@ gint procmime_write_multipart(MimeInfo *mimeinfo, FILE *fp)
                if (((str2 = strstr(str, boundary)) != NULL) && ((str2 - str) >= 2) &&
                    (*(str2 - 1) == '-') && (*(str2 - 2) == '-'))
                        *(str2 - 2) = '\0';
-               fwrite(str, strlen(str), sizeof(gchar), fp);
+               fwrite(str, sizeof(gchar), strlen(str), fp);
                g_free(str);
                break;
 
@@ -2041,7 +2146,7 @@ gint procmime_write_mimeinfo(MimeInfo *mimeinfo, FILE *fp)
        if (G_NODE_IS_LEAF(mimeinfo->node)) {
                switch (mimeinfo->content) {
                case MIMECONTENT_FILE:
-                       if ((infp = fopen(mimeinfo->data.filename, "rb")) == NULL) {
+                       if ((infp = g_fopen(mimeinfo->data.filename, "rb")) == NULL) {
                                FILE_OP_ERROR(mimeinfo->data.filename, "fopen");
                                return -1;
                        }
@@ -2050,7 +2155,10 @@ gint procmime_write_mimeinfo(MimeInfo *mimeinfo, FILE *fp)
                        return 0;
 
                case MIMECONTENT_MEM:
-                       fwrite(mimeinfo->data.mem, strlen(mimeinfo->data.mem), sizeof(gchar), fp);
+                       fwrite(mimeinfo->data.mem, 
+                                       sizeof(gchar), 
+                                       strlen(mimeinfo->data.mem), 
+                                       fp);
                        return 0;
 
                default:
@@ -2060,8 +2168,9 @@ gint procmime_write_mimeinfo(MimeInfo *mimeinfo, FILE *fp)
                /* Call writer for mime type */
                switch (mimeinfo->type) {
                case MIMETYPE_MESSAGE:
-                       if (g_ascii_strcasecmp(mimeinfo->subtype, "rfc822") == 0)
+                       if (g_ascii_strcasecmp(mimeinfo->subtype, "rfc822") == 0) {
                                return procmime_write_message_rfc822(mimeinfo, fp);
+                       }
                        break;
                        
                case MIMETYPE_MULTIPART: