Beispiel #1
0
GMimeContentType *
_g_mime_content_type_parse (GMimeParserOptions *options, const char *str, gint64 offset)
{
	GMimeContentType *content_type;
	const char *inptr = str;
	GMimeParamList *params;
	char *type, *subtype;
	
	g_return_val_if_fail (str != NULL, NULL);
	
	if (!g_mime_parse_content_type (&inptr, &type, &subtype)) {
		_g_mime_parser_options_warn (options, offset, GMIME_WARN_INVALID_CONTENT_TYPE, str);
		return g_mime_content_type_new ("application", "octet-stream");
	}
	
	content_type = g_object_new (GMIME_TYPE_CONTENT_TYPE, NULL);
	content_type->subtype = subtype;
	content_type->type = type;
	
	/* skip past any remaining junk that shouldn't be here... */
	skip_cfws (&inptr);
	while (*inptr && *inptr != ';')
		inptr++;
	
	if (*inptr++ == ';' && *inptr && (params = _g_mime_param_list_parse (options, inptr, offset))) {
		g_mime_event_add (params->changed, (GMimeEventCallback) param_list_changed, content_type);
		g_object_unref (content_type->params);
		content_type->params = params;
	}
	
	return content_type;
}
Beispiel #2
0
/**
 * g_mime_content_type_new_from_string:
 * @str: input string containing a content-type (and params)
 *
 * Constructs a new Content-Type object based on the input string.
 *
 * Returns: a new #GMimeContentType object based on the input string.
 **/
GMimeContentType *
g_mime_content_type_new_from_string (const char *str)
{
	GMimeContentType *mime_type;
	const char *inptr = str;
	char *type, *subtype;
	
	g_return_val_if_fail (str != NULL, NULL);
	
	if (!g_mime_parse_content_type (&inptr, &type, &subtype))
		return g_mime_content_type_new ("application", "octet-stream");
	
	mime_type = g_object_newv (GMIME_TYPE_CONTENT_TYPE, 0, NULL);
	mime_type->subtype = subtype;
	mime_type->type = type;
	
	/* skip past any remaining junk that shouldn't be here... */
	decode_lwsp (&inptr);
	while (*inptr && *inptr != ';')
		inptr++;
	
	if (*inptr++ == ';' && *inptr) {
		GMimeParam *param;
		
		param = mime_type->params = g_mime_param_new_from_string (inptr);
		while (param != NULL) {
			g_hash_table_insert (mime_type->param_hash, param->name, param);
			param = param->next;
		}
	}
	
	return mime_type;
}
Beispiel #3
0
static void
choose_alternative(GMimeObject *part)
{
	GList *l, *fpart;
	l = GMIME_MULTIPART(part)->subparts;
	// Look for a preferred part in this order:
	// * multipart/relative
	// * text/html unless text_only
	// * text/plain
	if (fpart = g_list_find_custom(l, g_mime_content_type_new("multipart", "related"), (GCompareFunc)find_part_of_type)) {
		choose_alternative(fpart->data);
		return;
	}
	if ((fpart = g_list_find_custom(l, g_mime_content_type_new("text", "html"), (GCompareFunc)find_part_of_type)) && text_only == 0) {
		write_part(fpart->data);
		return;
	}	
	if (fpart = g_list_find_custom(l, g_mime_content_type_new("text", "plain"), (GCompareFunc)find_part_of_type)) {
		write_part(fpart->data);
		return;
	}
}
Beispiel #4
0
/**
 * g_mime_message_part_new:
 * @subtype: message subtype or %NULL for "rfc822"
 *
 * Creates a new MIME message part object with a default content-type
 * of message/@subtype.
 *
 * Returns: an empty MIME message part object with a default
 * content-type of message/@subtype.
 **/
GMimeMessagePart *
g_mime_message_part_new (const char *subtype)
{
	GMimeContentType *content_type;
	GMimeMessagePart *part;
	
	part = g_object_new (GMIME_TYPE_MESSAGE_PART, NULL);
	
	content_type = g_mime_content_type_new ("message", subtype ? subtype : "rfc822");
	g_mime_object_set_content_type ((GMimeObject *) part, content_type);
	g_object_unref (content_type);
	
	return part;
}
Beispiel #5
0
/**
 * g_mime_multipart_new_with_subtype:
 * @subtype: content-type subtype
 *
 * Creates a new MIME multipart object with a content-type of
 * multipart/@subtype.
 *
 * Returns: an empty MIME multipart object with a content-type of
 * multipart/@subtype.
 **/
GMimeMultipart *
g_mime_multipart_new_with_subtype (const char *subtype)
{
	GMimeContentType *content_type;
	GMimeMultipart *multipart;
	
	multipart = g_object_newv (GMIME_TYPE_MULTIPART, 0, NULL);
	
	content_type = g_mime_content_type_new ("multipart", subtype ? subtype : "mixed");
	g_mime_object_set_content_type (GMIME_OBJECT (multipart), content_type);
	g_object_unref (content_type);
	
	return multipart;
}
Beispiel #6
0
/**
 * g_mime_part_new_with_type:
 * @type: content-type string
 * @subtype: content-subtype string
 *
 * Creates a new MIME Part with a sepcified type.
 *
 * Returns: an empty MIME Part object with the specified content-type.
 **/
GMimePart *
g_mime_part_new_with_type (const char *type, const char *subtype)
{
	GMimeContentType *content_type;
	GMimePart *mime_part;
	
	mime_part = g_object_newv (GMIME_TYPE_PART, 0, NULL);
	
	content_type = g_mime_content_type_new (type, subtype);
	g_mime_object_set_content_type (GMIME_OBJECT (mime_part), content_type);
	g_object_unref (content_type);
	
	return mime_part;
}
Beispiel #7
0
/**
 * g_mime_part_new:
 *
 * Creates a new MIME Part object with a default content-type of
 * text/plain.
 *
 * Returns: an empty MIME Part object with a default content-type of
 * text/plain.
 **/
GMimePart *
g_mime_part_new (void)
{
	GMimeContentType *content_type;
	GMimePart *mime_part;
	
	mime_part = g_object_newv (GMIME_TYPE_PART, 0, NULL);
	
	content_type = g_mime_content_type_new ("text", "plain");
	g_mime_object_set_content_type (GMIME_OBJECT (mime_part), content_type);
	g_object_unref (content_type);
	
	return mime_part;
}