replace deprecated g_memmove with memmove
[claws.git] / src / plugins / pgpinline / pgpinline.c
index dfe1ca7dc7b0a596f9f857d904d8632620f576c3..c5a05fb99b6830b403b0c8de2f6dc0b62acacb45 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2015 Colin Leroy and the Claws Mail team
+ * Copyright (C) 1999-2016 Colin Leroy and the Claws Mail team
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -28,6 +28,7 @@
 #include <glib/gi18n.h>
 #include <errno.h>
 #include <gpgme.h>
+#include <file-utils.h>
 
 #include "utils.h"
 #include "privacy.h"
@@ -70,7 +71,7 @@ static PrivacyDataPGP *pgpinline_new_privacydata()
        data->is_signed = FALSE;
        data->sigstatus = NULL;
        if ((err = gpgme_new(&data->ctx)) != GPG_ERR_NO_ERROR) {
-               debug_print(("Couldn't initialize GPG context, %s"), gpgme_strerror(err));
+               debug_print(("Couldn't initialize GPG context, %s\n"), gpgme_strerror(err));
                return NULL;
        }
        
@@ -114,7 +115,7 @@ static gboolean pgpinline_is_signed(MimeInfo *mimeinfo)
                        return data->is_signed;
        }
        
-       textdata = get_part_as_string(mimeinfo);
+       textdata = procmime_get_part_as_string(mimeinfo, TRUE);
        if (!textdata)
                return FALSE;
        
@@ -163,7 +164,7 @@ static gint pgpinline_check_signature(MimeInfo *mimeinfo)
        cm_return_val_if_fail(mimeinfo->privacy != NULL, 0);
        data = (PrivacyDataPGP *) mimeinfo->privacy;
 
-       textdata = get_part_as_string(mimeinfo);
+       textdata = procmime_get_part_as_string(mimeinfo, TRUE);
 
        if (!textdata) {
                g_free(textdata);
@@ -192,7 +193,7 @@ static gint pgpinline_check_signature(MimeInfo *mimeinfo)
        g_free(tmp);
        
        if ((err = gpgme_new(&data->ctx)) != GPG_ERR_NO_ERROR) {
-               debug_print(("Couldn't initialize GPG context, %s"), gpgme_strerror(err));
+               debug_print(("Couldn't initialize GPG context, %s\n"), gpgme_strerror(err));
                privacy_set_error(_("Couldn't initialize GPG context, %s"), gpgme_strerror(err));
                g_free(textdata);
                return 0;
@@ -264,7 +265,7 @@ static gboolean pgpinline_is_encrypted(MimeInfo *mimeinfo)
                mimeinfo->subtype = g_strdup("plain");
        }
 
-       textdata = get_part_as_string(mimeinfo);
+       textdata = procmime_get_part_as_string(mimeinfo, TRUE);
        if (!textdata)
                return FALSE;
 
@@ -316,7 +317,7 @@ static MimeInfo *pgpinline_decrypt(MimeInfo *mimeinfo)
                return NULL;
        }
 
-       textdata = get_part_as_string(mimeinfo);
+       textdata = procmime_get_part_as_string(mimeinfo, TRUE);
        if (!textdata) {
                gpgme_release(ctx);
                privacy_set_error(_("Couldn't get text data."));
@@ -340,8 +341,8 @@ static MimeInfo *pgpinline_decrypt(MimeInfo *mimeinfo)
        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, "fopen");
+       if ((dstfp = claws_fopen(fname, "wb")) == NULL) {
+               FILE_OP_ERROR(fname, "claws_fopen");
                privacy_set_error(_("Couldn't open decrypted file %s"), fname);
                g_free(fname);
                gpgme_data_release(plain);
@@ -366,24 +367,24 @@ static MimeInfo *pgpinline_decrypt(MimeInfo *mimeinfo)
        /* Store any part before encrypted text */
        pos = pgp_locate_armor_header(textdata, begin_indicator);
        if (pos != NULL && (pos - textdata) > 0) {
-           if (fwrite(textdata, 1, pos - textdata, dstfp) < pos - textdata) {
-               FILE_OP_ERROR(fname, "fwrite");
+           if (claws_fwrite(textdata, 1, pos - textdata, dstfp) < pos - textdata) {
+               FILE_OP_ERROR(fname, "claws_fwrite");
                privacy_set_error(_("Couldn't write to decrypted file %s"), fname);
                goto FILE_ERROR;
            }
        }
        
-       if (fwrite(_("\n--- Start of PGP/Inline encrypted data ---\n"), 1,
+       if (claws_fwrite(_("\n--- Start of PGP/Inline encrypted data ---\n"), 1,
                strlen(_("\n--- Start of PGP/Inline encrypted data ---\n")), 
                dstfp) < strlen(_("\n--- Start of PGP/Inline encrypted data ---\n"))) {
-               FILE_OP_ERROR(fname, "fwrite");
+               FILE_OP_ERROR(fname, "claws_fwrite");
                privacy_set_error(_("Couldn't write to decrypted file %s"), fname);
                goto FILE_ERROR;
        }
        chars = sgpgme_data_release_and_get_mem(plain, &len);
        if (len > 0) {
-               if (fwrite(chars, 1, len, dstfp) < len) {
-                       FILE_OP_ERROR(fname, "fwrite");
+               if (claws_fwrite(chars, 1, len, dstfp) < len) {
+                       FILE_OP_ERROR(fname, "claws_fwrite");
                        g_free(chars);
                        privacy_set_error(_("Couldn't write to decrypted file %s"), fname);
                        goto FILE_ERROR;
@@ -391,10 +392,10 @@ static MimeInfo *pgpinline_decrypt(MimeInfo *mimeinfo)
        }
        g_free(chars);
        /* Store any part after encrypted text */
-       if (fwrite(_("--- End of PGP/Inline encrypted data ---\n"), 1,
+       if (claws_fwrite(_("--- End of PGP/Inline encrypted data ---\n"), 1,
                strlen(_("--- End of PGP/Inline encrypted data ---\n")), 
                dstfp) < strlen(_("--- End of PGP/Inline encrypted data ---\n"))) {
-                       FILE_OP_ERROR(fname, "fwrite");
+                       FILE_OP_ERROR(fname, "claws_fwrite");
                        privacy_set_error(_("Couldn't write to decrypted file %s"), fname);
                        goto FILE_ERROR;
        }
@@ -402,16 +403,16 @@ static MimeInfo *pgpinline_decrypt(MimeInfo *mimeinfo)
            pos = pgp_locate_armor_header(pos, end_indicator);
            if (pos != NULL && *pos != '\0') {
                pos += strlen(end_indicator);
-               if (fwrite(pos, 1, strlen(pos), dstfp) < strlen(pos)) {
-                       FILE_OP_ERROR(fname, "fwrite");
+               if (claws_fwrite(pos, 1, strlen(pos), dstfp) < strlen(pos)) {
+                       FILE_OP_ERROR(fname, "claws_fwrite");
                        privacy_set_error(_("Couldn't write to decrypted file %s"), fname);
                        goto FILE_ERROR;
                }
            }
        }
 
-       if (fclose(dstfp) == EOF) {
-               FILE_OP_ERROR(fname, "fclose");
+       if (claws_safe_fclose(dstfp) == EOF) {
+               FILE_OP_ERROR(fname, "claws_fclose");
                privacy_set_error(_("Couldn't close decrypted file %s"), fname);
                g_free(fname);
                gpgme_data_release(plain);
@@ -462,7 +463,7 @@ static MimeInfo *pgpinline_decrypt(MimeInfo *mimeinfo)
        return decinfo;
 
 FILE_ERROR:
-       fclose(dstfp);
+       claws_fclose(dstfp);
        g_free(fname);
        gpgme_data_release(plain);
        gpgme_release(ctx);
@@ -500,21 +501,21 @@ static gboolean pgpinline_sign(MimeInfo *mimeinfo, PrefsAccount *account, const
        fp = my_tmpfile();
        if (fp == NULL) {
                perror("my_tmpfile");
-               privacy_set_error(_("Couldn't create temporary file."));
+               privacy_set_error(_("Couldn't create temporary file, %s"), g_strerror(errno));
                return FALSE;
        }
        procmime_write_mimeinfo(msgcontent, fp);
        rewind(fp);
 
        /* read temporary file into memory */
-       textstr = fp_read_noconv(fp);
+       textstr = file_read_stream_to_str_no_recode(fp);
        
-       fclose(fp);
+       claws_fclose(fp);
                
        gpgme_data_new_from_mem(&gpgtext, textstr, (size_t)strlen(textstr), 0);
        gpgme_data_new(&gpgsig);
        if ((err = gpgme_new(&ctx)) != GPG_ERR_NO_ERROR) {
-               debug_print(("Couldn't initialize GPG context, %s"), gpgme_strerror(err));
+               debug_print(("Couldn't initialize GPG context, %s\n"), gpgme_strerror(err));
                privacy_set_error(_("Couldn't initialize GPG context, %s"), gpgme_strerror(err));
                return FALSE;
        }
@@ -585,7 +586,7 @@ static gboolean pgpinline_sign(MimeInfo *mimeinfo, PrefsAccount *account, const
        }
 
        tmp = g_malloc(len+1);
-       g_memmove(tmp, sigcontent, len+1);
+       memmove(tmp, sigcontent, len+1);
        tmp[len] = '\0';
        gpgme_data_release(gpgtext);
        g_free(textstr);
@@ -653,7 +654,7 @@ static gboolean pgpinline_encrypt(MimeInfo *mimeinfo, const gchar *encrypt_data)
        kset = g_malloc(sizeof(gpgme_key_t)*(i+1));
        memset(kset, 0, sizeof(gpgme_key_t)*(i+1));
        if ((err = gpgme_new(&ctx)) != GPG_ERR_NO_ERROR) {
-               debug_print(("Couldn't initialize GPG context, %s"), gpgme_strerror(err));
+               debug_print(("Couldn't initialize GPG context, %s\n"), gpgme_strerror(err));
                privacy_set_error(_("Couldn't initialize GPG context, %s"), gpgme_strerror(err));
                g_free(kset);
                return FALSE;
@@ -701,15 +702,15 @@ static gboolean pgpinline_encrypt(MimeInfo *mimeinfo, const gchar *encrypt_data)
        rewind(fp);
 
        /* 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, (size_t)strlen(textstr), 0);
        gpgme_data_new(&gpgenc);
        if ((err = gpgme_new(&ctx)) != GPG_ERR_NO_ERROR) {
-               debug_print(("Couldn't initialize GPG context, %s"), gpgme_strerror(err));
+               debug_print(("Couldn't initialize GPG context, %s\n"), gpgme_strerror(err));
                privacy_set_error(_("Couldn't initialize GPG context, %s"), gpgme_strerror(err));
                g_free(kset);
                return FALSE;
@@ -732,7 +733,7 @@ static gboolean pgpinline_encrypt(MimeInfo *mimeinfo, const gchar *encrypt_data)
        }
 
        tmp = g_malloc(len+1);
-       g_memmove(tmp, enccontent, len+1);
+       memmove(tmp, enccontent, len+1);
        tmp[len] = '\0';
        g_free(enccontent);