From f5ba4dde57c0bd90e16f515f3dacc8a68637b5d5 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Fri, 26 May 2000 14:46:13 +0000 Subject: Don't set a default boundary. Require the caller to do that. * camel-multipart.c (camel_multipart_init): Don't set a default boundary. Require the caller to do that. (set_boundary): if boundary is NULL, generate a "random" boundary. * camel-mime-part-utils.c (camel_mime_part_construct_content_from_parser): Add a call to camel_multipart_set_boundary after creating a new multipart. svn path=/trunk/; revision=3217 --- camel/camel-multipart.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'camel/camel-multipart.c') diff --git a/camel/camel-multipart.c b/camel/camel-multipart.c index ea1f7d356f..e28c6542bf 100644 --- a/camel/camel-multipart.c +++ b/camel/camel-multipart.c @@ -32,6 +32,10 @@ #include "camel-multipart.h" #include "camel-mime-part.h" #include "camel-exception.h" +#include "md5-utils.h" + +#include /* for getpid */ +#include /* for time */ #define d(x) @@ -98,7 +102,6 @@ camel_multipart_init (gpointer object, gpointer klass) camel_data_wrapper_set_mime_type (CAMEL_DATA_WRAPPER (multipart), "multipart/mixed"); - camel_multipart_set_boundary (multipart, "=-=-=-="); multipart->preface = NULL; multipart->postface = NULL; } @@ -356,9 +359,27 @@ static void set_boundary (CamelMultipart *multipart, gchar *boundary) { CamelDataWrapper *cdw = CAMEL_DATA_WRAPPER (multipart); + char *bgen, digest[16], bbuf[27], *p; + int state, save; g_return_if_fail (cdw->mime_type != NULL); + if (!boundary) { + /* Generate a fairly random boundary string. */ + bgen = g_strdup_printf ("%p:%lu:%lu", multipart, + (unsigned long) getpid(), + (unsigned long) time(0)); + md5_get_digest (bgen, strlen (bgen), digest); + g_free (bgen); + strcpy (bbuf, "=-"); + p = bbuf + 2; + state = save = 0; + p += base64_encode_step (digest, 16, p, &state, &save); + *p = '\0'; + + boundary = bbuf; + } + gmime_content_field_set_parameter (cdw->mime_type, "boundary", boundary); } @@ -366,17 +387,17 @@ set_boundary (CamelMultipart *multipart, gchar *boundary) /** * camel_multipart_set_boundary: * @multipart: a CamelMultipart - * @boundary: the message boundary + * @boundary: the message boundary, or %NULL * * Sets the message boundary for @multipart to @boundary. This should * be a string which does not occur anywhere in any of @multipart's - * subparts. + * subparts. If @boundary is %NULL, a randomly-generated boundary will + * be used. **/ void camel_multipart_set_boundary (CamelMultipart *multipart, gchar *boundary) { g_return_if_fail (CAMEL_IS_MULTIPART (multipart)); - g_return_if_fail (boundary != NULL); CMP_CLASS (multipart)->set_boundary (multipart, boundary); } -- cgit v1.2.3