From f0b2eb198def2bb1674b1e5b3ad82f645d68e289 Mon Sep 17 00:00:00 2001 From: hiro Date: Mon, 28 Nov 2005 07:00:13 +0000 Subject: also normalize text files on win32 when saving parts. git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@784 ee746299-78ed-0310-b773-934348b2243d --- libsylph/procmime.c | 79 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 53 insertions(+), 26 deletions(-) (limited to 'libsylph') diff --git a/libsylph/procmime.c b/libsylph/procmime.c index 6207807e..13df59bd 100644 --- a/libsylph/procmime.c +++ b/libsylph/procmime.c @@ -543,6 +543,8 @@ FILE *procmime_decode_content(FILE *outfp, FILE *infp, MimeInfo *mimeinfo) gchar *boundary = NULL; gint boundary_len = 0; gboolean tmp_file = FALSE; + gboolean normalize_lbreak = FALSE; + ContentType content_type; g_return_val_if_fail(infp != NULL, NULL); g_return_val_if_fail(mimeinfo != NULL, NULL); @@ -561,27 +563,53 @@ FILE *procmime_decode_content(FILE *outfp, FILE *infp, MimeInfo *mimeinfo) boundary_len = strlen(boundary); } + content_type = procmime_scan_mime_type(mimeinfo->content_type); + if (content_type == MIME_TEXT || + content_type == MIME_TEXT_HTML) { + normalize_lbreak = TRUE; + } + if (mimeinfo->encoding_type == ENC_QUOTED_PRINTABLE) { + FILE *tmpfp = outfp; + + if (normalize_lbreak) { + tmpfp = my_tmpfile(); + if (!tmpfp) { + perror("tmpfile"); + if (tmp_file) fclose(outfp); + return NULL; + } + } + while (fgets(buf, sizeof(buf), infp) != NULL && (!boundary || !IS_BOUNDARY(buf, boundary, boundary_len))) { gint len; len = qp_decode_line(buf); - fwrite(buf, len, 1, outfp); + fwrite(buf, len, 1, tmpfp); + } + + if (normalize_lbreak) { + rewind(tmpfp); + while (fgets(buf, sizeof(buf), tmpfp) != NULL) { +#ifdef G_OS_WIN32 + strretchomp(buf); + fputs(buf, outfp); + fputs("\r\n", outfp); +#else + strcrchomp(buf); + fputs(buf, outfp); +#endif + } + fclose(tmpfp); } } else if (mimeinfo->encoding_type == ENC_BASE64) { gchar outbuf[BUFFSIZE]; gint len; Base64Decoder *decoder; FILE *tmpfp = outfp; -#ifndef G_OS_WIN32 - gboolean uncanonicalize = FALSE; - ContentType content_type; - - content_type = procmime_scan_mime_type(mimeinfo->content_type); - if (content_type == MIME_TEXT || - content_type == MIME_TEXT_HTML) { - uncanonicalize = TRUE; + + if (normalize_lbreak) { tmpfp = my_tmpfile(); if (!tmpfp) { perror("tmpfile"); @@ -589,7 +617,6 @@ FILE *procmime_decode_content(FILE *outfp, FILE *infp, MimeInfo *mimeinfo) return NULL; } } -#endif decoder = base64_decoder_new(); while (fgets(buf, sizeof(buf), infp) != NULL && @@ -605,16 +632,20 @@ FILE *procmime_decode_content(FILE *outfp, FILE *infp, MimeInfo *mimeinfo) } base64_decoder_free(decoder); -#ifndef G_OS_WIN32 - if (uncanonicalize) { + if (normalize_lbreak) { rewind(tmpfp); while (fgets(buf, sizeof(buf), tmpfp) != NULL) { +#ifdef G_OS_WIN32 + strretchomp(buf); + fputs(buf, outfp); + fputs("\r\n", outfp); +#else strcrchomp(buf); fputs(buf, outfp); +#endif } fclose(tmpfp); } -#endif } else if (mimeinfo->encoding_type == ENC_X_UUENCODE) { gchar outbuf[BUFFSIZE]; gint len; @@ -637,24 +668,20 @@ FILE *procmime_decode_content(FILE *outfp, FILE *infp, MimeInfo *mimeinfo) flag = TRUE; } } else { -#ifndef G_OS_WIN32 - gboolean uncanonicalize = FALSE; - ContentType content_type; - - content_type = procmime_scan_mime_type(mimeinfo->content_type); - if (content_type == MIME_TEXT || - content_type == MIME_TEXT_HTML) - uncanonicalize = TRUE; -#endif - while (fgets(buf, sizeof(buf), infp) != NULL && (!boundary || !IS_BOUNDARY(buf, boundary, boundary_len))) { -#ifndef G_OS_WIN32 - if (uncanonicalize) + if (normalize_lbreak) { +#ifdef G_OS_WIN32 + strretchomp(buf); + fputs(buf, outfp); + fputs("\r\n", outfp); +#else strcrchomp(buf); + fputs(buf, outfp); #endif - fputs(buf, outfp); + } else + fputs(buf, outfp); } } -- cgit v1.2.3