@@ -334,93 +334,24 @@ static GMimeContentType *find_type(const char *s)
334
334
return type ;
335
335
}
336
336
337
- static bool simple_boundary (const char * s , char * boundary )
338
- {
339
- int i = 0 ;
340
- bool wantquote = false;
341
- s += 9 ; // jump past 'boundary='
342
- if (s [0 ] == '"' ) {
343
- wantquote = true;
344
- s ++ ;
345
- }
346
- while (s [i ]) {
347
- if (wantquote && s [i ]== '"' ) {
348
- break ;
349
- }
350
- if (! wantquote && (isspace (s [i ]) || s [i ]== ';' ))
351
- break ;
352
- i ++ ;
353
- }
354
-
355
- strncpy (boundary , s , min (i , MAX_MIME_BLEN - 1 ));
356
- return true;
357
- }
358
-
359
- static bool wrapped_boundary (const char * s , char * boundary )
360
- {
361
- int i = 0 ;
362
- int decimal = 0 ;
363
- size_t buflen = MAX_MIME_BLEN - 1 ;
364
- char match [128 ];
365
- s += 11 ; // jump past 'boundary*0='
366
- while (true) {
367
- bool wantquote = false;
368
- if (s [0 ] == '"' ) {
369
- wantquote = true;
370
- s ++ ;
371
- }
372
- while (s [i ]) {
373
- if (wantquote && s [i ] == '"' )
374
- break ;
375
- if (! wantquote && (isspace (s [i ]) || s [i ]== ';' ))
376
- break ;
377
- i ++ ;
378
- }
379
- strncat (boundary , s , min (i , buflen ));
380
-
381
- if (! s [i ])
382
- break ;
383
-
384
- buflen = MAX_MIME_BLEN - strlen (boundary ) - 1 ;
385
- decimal ++ ;
386
-
387
- memset (match , 0 , sizeof (match ));
388
- snprintf (match , sizeof (match )- 1 , "boundary*%d=" , decimal );
389
- s = g_strcasestr (& s [i ], match );
390
- if (! s )
391
- break ;
392
-
393
- s += strlen (match );
394
- i = 0 ;
395
-
396
- if (! s [i ])
397
- break ;
398
-
399
- }
400
- return true;
401
- }
402
-
337
+ #define MAX_MIME_DEPTH 64
338
+ #define MAX_MIME_BLEN 128
403
339
404
340
static bool find_boundary (const char * s , char * boundary )
405
341
{
406
- char * rest = NULL ;
407
- char * type = find_type_header (s );
408
-
409
- memset (boundary , 0 , MAX_MIME_BLEN );
342
+ const gchar * param ;
343
+ GMimeContentType * type = find_type (s );
410
344
if (! type )
411
345
return false;
412
-
413
- if ((rest = g_strcasestr (type , "boundary=" ))) {
414
- g_free (type );
415
- return simple_boundary (rest , boundary );
416
- }
417
- if ((rest = g_strcasestr (type , "boundary*0=" ))) {
418
- g_free (type );
419
- return wrapped_boundary (rest , boundary );
346
+ param = g_mime_content_type_get_parameter (type , "boundary" );
347
+ if (! param ) {
348
+ g_object_unref (type );
349
+ return false;
420
350
}
421
-
422
- g_free (type );
423
- return false;
351
+ memset (boundary , 0 , MAX_MIME_BLEN );
352
+ strncpy (boundary , param , MAX_MIME_BLEN - 1 );
353
+ g_object_unref (type );
354
+ return true;
424
355
}
425
356
426
357
static DbmailMessage * _mime_retrieve (DbmailMessage * self )
@@ -506,7 +437,7 @@ static DbmailMessage * _mime_retrieve(DbmailMessage *self)
506
437
507
438
got_boundary = FALSE;
508
439
509
- if (is_header && find_boundary (str , boundary )) {
440
+ if (is_header && find_boundary (str , & boundary [ 0 ] )) {
510
441
got_boundary = TRUE;
511
442
dprint ("<boundary depth=\"%d\">%s</boundary>\n" , depth , boundary );
512
443
strncpy (blist [depth ], boundary , MAX_MIME_BLEN - 1 );
0 commit comments