implement RFE 3239, 'Remove "Content-Disposition: attachment" from PGP/MIME signed...
[claws.git] / src / plugins / pgpmime / pgpmime.c
index a54e527ba46546460dd0c67f13999f9de4d93c91..b9a3d7dfef5ebda13768ee662e833214da36d350 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2012 the Claws Mail team
+ * Copyright (C) 1999-2014 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
@@ -128,9 +128,10 @@ static gboolean pgpmime_is_signed(MimeInfo *mimeinfo)
                data = pgpmime_new_privacydata();
                mimeinfo->privacy = (PrivacyData *) data;
        }
-       
-       data->done_sigtest = TRUE;
-       data->is_signed = TRUE;
+       if (data != NULL) {
+               data->done_sigtest = TRUE;
+               data->is_signed = TRUE;
+       }
 
        return TRUE;
 }
@@ -241,10 +242,6 @@ static SignatureStatus pgpmime_get_sig_status(MimeInfo *mimeinfo)
        
        cm_return_val_if_fail(data != NULL, SIGNATURE_INVALID);
 
-       if (data->sigstatus == NULL && 
-           prefs_gpg_get_config()->auto_check_signatures)
-               pgpmime_check_signature(mimeinfo);
-       
        return sgpgme_sigstat_gpgme_to_privacy(data->ctx, data->sigstatus);
 }
 
@@ -254,23 +251,15 @@ static gchar *pgpmime_get_sig_info_short(MimeInfo *mimeinfo)
        
        cm_return_val_if_fail(data != NULL, g_strdup("Error"));
 
-       if (data->sigstatus == NULL && 
-           prefs_gpg_get_config()->auto_check_signatures)
-               pgpmime_check_signature(mimeinfo);
-       
        return sgpgme_sigstat_info_short(data->ctx, data->sigstatus);
 }
 
 static gchar *pgpmime_get_sig_info_full(MimeInfo *mimeinfo)
 {
        PrivacyDataPGP *data = (PrivacyDataPGP *) mimeinfo->privacy;
-       
+
        cm_return_val_if_fail(data != NULL, g_strdup("Error"));
 
-       if (data->sigstatus == NULL && 
-           prefs_gpg_get_config()->auto_check_signatures)
-               pgpmime_check_signature(mimeinfo);
-       
        return sgpgme_sigstat_info_full(data->ctx, data->sigstatus);
 }
 
@@ -433,12 +422,14 @@ static MimeInfo *pgpmime_decrypt(MimeInfo *mimeinfo)
                        data = pgpmime_new_privacydata();
                        decinfo->privacy = (PrivacyData *) data;        
                }
-               data->done_sigtest = TRUE;
-               data->is_signed = TRUE;
-               data->sigstatus = sigstat;
-               if (data->ctx)
-                       gpgme_release(data->ctx);
-               data->ctx = ctx;
+               if (data != NULL) {
+                       data->done_sigtest = TRUE;
+                       data->is_signed = TRUE;
+                       data->sigstatus = sigstat;
+                       if (data->ctx)
+                               gpgme_release(data->ctx);
+                       data->ctx = ctx;
+               }
        } else
                gpgme_release(ctx);
 
@@ -553,8 +544,8 @@ 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", gpgme_hash_algo_name(
-                               result->signatures->hash_algo));
+                       micalg = g_strdup_printf("pgp-%s", g_ascii_strdown(gpgme_hash_algo_name(
+                               result->signatures->hash_algo),-1));
                } else {
                        micalg = g_strdup(gpgme_hash_algo_name(
                                result->signatures->hash_algo));
@@ -590,6 +581,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;
        }
 
@@ -600,12 +592,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';
@@ -728,6 +716,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;
        }
 
@@ -781,6 +770,7 @@ static PrivacySystem pgpmime_system = {
        pgpmime_encrypt,
        pgpmime_get_encrypt_warning,
        pgpmime_inhibit_encrypt_warning,
+       prefs_gpg_auto_check_signatures,
 };
 
 void pgpmime_init()