#include "prefs_gpg.h"
#include "passphrase.h"
-extern struct GPGConfig prefs_gpg;
-
typedef struct _PrivacyDataPGP PrivacyDataPGP;
struct _PrivacyDataPGP
static void pgpmime_free_privacydata(PrivacyData *_data)
{
PrivacyDataPGP *data = (PrivacyDataPGP *) _data;
-
+ gpgme_release(data->ctx);
g_free(data);
}
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"))
return FALSE;
/* check if mimeinfo is the first child */
if (signature == NULL)
return FALSE;
if ((signature->type != MIMETYPE_APPLICATION) ||
- g_strcasecmp(signature->subtype, "pgp-signature"))
+ g_ascii_strcasecmp(signature->subtype, "pgp-signature"))
return FALSE;
if (data == NULL) {
debug_print("Checking PGP/MIME signature\n");
parent = procmime_mimeinfo_parent(mimeinfo);
- fp = fopen(parent->filename, "rb");
+ fp = fopen(parent->data.filename, "rb");
g_return_val_if_fail(fp != NULL, SIGNATURE_INVALID);
boundary = g_hash_table_lookup(parent->typeparameters, "boundary");
g_return_val_if_fail(data != NULL, SIGNATURE_INVALID);
if (data->sigstatus == GPGME_SIG_STAT_NONE &&
- prefs_gpg.auto_check_signatures)
+ prefs_gpg_get_config()->auto_check_signatures)
pgpmime_check_signature(mimeinfo);
return sgpgme_sigstat_gpgme_to_privacy(data->ctx, data->sigstatus);
g_return_val_if_fail(data != NULL, g_strdup("Error"));
if (data->sigstatus == GPGME_SIG_STAT_NONE &&
- prefs_gpg.auto_check_signatures)
+ prefs_gpg_get_config()->auto_check_signatures)
pgpmime_check_signature(mimeinfo);
return sgpgme_sigstat_info_short(data->ctx, data->sigstatus);
g_return_val_if_fail(data != NULL, g_strdup("Error"));
if (data->sigstatus == GPGME_SIG_STAT_NONE &&
- prefs_gpg.auto_check_signatures)
+ prefs_gpg_get_config()->auto_check_signatures)
pgpmime_check_signature(mimeinfo);
return sgpgme_sigstat_info_full(data->ctx, data->sigstatus);
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;
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;
plain = sgpgme_decrypt_verify(cipher, &sigstat, ctx);
gpgme_data_release(cipher);
- if (plain == NULL)
+ if (plain == NULL) {
+ gpgme_release(ctx);
return NULL;
-
+ }
+
fname = g_strdup_printf("%s%cplaintext.%08x",
get_mime_tmp_dir(), G_DIR_SEPARATOR, ++id);
FILE_OP_ERROR(fname, "fopen");
g_free(fname);
gpgme_data_release(plain);
+ gpgme_release(ctx);
return NULL;
}
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);
return NULL;
}
-gboolean pgpmime_sign(MimeInfo *mimeinfo)
+gboolean pgpmime_sign(MimeInfo *mimeinfo, PrefsAccount *account)
{
MimeInfo *msgcontent, *sigmultipart, *newinfo;
gchar *textstr, *opinfo, *micalg;
gchar *boundary, *sigcontent;
GpgmeCtx ctx;
GpgmeData gpgtext, gpgsig;
- guint len;
+ size_t len;
struct passphrase_cb_info_s info;
-
+
memset (&info, 0, sizeof info);
/* remove content node from message */
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) != GPGME_No_Error)
+ if (gpgme_op_sign(ctx, gpgtext, gpgsig, GPGME_SIG_MODE_DETACH) != GPGME_No_Error) {
+ gpgme_release(ctx);
return FALSE;
+ }
opinfo = gpgme_get_op_info(ctx, 0);
micalg = extract_micalg(opinfo);
g_free(opinfo);
newinfo->type = MIMETYPE_APPLICATION;
newinfo->subtype = g_strdup("pgp-signature");
newinfo->content = MIMECONTENT_MEM;
- newinfo->data = g_memdup(sigcontent, len + 1);
- newinfo->data[len] = '\0';
+ 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);
MimeInfo *msgcontent, *encmultipart, *newinfo;
FILE *fp;
gchar *boundary, *enccontent;
- guint len;
+ size_t len;
gchar *textstr;
GpgmeData gpgtext, gpgenc;
gchar **recipients, **nextrecp;
recipients = g_strsplit(encrypt_data, " ", 0);
gpgme_recipients_new(&recp);
for (nextrecp = recipients; *nextrecp != NULL; nextrecp++) {
- printf("%s\n", *nextrecp);
gpgme_recipients_add_name_with_validity(recp, *nextrecp,
GPGME_VALIDITY_FULL);
}
newinfo->type = MIMETYPE_APPLICATION;
newinfo->subtype = g_strdup("pgp-encrypted");
newinfo->content = MIMECONTENT_MEM;
- newinfo->data = g_strdup("Version: 1\n");
+ 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 = g_memdup(enccontent, len + 1);
- newinfo->data[len] = '\0';
+ 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);
static PrivacySystem pgpmime_system = {
"pgpmime", /* id */
- "PGP Mime", /* name */
+ "PGP/MIME", /* name */
pgpmime_free_privacydata, /* free_privacydata */