aboutsummaryrefslogtreecommitdiff
path: root/libsylph/procmime.c
diff options
context:
space:
mode:
authorhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2005-11-28 07:00:13 +0000
committerhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2005-11-28 07:00:13 +0000
commitf0b2eb198def2bb1674b1e5b3ad82f645d68e289 (patch)
treeae895e55981f8957200781ae4620803718cc1a8e /libsylph/procmime.c
parent928a2cc8708a85a7fbcceb4d77e163835b158934 (diff)
also normalize text files on win32 when saving parts.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@784 ee746299-78ed-0310-b773-934348b2243d
Diffstat (limited to 'libsylph/procmime.c')
-rw-r--r--libsylph/procmime.c79
1 files changed, 53 insertions, 26 deletions
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);
}
}