diff options
author | Jeffrey Stedfast <fejj@ximian.com> | 2001-03-17 08:11:55 +0800 |
---|---|---|
committer | Jeffrey Stedfast <fejj@src.gnome.org> | 2001-03-17 08:11:55 +0800 |
commit | b3ddd598997195c6c4944cfa931973bb32000e07 (patch) | |
tree | 833a316b19883d61150e0467c88858185795c227 /mail | |
parent | 6e914a335e31ef1189163038615b8b981ff01e07 (diff) | |
download | gsoc2013-evolution-b3ddd598997195c6c4944cfa931973bb32000e07.tar gsoc2013-evolution-b3ddd598997195c6c4944cfa931973bb32000e07.tar.gz gsoc2013-evolution-b3ddd598997195c6c4944cfa931973bb32000e07.tar.bz2 gsoc2013-evolution-b3ddd598997195c6c4944cfa931973bb32000e07.tar.lz gsoc2013-evolution-b3ddd598997195c6c4944cfa931973bb32000e07.tar.xz gsoc2013-evolution-b3ddd598997195c6c4944cfa931973bb32000e07.tar.zst gsoc2013-evolution-b3ddd598997195c6c4944cfa931973bb32000e07.zip |
New function to prepare the mime part and any subparts for pgp signing.
2001-03-16 Jeffrey Stedfast <fejj@ximian.com>
* mail-crypto.c (pgp_mime_part_sign_prepare_part): New function to
prepare the mime part and any subparts for pgp signing.
(pgp_mime_part_sign_restore_part): New convenience function to
undo the prepare_part.
(pgp_mime_part_sign): Don't assume the part passed in is a leaf
part, we could very easily get a multipart (and in fact were which
is why people have been having unexpected results when signing
messages with attachments) and set the encoding as if it were a
leaf part. Use our 2 new convenience functions to set the
encoding(s) instead.
svn path=/trunk/; revision=8766
Diffstat (limited to 'mail')
-rw-r--r-- | mail/ChangeLog | 13 | ||||
-rw-r--r-- | mail/mail-crypto.c | 72 |
2 files changed, 79 insertions, 6 deletions
diff --git a/mail/ChangeLog b/mail/ChangeLog index e78d9223c2..86117239bb 100644 --- a/mail/ChangeLog +++ b/mail/ChangeLog @@ -1,3 +1,16 @@ +2001-03-16 Jeffrey Stedfast <fejj@ximian.com> + + * mail-crypto.c (pgp_mime_part_sign_prepare_part): New function to + prepare the mime part and any subparts for pgp signing. + (pgp_mime_part_sign_restore_part): New convenience function to + undo the prepare_part. + (pgp_mime_part_sign): Don't assume the part passed in is a leaf + part, we could very easily get a multipart (and in fact were which + is why people have been having unexpected results when signing + messages with attachments) and set the encoding as if it were a + leaf part. Use our 2 new convenience functions to set the + encoding(s) instead. + 2001-03-15 Miguel de Icaza <miguel@ximian.com> * folder-browser-factory.c (folder_browser_setup_view_menus): Fix diff --git a/mail/mail-crypto.c b/mail/mail-crypto.c index 0ae5083c33..744a171c8e 100644 --- a/mail/mail-crypto.c +++ b/mail/mail-crypto.c @@ -214,6 +214,64 @@ mail_crypto_is_pkcs7_mime (CamelMimePart *mime_part) return FALSE; } +static void +pgp_mime_part_sign_restore_part (CamelMimePart *mime_part, GSList *encodings) +{ + CamelDataWrapper *wrapper; + + wrapper = camel_medium_get_content_object (CAMEL_MEDIUM (mime_part)); + if (!wrapper) + return; + + if (CAMEL_IS_MULTIPART (wrapper)) { + int parts, i; + + parts = camel_multipart_get_number (CAMEL_MULTIPART (wrapper)); + for (i = 0; i < parts; i++) { + CamelMimePart *part = camel_multipart_get_part (CAMEL_MULTIPART (wrapper), i); + + pgp_mime_part_sign_restore_part (part, encodings); + encodings = encodings->next; + } + } else { + CamelMimePartEncodingType encoding; + + encoding = GPOINTER_TO_INT (encodings->data); + + camel_mime_part_set_encoding (mime_part, encoding); + } +} + +static void +pgp_mime_part_sign_prepare_part (CamelMimePart *mime_part, GSList **encodings) +{ + CamelDataWrapper *wrapper; + int parts, i; + + wrapper = camel_medium_get_content_object (CAMEL_MEDIUM (mime_part)); + if (!wrapper) + return; + + if (CAMEL_IS_MULTIPART (wrapper)) { + parts = camel_multipart_get_number (CAMEL_MULTIPART (wrapper)); + for (i = 0; i < parts; i++) { + CamelMimePart *part = camel_multipart_get_part (CAMEL_MULTIPART (wrapper), i); + + pgp_mime_part_sign_prepare_part (part, encodings); + } + } else { + CamelMimePartEncodingType encoding; + + encoding = camel_mime_part_get_encoding (mime_part); + + /* the encoding should really be QP or Base64 */ + if (encoding != CAMEL_MIME_PART_ENCODING_BASE64) + camel_mime_part_set_encoding (mime_part, CAMEL_MIME_PART_ENCODING_QUOTEDPRINTABLE); + + *encodings = g_slist_append (*encodings, GINT_TO_POINTER (encoding)); + } +} + /** * pgp_mime_part_sign: @@ -231,7 +289,6 @@ pgp_mime_part_sign (CamelMimePart **mime_part, const gchar *userid, PgpHashType { CamelMimePart *part, *signed_part; CamelMultipart *multipart; - CamelMimePartEncodingType encoding; CamelContentType *mime_type; CamelStreamFilter *filtered_stream; CamelMimeFilter *crlf_filter, *from_filter; @@ -239,6 +296,7 @@ pgp_mime_part_sign (CamelMimePart **mime_part, const gchar *userid, PgpHashType GByteArray *content; gchar *signature; gchar *hash_type = NULL; + GSList *encodings = NULL; g_return_if_fail (*mime_part != NULL); g_return_if_fail (CAMEL_IS_MIME_PART (*mime_part)); @@ -246,11 +304,9 @@ pgp_mime_part_sign (CamelMimePart **mime_part, const gchar *userid, PgpHashType g_return_if_fail (hash != PGP_HASH_TYPE_NONE); part = *mime_part; - encoding = camel_mime_part_get_encoding (part); - /* the encoding should really be QP or Base64 */ - if (encoding != CAMEL_MIME_PART_ENCODING_BASE64) - camel_mime_part_set_encoding (part, CAMEL_MIME_PART_ENCODING_QUOTEDPRINTABLE); + /* Prepare all the parts for signing... */ + pgp_mime_part_sign_prepare_part (part, &encodings); /* get the cleartext */ content = g_byte_array_new (); @@ -273,10 +329,14 @@ pgp_mime_part_sign (CamelMimePart **mime_part, const gchar *userid, PgpHashType g_byte_array_free (content, TRUE); if (camel_exception_is_set (ex)) { /* restore the original encoding */ - camel_mime_part_set_encoding (part, encoding); + pgp_mime_part_sign_restore_part (part, encodings); + g_slist_free (encodings); return; } + /* we don't need these anymore... */ + g_slist_free (encodings); + /* construct the pgp-signature mime part */ fprintf (stderr, "signature:\n%s\n", signature); signed_part = camel_mime_part_new (); |