2009-06-18 [colin] 3.7.1cvs76
[claws.git] / src / plugins / pgpmime / pgpmime.c
index f59fc6f0fa3ebadd6e4f799b087a53a3879bb246..84ba17d10175efdf4179981e17a1930d5251e2ab 100644 (file)
@@ -1,10 +1,10 @@
 /*
- * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2003 Hiroyuki Yamamoto & the Sylpheed-Claws team
+ * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2009 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
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation; either version 3 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
@@ -13,8 +13,8 @@
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * 
  */
 
 #ifdef HAVE_CONFIG_H
 
 #include "defs.h"
 #include <glib.h>
+#include <glib/gi18n.h>
 #include <gpgme.h>
 #include <ctype.h>
+#include <errno.h>
 
 #include "utils.h"
 #include "privacy.h"
 #include "procmime.h"
+#include "plugin.h"
 
 #include "pgpmime.h"
 #include <plugins/pgpcore/sgpgme.h>
@@ -49,7 +52,6 @@ struct _PrivacyDataPGP
        gboolean        is_signed;
        gpgme_verify_result_t   sigstatus;
        gpgme_ctx_t     ctx;
-       gboolean        is_pkcs7;
 };
 
 static PrivacySystem pgpmime_system;
@@ -59,13 +61,17 @@ static gint pgpmime_check_signature(MimeInfo *mimeinfo);
 static PrivacyDataPGP *pgpmime_new_privacydata()
 {
        PrivacyDataPGP *data;
+       gpgme_error_t err;
 
        data = g_new0(PrivacyDataPGP, 1);
        data->data.system = &pgpmime_system;
        data->done_sigtest = FALSE;
        data->is_signed = FALSE;
        data->sigstatus = NULL;
-       gpgme_new(&data->ctx);
+       if ((err = gpgme_new(&data->ctx)) != GPG_ERR_NO_ERROR) {
+               g_warning(_("Couldn't initialize GPG context, %s"), gpgme_strerror(err));
+               return NULL;
+       }
        
        return data;
 }
@@ -84,7 +90,7 @@ static gboolean pgpmime_is_signed(MimeInfo *mimeinfo)
        const gchar *protocol;
        PrivacyDataPGP *data = NULL;
        
-       g_return_val_if_fail(mimeinfo != NULL, FALSE);
+       cm_return_val_if_fail(mimeinfo != NULL, FALSE);
        if (mimeinfo->privacy != NULL) {
                data = (PrivacyDataPGP *) mimeinfo->privacy;
                if (data->done_sigtest)
@@ -100,9 +106,7 @@ static gboolean pgpmime_is_signed(MimeInfo *mimeinfo)
                return FALSE;
        protocol = procmime_mimeinfo_get_parameter(parent, "protocol");
        if ((protocol == NULL) || 
-           (g_ascii_strcasecmp(protocol, "application/pgp-signature") &&
-            g_ascii_strcasecmp(protocol, "application/pkcs7-signature") &&
-            g_ascii_strcasecmp(protocol, "application/x-pkcs7-signature")))
+           (g_ascii_strcasecmp(protocol, "application/pgp-signature")))
                return FALSE;
 
        /* check if mimeinfo is the first child */
@@ -115,9 +119,7 @@ static gboolean pgpmime_is_signed(MimeInfo *mimeinfo)
        if (signature == NULL)
                return FALSE;
        if ((signature->type != MIMETYPE_APPLICATION) ||
-           (g_ascii_strcasecmp(signature->subtype, "pgp-signature") &&
-            g_ascii_strcasecmp(signature->subtype, "pkcs7-signature") &&
-            g_ascii_strcasecmp(signature->subtype, "x-pkcs7-signature")))
+           (g_ascii_strcasecmp(signature->subtype, "pgp-signature")))
                return FALSE;
 
        if (data == NULL) {
@@ -125,12 +127,6 @@ static gboolean pgpmime_is_signed(MimeInfo *mimeinfo)
                mimeinfo->privacy = (PrivacyData *) data;
        }
        
-       if (!g_ascii_strcasecmp(signature->subtype, "pkcs7-signature") ||
-           !g_ascii_strcasecmp(signature->subtype, "x-pkcs7-signature"))
-               data->is_pkcs7 = TRUE;
-       else
-               data->is_pkcs7 = FALSE;
-
        data->done_sigtest = TRUE;
        data->is_signed = TRUE;
 
@@ -177,17 +173,19 @@ static gint pgpmime_check_signature(MimeInfo *mimeinfo)
        gchar *textstr;
        gpgme_data_t sigdata = NULL, textdata = NULL;
        gpgme_error_t err;
-       g_return_val_if_fail(mimeinfo != NULL, -1);
-       g_return_val_if_fail(mimeinfo->privacy != NULL, -1);
+       cm_return_val_if_fail(mimeinfo != NULL, -1);
+       cm_return_val_if_fail(mimeinfo->privacy != NULL, -1);
        data = (PrivacyDataPGP *) mimeinfo->privacy;
-       gpgme_new(&data->ctx);
+       if ((err = gpgme_new(&data->ctx)) != GPG_ERR_NO_ERROR) {
+               debug_print(("Couldn't initialize GPG context, %s"), gpgme_strerror(err));
+               privacy_set_error(_("Couldn't initialize GPG context, %s"), gpgme_strerror(err));
+               return 0;
+       }
+
        
-       debug_print("Checking %s/MIME signature\n", data->is_pkcs7?"S":"PGP");
+       debug_print("Checking PGP/MIME signature\n");
 
-       if (data->is_pkcs7) {
-               err = gpgme_set_protocol(data->ctx, GPGME_PROTOCOL_CMS);
-       } else
-               err = gpgme_set_protocol(data->ctx, GPGME_PROTOCOL_OpenPGP);
+       err = gpgme_set_protocol(data->ctx, GPGME_PROTOCOL_OpenPGP);
 
        if (err) {
                debug_print ("gpgme_set_protocol failed: %s\n",
@@ -196,19 +194,17 @@ static gint pgpmime_check_signature(MimeInfo *mimeinfo)
        parent = procmime_mimeinfo_parent(mimeinfo);
 
        fp = g_fopen(parent->data.filename, "rb");
-       if (fp == NULL) {
-               perror("my_tmpfile");
-               return 0;
-       }
-       g_return_val_if_fail(fp != NULL, SIGNATURE_INVALID);
+       cm_return_val_if_fail(fp != NULL, SIGNATURE_INVALID);
        
        boundary = g_hash_table_lookup(parent->typeparameters, "boundary");
-       if (!boundary)
+       if (!boundary) {
+               privacy_set_error(_("Signature boundary not found."));
+               fclose(fp);
                return 0;
-
+       }
        textstr = get_canonical_content(fp, boundary);
 
-       err = gpgme_data_new_from_mem(&textdata, textstr, strlen(textstr), 0);
+       err = gpgme_data_new_from_mem(&textdata, textstr, (size_t)strlen(textstr), 0);
        if (err) {
                debug_print ("gpgme_data_new_from_mem failed: %s\n",
                    gpgme_strerror (err));
@@ -241,7 +237,7 @@ static SignatureStatus pgpmime_get_sig_status(MimeInfo *mimeinfo)
 {
        PrivacyDataPGP *data = (PrivacyDataPGP *) mimeinfo->privacy;
        
-       g_return_val_if_fail(data != NULL, SIGNATURE_INVALID);
+       cm_return_val_if_fail(data != NULL, SIGNATURE_INVALID);
 
        if (data->sigstatus == NULL && 
            prefs_gpg_get_config()->auto_check_signatures)
@@ -254,7 +250,7 @@ static gchar *pgpmime_get_sig_info_short(MimeInfo *mimeinfo)
 {
        PrivacyDataPGP *data = (PrivacyDataPGP *) mimeinfo->privacy;
        
-       g_return_val_if_fail(data != NULL, g_strdup("Error"));
+       cm_return_val_if_fail(data != NULL, g_strdup("Error"));
 
        if (data->sigstatus == NULL && 
            prefs_gpg_get_config()->auto_check_signatures)
@@ -267,7 +263,7 @@ static gchar *pgpmime_get_sig_info_full(MimeInfo *mimeinfo)
 {
        PrivacyDataPGP *data = (PrivacyDataPGP *) mimeinfo->privacy;
        
-       g_return_val_if_fail(data != NULL, g_strdup("Error"));
+       cm_return_val_if_fail(data != NULL, g_strdup("Error"));
 
        if (data->sigstatus == NULL && 
            prefs_gpg_get_config()->auto_check_signatures)
@@ -318,12 +314,15 @@ static MimeInfo *pgpmime_decrypt(MimeInfo *mimeinfo)
        gpgme_ctx_t ctx;
        gchar *chars;
        size_t len;
+       gpgme_error_t err;
 
-       if (gpgme_new(&ctx) != GPG_ERR_NO_ERROR)
+       if ((err = gpgme_new(&ctx)) != GPG_ERR_NO_ERROR) {
+               debug_print(("Couldn't initialize GPG context, %s"), gpgme_strerror(err));
+               privacy_set_error(_("Couldn't initialize GPG context, %s"), gpgme_strerror(err));
                return NULL;
-
+       }
        
-       g_return_val_if_fail(pgpmime_is_encrypted(mimeinfo), NULL);
+       cm_return_val_if_fail(pgpmime_is_encrypted(mimeinfo), NULL);
        
        encinfo = (MimeInfo *) g_node_nth_child(mimeinfo->node, 1)->data;
 
@@ -342,6 +341,7 @@ static MimeInfo *pgpmime_decrypt(MimeInfo *mimeinfo)
 
        if ((dstfp = g_fopen(fname, "wb")) == NULL) {
                FILE_OP_ERROR(fname, "fopen");
+               privacy_set_error(_("Couldn't open decrypted file %s"), fname);
                g_free(fname);
                gpgme_data_release(plain);
                gpgme_release(ctx);
@@ -349,22 +349,51 @@ static MimeInfo *pgpmime_decrypt(MimeInfo *mimeinfo)
                return NULL;
        }
 
-       fprintf(dstfp, "MIME-Version: 1.0\n");
+       if (fprintf(dstfp, "MIME-Version: 1.0\n") < 0) {
+               FILE_OP_ERROR(fname, "fprintf");
+               fclose(dstfp);
+               privacy_set_error(_("Couldn't write to decrypted file %s"), fname);
+               g_free(fname);
+               gpgme_data_release(plain);
+               gpgme_release(ctx);
+               debug_print("can't open!\n");
+               return NULL;
+       }
 
-       chars = gpgme_data_release_and_get_mem(plain, &len);
-       if (len > 0)
-               fwrite(chars, len, 1, dstfp);
-       fclose(dstfp);
+       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);
+                       privacy_set_error(_("Couldn't write to decrypted file %s"), fname);
+                       g_free(fname);
+                       gpgme_data_release(plain);
+                       gpgme_release(ctx);
+                       debug_print("can't open!\n");
+                       return NULL;
+               }
+       }
+       if (fclose(dstfp) == EOF) {
+               FILE_OP_ERROR(fname, "fclose");
+               privacy_set_error(_("Couldn't close decrypted file %s"), fname);
+               g_free(fname);
+               gpgme_data_release(plain);
+               gpgme_release(ctx);
+               debug_print("can't open!\n");
+               return NULL;
+       }
 
        parseinfo = procmime_scan_file(fname);
        g_free(fname);
        if (parseinfo == NULL) {
                gpgme_release(ctx);
+               privacy_set_error(_("Couldn't parse decrypted file."));
                return NULL;
        }
        decinfo = g_node_first_child(parseinfo->node) != NULL ?
                g_node_first_child(parseinfo->node)->data : NULL;
        if (decinfo == NULL) {
+               privacy_set_error(_("Couldn't parse decrypted file parts."));
                gpgme_release(ctx);
                return NULL;
        }
@@ -393,7 +422,7 @@ static MimeInfo *pgpmime_decrypt(MimeInfo *mimeinfo)
        return decinfo;
 }
 
-gboolean pgpmime_sign(MimeInfo *mimeinfo, PrefsAccount *account)
+gboolean pgpmime_sign(MimeInfo *mimeinfo, PrefsAccount *account, const gchar *from_addr)
 {
        MimeInfo *msgcontent, *sigmultipart, *newinfo;
        gchar *textstr, *micalg;
@@ -402,6 +431,7 @@ gboolean pgpmime_sign(MimeInfo *mimeinfo, PrefsAccount *account)
        gchar *sigcontent;
        gpgme_ctx_t ctx;
        gpgme_data_t gpgtext, gpgsig;
+       gpgme_error_t err;
        size_t len;
        struct passphrase_cb_info_s info;
        gpgme_sign_result_t result = NULL;
@@ -409,7 +439,7 @@ gboolean pgpmime_sign(MimeInfo *mimeinfo, PrefsAccount *account)
        
        fp = my_tmpfile();
        if (fp == NULL) {
-               perror("my_tmpfile");
+               privacy_set_error(_("Couldn't create temporary file: %s"), strerror(errno));
                return FALSE;
        }
        procmime_write_mimeinfo(mimeinfo, fp);
@@ -431,8 +461,7 @@ gboolean pgpmime_sign(MimeInfo *mimeinfo, PrefsAccount *account)
        sigmultipart->subtype = g_strdup("signed");
        
        do {
-               if (boundary)
-                       g_free(boundary);
+               g_free(boundary);
                boundary = generate_mime_boundary("Sig");
        } while (strstr(test_msg, boundary) != NULL);
        
@@ -449,6 +478,7 @@ gboolean pgpmime_sign(MimeInfo *mimeinfo, PrefsAccount *account)
        fp = my_tmpfile();
        if (fp == NULL) {
                perror("my_tmpfile");
+               privacy_set_error(_("Couldn't create temporary file: %s"), strerror(errno));
                return FALSE;
        }
        procmime_write_mimeinfo(sigmultipart, fp);
@@ -459,46 +489,86 @@ gboolean pgpmime_sign(MimeInfo *mimeinfo, PrefsAccount *account)
 
        fclose(fp);
 
-       gpgme_data_new_from_mem(&gpgtext, textstr, strlen(textstr), 0);
+       gpgme_data_new_from_mem(&gpgtext, textstr, (size_t)strlen(textstr), 0);
        gpgme_data_new(&gpgsig);
-       gpgme_new(&ctx);
+       if ((err = gpgme_new(&ctx)) != GPG_ERR_NO_ERROR) {
+               debug_print(("Couldn't initialize GPG context, %s"), gpgme_strerror(err));
+               privacy_set_error(_("Couldn't initialize GPG context, %s"), gpgme_strerror(err));
+               return FALSE;
+       }
        gpgme_set_textmode(ctx, 1);
        gpgme_set_armor(ctx, 1);
        gpgme_signers_clear (ctx);
 
-       if (!sgpgme_setup_signers(ctx, account)) {
+       if (!sgpgme_setup_signers(ctx, account, from_addr)) {
                gpgme_release(ctx);
                return FALSE;
        }
 
-       if (!getenv("GPG_AGENT_INFO")) {
-               info.c = ctx;
+       prefs_gpg_enable_agent(prefs_gpg_get_config()->use_gpg_agent);
+       if (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;
                gpgme_set_passphrase_cb (ctx, gpgmegtk_passphrase_cb, &info);
        }
 
-       if (gpgme_op_sign(ctx, gpgtext, gpgsig, GPGME_SIG_MODE_DETACH) != GPG_ERR_NO_ERROR) {
+       err = gpgme_op_sign(ctx, gpgtext, gpgsig, GPGME_SIG_MODE_DETACH);
+       if (err != GPG_ERR_NO_ERROR) {
+               if (err == GPG_ERR_CANCELED) {
+                       /* ignore cancelled signing */
+                       privacy_reset_error();
+                       debug_print("gpgme_op_sign cancelled\n");
+               } else {
+                       privacy_set_error(_("Data signing failed, %s"), gpgme_strerror(err));
+                       debug_print("gpgme_op_sign error : %x\n", err);
+               }
                gpgme_release(ctx);
                return FALSE;
        }
        result = gpgme_op_sign_result(ctx);
        if (result && result->signatures) {
-           if (gpgme_get_protocol(ctx) == GPGME_PROTOCOL_OpenPGP) {
-               micalg = g_strdup_printf("PGP-%s", gpgme_hash_algo_name(
-                           result->signatures->hash_algo));
-           } else {
-               micalg = g_strdup(gpgme_hash_algo_name(
-                           result->signatures->hash_algo));
-           }
+               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));
+               } else {
+                       micalg = g_strdup(gpgme_hash_algo_name(
+                               result->signatures->hash_algo));
+               }
+               while (sig) {
+                       debug_print("valid signature: %s\n", sig->fpr);
+                       sig = sig->next;
+               }
+       } else if (result && result->invalid_signers) {
+               gpgme_invalid_key_t invalid = result->invalid_signers;
+               while (invalid) {
+                       g_warning("invalid signer: %s (%s)", invalid->fpr, 
+                               gpgme_strerror(invalid->reason));
+                       privacy_set_error(_("Data signing failed due to invalid signer: %s"), 
+                               gpgme_strerror(invalid->reason));
+                       invalid = invalid->next;
+               }
+               gpgme_release(ctx);
+               return FALSE;
        } else {
-           /* can't get result (maybe no signing key?) */
-           return FALSE;
+               /* can't get result (maybe no signing key?) */
+               debug_print("gpgme_op_sign_result error\n");
+               privacy_set_error(_("Data signing failed, no results."));
+               gpgme_release(ctx);
+               return FALSE;
        }
 
-       gpgme_release(ctx);
-       sigcontent = gpgme_data_release_and_get_mem(gpgsig, &len);
+       sigcontent = sgpgme_data_release_and_get_mem(gpgsig, &len);
        gpgme_data_release(gpgtext);
        g_free(textstr);
 
+       if (sigcontent == NULL || len <= 0) {
+               g_warning("sgpgme_data_release_and_get_mem failed");
+               privacy_set_error(_("Data signing failed, no contents."));
+               return FALSE;
+       }
+
        /* add signature */
        g_hash_table_insert(sigmultipart->typeparameters, g_strdup("micalg"),
                             micalg);
@@ -506,19 +576,42 @@ gboolean pgpmime_sign(MimeInfo *mimeinfo, PrefsAccount *account)
        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->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';
        g_node_append(sigmultipart->node, newinfo->node);
 
        g_free(sigcontent);
+       gpgme_release(ctx);
 
        return TRUE;
 }
 gchar *pgpmime_get_encrypt_data(GSList *recp_names)
 {
-       return sgpgme_get_encrypt_data(recp_names);
+       return sgpgme_get_encrypt_data(recp_names, GPGME_PROTOCOL_OpenPGP);
+}
+
+static const gchar *pgpmime_get_encrypt_warning(void)
+{
+       if (prefs_gpg_should_skip_encryption_warning(pgpmime_system.id))
+               return NULL;
+       else
+               return _("Please note that email headers, like Subject, "
+                        "are not encrypted by the PGP/Mime system.");
+}
+
+static void pgpmime_inhibit_encrypt_warning(gboolean inhibit)
+{
+       if (inhibit)
+               prefs_gpg_add_skip_encryption_warning(pgpmime_system.id);
+       else
+               prefs_gpg_remove_skip_encryption_warning(pgpmime_system.id);
 }
 
 gboolean pgpmime_encrypt(MimeInfo *mimeinfo, const gchar *encrypt_data)
@@ -533,21 +626,27 @@ gboolean pgpmime_encrypt(MimeInfo *mimeinfo, const gchar *encrypt_data)
        gpgme_key_t *kset = NULL;
        gchar **fprs = g_strsplit(encrypt_data, " ", -1);
        gint i = 0;
+       gpgme_error_t err;
+       
        while (fprs[i] && strlen(fprs[i])) {
                i++;
        }
        
        kset = g_malloc(sizeof(gpgme_key_t)*(i+1));
        memset(kset, 0, sizeof(gpgme_key_t)*(i+1));
-       gpgme_new(&ctx);
+       if ((err = gpgme_new(&ctx)) != GPG_ERR_NO_ERROR) {
+               debug_print(("Couldn't initialize GPG context, %s"), gpgme_strerror(err));
+               privacy_set_error(_("Couldn't initialize GPG context, %s"), gpgme_strerror(err));
+               return FALSE;
+       }
        i = 0;
        while (fprs[i] && strlen(fprs[i])) {
                gpgme_key_t key;
-               gpgme_error_t err;
                err = gpgme_get_key(ctx, fprs[i], &key, 0);
                if (err) {
                        debug_print("can't add key '%s'[%d] (%s)\n", fprs[i],i, gpgme_strerror(err));
-                       break;
+                       privacy_set_error(_("Couldn't add GPG key %s, %s"), fprs[i], gpgme_strerror(err));
+                       return FALSE;
                }
                debug_print("found %s at %d\n", fprs[i], i);
                kset[i] = key;
@@ -574,7 +673,7 @@ gboolean pgpmime_encrypt(MimeInfo *mimeinfo, const gchar *encrypt_data)
        /* write message content to temporary file */
        fp = my_tmpfile();
        if (fp == NULL) {
-               perror("my_tmpfile");
+               privacy_set_error(_("Couldn't create temporary file, %s"), strerror(errno));
                return FALSE;
        }
        procmime_write_mimeinfo(encmultipart, fp);
@@ -586,18 +685,24 @@ gboolean pgpmime_encrypt(MimeInfo *mimeinfo, const gchar *encrypt_data)
        fclose(fp);
 
        /* encrypt data */
-       gpgme_data_new_from_mem(&gpgtext, textstr, strlen(textstr), 0);
+       gpgme_data_new_from_mem(&gpgtext, textstr, (size_t)strlen(textstr), 0);
        gpgme_data_new(&gpgenc);
        gpgme_set_armor(ctx, 1);
-       gpgme_data_rewind(gpgtext);
+       cm_gpgme_data_rewind(gpgtext);
        
-       gpgme_op_encrypt(ctx, kset, GPGME_ENCRYPT_ALWAYS_TRUST, gpgtext, gpgenc);
+       err = gpgme_op_encrypt(ctx, kset, GPGME_ENCRYPT_ALWAYS_TRUST, gpgtext, gpgenc);
 
-       gpgme_release(ctx);
-       enccontent = gpgme_data_release_and_get_mem(gpgenc, &len);
+       enccontent = sgpgme_data_release_and_get_mem(gpgenc, &len);
        gpgme_data_release(gpgtext);
        g_free(textstr);
 
+       if (enccontent == NULL || len <= 0) {
+               g_warning("sgpgme_data_release_and_get_mem failed");
+               privacy_set_error(_("Encryption failed, %s"), gpgme_strerror(err));
+               gpgme_release(ctx);
+               return FALSE;
+       }
+
        /* create encrypted multipart */
        g_node_unlink(msgcontent->node);
        procmime_mimeinfo_free_all(msgcontent);
@@ -620,6 +725,7 @@ gboolean pgpmime_encrypt(MimeInfo *mimeinfo, const gchar *encrypt_data)
        g_node_append(encmultipart->node, newinfo->node);
 
        g_free(enccontent);
+       gpgme_release(ctx);
 
        return TRUE;
 }
@@ -645,6 +751,8 @@ static PrivacySystem pgpmime_system = {
        TRUE,
        pgpmime_get_encrypt_data,
        pgpmime_encrypt,
+       pgpmime_get_encrypt_warning,
+       pgpmime_inhibit_encrypt_warning,
 };
 
 void pgpmime_init()
@@ -657,4 +765,11 @@ void pgpmime_done()
        privacy_unregister_system(&pgpmime_system);
 }
 
+struct PluginFeature *plugin_provides(void)
+{
+       static struct PluginFeature features[] = 
+               { {PLUGIN_PRIVACY, N_("PGP/Mime")},
+                 {PLUGIN_NOTHING, NULL}};
+       return features;
+}
 #endif /* USE_GPGME */