diff options
author | Jeffrey Stedfast <fejj@helixcode.com> | 2000-12-16 07:05:55 +0800 |
---|---|---|
committer | Jeffrey Stedfast <fejj@src.gnome.org> | 2000-12-16 07:05:55 +0800 |
commit | 96c13f461a2aa25578b766c56a895791108171f5 (patch) | |
tree | 93e3a995bf620854a80d25f215a19395e3edbd9f /mail/mail-format.c | |
parent | 7fbf92b1d677fdb27942e3e5e5b99577f0276275 (diff) | |
download | gsoc2013-evolution-96c13f461a2aa25578b766c56a895791108171f5.tar gsoc2013-evolution-96c13f461a2aa25578b766c56a895791108171f5.tar.gz gsoc2013-evolution-96c13f461a2aa25578b766c56a895791108171f5.tar.bz2 gsoc2013-evolution-96c13f461a2aa25578b766c56a895791108171f5.tar.lz gsoc2013-evolution-96c13f461a2aa25578b766c56a895791108171f5.tar.xz gsoc2013-evolution-96c13f461a2aa25578b766c56a895791108171f5.tar.zst gsoc2013-evolution-96c13f461a2aa25578b766c56a895791108171f5.zip |
New callback to handle multipart/signed parts. (decode_pgp): Update to
2000-12-15 Jeffrey Stedfast <fejj@helixcode.com>
* mail-format.c (handle_multipart_signed): New callback to handle
multipart/signed parts.
(decode_pgp): Update to account for the cipherlen argument needed
for openpgp_decrypt.
(is_rfc2015): Removed as we now have a better version in
mail-crypto.
(handle_multipart_encrypted): Updated to use the PGP/MIME utility
functions.
* mail-crypto.c (mail_crypto_openpgp_decrypt): Don't check
(!*plaintext) as it could be a binary stream. Now also takes a
cipherlen argument.
(mail_crypto_openpgp_sign): New function.
(pgp_mime_part_sign): New function to replace a mime part with the
pgp signed equivalent.
(pgp_mime_part_encrypt): New function to replace a mime part with
the pgp encrypted equivalent.
(pgp_mime_part_decrypt): New function to decrypt a pgp encrypted
mime part (like from pgp_mime_part_encrypt) and replace it.
(is_rfc2015_signed): New function to determine if a mime part is
an rfc2015 signed part.
(is_rfc2015_encrypted): New function to determine if a mime part
is an rfc2015 encrypted part.
(mail_crypto_openpgp_verify): New openpgp function to verify a
signature.
svn path=/trunk/; revision=7056
Diffstat (limited to 'mail/mail-format.c')
-rw-r--r-- | mail/mail-format.c | 124 |
1 files changed, 48 insertions, 76 deletions
diff --git a/mail/mail-format.c b/mail/mail-format.c index b7eb7dbea0..b63b9a8d3d 100644 --- a/mail/mail-format.c +++ b/mail/mail-format.c @@ -75,6 +75,9 @@ static gboolean handle_multipart_appledouble (CamelMimePart *part, static gboolean handle_multipart_encrypted (CamelMimePart *part, const char *mime_type, MailDisplay *md); +static gboolean handle_multipart_signed (CamelMimePart *part, + const char *mime_type, + MailDisplay *md); static gboolean handle_message_rfc822 (CamelMimePart *part, const char *mime_type, MailDisplay *md); @@ -305,6 +308,8 @@ setup_mime_tables (void) handle_multipart_appledouble); g_hash_table_insert (mime_function_table, "multipart/encrypted", handle_multipart_encrypted); + g_hash_table_insert (mime_function_table, "multipart/signed", + handle_multipart_signed); /* RFC 2046 says unrecognized text subtypes can be treated * as text/plain (as long as you recognize the character set), @@ -835,8 +840,9 @@ decode_pgp (const char *ciphertext, int *outlen, MailDisplay *md) camel_exception_init (&ex); #ifdef PGP_PROGRAM /* FIXME: multipart parts */ + /* another FIXME: this doesn't have to return plaintext you realize... */ if (g_datalist_get_data (md->data, "show_pgp")) { - plaintext = mail_crypto_openpgp_decrypt (ciphertext, outlen, &ex); + plaintext = mail_crypto_openpgp_decrypt (ciphertext, strlen (ciphertext), outlen, &ex); if (plaintext) return plaintext; } @@ -880,11 +886,12 @@ try_inline_pgp (char *start, MailDisplay *md) if (!end) return start; - end += sizeof ("-----END PGP MESSAGE-----") - 1; + end += strlen ("-----END PGP MESSAGE-----") - 1; mail_html_write (md->html, md->stream, "<hr>"); - /* FIXME: uhm, pgp decrypted data doesn't have to be plaintext */ + /* FIXME: uhm, pgp decrypted data doesn't have to be plaintext + * however, I suppose that since it was 'inline', it probably is */ ciphertext = g_strndup (start, end - start); plaintext = decode_pgp (ciphertext, &outlen, md); g_free (ciphertext); @@ -1189,90 +1196,55 @@ handle_multipart_mixed (CamelMimePart *part, const char *mime_type, } static gboolean -is_rfc2015 (CamelMimePart *part) +handle_multipart_encrypted (CamelMimePart *part, const char *mime_type, + MailDisplay *md) { - int nparts; - char *text; CamelDataWrapper *wrapper; - CamelMultipart *mp; - GMimeContentField *type; - - wrapper = camel_medium_get_content_object (CAMEL_MEDIUM (part)); - mp = CAMEL_MULTIPART (wrapper); - nparts = camel_multipart_get_number (mp); - if (nparts != 2) - return FALSE; - - /* Check for application/pgp-encrypted in the first part. */ - part = camel_multipart_get_part (mp, 0); - type = camel_mime_part_get_content_type (part); - if (!gmime_content_field_is_type (type, "application", "pgp-encrypted")) - return FALSE; - - /* Check version. */ + CamelMimePart *mime_part; + CamelException ex; + wrapper = camel_medium_get_content_object (CAMEL_MEDIUM (part)); - text = get_data_wrapper_text (wrapper); - if (!text || !strstr(text, "Version: 1")) { - g_free(text); - return FALSE; + g_return_val_if_fail (CAMEL_IS_MULTIPART (wrapper), FALSE); + + /* Currently we only handle RFC2015-style PGP encryption. */ + if (!is_rfc2015_encrypted (part)) + return handle_multipart_mixed (part, mime_type, md); + + camel_exception_init (&ex); + mime_part = pgp_mime_part_decrypt (part, &ex); + if (camel_exception_is_set (&ex)) { + /* I guess we just treat this as a multipart/mixed */ + return handle_multipart_mixed (part, mime_type, md); + } else { + gboolean retcode; + + retcode = call_handler_function (mime_part, md); + camel_object_unref (CAMEL_OBJECT (mime_part)); + + return retcode; } - g_free(text); - - /* Check for application/octet-stream in the second part. */ - part = camel_multipart_get_part(mp, 1); - type = camel_mime_part_get_content_type (part); - if (!gmime_content_field_is_type (type, "application", "octet-stream")) - return FALSE; - - return TRUE; } +/* FIXME: So this function is mostly just a place-holder for now */ static gboolean -handle_multipart_encrypted (CamelMimePart *part, const char *mime_type, - MailDisplay *md) +handle_multipart_signed (CamelMimePart *part, const char *mime_type, + MailDisplay *md) { - CamelDataWrapper *wrapper = - camel_medium_get_content_object (CAMEL_MEDIUM (part)); - CamelMultipart *mp; - char *ciphertext, *plaintext; - int outlen; - + CamelDataWrapper *wrapper; + CamelException ex; + gboolean valid; + + wrapper = camel_medium_get_content_object (CAMEL_MEDIUM (part)); g_return_val_if_fail (CAMEL_IS_MULTIPART (wrapper), FALSE); - mp = CAMEL_MULTIPART (wrapper); - - /* Currently we only handle RFC2015-style PGP encryption. */ - if (!is_rfc2015 (part)) + + /* Currently we only handle RFC2015-style PGP signatures. */ + if (!is_rfc2015_signed (part)) return handle_multipart_mixed (part, mime_type, md); - - part = camel_multipart_get_part (mp, 1); - wrapper = camel_medium_get_content_object (CAMEL_MEDIUM (part)); - ciphertext = get_data_wrapper_text (wrapper); - if (!ciphertext) - return FALSE; - /* FIXME: please note that decrypted data does NOT have to be plaintext */ - plaintext = decode_pgp (ciphertext, &outlen, md); - if (plaintext) { - 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)); - - mail_html_write (md->html, md->stream, - "<table width=\"100%%\" border=2 " - "cellpadding=4><tr><td>"); - call_handler_function (part, md); - mail_html_write (md->html, md->stream, "</td></tr></table>"); - camel_object_hook_event (CAMEL_OBJECT (md->current_message), - "finalize", destroy_part, part); - g_free (plaintext); - } - - return TRUE; + camel_exception_init (&ex); + valid = pgp_mime_part_verify (part, &ex); + + return valid; } /* As seen in RFC 2387! */ |