From ed88f237863dc3dd5aec568196b61008df2e9b8c Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Fri, 11 Aug 2000 20:27:12 +0000 Subject: Update this for CamelObject (try_inline_pgp): Deal with decrypting here * mail-format.c (destroy_part): Update this for CamelObject (try_inline_pgp): Deal with decrypting here rather than trying to pawn the data off to handle_multipart_encrypted, since it most likely won't be correct (won't have the proper MIME headers inside the encrypted part). (handle_multipart_encrypted): Add code from Nathan Thompson-Amato to re-MIME-parse the decrypted data after decrypting. * mail-crypto.c (mail_crypto_openpgp_{de,en}crypt): Get the password here rather than having it passed in. Remove some dead code. * session.c (mail_request_dialog): Allow this to work in either a sync or an async context. svn path=/trunk/; revision=4751 --- mail/ChangeLog | 17 ++++++++ mail/mail-crypto.c | 56 +++++++++++++------------ mail/mail-format.c | 119 ++++++++++++++++++++++++++--------------------------- mail/mail.h | 8 ++-- mail/session.c | 41 +++++++----------- 5 files changed, 123 insertions(+), 118 deletions(-) (limited to 'mail') diff --git a/mail/ChangeLog b/mail/ChangeLog index 34d7756c07..07faeb7cc8 100644 --- a/mail/ChangeLog +++ b/mail/ChangeLog @@ -1,3 +1,20 @@ +2000-08-11 Dan Winship + + * mail-format.c (destroy_part): Update this for CamelObject + (try_inline_pgp): Deal with decrypting here rather than trying to + pawn the data off to handle_multipart_encrypted, since it most + likely won't be correct (won't have the proper MIME headers inside + the encrypted part). + (handle_multipart_encrypted): Add code from Nathan Thompson-Amato + to re-MIME-parse the decrypted data after decrypting. + + * mail-crypto.c (mail_crypto_openpgp_{de,en}crypt): Get the + password here rather than having it passed in. Remove some dead + code. + + * session.c (mail_request_dialog): Allow this to work in either a + sync or an async context. + 2000-08-11 Peter Williams * mail-tools.c (mail_tool_fetch_mail_into_searchable): Don't diff --git a/mail/mail-crypto.c b/mail/mail-crypto.c index 7314aaeffc..1055bb4569 100644 --- a/mail/mail-crypto.c +++ b/mail/mail-crypto.c @@ -326,22 +326,22 @@ crypto_exec_with_passwd (char *path, char *argv[], const char *input, char * -mail_crypto_openpgp_decrypt (const char *ciphertext, const char *passphrase, - CamelException *ex) +mail_crypto_openpgp_decrypt (const char *ciphertext, CamelException *ex) { - int retval; + int retval, i; char *path, *argv[12]; - int i; - char *plaintext = NULL; - char *diagnostics = NULL; + char *passphrase, *plaintext = NULL, *diagnostics = NULL; int passwd_fds[2]; char passwd_fd[32]; -#ifndef PGP_PROGRAM - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - _("No GPG/PGP program available.")); - return NULL; -#endif + passphrase = mail_request_dialog ( + _("Please enter your PGP/GPG passphrase."), + TRUE, "pgp", FALSE); + if (!passphrase) { + camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM, + _("No password provided.")); + return NULL; + } if (pipe (passwd_fds) < 0) { camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, @@ -403,24 +403,26 @@ mail_crypto_openpgp_decrypt (const char *ciphertext, const char *passphrase, } char * -mail_crypto_openpgp_encrypt (const char *plaintext, const GPtrArray *recipients, const char *passphrase, +mail_crypto_openpgp_encrypt (const char *plaintext, + const GPtrArray *recipients, gboolean sign, CamelException *ex) { GPtrArray *recipient_list = NULL; - int retval; + int retval, i, r; char *path, *argv[12]; - int i, r; - char *cyphertext = NULL; - char *diagnostics = NULL; + char *passphrase, *ciphertext = NULL, *diagnostics = NULL; int passwd_fds[2]; char passwd_fd[32]; -#ifndef PGP_PROGRAM - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - _("No GPG/PGP program available.")); - return NULL; -#endif - + passphrase = mail_request_dialog ( + _("Please enter your PGP/GPG passphrase."), + TRUE, "pgp", FALSE); + if (!passphrase) { + camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM, + _("No password provided.")); + return NULL; + } + if (pipe (passwd_fds) < 0) { camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, _("Couldn't create pipe to GPG/PGP: %s"), @@ -488,14 +490,14 @@ mail_crypto_openpgp_encrypt (const char *plaintext, const GPtrArray *recipients, argv[i++] = NULL; retval = crypto_exec_with_passwd (path, argv, plaintext, passwd_fds, - passphrase, &cyphertext, + passphrase, &ciphertext, &diagnostics); - if (retval != 0 || !*cyphertext) { + if (retval != 0 || !*ciphertext) { camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, "%s", diagnostics); - g_free (cyphertext); - cyphertext = NULL; + g_free (ciphertext); + ciphertext = NULL; } if (recipient_list) { @@ -505,7 +507,7 @@ mail_crypto_openpgp_encrypt (const char *plaintext, const GPtrArray *recipients, } g_free (diagnostics); - return cyphertext; + return ciphertext; } #endif /* PGP_PROGRAM */ diff --git a/mail/mail-format.c b/mail/mail-format.c index 5ec2fe68b0..b9f215da1f 100644 --- a/mail/mail-format.c +++ b/mail/mail-format.c @@ -682,22 +682,35 @@ fake_mime_part_from_data (const char *data, int len, const char *type) return part; } - static void -destroy_part (GtkObject *root, GtkObject *part) +static void +destroy_part (CamelObject *root, gpointer event_data, gpointer user_data) +{ + camel_object_unref (user_data); +} + +static void +pgp_error (struct mail_format_data *mfd, CamelException *ex) { - gtk_object_unref (part); + mail_html_write (mfd->html, mfd->stream, "
" + "
" + "
", + get_url_for_icon ("gnome-lockscreen.png", mfd)); + mail_error_write (mfd->html, mfd->stream, + "(Encrypted message not displayed)\n\n%s", + camel_exception_get_description (&ex)); + mail_html_write (mfd->html, mfd->stream, "
"); + camel_exception_clear (ex); } static char * try_inline_pgp (char *start, struct mail_format_data *mfd) { - char *end; + char *end, *ciphertext, *plaintext; CamelMimePart *part; CamelMultipart *mp; + CamelException ex; - /* FIXME: This should deal with converting to multipart/signed - * as well. - */ + /* FIXME: This should deal with signed data as well. */ end = strstr (start, "-----END PGP MESSAGE-----"); if (!end) @@ -705,30 +718,24 @@ try_inline_pgp (char *start, struct mail_format_data *mfd) end += sizeof ("-----END PGP MESSAGE-----") - 1; - /* Build a multipart/encrypted. */ - mp = camel_multipart_new (); - camel_data_wrapper_set_mime_type (CAMEL_DATA_WRAPPER (mp), - "multipart/encrypted"); - - part = fake_mime_part_from_data ("Version: 1\n", 11, - "application/pgp-encrypted"); - camel_multipart_add_part (mp, part); - gtk_object_unref (GTK_OBJECT (part)); - - part = fake_mime_part_from_data (start, end - start, - "application/octet-stream"); - camel_multipart_add_part (mp, part); - gtk_object_unref (GTK_OBJECT (part)); + mail_html_write (mfd->html, mfd->stream, "
"); - part = camel_mime_part_new (); - camel_medium_set_content_object (CAMEL_MEDIUM (part), - CAMEL_DATA_WRAPPER (mp)); - gtk_object_unref (GTK_OBJECT (mp)); + camel_exception_init (&ex); +#ifdef PGP_PROGRAM + ciphertext = g_strndup (start, end - start); + plaintext = mail_crypto_openpgp_decrypt (ciphertext, &ex); + g_free (ciphertext); +#else + camel_exception_set (&ex, CAMEL_EXCEPTION_SYSTEM, + "No GPG/PGP support available in this copy " + "of Evolution."); +#endif - gtk_signal_connect (GTK_OBJECT (mfd->root), "destroy", - destroy_part, part); - mail_html_write (mfd->html, mfd->stream, "
"); - call_handler_function (part, mfd); + if (camel_exception_is_set (&ex)) + pgp_error (mfd, &ex); + else + mail_text_write (mfd->html, mfd->stream, "%s", plaintext); + g_free (plaintext); return end; } @@ -769,8 +776,8 @@ try_uudecoding (char *start, struct mail_format_data *mfd) g_free (out); camel_mime_part_set_filename (part, filename); g_free (filename); - gtk_signal_connect (GTK_OBJECT (mfd->root), "destroy", - destroy_part, part); + camel_object_hook_event (CAMEL_OBJECT (mfd->root), "finalize", + destroy_part, part); mail_html_write (mfd->html, mfd->stream, "
"); call_handler_function (part, mfd); @@ -797,8 +804,8 @@ try_inline_binhex (char *start, struct mail_format_data *mfd) part = fake_mime_part_from_data (start, p - start, "application/mac-binhex40"); - gtk_signal_connect (GTK_OBJECT (mfd->root), "destroy", - destroy_part, part); + camel_object_hook_event (CAMEL_OBJECT (mfd->root), "finalize", + destroy_part, part); mail_html_write (mfd->html, mfd->stream, "
"); call_handler_function (part, mfd); @@ -1067,7 +1074,7 @@ handle_multipart_encrypted (CamelMimePart *part, const char *mime_type, CamelDataWrapper *wrapper = camel_medium_get_content_object (CAMEL_MEDIUM (part)); CamelMultipart *mp; - char *ciphertext, *passphrase; + char *ciphertext; char *plaintext = NULL; CamelException ex; @@ -1087,17 +1094,7 @@ handle_multipart_encrypted (CamelMimePart *part, const char *mime_type, camel_exception_init (&ex); #ifdef PGP_PROGRAM - /* Get the passphrase. */ - passphrase = mail_request_dialog ( - "Please enter your PGP/GPG passphrase.", TRUE, "pgp"); - if (passphrase) { - plaintext = mail_crypto_openpgp_decrypt (ciphertext, - passphrase, &ex); - g_free (passphrase); - } else { - camel_exception_set (&ex, CAMEL_EXCEPTION_SYSTEM, - "No password provided."); - } + plaintext = mail_crypto_openpgp_decrypt (ciphertext, &ex); #else camel_exception_set (&ex, CAMEL_EXCEPTION_SYSTEM, "No GPG/PGP support available in this copy " @@ -1105,23 +1102,23 @@ handle_multipart_encrypted (CamelMimePart *part, const char *mime_type, #endif g_free (ciphertext); - if (camel_exception_is_set (&ex)) { - mail_html_write (mfd->html, mfd->stream, - "
" - "
" - "
", - get_url_for_icon ("gnome-lockscreen.png", - mfd)); - mail_error_write (mfd->html, mfd->stream, - "(Encrypted message not displayed)\n\n%s", - camel_exception_get_description (&ex)); - mail_html_write (mfd->html, mfd->stream, "
"); - - camel_exception_clear (&ex); - } else { - mail_text_write (mfd->html, mfd->stream, "%s", plaintext); - g_free (plaintext); + if (camel_exception_is_set (&ex)) + pgp_error (mfd, &ex); + else { + CamelStream *memstream; + + memstream = camel_stream_mem_new_with_buffer (plaintext, + strlen (plaintext)); + part = camel_mime_part_new (); + camel_data_wrapper_construct_from_stream (CAMEL_DATA_WRAPPER (part), + memstream); + camel_object_unref (CAMEL_OBJECT (memstream)); + + call_handler_function (part, mfd); + camel_object_hook_event (CAMEL_OBJECT (mfd->root), "finalize", + destroy_part, part); } + g_free (plaintext); return TRUE; } diff --git a/mail/mail.h b/mail/mail.h index 9e0e19e1ce..8099948c17 100644 --- a/mail/mail.h +++ b/mail/mail.h @@ -37,12 +37,10 @@ void mail_config_druid (void); /* mail-crypto */ char *mail_crypto_openpgp_decrypt (const char *ciphertext, - const char *passphrase, CamelException *ex); char *mail_crypto_openpgp_encrypt (const char *plaintext, const GPtrArray *recipients, - const char *passphrase, gboolean sign, CamelException *ex); /* FIXME: add encryption & signing functions */ @@ -93,6 +91,8 @@ GtkWidget *mail_view_create (CamelFolder *source, const char *uid, CamelMimeMess /* session */ void session_init (void); -char *mail_request_dialog (const char *prompt, gboolean secret, const char *key); -void forget_passwords (BonoboUIHandler *uih, void *user_data, const char *path); +char *mail_request_dialog (const char *prompt, gboolean secret, + const char *key, gboolean async); +void forget_passwords (BonoboUIHandler *uih, void *user_data, + const char *path); extern CamelSession *session; diff --git a/mail/session.c b/mail/session.c index 086a7c12fc..9f9072e93f 100644 --- a/mail/session.c +++ b/mail/session.c @@ -14,14 +14,6 @@ CamelSession *session; GHashTable *passwords; -/* FIXME: Will this ever be called in a non-async - * manner? Better hope not, cause if that happens - * we deadlock.... - */ - -#define ASYNC_AUTH_CALLBACK - -#ifndef ASYNC_AUTH_CALLBACK static void request_callback (gchar *string, gpointer data) { @@ -32,14 +24,12 @@ request_callback (gchar *string, gpointer data) else *ans = NULL; } -#endif char * -mail_request_dialog (const char *prompt, gboolean secret, const char *key) +mail_request_dialog (const char *prompt, gboolean secret, const char *key, + gboolean async) { -#ifndef ASYNC_AUTH_CALLBACK GtkWidget *dialog; -#endif char *ans; @@ -50,19 +40,18 @@ mail_request_dialog (const char *prompt, gboolean secret, const char *key) if (ans) return g_strdup (ans); -#ifndef ASYNC_AUTH_CALLBACK - /* XXX parent window? */ - dialog = gnome_request_dialog (secret, prompt, NULL, 0, - request_callback, &ans, NULL); - if (!dialog) - return NULL; - if (gnome_dialog_run_and_close (GNOME_DIALOG (dialog)) == -1 || - ans == NULL) - return NULL; -#else - if (!mail_op_get_password ((char *) prompt, secret, &ans)) - return NULL; -#endif + if (!async) { + dialog = gnome_request_dialog (secret, prompt, NULL, 0, + request_callback, &ans, NULL); + if (!dialog) + return NULL; + if (gnome_dialog_run_and_close (GNOME_DIALOG (dialog)) == -1 || + ans == NULL) + return NULL; + } else { + if (!mail_op_get_password ((char *) prompt, secret, &ans)) + return NULL; + } g_hash_table_insert (passwords, g_strdup (key), g_strdup (ans)); return ans; @@ -101,7 +90,7 @@ auth_callback (CamelAuthCallbackMode mode, char *data, gboolean secret, return NULL; } - ans = mail_request_dialog (data, secret, key); + ans = mail_request_dialog (data, secret, key, TRUE); g_free (key); if (!ans) { -- cgit v1.2.3