Cosmetic: use always g_getenv instead of getenv
[claws.git] / src / plugins / pgpmime / pgpmime.c
index d22a85af08f516fd1222119fb5f9e4aa2b0303c4..670dfdc89f4a50e52aff185dcb12aa05c8bc0b55 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2014 the Claws Mail team
+ * Copyright (C) 1999-2015 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
@@ -14,7 +14,6 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * 
  */
 
 #ifdef HAVE_CONFIG_H
@@ -71,7 +70,7 @@ static PrivacyDataPGP *pgpmime_new_privacydata()
        data->is_signed = FALSE;
        data->sigstatus = NULL;
        if ((err = gpgme_new(&data->ctx)) != GPG_ERR_NO_ERROR) {
-               g_warning(_("Couldn't initialize GPG context, %s"), gpgme_strerror(err));
+               g_warning("Couldn't initialize GPG context: %s", gpgme_strerror(err));
                return NULL;
        }
        
@@ -453,7 +452,7 @@ gboolean pgpmime_sign(MimeInfo *mimeinfo, PrefsAccount *account, const gchar *fr
        
        fp = my_tmpfile();
        if (fp == NULL) {
-               privacy_set_error(_("Couldn't create temporary file: %s"), strerror(errno));
+               privacy_set_error(_("Couldn't create temporary file: %s"), g_strerror(errno));
                return FALSE;
        }
        procmime_write_mimeinfo(mimeinfo, fp);
@@ -492,7 +491,7 @@ gboolean pgpmime_sign(MimeInfo *mimeinfo, PrefsAccount *account, const gchar *fr
        fp = my_tmpfile();
        if (fp == NULL) {
                perror("my_tmpfile");
-               privacy_set_error(_("Couldn't create temporary file: %s"), strerror(errno));
+               privacy_set_error(_("Couldn't create temporary file: %s"), g_strerror(errno));
                return FALSE;
        }
        procmime_write_mimeinfo(sigmultipart, fp);
@@ -520,7 +519,7 @@ gboolean pgpmime_sign(MimeInfo *mimeinfo, PrefsAccount *account, const gchar *fr
        }
 
        prefs_gpg_enable_agent(prefs_gpg_get_config()->use_gpg_agent);
-       if (getenv("GPG_AGENT_INFO") && prefs_gpg_get_config()->use_gpg_agent) {
+       if (g_getenv("GPG_AGENT_INFO") && prefs_gpg_get_config()->use_gpg_agent) {
                debug_print("GPG_AGENT_INFO environment defined, running without passphrase callback\n");
        } else {
                info.c = ctx;
@@ -544,8 +543,10 @@ gboolean pgpmime_sign(MimeInfo *mimeinfo, PrefsAccount *account, const gchar *fr
        if (result && result->signatures) {
                gpgme_new_signature_t sig = result->signatures;
                if (gpgme_get_protocol(ctx) == GPGME_PROTOCOL_OpenPGP) {
-                       micalg = g_strdup_printf("pgp-%s", g_ascii_strdown(gpgme_hash_algo_name(
-                               result->signatures->hash_algo),-1));
+                       gchar *down_algo = g_ascii_strdown(gpgme_hash_algo_name(
+                               result->signatures->hash_algo), -1);
+                       micalg = g_strdup_printf("pgp-%s", down_algo);
+                       g_free(down_algo);
                } else {
                        micalg = g_strdup(gpgme_hash_algo_name(
                                result->signatures->hash_algo));
@@ -581,6 +582,7 @@ gboolean pgpmime_sign(MimeInfo *mimeinfo, PrefsAccount *account, const gchar *fr
                g_warning("sgpgme_data_release_and_get_mem failed");
                privacy_set_error(_("Data signing failed, no contents."));
                g_free(micalg);
+               g_free(sigcontent);
                return FALSE;
        }
 
@@ -591,12 +593,8 @@ gboolean pgpmime_sign(MimeInfo *mimeinfo, PrefsAccount *account, const gchar *fr
        newinfo = procmime_mimeinfo_new();
        newinfo->type = MIMETYPE_APPLICATION;
        newinfo->subtype = g_strdup("pgp-signature");
-       g_hash_table_insert(newinfo->typeparameters, g_strdup("name"),
-                            g_strdup("signature.asc"));
+       newinfo->description = g_strdup(_("OpenPGP digital signature"));
        newinfo->content = MIMECONTENT_MEM;
-       newinfo->disposition = DISPOSITIONTYPE_ATTACHMENT;
-       g_hash_table_insert(newinfo->dispositionparameters, g_strdup("filename"),
-                           g_strdup("signature.asc"));
        newinfo->data.mem = g_malloc(len + 1);
        g_memmove(newinfo->data.mem, sigcontent, len);
        newinfo->data.mem[len] = '\0';
@@ -690,7 +688,7 @@ gboolean pgpmime_encrypt(MimeInfo *mimeinfo, const gchar *encrypt_data)
        /* write message content to temporary file */
        fp = my_tmpfile();
        if (fp == NULL) {
-               privacy_set_error(_("Couldn't create temporary file, %s"), strerror(errno));
+               privacy_set_error(_("Couldn't create temporary file, %s"), g_strerror(errno));
                g_free(kset);
                return FALSE;
        }
@@ -719,6 +717,7 @@ gboolean pgpmime_encrypt(MimeInfo *mimeinfo, const gchar *encrypt_data)
                g_warning("sgpgme_data_release_and_get_mem failed");
                privacy_set_error(_("Encryption failed, %s"), gpgme_strerror(err));
                gpgme_release(ctx);
+               g_free(enccontent);
                return FALSE;
        }