2005-12-02 [paul] 1.9.100cvs55
[claws.git] / src / plugins / pgpmime / pgpmime.c
index b45b0e02718c391b529153a1e8f1dd2e672f133c..2784e53bccd4a59788aab7e384915ff4c4b3e0b2 100644 (file)
@@ -14,7 +14,7 @@
  *
  * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
 #ifdef HAVE_CONFIG_H
 #include "defs.h"
 #include <glib.h>
 #include <gpgme.h>
+#include <ctype.h>
 
 #include "utils.h"
 #include "privacy.h"
 #include "procmime.h"
+
 #include "pgpmime.h"
-#include "sgpgme.h"
+#include <plugins/pgpcore/sgpgme.h>
+#include <plugins/pgpcore/prefs_gpg.h>
+#include <plugins/pgpcore/passphrase.h>
+
 #include "prefs_common.h"
 
 typedef struct _PrivacyDataPGP PrivacyDataPGP;
@@ -42,8 +47,9 @@ struct _PrivacyDataPGP
        
        gboolean        done_sigtest;
        gboolean        is_signed;
-       GpgmeSigStat    sigstatus;
-       GpgmeCtx        ctx;
+       gpgme_verify_result_t   sigstatus;
+       gpgme_ctx_t     ctx;
+       gboolean        is_pkcs7;
 };
 
 static PrivacySystem pgpmime_system;
@@ -58,7 +64,7 @@ static PrivacyDataPGP *pgpmime_new_privacydata()
        data->data.system = &pgpmime_system;
        data->done_sigtest = FALSE;
        data->is_signed = FALSE;
-       data->sigstatus = GPGME_SIG_STAT_NONE;
+       data->sigstatus = NULL;
        gpgme_new(&data->ctx);
        
        return data;
@@ -67,7 +73,7 @@ static PrivacyDataPGP *pgpmime_new_privacydata()
 static void pgpmime_free_privacydata(PrivacyData *_data)
 {
        PrivacyDataPGP *data = (PrivacyDataPGP *) _data;
-       
+       gpgme_release(data->ctx);
        g_free(data);
 }
 
@@ -90,10 +96,13 @@ static gboolean pgpmime_is_signed(MimeInfo *mimeinfo)
        if (parent == NULL)
                return FALSE;
        if ((parent->type != MIMETYPE_MULTIPART) ||
-           g_strcasecmp(parent->subtype, "signed"))
+           g_ascii_strcasecmp(parent->subtype, "signed"))
                return FALSE;
        protocol = procmime_mimeinfo_get_parameter(parent, "protocol");
-       if ((protocol == NULL) || g_strcasecmp(protocol, "application/pgp-signature"))
+       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")))
                return FALSE;
 
        /* check if mimeinfo is the first child */
@@ -106,75 +115,119 @@ static gboolean pgpmime_is_signed(MimeInfo *mimeinfo)
        if (signature == NULL)
                return FALSE;
        if ((signature->type != MIMETYPE_APPLICATION) ||
-           g_strcasecmp(signature->subtype, "pgp-signature"))
+           (g_ascii_strcasecmp(signature->subtype, "pgp-signature") &&
+            g_ascii_strcasecmp(signature->subtype, "pkcs7-signature") &&
+            g_ascii_strcasecmp(signature->subtype, "x-pkcs7-signature")))
                return FALSE;
 
        if (data == NULL) {
                data = pgpmime_new_privacydata();
                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;
 
-       if (prefs_common.auto_check_signatures)
-               pgpmime_check_signature(mimeinfo);
-       
        return TRUE;
 }
 
+static gchar *get_canonical_content(FILE *fp, const gchar *boundary)
+{
+       gchar *ret;
+       GString *textbuffer;
+       guint boundary_len;
+       gchar buf[BUFFSIZE];
+
+       boundary_len = strlen(boundary);
+       while (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) {
+               gchar *buf2;
+
+               if (IS_BOUNDARY(buf, boundary, boundary_len))
+                       break;
+               
+               buf2 = canonicalize_str(buf);
+               g_string_append(textbuffer, buf2);
+               g_free(buf2);
+       }
+       g_string_truncate(textbuffer, textbuffer->len - 2);
+               
+       ret = textbuffer->str;
+       g_string_free(textbuffer, FALSE);
+
+       return ret;
+}
+
 static gint pgpmime_check_signature(MimeInfo *mimeinfo)
 {
        PrivacyDataPGP *data;
        MimeInfo *parent, *signature;
        FILE *fp;
-       gchar buf[BUFFSIZE];
        gchar *boundary;
-       GString *textstr;
-       gint boundary_len;
-       GpgmeData sigdata, textdata;
-       
+       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);
        data = (PrivacyDataPGP *) mimeinfo->privacy;
+       gpgme_new(&data->ctx);
        
-       debug_print("Checking PGP/MIME signature\n");
+       debug_print("Checking %s/MIME signature\n", data->is_pkcs7?"S":"PGP");
+
+       if (data->is_pkcs7) {
+               err = gpgme_set_protocol(data->ctx, GPGME_PROTOCOL_CMS);
+       } else
+               err = gpgme_set_protocol(data->ctx, GPGME_PROTOCOL_OpenPGP);
+
+       if (err) {
+               debug_print ("gpgme_set_protocol failed: %s\n",
+                   gpgme_strerror (err));
+       }
        parent = procmime_mimeinfo_parent(mimeinfo);
 
-       fp = fopen(parent->filename, "rb");
+       fp = g_fopen(parent->data.filename, "rb");
        g_return_val_if_fail(fp != NULL, SIGNATURE_INVALID);
        
-       boundary = g_hash_table_lookup(parent->parameters, "boundary");
+       boundary = g_hash_table_lookup(parent->typeparameters, "boundary");
        if (!boundary)
                return 0;
 
-       boundary_len = strlen(boundary);
-       while (fgets(buf, sizeof(buf), fp) != NULL)
-               if (IS_BOUNDARY(buf, boundary, boundary_len))
-                       break;
-
-       textstr = g_string_new("");
-       while (fgets(buf, sizeof(buf), fp) != NULL) {
-               gchar *buf2;
+       textstr = get_canonical_content(fp, boundary);
 
-               if (IS_BOUNDARY(buf, boundary, boundary_len))
-                       break;
-               
-               buf2 = canonicalize_str(buf);
-               g_string_append(textstr, buf2);
-               g_free(buf2);
+       err = gpgme_data_new_from_mem(&textdata, textstr, strlen(textstr), 0);
+       if (err) {
+               debug_print ("gpgme_data_new_from_mem failed: %s\n",
+                   gpgme_strerror (err));
        }
-       g_string_truncate(textstr, textstr->len - 2);
-               
-       gpgme_data_new_from_mem(&textdata, textstr->str, textstr->len, 0);
        signature = (MimeInfo *) mimeinfo->node->next->data;
        sigdata = sgpgme_data_from_mimeinfo(signature);
 
-       data->sigstatus =
-               sgpgme_verify_signature (data->ctx, sigdata, textdata);
+       err = 0;
+       if (signature->encoding_type == ENC_BASE64) {
+               err = gpgme_data_set_encoding (sigdata, GPGME_DATA_ENCODING_BASE64);
+       }
        
+       if (err) {
+               debug_print ("gpgme_data_set_encoding failed: %s\n",
+                       gpgme_strerror (err));
+       }
+
+       data->sigstatus =
+               sgpgme_verify_signature (data->ctx, sigdata, textdata, NULL);
+
        gpgme_data_release(sigdata);
        gpgme_data_release(textdata);
-       g_string_free(textstr, TRUE);
+       g_free(textstr);
        fclose(fp);
        
        return 0;
@@ -186,6 +239,10 @@ static SignatureStatus pgpmime_get_sig_status(MimeInfo *mimeinfo)
        
        g_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);
 }
 
@@ -195,6 +252,10 @@ static gchar *pgpmime_get_sig_info_short(MimeInfo *mimeinfo)
        
        g_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);
 }
 
@@ -204,6 +265,10 @@ static gchar *pgpmime_get_sig_info_full(MimeInfo *mimeinfo)
        
        g_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);
 }
 
@@ -214,10 +279,10 @@ static gboolean pgpmime_is_encrypted(MimeInfo *mimeinfo)
        
        if (mimeinfo->type != MIMETYPE_MULTIPART)
                return FALSE;
-       if (g_strcasecmp(mimeinfo->subtype, "encrypted"))
+       if (g_ascii_strcasecmp(mimeinfo->subtype, "encrypted"))
                return FALSE;
        tmpstr = procmime_mimeinfo_get_parameter(mimeinfo, "protocol");
-       if ((tmpstr == NULL) || g_strcasecmp(tmpstr, "application/pgp-encrypted"))
+       if ((tmpstr == NULL) || g_ascii_strcasecmp(tmpstr, "application/pgp-encrypted"))
                return FALSE;
        if (g_node_n_children(mimeinfo->node) != 2)
                return FALSE;
@@ -225,13 +290,13 @@ static gboolean pgpmime_is_encrypted(MimeInfo *mimeinfo)
        tmpinfo = (MimeInfo *) g_node_nth_child(mimeinfo->node, 0)->data;
        if (tmpinfo->type != MIMETYPE_APPLICATION)
                return FALSE;
-       if (g_strcasecmp(tmpinfo->subtype, "pgp-encrypted"))
+       if (g_ascii_strcasecmp(tmpinfo->subtype, "pgp-encrypted"))
                return FALSE;
        
        tmpinfo = (MimeInfo *) g_node_nth_child(mimeinfo->node, 1)->data;
        if (tmpinfo->type != MIMETYPE_APPLICATION)
                return FALSE;
-       if (g_strcasecmp(tmpinfo->subtype, "octet-stream"))
+       if (g_ascii_strcasecmp(tmpinfo->subtype, "octet-stream"))
                return FALSE;
        
        return TRUE;
@@ -240,17 +305,17 @@ static gboolean pgpmime_is_encrypted(MimeInfo *mimeinfo)
 static MimeInfo *pgpmime_decrypt(MimeInfo *mimeinfo)
 {
        MimeInfo *encinfo, *decinfo, *parseinfo;
-       GpgmeData cipher, plain;
+       gpgme_data_t cipher = NULL, plain = NULL;
        static gint id = 0;
        FILE *dstfp;
-       gint nread;
        gchar *fname;
-       gchar buf[BUFFSIZE];
-       GpgmeSigStat sigstat = 0;
+       gpgme_verify_result_t sigstat = NULL;
        PrivacyDataPGP *data = NULL;
-       GpgmeCtx ctx;
-       
-       if (gpgme_new(&ctx) != GPGME_No_Error)
+       gpgme_ctx_t ctx;
+       gchar *chars;
+       size_t len;
+
+       if (gpgme_new(&ctx) != GPG_ERR_NO_ERROR)
                return NULL;
 
        
@@ -262,43 +327,50 @@ static MimeInfo *pgpmime_decrypt(MimeInfo *mimeinfo)
        plain = sgpgme_decrypt_verify(cipher, &sigstat, ctx);
 
        gpgme_data_release(cipher);
-       if (plain == NULL)
+       if (plain == NULL) {
+               debug_print("plain is null!\n");
+               gpgme_release(ctx);
                return NULL;
-       
+       }
+
        fname = g_strdup_printf("%s%cplaintext.%08x",
                get_mime_tmp_dir(), G_DIR_SEPARATOR, ++id);
 
-       if ((dstfp = fopen(fname, "wb")) == NULL) {
+       if ((dstfp = g_fopen(fname, "wb")) == NULL) {
                FILE_OP_ERROR(fname, "fopen");
                g_free(fname);
                gpgme_data_release(plain);
+               gpgme_release(ctx);
+               debug_print("can't open!\n");
                return NULL;
        }
 
        fprintf(dstfp, "MIME-Version: 1.0\n");
-       gpgme_data_rewind (plain);
-       while (gpgme_data_read(plain, buf, sizeof(buf), &nread) == GPGME_No_Error) {
-               fwrite (buf, nread, 1, dstfp);
-       }
+
+       chars = gpgme_data_release_and_get_mem(plain, &len);
+       if (len > 0)
+               fwrite(chars, len, 1, dstfp);
        fclose(dstfp);
-       
-       gpgme_data_release(plain);
 
        parseinfo = procmime_scan_file(fname);
        g_free(fname);
-       if (parseinfo == NULL)
+       if (parseinfo == NULL) {
+               gpgme_release(ctx);
                return NULL;
+       }
        decinfo = g_node_first_child(parseinfo->node) != NULL ?
                g_node_first_child(parseinfo->node)->data : NULL;
-       if (decinfo == NULL)
+       if (decinfo == NULL) {
+               gpgme_release(ctx);
                return NULL;
+       }
 
        g_node_unlink(decinfo->node);
        procmime_mimeinfo_free_all(parseinfo);
 
-       decinfo->tmpfile = TRUE;
+       decinfo->tmp = TRUE;
 
-       if (sigstat != GPGME_SIG_STAT_NONE) {
+       if (sigstat != NULL && sigstat->signatures != NULL) {
                if (decinfo->privacy != NULL) {
                        data = (PrivacyDataPGP *) decinfo->privacy;
                } else {
@@ -311,15 +383,251 @@ static MimeInfo *pgpmime_decrypt(MimeInfo *mimeinfo)
                if (data->ctx)
                        gpgme_release(data->ctx);
                data->ctx = ctx;
+       } else
+               gpgme_release(ctx);
+
+       return decinfo;
+}
+
+gboolean pgpmime_sign(MimeInfo *mimeinfo, PrefsAccount *account)
+{
+       MimeInfo *msgcontent, *sigmultipart, *newinfo;
+       gchar *textstr, *micalg;
+       FILE *fp;
+       gchar *boundary = NULL;
+       gchar *sigcontent;
+       gpgme_ctx_t ctx;
+       gpgme_data_t gpgtext, gpgsig;
+       size_t len;
+       struct passphrase_cb_info_s info;
+       gpgme_sign_result_t result = NULL;
+       gchar *test_msg;
+       
+       fp = my_tmpfile();
+       if (fp == NULL) {
+               perror("my_tmpfile");
+               return FALSE;
        }
+       procmime_write_mimeinfo(mimeinfo, fp);
+       rewind(fp);
 
+       /* read temporary file into memory */
+       test_msg = file_read_stream_to_str(fp);
+       fclose(fp);
        
-       return decinfo;
+       memset (&info, 0, sizeof info);
+
+       /* remove content node from message */
+       msgcontent = (MimeInfo *) mimeinfo->node->children->data;
+       g_node_unlink(msgcontent->node);
+
+       /* create temporary multipart for content */
+       sigmultipart = procmime_mimeinfo_new();
+       sigmultipart->type = MIMETYPE_MULTIPART;
+       sigmultipart->subtype = g_strdup("signed");
+       
+       do {
+               if (boundary)
+                       g_free(boundary);
+               boundary = generate_mime_boundary("Sig");
+       } while (strstr(test_msg, boundary) != NULL);
+       
+       g_free(test_msg);
+
+       g_hash_table_insert(sigmultipart->typeparameters, g_strdup("boundary"),
+                            g_strdup(boundary));
+       g_hash_table_insert(sigmultipart->typeparameters, g_strdup("protocol"),
+                            g_strdup("application/pgp-signature"));
+       g_node_append(sigmultipart->node, msgcontent->node);
+       g_node_append(mimeinfo->node, sigmultipart->node);
+
+       /* write message content to temporary file */
+       fp = my_tmpfile();
+       if (fp == NULL) {
+               perror("my_tmpfile");
+               return FALSE;
+       }
+       procmime_write_mimeinfo(sigmultipart, fp);
+       rewind(fp);
+
+       /* read temporary file into memory */
+       textstr = get_canonical_content(fp, boundary);
+
+       fclose(fp);
+
+       gpgme_data_new_from_mem(&gpgtext, textstr, strlen(textstr), 0);
+       gpgme_data_new(&gpgsig);
+       gpgme_new(&ctx);
+       gpgme_set_textmode(ctx, 1);
+       gpgme_set_armor(ctx, 1);
+       gpgme_signers_clear (ctx);
+
+       if (!sgpgme_setup_signers(ctx, account)) {
+               gpgme_release(ctx);
+               return FALSE;
+       }
+
+       if (!getenv("GPG_AGENT_INFO")) {
+               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) {
+               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));
+           }
+       } else {
+           /* can't get result (maybe no signing key?) */
+           return FALSE;
+       }
+
+       gpgme_release(ctx);
+       sigcontent = gpgme_data_release_and_get_mem(gpgsig, &len);
+       gpgme_data_release(gpgtext);
+       g_free(textstr);
+
+       /* add signature */
+       g_hash_table_insert(sigmultipart->typeparameters, g_strdup("micalg"),
+                            micalg);
+
+       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);
+
+       return TRUE;
+}
+gchar *pgpmime_get_encrypt_data(GSList *recp_names)
+{
+       return sgpgme_get_encrypt_data(recp_names);
+}
+
+gboolean pgpmime_encrypt(MimeInfo *mimeinfo, const gchar *encrypt_data)
+{
+       MimeInfo *msgcontent, *encmultipart, *newinfo;
+       FILE *fp;
+       gchar *boundary, *enccontent;
+       size_t len;
+       gchar *textstr;
+       gpgme_data_t gpgtext = NULL, gpgenc = NULL;
+       gpgme_ctx_t ctx = NULL;
+       gpgme_key_t *kset = NULL;
+       gchar **fprs = g_strsplit(encrypt_data, " ", -1);
+       gint i = 0;
+       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);
+       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;
+               }
+               debug_print("found %s at %d\n", fprs[i], i);
+               kset[i] = key;
+               i++;
+       }
+       
+       debug_print("Encrypting message content\n");
+
+       /* remove content node from message */
+       msgcontent = (MimeInfo *) mimeinfo->node->children->data;
+       g_node_unlink(msgcontent->node);
+
+       /* create temporary multipart for content */
+       encmultipart = procmime_mimeinfo_new();
+       encmultipart->type = MIMETYPE_MULTIPART;
+       encmultipart->subtype = g_strdup("encrypted");
+       boundary = generate_mime_boundary("Encrypt");
+       g_hash_table_insert(encmultipart->typeparameters, g_strdup("boundary"),
+                            g_strdup(boundary));
+       g_hash_table_insert(encmultipart->typeparameters, g_strdup("protocol"),
+                            g_strdup("application/pgp-encrypted"));
+       g_node_append(encmultipart->node, msgcontent->node);
+
+       /* write message content to temporary file */
+       fp = my_tmpfile();
+       if (fp == NULL) {
+               perror("my_tmpfile");
+               return FALSE;
+       }
+       procmime_write_mimeinfo(encmultipart, fp);
+       rewind(fp);
+
+       /* read temporary file into memory */
+       textstr = get_canonical_content(fp, boundary);
+
+       fclose(fp);
+
+       /* encrypt data */
+       gpgme_data_new_from_mem(&gpgtext, textstr, strlen(textstr), 0);
+       gpgme_data_new(&gpgenc);
+       gpgme_set_armor(ctx, 1);
+       gpgme_data_rewind(gpgtext);
+       
+       gpgme_op_encrypt(ctx, kset, GPGME_ENCRYPT_ALWAYS_TRUST, gpgtext, gpgenc);
+
+       gpgme_release(ctx);
+       enccontent = gpgme_data_release_and_get_mem(gpgenc, &len);
+       gpgme_data_release(gpgtext);
+       g_free(textstr);
+
+       /* create encrypted multipart */
+       g_node_unlink(msgcontent->node);
+       procmime_mimeinfo_free_all(msgcontent);
+       g_node_append(mimeinfo->node, encmultipart->node);
+
+       newinfo = procmime_mimeinfo_new();
+       newinfo->type = MIMETYPE_APPLICATION;
+       newinfo->subtype = g_strdup("pgp-encrypted");
+       newinfo->content = MIMECONTENT_MEM;
+       newinfo->data.mem = g_strdup("Version: 1\n");
+       g_node_append(encmultipart->node, newinfo->node);
+
+       newinfo = procmime_mimeinfo_new();
+       newinfo->type = MIMETYPE_APPLICATION;
+       newinfo->subtype = g_strdup("octet-stream");
+       newinfo->content = MIMECONTENT_MEM;
+       newinfo->data.mem = g_malloc(len + 1);
+       g_memmove(newinfo->data.mem, enccontent, len);
+       newinfo->data.mem[len] = '\0';
+       g_node_append(encmultipart->node, newinfo->node);
+
+       g_free(enccontent);
+
+       return TRUE;
 }
 
 static PrivacySystem pgpmime_system = {
        "pgpmime",                      /* id */
-       "PGP/Mime",                     /* name */
+       "PGP MIME",                     /* name */
 
        pgpmime_free_privacydata,       /* free_privacydata */
 
@@ -331,6 +639,13 @@ static PrivacySystem pgpmime_system = {
 
        pgpmime_is_encrypted,           /* is_encrypted(MimeInfo *) */
        pgpmime_decrypt,                /* decrypt(MimeInfo *) */
+
+       TRUE,
+       pgpmime_sign,
+
+       TRUE,
+       pgpmime_get_encrypt_data,
+       pgpmime_encrypt,
 };
 
 void pgpmime_init()