From dab1c82a2155a56ae2444108b4182bb7c19d4889 Mon Sep 17 00:00:00 2001 From: Not Zed Date: Fri, 30 Jan 2004 03:10:14 +0000 Subject: ** See bug #53558 (plus other fixes/cleanups) 2004-01-30 Not Zed ** See bug #53558 (plus other fixes/cleanups) * em-format.c (emf_format_secure): default implementation, handle output of inner part, but dont output any sign/encrypt info. (emf_multipart_signed, emf_multipart_encrypted): replaced with implementations from em-format-html.c, which now call em_format_format_secure to output guts. (emf_class_init): hook-up virtual method format_secure. * em-format.[ch]: add a virtual method for outputing secured parts. Moved all validity stuff from em-format-html.[ch] to here. * mail-component.c (impl_createControls): set the session interactive too. * em-format-html-display.c: make smime stuff dependent on HAVE_NSS. (efhd_multipart_signed, efhd_application_xpkcs7mime): removed, now handled by root class. (efhd_output_secure): renamed to efhd_format_secure, and use EMFormat::format_secure to kick off. (efhd_class_init): setup format_secure virtual method. * em-format-html.c (efh_multipart_encrypted): We need to handle this here so we can properly keep track of the ciphervalidity stuff. Also do it directly using the context, not multipartencrypted part. (efh_multipart_signed): with unsupported signature format, format as multipart/mixed, not as an attachment. (efh_multipart_signed): make the smime stuff optional. (efh_multipart_signed, efh_multipart_encrypted): Moved to em-format.c. (efh_application_xpkcs7mime): moved to em-format.c (efh_output_secure): renamed to efh_format_secure, linked into virtual method. call parent class to do the validation foo then output the info if needed. (efh_format_message): fixed access to validity stuff to parent object. (efh_class_init): hook up format_secure virtual method. (*): removed some now-unused headers. svn path=/trunk/; revision=24531 --- mail/em-format-html-display.c | 112 +++++------------------------------------- 1 file changed, 11 insertions(+), 101 deletions(-) (limited to 'mail/em-format-html-display.c') diff --git a/mail/em-format-html-display.c b/mail/em-format-html-display.c index 64fefde3fe..04a741fc79 100644 --- a/mail/em-format-html-display.c +++ b/mail/em-format-html-display.c @@ -64,10 +64,9 @@ #include #include #include -#include #include #include -#include +#include /* should this be in e-util rather than gal? */ #include @@ -76,8 +75,7 @@ #include #include -#if defined(HAVE_NSS) -#include +#ifdef HAVE_NSS #include "certificate-viewer.h" #include "e-cert-db.h" #endif @@ -137,6 +135,7 @@ static void efhd_format_error(EMFormat *emf, CamelStream *stream, const char *tx static void efhd_format_message(EMFormat *, CamelStream *, CamelMedium *); static void efhd_format_source(EMFormat *, CamelStream *, CamelMimePart *); static void efhd_format_attachment(EMFormat *, CamelStream *, CamelMimePart *, const char *, const EMFormatHandler *); +static void efhd_format_secure(EMFormat *emf, CamelStream *stream, CamelMimePart *part, CamelCipherValidity *valid); static void efhd_complete(EMFormat *); static gboolean efhd_bonobo_object(EMFormatHTML *efh, GtkHTMLEmbedded *eb, EMFormatHTMLPObject *pobject); @@ -156,6 +155,7 @@ static guint efhd_signals[EFHD_LAST_SIGNAL] = { 0 }; /* EMFormatHandler's for bonobo objects */ static GHashTable *efhd_bonobo_handlers; static EMFormatHTMLClass *efhd_parent; +static EMFormatClass *efhd_format_class; static void efhd_gtkhtml_realise(GtkHTML *html, EMFormatHTMLDisplay *efhd) @@ -275,6 +275,7 @@ efhd_class_init(GObjectClass *klass) ((EMFormatClass *)klass)->format_message = efhd_format_message; ((EMFormatClass *)klass)->format_source = efhd_format_source; ((EMFormatClass *)klass)->format_attachment = efhd_format_attachment; + ((EMFormatClass *)klass)->format_secure = efhd_format_secure; ((EMFormatClass *)klass)->complete = efhd_complete; klass->finalize = efhd_finalise; @@ -327,6 +328,7 @@ em_format_html_display_get_type(void) (GInstanceInitFunc)efhd_init }; efhd_parent = g_type_class_ref(em_format_html_get_type()); + efhd_format_class = g_type_class_ref(em_format_get_type()); type = g_type_register_static(em_format_html_get_type(), "EMFormatHTMLDisplay", &info, 0); efhd_bonobo_handlers = g_hash_table_new(g_str_hash, g_str_equal); @@ -675,7 +677,7 @@ efhd_xpkcs7mime_info_response(GtkWidget *w, guint button, struct _smime_pobject po->widget = NULL; } -#if defined(HAVE_NSS) +#ifdef HAVE_NSS static void efhd_xpkcs7mime_viewcert_clicked(GtkWidget *button, struct _smime_pobject *po) { @@ -839,29 +841,12 @@ efhd_xpkcs7mime_button(EMFormatHTML *efh, GtkHTMLEmbedded *eb, EMFormatHTMLPObje } static void -efhd_output_secure(EMFormat *emf, CamelStream *stream, CamelMimePart *part, CamelCipherValidity *valid) +efhd_format_secure(EMFormat *emf, CamelStream *stream, CamelMimePart *part, CamelCipherValidity *valid) { - CamelCipherValidity *save = ((EMFormatHTML *)emf)->valid_parent; - int len; - - /* Note: this same logic is in efh_output_secure */ - if (((EMFormatHTML *)emf)->valid == NULL) { - ((EMFormatHTML *)emf)->valid = valid; - } else { - e_dlist_addtail(&((EMFormatHTML *)emf)->valid_parent->children, (EDListNode *)valid); - camel_cipher_validity_envelope(((EMFormatHTML *)emf)->valid_parent, valid); - } + /* Note: We call EMFormatClass directly, not EMFormatHTML, our parent */ + efhd_format_class->format_secure(emf, stream, part, valid); - ((EMFormatHTML *)emf)->valid_parent = valid; - - len = emf->part_id->len; - g_string_append_printf(emf->part_id, ".signed"); - em_format_part(emf, stream, part); - g_string_truncate(emf->part_id, len); - - ((EMFormatHTML *)emf)->valid_parent = save; - - if (((EMFormatHTML *)emf)->valid == valid + if (emf->valid == valid && (valid->encrypt.status != CAMEL_CIPHER_VALIDITY_ENCRYPT_NONE || valid->sign.status != CAMEL_CIPHER_VALIDITY_SIGN_NONE)) { char *classid; @@ -888,84 +873,9 @@ efhd_output_secure(EMFormat *emf, CamelStream *stream, CamelMimePart *part, Came } } -static void -efhd_application_xpkcs7mime(EMFormat *emf, CamelStream *stream, CamelMimePart *part, const EMFormatHandler *info) -{ - CamelCipherContext *context; - CamelException *ex; - extern CamelSession *session; - CamelMimePart *opart; - CamelCipherValidity *valid; - - ex = camel_exception_new(); - - context = camel_smime_context_new(session); - - opart = camel_mime_part_new(); - valid = camel_cipher_decrypt(context, part, opart, ex); - if (valid == NULL) { - em_format_format_error(emf, stream, ex->desc?ex->desc:_("Could not parse S/MIME message: Unknown error")); - em_format_part_as(emf, stream, part, NULL); - } else { - efhd_output_secure(emf, stream, opart, valid); - } - - camel_object_unref(opart); - camel_object_unref(context); - camel_exception_free(ex); -} - -/* ********************************************************************** */ - -static void -efhd_multipart_signed (EMFormat *emf, CamelStream *stream, CamelMimePart *part, const EMFormatHandler *info) -{ - CamelMultipartSigned *mps; - CamelMimePart *cpart; - CamelCipherContext *cipher = NULL; - - mps = (CamelMultipartSigned *)camel_medium_get_content_object((CamelMedium *)part); - if (!CAMEL_IS_MULTIPART_SIGNED(mps) - || (cpart = camel_multipart_get_part((CamelMultipart *)mps, CAMEL_MULTIPART_SIGNED_CONTENT)) == NULL) { - em_format_format_source(emf, stream, part); - return; - } - - /* FIXME: Should be done via a plugin interface */ - /* FIXME: duplicated in em-format-html.c */ - if (g_ascii_strcasecmp("application/x-pkcs7-signature", mps->protocol) == 0 - || g_ascii_strcasecmp("application/pkcs7-signature", mps->protocol) == 0) - cipher = camel_smime_context_new(emf->session); - else if (g_ascii_strcasecmp("application/pgp-signature", mps->protocol) == 0) - cipher = camel_gpg_context_new(emf->session); - - if (cipher == NULL) { - em_format_format_error(emf, stream, _("Unsupported signature format")); - em_format_part_as(emf, stream, part, NULL); - } else { - CamelException *ex = camel_exception_new(); - CamelCipherValidity *valid; - - valid = camel_cipher_verify(cipher, part, ex); - if (valid == NULL) { - em_format_format_error(emf, stream, ex->desc?ex->desc:_("Unknown error verifying signature")); - em_format_part_as(emf, stream, part, NULL); - } else { - efhd_output_secure(emf, stream, cpart, valid); - } - - camel_exception_free(ex); - camel_object_unref(cipher); - } -} - /* ********************************************************************** */ static EMFormatHandler type_builtin_table[] = { - { "application/x-pkcs7-mime", (EMFormatFunc)efhd_application_xpkcs7mime }, - { "application/pkcs7-mime", (EMFormatFunc)efhd_application_xpkcs7mime }, - - { "multipart/signed", (EMFormatFunc)efhd_multipart_signed }, }; static void -- cgit v1.2.3