various clean-ups and optimisations by Olaf Hering
[claws.git] / src / plugins / pgpmime / pgpmime.c
blob1841b9fb53325d4b17a7869295ff3fef5a9b7b45
1 /*
2 * Claws Mail -- a GTK based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2024 the Claws Mail team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #ifdef HAVE_CONFIG_H
20 # include "config.h"
21 #include "claws-features.h"
22 #endif
24 #ifdef USE_GPGME
26 #include "defs.h"
27 #include <glib.h>
28 #include <glib/gi18n.h>
29 #include <gpgme.h>
30 #include <ctype.h>
31 #include <errno.h>
33 #include "utils.h"
34 #include "privacy.h"
35 #include "procmime.h"
36 #include "plugin.h"
38 #include "pgpmime.h"
39 #include <plugins/pgpcore/sgpgme.h>
40 #include <plugins/pgpcore/prefs_gpg.h>
41 #include <plugins/pgpcore/passphrase.h>
42 #include <plugins/pgpcore/pgp_utils.h>
44 #include "prefs_common.h"
45 #include "file-utils.h"
47 typedef struct _PrivacyDataPGP PrivacyDataPGP;
49 struct _PrivacyDataPGP
51 PrivacyData data;
53 gboolean done_sigtest;
54 gboolean is_signed;
57 static PrivacySystem pgpmime_system;
59 static PrivacyDataPGP *pgpmime_new_privacydata()
61 PrivacyDataPGP *data;
63 data = g_new0(PrivacyDataPGP, 1);
64 data->data.system = &pgpmime_system;
66 return data;
69 static void pgpmime_free_privacydata(PrivacyData *data)
71 g_free(data);
74 static gboolean pgpmime_is_signed(MimeInfo *mimeinfo)
76 MimeInfo *parent;
77 MimeInfo *signature;
78 const gchar *protocol;
79 PrivacyDataPGP *data = NULL;
81 cm_return_val_if_fail(mimeinfo != NULL, FALSE);
82 if (mimeinfo->privacy != NULL) {
83 data = (PrivacyDataPGP *) mimeinfo->privacy;
84 if (data->done_sigtest)
85 return data->is_signed;
88 /* check parent */
89 parent = procmime_mimeinfo_parent(mimeinfo);
90 if (parent == NULL)
91 return FALSE;
92 if ((parent->type != MIMETYPE_MULTIPART) ||
93 g_ascii_strcasecmp(parent->subtype, "signed"))
94 return FALSE;
95 protocol = procmime_mimeinfo_get_parameter(parent, "protocol");
96 if ((protocol == NULL) ||
97 (g_ascii_strcasecmp(protocol, "application/pgp-signature")))
98 return FALSE;
100 /* check if mimeinfo is the first child */
101 if (parent->node->children->data != mimeinfo)
102 return FALSE;
104 /* check signature */
105 signature = parent->node->children->next != NULL ?
106 (MimeInfo *) parent->node->children->next->data : NULL;
107 if (signature == NULL)
108 return FALSE;
109 if ((signature->type != MIMETYPE_APPLICATION) ||
110 (g_ascii_strcasecmp(signature->subtype, "pgp-signature")))
111 return FALSE;
113 if (data == NULL) {
114 data = pgpmime_new_privacydata();
115 mimeinfo->privacy = (PrivacyData *) data;
117 if (data != NULL) {
118 data->done_sigtest = TRUE;
119 data->is_signed = TRUE;
122 return TRUE;
125 static gchar *get_canonical_content(FILE *fp, const gchar *boundary)
127 GString *textbuffer;
128 guint boundary_len;
129 gchar buf[BUFFSIZE];
131 boundary_len = strlen(boundary);
132 while (claws_fgets(buf, sizeof(buf), fp) != NULL)
133 if (IS_BOUNDARY(buf, boundary, boundary_len))
134 break;
136 textbuffer = g_string_new("");
137 while (claws_fgets(buf, sizeof(buf), fp) != NULL) {
138 gchar *buf2;
140 if (IS_BOUNDARY(buf, boundary, boundary_len))
141 break;
143 buf2 = canonicalize_str(buf);
144 g_string_append(textbuffer, buf2);
145 g_free(buf2);
147 g_string_truncate(textbuffer, textbuffer->len - 2);
149 return g_string_free(textbuffer, FALSE);
152 static gint pgpmime_check_sig_async(MimeInfo *mimeinfo,
153 GCancellable *cancellable,
154 GAsyncReadyCallback callback,
155 gpointer user_data)
157 return cm_check_detached_sig_async(mimeinfo,
158 cancellable,
159 callback,
160 user_data,
161 GPGME_PROTOCOL_OpenPGP,
162 get_canonical_content);
165 static gboolean pgpmime_is_encrypted(MimeInfo *mimeinfo)
167 MimeInfo *tmpinfo;
168 const gchar *tmpstr;
169 const gchar *begin_indicator = "-----BEGIN PGP MESSAGE-----";
170 const gchar *end_indicator = "-----END PGP MESSAGE-----";
171 gchar *textdata;
173 if (mimeinfo->type != MIMETYPE_MULTIPART)
174 return FALSE;
175 if (g_ascii_strcasecmp(mimeinfo->subtype, "encrypted"))
176 return FALSE;
177 tmpstr = procmime_mimeinfo_get_parameter(mimeinfo, "protocol");
178 if ((tmpstr == NULL) || g_ascii_strcasecmp(tmpstr, "application/pgp-encrypted"))
179 return FALSE;
180 if (g_node_n_children(mimeinfo->node) != 2)
181 return FALSE;
183 tmpinfo = (MimeInfo *) g_node_nth_child(mimeinfo->node, 0)->data;
184 if (tmpinfo->type != MIMETYPE_APPLICATION)
185 return FALSE;
186 if (g_ascii_strcasecmp(tmpinfo->subtype, "pgp-encrypted"))
187 return FALSE;
189 tmpinfo = (MimeInfo *) g_node_nth_child(mimeinfo->node, 1)->data;
190 if (tmpinfo->type != MIMETYPE_APPLICATION)
191 return FALSE;
192 if (g_ascii_strcasecmp(tmpinfo->subtype, "octet-stream"))
193 return FALSE;
195 textdata = procmime_get_part_as_string(tmpinfo, TRUE);
196 if (!textdata)
197 return FALSE;
199 if (!pgp_locate_armor_header(textdata, begin_indicator)) {
200 g_free(textdata);
201 return FALSE;
203 if (!pgp_locate_armor_header(textdata, end_indicator)) {
204 g_free(textdata);
205 return FALSE;
208 g_free(textdata);
210 return TRUE;
213 static MimeInfo *pgpmime_decrypt(MimeInfo *mimeinfo)
215 MimeInfo *encinfo, *decinfo, *parseinfo;
216 gpgme_data_t cipher = NULL, plain = NULL;
217 static gint id = 0;
218 FILE *dstfp;
219 gchar *fname;
220 gpgme_verify_result_t sigstat = NULL;
221 PrivacyDataPGP *data = NULL;
222 gpgme_ctx_t ctx;
223 gchar *chars;
224 size_t len;
225 gpgme_error_t err;
226 SignatureData *sig_data = NULL;
228 if ((err = gpgme_new(&ctx)) != GPG_ERR_NO_ERROR) {
229 debug_print("Couldn't initialize GPG context, %s\n", gpgme_strerror(err));
230 privacy_set_error(_("Couldn't initialize GPG context, %s"), gpgme_strerror(err));
231 return NULL;
234 cm_return_val_if_fail(pgpmime_is_encrypted(mimeinfo), NULL);
236 encinfo = (MimeInfo *) g_node_nth_child(mimeinfo->node, 1)->data;
238 cipher = sgpgme_data_from_mimeinfo(encinfo);
239 plain = sgpgme_decrypt_verify(cipher, &sigstat, ctx);
241 if (sigstat != NULL && sigstat->signatures != NULL) {
242 sig_data = g_new0(SignatureData, 1);
243 sig_data->status = sgpgme_sigstat_gpgme_to_privacy(ctx, sigstat);
244 sig_data->info_short = sgpgme_sigstat_info_short(ctx, sigstat);
245 sig_data->info_full = sgpgme_sigstat_info_full(ctx, sigstat);
248 gpgme_release(ctx);
249 gpgme_data_release(cipher);
250 if (plain == NULL) {
251 debug_print("plain is null!\n");
252 if (sig_data)
253 privacy_free_signature_data(sig_data);
254 return NULL;
257 fname = g_strdup_printf("%s%cplaintext.%08x",
258 get_mime_tmp_dir(), G_DIR_SEPARATOR, ++id);
260 if ((dstfp = claws_fopen(fname, "wb")) == NULL) {
261 FILE_OP_ERROR(fname, "claws_fopen");
262 privacy_set_error(_("Couldn't open decrypted file %s"), fname);
263 if (sig_data)
264 privacy_free_signature_data(sig_data);
265 g_free(fname);
266 gpgme_data_release(plain);
267 debug_print("can't open!\n");
268 return NULL;
271 if (fprintf(dstfp, "MIME-Version: 1.0\n") < 0) {
272 FILE_OP_ERROR(fname, "fprintf");
273 claws_fclose(dstfp);
274 privacy_set_error(_("Couldn't write to decrypted file %s"), fname);
275 if (sig_data)
276 privacy_free_signature_data(sig_data);
277 g_free(fname);
278 gpgme_data_release(plain);
279 debug_print("can't open!\n");
280 return NULL;
283 chars = sgpgme_data_release_and_get_mem(plain, &len);
284 if (len > 0) {
285 if (claws_fwrite(chars, 1, len, dstfp) < len) {
286 FILE_OP_ERROR(fname, "claws_fwrite");
287 g_free(chars);
288 claws_fclose(dstfp);
289 privacy_set_error(_("Couldn't write to decrypted file %s"), fname);
290 if (sig_data)
291 privacy_free_signature_data(sig_data);
292 g_free(fname);
293 gpgme_data_release(plain);
294 debug_print("can't open!\n");
295 return NULL;
298 g_free(chars);
300 if (claws_safe_fclose(dstfp) == EOF) {
301 FILE_OP_ERROR(fname, "claws_fclose");
302 privacy_set_error(_("Couldn't close decrypted file %s"), fname);
303 if (sig_data)
304 privacy_free_signature_data(sig_data);
305 g_free(fname);
306 gpgme_data_release(plain);
307 debug_print("can't open!\n");
308 return NULL;
311 parseinfo = procmime_scan_file(fname);
312 g_free(fname);
313 if (parseinfo == NULL) {
314 privacy_set_error(_("Couldn't parse decrypted file."));
315 if (sig_data)
316 privacy_free_signature_data(sig_data);
317 return NULL;
319 decinfo = g_node_first_child(parseinfo->node) != NULL ?
320 g_node_first_child(parseinfo->node)->data : NULL;
321 if (decinfo == NULL) {
322 privacy_set_error(_("Couldn't parse decrypted file parts."));
323 if (sig_data)
324 privacy_free_signature_data(sig_data);
325 return NULL;
328 g_node_unlink(decinfo->node);
329 procmime_mimeinfo_free_all(&parseinfo);
331 decinfo->tmp = TRUE;
333 if (sig_data != NULL) {
334 if (decinfo->privacy != NULL) {
335 data = (PrivacyDataPGP *) decinfo->privacy;
336 } else {
337 data = pgpmime_new_privacydata();
338 decinfo->privacy = (PrivacyData *) data;
341 if (data != NULL) {
342 data->done_sigtest = TRUE;
343 data->is_signed = TRUE;
344 decinfo->sig_data = sig_data;
348 return decinfo;
351 gboolean pgpmime_sign(MimeInfo *mimeinfo, PrefsAccount *account, const gchar *from_addr)
353 MimeInfo *msgcontent, *sigmultipart, *newinfo;
354 gchar *textstr, *micalg = NULL;
355 FILE *fp;
356 gchar *boundary = NULL;
357 gchar *sigcontent;
358 gpgme_ctx_t ctx;
359 gpgme_data_t gpgtext, gpgsig;
360 gpgme_error_t err;
361 size_t len;
362 struct passphrase_cb_info_s info;
363 gpgme_sign_result_t result = NULL;
364 gchar *test_msg;
366 fp = my_tmpfile();
367 if (fp == NULL) {
368 perror("my_tmpfile");
369 privacy_set_error(_("Couldn't create temporary file: %s"), g_strerror(errno));
370 return FALSE;
372 procmime_write_mimeinfo(mimeinfo, fp);
373 rewind(fp);
375 /* read temporary file into memory */
376 test_msg = file_read_stream_to_str(fp);
377 claws_fclose(fp);
379 memset (&info, 0, sizeof info);
381 /* remove content node from message */
382 msgcontent = (MimeInfo *) mimeinfo->node->children->data;
383 g_node_unlink(msgcontent->node);
385 /* create temporary multipart for content */
386 sigmultipart = procmime_mimeinfo_new();
387 sigmultipart->type = MIMETYPE_MULTIPART;
388 sigmultipart->subtype = g_strdup("signed");
390 do {
391 g_free(boundary);
392 boundary = generate_mime_boundary("Sig");
393 } while (strstr(test_msg, boundary) != NULL);
395 g_free(test_msg);
397 g_hash_table_insert(sigmultipart->typeparameters, g_strdup("boundary"),
398 g_strdup(boundary));
399 g_hash_table_insert(sigmultipart->typeparameters, g_strdup("protocol"),
400 g_strdup("application/pgp-signature"));
401 g_node_append(sigmultipart->node, msgcontent->node);
402 g_node_append(mimeinfo->node, sigmultipart->node);
404 /* write message content to temporary file */
405 fp = my_tmpfile();
406 if (fp == NULL) {
407 perror("my_tmpfile");
408 privacy_set_error(_("Couldn't create temporary file: %s"), g_strerror(errno));
409 g_free(boundary);
410 return FALSE;
412 procmime_write_mimeinfo(sigmultipart, fp);
413 rewind(fp);
415 /* read temporary file into memory */
416 textstr = get_canonical_content(fp, boundary);
418 g_free(boundary);
419 claws_fclose(fp);
421 gpgme_data_new_from_mem(&gpgtext, textstr, (size_t)strlen(textstr), 0);
422 gpgme_data_new(&gpgsig);
423 if ((err = gpgme_new(&ctx)) != GPG_ERR_NO_ERROR) {
424 debug_print("Couldn't initialize GPG context, %s\n", gpgme_strerror(err));
425 privacy_set_error(_("Couldn't initialize GPG context, %s"), gpgme_strerror(err));
426 return FALSE;
428 gpgme_set_textmode(ctx, 1);
429 gpgme_set_armor(ctx, 1);
430 gpgme_signers_clear (ctx);
432 if (!sgpgme_setup_signers(ctx, account, from_addr)) {
433 gpgme_release(ctx);
434 return FALSE;
437 prefs_gpg_enable_agent(prefs_gpg_get_config()->use_gpg_agent);
438 if (g_getenv("GPG_AGENT_INFO") && prefs_gpg_get_config()->use_gpg_agent) {
439 debug_print("GPG_AGENT_INFO environment defined, running without passphrase callback\n");
440 } else {
441 info.c = ctx;
442 gpgme_set_passphrase_cb (ctx, gpgmegtk_passphrase_cb, &info);
445 err = gpgme_op_sign(ctx, gpgtext, gpgsig, GPGME_SIG_MODE_DETACH);
446 if (err != GPG_ERR_NO_ERROR) {
447 if (err == GPG_ERR_CANCELED) {
448 /* ignore cancelled signing */
449 privacy_reset_error();
450 debug_print("gpgme_op_sign cancelled\n");
451 } else {
452 privacy_set_error(_("Data signing failed, %s"), gpgme_strerror(err));
453 debug_print("gpgme_op_sign error : %x\n", err);
455 gpgme_release(ctx);
456 return FALSE;
458 result = gpgme_op_sign_result(ctx);
459 if (result && result->signatures) {
460 gpgme_new_signature_t sig = result->signatures;
461 if (gpgme_get_protocol(ctx) == GPGME_PROTOCOL_OpenPGP) {
462 gchar *down_algo = g_ascii_strdown(gpgme_hash_algo_name(
463 result->signatures->hash_algo), -1);
464 micalg = g_strdup_printf("pgp-%s", down_algo);
465 g_free(down_algo);
466 } else {
467 micalg = g_strdup(gpgme_hash_algo_name(
468 result->signatures->hash_algo));
470 while (sig) {
471 debug_print("valid signature: %s\n", sig->fpr);
472 sig = sig->next;
474 } else if (result && result->invalid_signers) {
475 gpgme_invalid_key_t invalid = result->invalid_signers;
476 while (invalid) {
477 g_warning("invalid signer: %s (%s)", invalid->fpr,
478 gpgme_strerror(invalid->reason));
479 privacy_set_error(_("Data signing failed due to invalid signer: %s"),
480 gpgme_strerror(invalid->reason));
481 invalid = invalid->next;
483 gpgme_release(ctx);
484 return FALSE;
485 } else {
486 /* can't get result (maybe no signing key?) */
487 debug_print("gpgme_op_sign_result error\n");
488 privacy_set_error(_("Data signing failed, no results."));
489 gpgme_release(ctx);
490 return FALSE;
493 sigcontent = sgpgme_data_release_and_get_mem(gpgsig, &len);
494 gpgme_data_release(gpgtext);
495 g_free(textstr);
497 if (sigcontent == NULL || len <= 0) {
498 g_warning("sgpgme_data_release_and_get_mem failed");
499 privacy_set_error(_("Data signing failed, no contents."));
500 g_free(micalg);
501 g_free(sigcontent);
502 gpgme_release(ctx);
503 return FALSE;
506 /* add signature */
507 g_hash_table_insert(sigmultipart->typeparameters, g_strdup("micalg"),
508 micalg);
510 newinfo = procmime_mimeinfo_new();
511 newinfo->type = MIMETYPE_APPLICATION;
512 newinfo->subtype = g_strdup("pgp-signature");
513 newinfo->description = g_strdup(_("OpenPGP digital signature"));
514 newinfo->content = MIMECONTENT_MEM;
515 newinfo->data.mem = g_malloc(len + 1);
516 memmove(newinfo->data.mem, sigcontent, len);
517 newinfo->data.mem[len] = '\0';
518 newinfo->tmp = TRUE;
519 g_node_append(sigmultipart->node, newinfo->node);
521 g_free(sigcontent);
522 gpgme_release(ctx);
524 return TRUE;
526 gchar *pgpmime_get_encrypt_data(GSList *recp_names)
528 return sgpgme_get_encrypt_data(recp_names, GPGME_PROTOCOL_OpenPGP);
531 static const gchar *pgpmime_get_encrypt_warning(void)
533 if (prefs_gpg_should_skip_encryption_warning(pgpmime_system.id))
534 return NULL;
535 else
536 return _("Please note that email headers, like Subject, "
537 "are not encrypted by the PGP/Mime system.");
540 static void pgpmime_inhibit_encrypt_warning(gboolean inhibit)
542 if (inhibit)
543 prefs_gpg_add_skip_encryption_warning(pgpmime_system.id);
544 else
545 prefs_gpg_remove_skip_encryption_warning(pgpmime_system.id);
548 gboolean pgpmime_encrypt(MimeInfo *mimeinfo, const gchar *encrypt_data)
550 MimeInfo *msgcontent, *encmultipart, *newinfo;
551 FILE *fp;
552 gchar *boundary, *enccontent;
553 size_t len;
554 gchar *textstr;
555 gpgme_data_t gpgtext = NULL, gpgenc = NULL;
556 gpgme_ctx_t ctx = NULL;
557 gpgme_key_t *kset = NULL;
558 gchar **fprs = g_strsplit(encrypt_data, " ", -1);
559 gint i = 0;
560 gpgme_error_t err;
562 while (fprs[i] && strlen(fprs[i])) {
563 i++;
566 kset = g_malloc0(sizeof(gpgme_key_t)*(i+1));
567 if ((err = gpgme_new(&ctx)) != GPG_ERR_NO_ERROR) {
568 debug_print("Couldn't initialize GPG context, %s\n", gpgme_strerror(err));
569 privacy_set_error(_("Couldn't initialize GPG context, %s"), gpgme_strerror(err));
570 g_free(kset);
571 g_free(fprs);
572 return FALSE;
574 i = 0;
575 while (fprs[i] && strlen(fprs[i])) {
576 gpgme_key_t key;
577 err = gpgme_get_key(ctx, fprs[i], &key, 0);
578 if (err) {
579 debug_print("can't add key '%s'[%d] (%s)\n", fprs[i],i, gpgme_strerror(err));
580 privacy_set_error(_("Couldn't add GPG key %s, %s"), fprs[i], gpgme_strerror(err));
581 for (gint x = 0; x < i; x++)
582 gpgme_key_unref(kset[x]);
583 g_free(kset);
584 g_free(fprs);
585 gpgme_release(ctx);
586 return FALSE;
588 debug_print("found %s at %d\n", fprs[i], i);
589 kset[i] = key;
590 i++;
593 debug_print("Encrypting message content\n");
595 /* remove content node from message */
596 msgcontent = (MimeInfo *) mimeinfo->node->children->data;
597 g_node_unlink(msgcontent->node);
599 /* create temporary multipart for content */
600 encmultipart = procmime_mimeinfo_new();
601 encmultipart->type = MIMETYPE_MULTIPART;
602 encmultipart->subtype = g_strdup("encrypted");
603 boundary = generate_mime_boundary("Encrypt");
604 g_hash_table_insert(encmultipart->typeparameters, g_strdup("boundary"),
605 g_strdup(boundary));
606 g_hash_table_insert(encmultipart->typeparameters, g_strdup("protocol"),
607 g_strdup("application/pgp-encrypted"));
608 g_node_append(encmultipart->node, msgcontent->node);
610 /* write message content to temporary file */
611 fp = my_tmpfile();
612 if (fp == NULL) {
613 perror("my_tmpfile");
614 privacy_set_error(_("Couldn't create temporary file, %s"), g_strerror(errno));
615 for (gint x = 0; x < i; x++)
616 gpgme_key_unref(kset[x]);
617 g_free(kset);
618 g_free(boundary);
619 g_free(fprs);
620 gpgme_release(ctx);
621 return FALSE;
623 procmime_write_mimeinfo(encmultipart, fp);
624 rewind(fp);
626 /* read temporary file into memory */
627 textstr = get_canonical_content(fp, boundary);
629 g_free(boundary);
630 claws_fclose(fp);
632 /* encrypt data */
633 gpgme_data_new_from_mem(&gpgtext, textstr, (size_t)strlen(textstr), 0);
634 gpgme_data_new(&gpgenc);
635 gpgme_set_armor(ctx, 1);
636 cm_gpgme_data_rewind(gpgtext);
638 err = gpgme_op_encrypt(ctx, kset, GPGME_ENCRYPT_ALWAYS_TRUST, gpgtext, gpgenc);
640 enccontent = sgpgme_data_release_and_get_mem(gpgenc, &len);
641 gpgme_data_release(gpgtext);
642 g_free(textstr);
643 for (gint x = 0; x < i; x++)
644 gpgme_key_unref(kset[x]);
645 g_free(kset);
647 if (enccontent == NULL || len <= 0) {
648 g_warning("sgpgme_data_release_and_get_mem failed");
649 privacy_set_error(_("Encryption failed, %s"), gpgme_strerror(err));
650 gpgme_release(ctx);
651 g_free(enccontent);
652 g_free(fprs);
653 return FALSE;
656 /* create encrypted multipart */
657 g_node_unlink(msgcontent->node);
658 procmime_mimeinfo_free_all(&msgcontent);
659 g_node_append(mimeinfo->node, encmultipart->node);
661 newinfo = procmime_mimeinfo_new();
662 newinfo->type = MIMETYPE_APPLICATION;
663 newinfo->subtype = g_strdup("pgp-encrypted");
664 newinfo->content = MIMECONTENT_MEM;
665 newinfo->data.mem = g_strdup("Version: 1\n");
666 newinfo->tmp = TRUE;
667 g_node_append(encmultipart->node, newinfo->node);
669 newinfo = procmime_mimeinfo_new();
670 newinfo->type = MIMETYPE_APPLICATION;
671 newinfo->subtype = g_strdup("octet-stream");
672 newinfo->content = MIMECONTENT_MEM;
673 newinfo->data.mem = g_malloc(len + 1);
674 newinfo->tmp = TRUE;
675 memmove(newinfo->data.mem, enccontent, len);
676 newinfo->data.mem[len] = '\0';
677 g_node_append(encmultipart->node, newinfo->node);
679 g_free(enccontent);
680 gpgme_release(ctx);
682 g_free(fprs);
684 return TRUE;
687 static PrivacySystem pgpmime_system = {
688 "pgpmime", /* id */
689 "PGP MIME", /* name */
691 pgpmime_free_privacydata, /* free_privacydata */
693 pgpmime_is_signed, /* is_signed(MimeInfo *) */
694 pgpmime_check_sig_async,
696 pgpmime_is_encrypted, /* is_encrypted(MimeInfo *) */
697 pgpmime_decrypt, /* decrypt(MimeInfo *) */
699 TRUE,
700 pgpmime_sign,
702 TRUE,
703 pgpmime_get_encrypt_data,
704 pgpmime_encrypt,
705 pgpmime_get_encrypt_warning,
706 pgpmime_inhibit_encrypt_warning,
707 prefs_gpg_auto_check_signatures,
710 void pgpmime_init()
712 privacy_register_system(&pgpmime_system);
715 void pgpmime_done()
717 privacy_unregister_system(&pgpmime_system);
720 struct PluginFeature *plugin_provides(void)
722 static struct PluginFeature features[] =
723 { {PLUGIN_PRIVACY, N_("PGP/Mime")},
724 {PLUGIN_NOTHING, NULL}};
725 return features;
727 #endif /* USE_GPGME */