#include "prefs_common.h"
#include "procmime.h"
#include "plugin.h"
+#include "file-utils.h"
typedef struct _PrivacyDataPGP PrivacyDataPGP;
if (boundary) {
boundary_len = strlen(boundary);
- while (fgets(buf, sizeof(buf), fp) != NULL)
+ while (claws_fgets(buf, sizeof(buf), fp) != NULL)
if (IS_BOUNDARY(buf, boundary, boundary_len))
break;
}
textbuffer = g_string_new("");
- while (fgets(buf, sizeof(buf), fp) != NULL) {
+ while (claws_fgets(buf, sizeof(buf), fp) != NULL) {
gchar *buf2;
if (boundary && IS_BOUNDARY(buf, boundary, boundary_len))
}
parent = procmime_mimeinfo_parent(mimeinfo);
- fp = g_fopen(parent->data.filename, "rb");
+ fp = claws_fopen(parent->data.filename, "rb");
cm_return_val_if_fail(fp != NULL, SIGNATURE_INVALID);
boundary = g_hash_table_lookup(parent->typeparameters, "boundary");
g_free(textstr);
cm_gpgme_data_rewind(cipher);
textstr = sgpgme_data_release_and_get_mem(cipher, &len);
- fclose(fp);
+ claws_fclose(fp);
if (textstr && len > 0)
textstr[len-1]='\0';
gchar *tmp_file = get_tmp_file();
MimeInfo *newinfo = NULL, *decinfo = NULL, *parentinfo = NULL;
- str_write_to_file(textstr, tmp_file);
+ str_write_to_file(textstr, tmp_file, TRUE);
newinfo = procmime_scan_file(tmp_file);
decinfo = g_node_first_child(newinfo->node) != NULL ?
g_node_first_child(newinfo->node)->data : NULL;
}
}
g_node_prepend(parentinfo->node, decinfo->node);
+ g_free(textstr);
return 0;
} else {
- g_free(textstr);
+ if (textstr)
+ g_free(textstr);
return -1;
}
}
gpgme_data_release(sigdata);
gpgme_data_release(textdata);
g_free(textstr);
- fclose(fp);
+ claws_fclose(fp);
return 0;
}
fname = g_strdup_printf("%s%cplaintext.%08x",
get_mime_tmp_dir(), G_DIR_SEPARATOR, ++id);
- if ((dstfp = g_fopen(fname, "wb")) == NULL) {
- FILE_OP_ERROR(fname, "g_fopen");
+ if ((dstfp = claws_fopen(fname, "wb")) == NULL) {
+ FILE_OP_ERROR(fname, "claws_fopen");
g_free(fname);
gpgme_data_release(plain);
gpgme_release(ctx);
if (fprintf(dstfp, "MIME-Version: 1.0\n") < 0) {
FILE_OP_ERROR(fname, "fprintf");
g_free(fname);
- fclose(dstfp);
+ claws_fclose(dstfp);
gpgme_data_release(plain);
gpgme_release(ctx);
debug_print("can't close!\n");
chars = sgpgme_data_release_and_get_mem(plain, &len);
if (len > 0) {
- if (fwrite(chars, 1, len, dstfp) < len) {
- FILE_OP_ERROR(fname, "fwrite");
- fclose(dstfp);
+ if (claws_fwrite(chars, 1, len, dstfp) < len) {
+ FILE_OP_ERROR(fname, "claws_fwrite");
+ claws_fclose(dstfp);
g_free(fname);
g_free(chars);
gpgme_data_release(plain);
return NULL;
}
}
- if (fclose(dstfp) == EOF) {
- FILE_OP_ERROR(fname, "fclose");
+ if (claws_safe_fclose(dstfp) == EOF) {
+ FILE_OP_ERROR(fname, "claws_fclose");
g_free(fname);
g_free(chars);
gpgme_data_release(plain);
/* read temporary file into memory */
test_msg = file_read_stream_to_str(fp);
- fclose(fp);
+ claws_fclose(fp);
memset (&info, 0, sizeof info);
g_free(boundary);
- fclose(fp);
+ claws_fclose(fp);
gpgme_data_new_from_mem(&gpgtext, textstr, textstr?strlen(textstr):0, 0);
gpgme_data_new(&gpgsig);
g_hash_table_insert(newinfo->dispositionparameters, g_strdup("filename"),
g_strdup("smime.p7s"));
newinfo->data.mem = g_malloc(len + 1);
- g_memmove(newinfo->data.mem, real_content, len);
+ newinfo->tmp = TRUE;
+ memmove(newinfo->data.mem, real_content, len);
newinfo->data.mem[len] = '\0';
newinfo->encoding_type = ENC_BASE64;
g_node_append(sigmultipart->node, newinfo->node);
/* write message content to temporary file */
tmpfile = get_tmp_file();
- fp = g_fopen(tmpfile, "wb");
+ fp = claws_fopen(tmpfile, "wb");
if (fp == NULL) {
FILE_OP_ERROR(tmpfile, "create");
g_free(kset);
procmime_decode_content(msgcontent);
procmime_write_mime_header(msgcontent, fp);
procmime_write_mimeinfo(msgcontent, fp);
- fclose(fp);
+ claws_safe_fclose(fp);
canonicalize_file_replace(tmpfile);
- fp = g_fopen(tmpfile, "rb");
+ fp = claws_fopen(tmpfile, "rb");
if (fp == NULL) {
FILE_OP_ERROR(tmpfile, "open");
g_free(kset);
g_free(tmpfile);
/* read temporary file into memory */
- textstr = fp_read_noconv(fp);
+ textstr = file_read_stream_to_str_no_recode(fp);
- fclose(fp);
+ claws_fclose(fp);
/* encrypt data */
gpgme_data_new_from_mem(&gpgtext, textstr, textstr?strlen(textstr):0, 0);
}
tmpfile = get_tmp_file();
- fp = g_fopen(tmpfile, "wb");
+ fp = claws_fopen(tmpfile, "wb");
if (fp) {
- if (fwrite(enccontent, 1, len, fp) < len) {
- FILE_OP_ERROR(tmpfile, "fwrite");
- fclose(fp);
+ if (claws_fwrite(enccontent, 1, len, fp) < len) {
+ FILE_OP_ERROR(tmpfile, "claws_fwrite");
+ claws_fclose(fp);
claws_unlink(tmpfile);
g_free(tmpfile);
g_free(enccontent);
return FALSE;
}
- if (fclose(fp) == EOF) {
- FILE_OP_ERROR(tmpfile, "fclose");
+ if (claws_safe_fclose(fp) == EOF) {
+ FILE_OP_ERROR(tmpfile, "claws_fclose");
claws_unlink(tmpfile);
g_free(tmpfile);
g_free(enccontent);
encmultipart->content = MIMECONTENT_FILE;
encmultipart->data.filename = tmpfile;
+ encmultipart->tmp = TRUE;
procmime_encode_content(encmultipart, ENC_BASE64);
g_free(enccontent);