Revision 3247 libsylph/procmsg.c

View differences:

procmsg.c
1807 1807
				get_mime_tmp_dir(), G_DIR_SEPARATOR,
1808 1808
				print_id++);
1809 1809

  
1810
	if ((prfp = g_fopen(prtmp, "wb")) == NULL) {
1810
	if ((prfp = g_fopen(prtmp, "w")) == NULL) {
1811 1811
		FILE_OP_ERROR(prtmp, "procmsg_print_message: fopen");
1812 1812
		g_free(prtmp);
1813 1813
		fclose(tmpfp);
......
1860 1860
	prtmp = g_strdup_printf("%s%cprinttmp-%08x.txt",
1861 1861
				get_mime_tmp_dir(), G_DIR_SEPARATOR,
1862 1862
				print_id++);
1863
	if ((prfp = g_fopen(prtmp, "wb")) == NULL) {
1863
	if ((prfp = g_fopen(prtmp, "w")) == NULL) {
1864 1864
		FILE_OP_ERROR(prtmp, "procmsg_print_message_part: fopen");
1865 1865
		g_free(prtmp);
1866 1866
		fclose(tmpfp);
......
1886 1886
	FILE *tmpfp;
1887 1887
	FILE *destfp;
1888 1888
	gchar buf[BUFFSIZE];
1889
	gchar *part_str;
1890
	gint ret = 0;
1889 1891

  
1890 1892
	g_return_val_if_fail(msginfo != NULL, -1);
1891 1893
	g_return_val_if_fail(dest != NULL, -1);
......
1897 1899
		procmime_mimeinfo_free_all(mimeinfo);
1898 1900
		return -1;
1899 1901
	}
1900
	if ((destfp = g_fopen(dest, "wb")) == NULL) {
1902
	if ((destfp = g_fopen(dest, "w")) == NULL) {
1901 1903
		fclose(fp);
1902 1904
		procmime_mimeinfo_free_all(mimeinfo);
1903 1905
		return -1;
......
1921 1923
			g_snprintf(buf, sizeof(buf), "\n[%s (%s)]\n",
1922 1924
				   partinfo->content_type,
1923 1925
				   to_human_readable(partinfo->content_size));
1926
		part_str = conv_codeset_strdup(buf, CS_INTERNAL, encoding);
1924 1927

  
1925 1928
		if (partinfo->mime_type == MIME_TEXT ||
1926 1929
		    partinfo->mime_type == MIME_TEXT_HTML) {
1927 1930
			if (!partinfo->main &&
1928 1931
			    partinfo->parent &&
1929 1932
			    partinfo->parent->children != partinfo) {
1930
				fputs(buf, destfp);
1933
				fputs(part_str, destfp);
1931 1934
			}
1932 1935

  
1933
			if ((tmpfp = procmime_get_text_content(partinfo, fp, encoding)) == NULL)
1936
			if ((tmpfp = procmime_get_text_content(partinfo, fp, encoding)) == NULL) {
1937
				g_free(part_str);
1934 1938
				break;
1935
			if (copy_file_stream(tmpfp, destfp) < 0) {
1936
				fclose(tmpfp);
1937
				break;
1938 1939
			}
1940
			while (fgets(buf, sizeof(buf), tmpfp) != NULL)
1941
				fputs(buf, destfp);
1939 1942

  
1940 1943
			fclose(tmpfp);
1941 1944
		} else if (partinfo->mime_type == MIME_MESSAGE_RFC822) {
1942
			fputs(buf, destfp);
1945
			fputs(part_str, destfp);
1943 1946
			while (fgets(buf, sizeof(buf), fp) != NULL)
1944 1947
				if (buf[0] == '\r' || buf[0] == '\n') break;
1945 1948
			procmsg_write_headers(msginfo, partinfo, fp, destfp, encoding, all_headers);
1946 1949
			fputc('\n', destfp);
1947 1950
		} else if (partinfo->mime_type != MIME_MULTIPART) {
1948
			fputs(buf, destfp);
1951
			fputs(part_str, destfp);
1949 1952
		}
1950 1953

  
1954
		g_free(part_str);
1955

  
1951 1956
		if (partinfo->parent && partinfo->parent->content_type &&
1952 1957
		    !g_ascii_strcasecmp(partinfo->parent->content_type,
1953 1958
					"multipart/alternative"))
......
1956 1961
			partinfo = procmime_mimeinfo_next(partinfo);
1957 1962
	}
1958 1963

  
1959
	fclose(destfp);
1964
	if (fclose(destfp) == EOF) {
1965
		FILE_OP_ERROR(dest, "fclose");
1966
		g_unlink(dest);
1967
		ret = -1;
1968
	}
1969

  
1960 1970
	fclose(fp);
1961 1971
	procmime_mimeinfo_free_all(mimeinfo);
1962 1972

  
1963
	return 0;
1973
	return ret;
1964 1974
}
1965 1975

  
1966 1976
/**

Also available in: Unified diff