Revision 144 src/procmime.c

procmime.c (revision 144)
1 1
/*
2 2
 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3
 * Copyright (C) 1999-2004 Hiroyuki Yamamoto
3
 * Copyright (C) 1999-2005 Hiroyuki Yamamoto
4 4
 *
5 5
 * This program is free software; you can redistribute it and/or modify
6 6
 * it under the terms of the GNU General Public License as published by
......
35 35
#include "base64.h"
36 36
#include "quoted-printable.h"
37 37
#include "uuencode.h"
38
#include "unmime.h"
39 38
#include "html.h"
40 39
#include "codeconv.h"
41 40
#include "utils.h"
......
346 345

  
347 346
void procmime_scan_content_type(MimeInfo *mimeinfo, const gchar *content_type)
348 347
{
349
	gchar *delim, *p, *cnttype;
350
	gchar *buf;
351

  
352
	Xstrdup_a(buf, content_type, return);
353

  
354 348
	g_free(mimeinfo->content_type);
355 349
	g_free(mimeinfo->charset);
356 350
	g_free(mimeinfo->name);
351
	g_free(mimeinfo->boundary);
357 352
	mimeinfo->content_type = NULL;
358 353
	mimeinfo->charset      = NULL;
359 354
	mimeinfo->name         = NULL;
355
	mimeinfo->boundary     = NULL;
360 356

  
357
	procmime_scan_content_type_str(content_type, &mimeinfo->content_type,
358
				       &mimeinfo->charset, &mimeinfo->name,
359
				       &mimeinfo->boundary);
360

  
361
	mimeinfo->mime_type = procmime_scan_mime_type(mimeinfo->content_type);
362
	if (mimeinfo->mime_type == MIME_MULTIPART && !mimeinfo->boundary)
363
		mimeinfo->mime_type = MIME_TEXT;
364
}
365

  
366
void procmime_scan_content_type_str(const gchar *content_type,
367
				    gchar **mime_type, gchar **charset,
368
				    gchar **name, gchar **boundary)
369
{
370
	gchar *delim, *p;
371
	gchar *buf;
372

  
373
	Xstrdup_a(buf, content_type, return);
374

  
361 375
	if ((delim = strchr(buf, ';'))) *delim = '\0';
362
	mimeinfo->content_type = cnttype = g_strdup(g_strstrip(buf));
376
	if (mime_type)
377
		*mime_type = g_strdup(g_strstrip(buf));
363 378

  
364
	mimeinfo->mime_type = procmime_scan_mime_type(cnttype);
365

  
366 379
	if (!delim) return;
367 380
	p = delim + 1;
368 381

  
......
388 401
		}
389 402

  
390 403
		if (*value) {
391
			if (!strcasecmp(attr, "charset"))
392
				mimeinfo->charset = g_strdup(value);
393
			else if (!strcasecmp(attr, "name")) {
404
			if (charset && !g_strcasecmp(attr, "charset"))
405
				*charset = g_strdup(value);
406
			else if (name && !g_strcasecmp(attr, "name")) {
394 407
				gchar *tmp;
395 408
				size_t len;
396 409

  
397 410
				len = strlen(value) + 1;
398 411
				Xalloca(tmp, len, return);
399 412
				conv_unmime_header(tmp, len, value, NULL);
400
				mimeinfo->name = g_strdup(tmp);
401
			} else if (!strcasecmp(attr, "boundary"))
402
				mimeinfo->boundary = g_strdup(value);
413
				*name = g_strdup(tmp);
414
			} else if (boundary && !g_strcasecmp(attr, "boundary"))
415
				*boundary = g_strdup(value);
403 416
		}
404 417

  
405 418
		if (!delim) break;
406 419
		p = delim + 1;
407 420
	}
408

  
409
	if (mimeinfo->mime_type == MIME_MULTIPART && !mimeinfo->boundary)
410
		mimeinfo->mime_type = MIME_TEXT;
411 421
}
412 422

  
413 423
void procmime_scan_content_disposition(MimeInfo *mimeinfo,

Also available in: Unified diff