[evolution] Bug #314333 - Decrypt body in reply to an inline-PGP encrypted mail
- From: Milan Crha <mcrha src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [evolution] Bug #314333 - Decrypt body in reply to an inline-PGP encrypted mail
- Date: Thu, 15 Oct 2009 12:26:32 +0000 (UTC)
commit 13651b3d19f142162f310a7e3aead064ef765dd7
Author: Milan Crha <mcrha redhat com>
Date: Thu Oct 15 14:25:38 2009 +0200
Bug #314333 - Decrypt body in reply to an inline-PGP encrypted mail
em-format/em-format.c | 40 +++++++++++++++++++++++++++++++++++++---
em-format/em-format.h | 7 +++++++
mail/em-composer-utils.c | 38 ++++++++++++++++++++++++++++++++++----
mail/em-utils.c | 7 ++++++-
mail/em-utils.h | 2 +-
5 files changed, 85 insertions(+), 9 deletions(-)
---
diff --git a/em-format/em-format.c b/em-format/em-format.c
index 71cd977..19423e9 100644
--- a/em-format/em-format.c
+++ b/em-format/em-format.c
@@ -182,6 +182,7 @@ emf_init (EMFormat *emf)
e_dlist_init(&emf->header_list);
em_format_default_headers(emf);
emf->part_id = g_string_new("");
+ emf->validity_found = 0;
shell = e_shell_get_default ();
shell_settings = e_shell_get_shell_settings (shell);
@@ -1306,6 +1307,21 @@ em_format_describe_part(CamelMimePart *part, const gchar *mime_type)
return g_string_free (stext, FALSE);
}
+static void
+add_validity_found (EMFormat *emf, CamelCipherValidity *valid)
+{
+ g_return_if_fail (emf != NULL);
+
+ if (!valid)
+ return;
+
+ if (valid->sign.status != CAMEL_CIPHER_VALIDITY_SIGN_NONE)
+ emf->validity_found |= EM_FORMAT_VALIDITY_FOUND_SIGNED;
+
+ if (valid->encrypt.status != CAMEL_CIPHER_VALIDITY_ENCRYPT_NONE)
+ emf->validity_found |= EM_FORMAT_VALIDITY_FOUND_ENCRYPTED;
+}
+
/* ********************************************************************** */
#ifdef ENABLE_SMIME
@@ -1329,6 +1345,8 @@ emf_application_xpkcs7mime(EMFormat *emf, CamelStream *stream, CamelMimePart *pa
context = camel_smime_context_new(emf->session);
+ emf->validity_found |= EM_FORMAT_VALIDITY_FOUND_ENCRYPTED | EM_FORMAT_VALIDITY_FOUND_SMIME;
+
opart = camel_mime_part_new();
valid = camel_cipher_decrypt(context, part, opart, ex);
if (valid == NULL) {
@@ -1341,6 +1359,7 @@ emf_application_xpkcs7mime(EMFormat *emf, CamelStream *stream, CamelMimePart *pa
emfc->valid = camel_cipher_validity_clone(valid);
camel_object_ref((emfc->secured = opart));
+ add_validity_found (emf, valid);
em_format_format_secure(emf, stream, opart, valid);
}
@@ -1482,6 +1501,8 @@ emf_multipart_encrypted(EMFormat *emf, CamelStream *stream, CamelMimePart *part,
return;
}
+ emf->validity_found |= EM_FORMAT_VALIDITY_FOUND_ENCRYPTED | EM_FORMAT_VALIDITY_FOUND_PGP;
+
ex = camel_exception_new();
context = camel_gpg_context_new(emf->session);
opart = camel_mime_part_new();
@@ -1498,6 +1519,7 @@ emf_multipart_encrypted(EMFormat *emf, CamelStream *stream, CamelMimePart *part,
emfc->valid = camel_cipher_validity_clone(valid);
camel_object_ref((emfc->secured = opart));
+ add_validity_found (emf, valid);
em_format_format_secure(emf, stream, opart, valid);
}
@@ -1636,14 +1658,19 @@ emf_multipart_signed(EMFormat *emf, CamelStream *stream, CamelMimePart *part, co
if (mps->protocol) {
#ifdef ENABLE_SMIME
if (g_ascii_strcasecmp("application/x-pkcs7-signature", mps->protocol) == 0
- || g_ascii_strcasecmp("application/pkcs7-signature", mps->protocol) == 0)
+ || g_ascii_strcasecmp("application/pkcs7-signature", mps->protocol) == 0) {
cipher = camel_smime_context_new(emf->session);
- else
+ emf->validity_found |= EM_FORMAT_VALIDITY_FOUND_SMIME;
+ } else
#endif
- if (g_ascii_strcasecmp("application/pgp-signature", mps->protocol) == 0)
+ if (g_ascii_strcasecmp("application/pgp-signature", mps->protocol) == 0) {
cipher = camel_gpg_context_new(emf->session);
+ emf->validity_found |= EM_FORMAT_VALIDITY_FOUND_PGP;
+ }
}
+ emf->validity_found |= EM_FORMAT_VALIDITY_FOUND_SIGNED;
+
if (cipher == NULL) {
em_format_format_error(emf, stream, _("Unsupported signature format"));
em_format_part_as(emf, stream, part, "multipart/mixed");
@@ -1664,6 +1691,7 @@ emf_multipart_signed(EMFormat *emf, CamelStream *stream, CamelMimePart *part, co
emfc->valid = camel_cipher_validity_clone(valid);
camel_object_ref((emfc->secured = cpart));
+ add_validity_found (emf, valid);
em_format_format_secure(emf, stream, cpart, valid);
}
@@ -1786,6 +1814,8 @@ emf_inlinepgp_signed(EMFormat *emf, CamelStream *stream, CamelMimePart *ipart, E
return;
}
+ emf->validity_found |= EM_FORMAT_VALIDITY_FOUND_SIGNED | EM_FORMAT_VALIDITY_FOUND_PGP;
+
ex = camel_exception_new();
cipher = camel_gpg_context_new(emf->session);
/* Verify the signature of the message */
@@ -1838,6 +1868,7 @@ emf_inlinepgp_signed(EMFormat *emf, CamelStream *stream, CamelMimePart *ipart, E
camel_medium_set_content_object ((CamelMedium *) opart, dw);
camel_data_wrapper_set_mime_type_field ((CamelDataWrapper *) opart, dw->mime_type);
+ add_validity_found (emf, valid);
/* Pass it off to the real formatter */
em_format_format_secure(emf, stream, opart, valid);
@@ -1859,6 +1890,8 @@ emf_inlinepgp_encrypted(EMFormat *emf, CamelStream *stream, CamelMimePart *ipart
CamelDataWrapper *dw;
gchar *mime_type;
+ emf->validity_found |= EM_FORMAT_VALIDITY_FOUND_ENCRYPTED | EM_FORMAT_VALIDITY_FOUND_PGP;
+
cipher = camel_gpg_context_new(emf->session);
ex = camel_exception_new();
opart = camel_mime_part_new();
@@ -1889,6 +1922,7 @@ emf_inlinepgp_encrypted(EMFormat *emf, CamelStream *stream, CamelMimePart *ipart
g_free (mime_type);
+ add_validity_found (emf, valid);
/* Pass it off to the real formatter */
em_format_format_secure(emf, stream, opart, valid);
diff --git a/em-format/em-format.h b/em-format/em-format.h
index 7e59ecf..d3a331b 100644
--- a/em-format/em-format.h
+++ b/em-format/em-format.h
@@ -181,6 +181,11 @@ struct _EMFormatHeader {
#define EM_FORMAT_HEADER_BOLD (1<<0)
#define EM_FORMAT_HEADER_LAST (1<<4) /* reserve 4 slots */
+#define EM_FORMAT_VALIDITY_FOUND_PGP (1<<0)
+#define EM_FORMAT_VALIDITY_FOUND_SMIME (1<<1)
+#define EM_FORMAT_VALIDITY_FOUND_SIGNED (1<<2)
+#define EM_FORMAT_VALIDITY_FOUND_ENCRYPTED (1<<3)
+
/**
* struct _EMFormat - Mail formatter object.
*
@@ -231,6 +236,8 @@ struct _EMFormat {
/* for validity enveloping */
CamelCipherValidity *valid;
CamelCipherValidity *valid_parent;
+ /* for checking whether found any signed/encrypted parts */
+ guint32 validity_found;
/* for forcing inlining */
GHashTable *inline_table;
diff --git a/mail/em-composer-utils.c b/mail/em-composer-utils.c
index 615ead6..33972e1 100644
--- a/mail/em-composer-utils.c
+++ b/mail/em-composer-utils.c
@@ -47,6 +47,7 @@
#include "em-utils.h"
#include "em-composer-utils.h"
#include "composer/e-msg-composer.h"
+#include "composer/e-composer-actions.h"
#include "composer/e-composer-autosave.h"
#include "composer/e-composer-post-header.h"
#include "em-folder-selector.h"
@@ -993,6 +994,30 @@ em_utils_edit_messages (CamelFolder *folder, GPtrArray *uids, gboolean replace)
mail_get_messages (folder, uids, edit_messages, GINT_TO_POINTER (replace));
}
+static void
+emu_update_composers_security (EMsgComposer *composer, guint32 validity_found)
+{
+ GtkToggleAction *action;
+
+ g_return_if_fail (composer != NULL);
+
+ if (validity_found & EM_FORMAT_VALIDITY_FOUND_SIGNED) {
+ if (validity_found & EM_FORMAT_VALIDITY_FOUND_SMIME)
+ action = GTK_TOGGLE_ACTION (E_COMPOSER_ACTION_SMIME_SIGN (composer));
+ else
+ action = GTK_TOGGLE_ACTION (E_COMPOSER_ACTION_PGP_SIGN (composer));
+ gtk_toggle_action_set_active (action, TRUE);
+ }
+
+ if (validity_found & EM_FORMAT_VALIDITY_FOUND_ENCRYPTED) {
+ if (validity_found & EM_FORMAT_VALIDITY_FOUND_SMIME)
+ action = GTK_TOGGLE_ACTION (E_COMPOSER_ACTION_SMIME_ENCRYPT (composer));
+ else
+ action = GTK_TOGGLE_ACTION (E_COMPOSER_ACTION_PGP_ENCRYPT (composer));
+ gtk_toggle_action_set_active (action, TRUE);
+ }
+}
+
/* Forwarding messages... */
struct forward_attached_data
{
@@ -1128,11 +1153,12 @@ forward_non_attached (CamelFolder *folder, GPtrArray *uids, GPtrArray *messages,
for (i = 0; i < messages->len; i++) {
gssize len;
+ guint32 validity_found = 0;
message = messages->pdata[i];
subject = mail_tool_generate_forward_subject (message);
- text = em_utils_message_to_html (message, _("-------- Forwarded Message --------"), flags, &len, NULL, NULL);
+ text = em_utils_message_to_html (message, _("-------- Forwarded Message --------"), flags, &len, NULL, NULL, &validity_found);
if (text) {
composer = create_new_composer (subject, fromuri, FALSE);
@@ -1150,6 +1176,7 @@ forward_non_attached (CamelFolder *folder, GPtrArray *uids, GPtrArray *messages,
emcs_set_folder_info (emcs, folder, uids->pdata[i], CAMEL_MESSAGE_FORWARDED, CAMEL_MESSAGE_FORWARDED);
}
+ emu_update_composers_security (composer, validity_found);
composer_set_no_change (composer, TRUE, FALSE);
gtk_widget_show (GTK_WIDGET (composer));
@@ -2235,6 +2262,7 @@ composer_set_body (EMsgComposer *composer, CamelMimeMessage *message, EMFormat *
GConfClient *gconf;
gssize len = 0;
gboolean start_bottom;
+ guint32 validity_found = 0;
gconf = mail_config_get_gconf_client ();
start_bottom = gconf_client_get_bool (gconf, "/apps/evolution/mail/composer/reply_start_bottom", NULL);
@@ -2250,19 +2278,21 @@ composer_set_body (EMsgComposer *composer, CamelMimeMessage *message, EMFormat *
camel_object_unref (part);
break;
case MAIL_CONFIG_REPLY_OUTLOOK:
- text = em_utils_message_to_html (message, _("-----Original Message-----"), EM_FORMAT_QUOTE_HEADERS, &len, source, start_bottom ? "<BR>" : NULL);
+ text = em_utils_message_to_html (message, _("-----Original Message-----"), EM_FORMAT_QUOTE_HEADERS, &len, source, start_bottom ? "<BR>" : NULL, &validity_found);
e_msg_composer_set_body_text(composer, text, len);
g_free (text);
+ emu_update_composers_security (composer, validity_found);
break;
case MAIL_CONFIG_REPLY_QUOTED:
default:
/* do what any sane user would want when replying... */
credits = attribution_format (ATTRIBUTION, message);
- text = em_utils_message_to_html (message, credits, EM_FORMAT_QUOTE_CITE, &len, source, start_bottom ? "<BR>" : NULL);
+ text = em_utils_message_to_html (message, credits, EM_FORMAT_QUOTE_CITE, &len, source, start_bottom ? "<BR>" : NULL, &validity_found);
g_free (credits);
e_msg_composer_set_body_text(composer, text, len);
g_free (text);
+ emu_update_composers_security (composer, validity_found);
break;
}
@@ -2296,7 +2326,7 @@ em_utils_construct_composer_text (CamelMimeMessage *message, EMFormat *source)
gboolean start_bottom = 0;
credits = attribution_format (ATTRIBUTION, message);
- text = em_utils_message_to_html (message, credits, EM_FORMAT_QUOTE_CITE, &len, source, start_bottom ? "<BR>" : NULL);
+ text = em_utils_message_to_html (message, credits, EM_FORMAT_QUOTE_CITE, &len, source, start_bottom ? "<BR>" : NULL, NULL);
g_free (credits);
return text;
diff --git a/mail/em-utils.c b/mail/em-utils.c
index 5cd024b..79b11bc 100644
--- a/mail/em-utils.c
+++ b/mail/em-utils.c
@@ -1509,6 +1509,9 @@ em_utils_get_proxy_uri (const gchar *pUri)
* @len:
* @source:
* @append: Text to append, can be NULL.
+ * @validity_found: if not NULL, then here will be set what validities
+ * had been found during message conversion. Value is a bit OR
+ * of EM_FORMAT_VALIDITY_FOUND_* constants.
*
* Convert a message to html, quoting if the @credits attribution
* string is given.
@@ -1516,7 +1519,7 @@ em_utils_get_proxy_uri (const gchar *pUri)
* Return value: The html version.
**/
gchar *
-em_utils_message_to_html(CamelMimeMessage *message, const gchar *credits, guint32 flags, gssize *len, EMFormat *source, const gchar *append)
+em_utils_message_to_html (CamelMimeMessage *message, const gchar *credits, guint32 flags, gssize *len, EMFormat *source, const gchar *append, guint32 *validity_found)
{
EMFormatQuote *emfq;
CamelStreamMem *mem;
@@ -1543,6 +1546,8 @@ em_utils_message_to_html(CamelMimeMessage *message, const gchar *credits, guint3
}
em_format_format_clone((EMFormat *)emfq, NULL, NULL, message, source);
+ if (validity_found)
+ *validity_found = ((EMFormat *)emfq)->validity_found;
g_object_unref (emfq);
if (append && *append)
diff --git a/mail/em-utils.h b/mail/em-utils.h
index e1064c5..0c6a00b 100644
--- a/mail/em-utils.h
+++ b/mail/em-utils.h
@@ -84,7 +84,7 @@ void em_utils_adjustment_page(GtkAdjustment *adj, gboolean down);
gchar *em_utils_get_proxy_uri (const gchar *uri);
/* FIXME: should this have an override charset? */
-gchar *em_utils_message_to_html(CamelMimeMessage *msg, const gchar *credits, guint32 flags, gssize *len, struct _EMFormat *source, const gchar *append);
+gchar *em_utils_message_to_html (CamelMimeMessage *msg, const gchar *credits, guint32 flags, gssize *len, struct _EMFormat *source, const gchar *append, guint32 *validity_found);
void em_utils_expunge_folder (GtkWidget *parent, CamelFolder *folder);
void em_utils_empty_trash (GtkWidget *parent);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]