Ejemplo n.º 1
0
static gboolean
emfe_error_format (EMailFormatterExtension *extension,
                   EMailFormatter *formatter,
                   EMailFormatterContext *context,
                   EMailPart *part,
                   GOutputStream *stream,
                   GCancellable *cancellable)
{
	GOutputStream *filtered_stream;
	CamelMimeFilter *filter;
	CamelMimePart *mime_part;
	CamelDataWrapper *dw;
	const gchar *string;
	gchar *html;

	mime_part = e_mail_part_ref_mime_part (part);
	dw = camel_medium_get_content (CAMEL_MEDIUM (mime_part));

	html = g_strdup_printf (
		"<div class=\"part-container -e-mail-formatter-frame-color "
		"-e-mail-formatter-body-color -e-web-view-text-color\">"
		"<div class=\"part-container-inner-margin pre\">\n"
		"<table border=\"0\" cellspacing=\"10\" "
		"cellpadding=\"0\" width=\"100%%\">\n"
		"<tr valign=\"top\"><td width=50>"
		"<img src=\"gtk-stock://%s/?size=%d\" /></td>\n"
		"<td style=\"color: red;\">",
		"dialog-error", GTK_ICON_SIZE_DIALOG);

	g_output_stream_write_all (
		stream, html, strlen (html), NULL, cancellable, NULL);

	g_free (html);

	filter = camel_mime_filter_tohtml_new (
		CAMEL_MIME_FILTER_TOHTML_CONVERT_NL |
		CAMEL_MIME_FILTER_TOHTML_CONVERT_URLS, 0);
	filtered_stream = camel_filter_output_stream_new (stream, filter);
	g_object_unref (filter);

	camel_data_wrapper_decode_to_output_stream_sync (
		dw, filtered_stream, cancellable, NULL);
	g_output_stream_flush (filtered_stream, cancellable, NULL);

	g_object_unref (filtered_stream);

	string = "</td></tr></table></div></div>";

	g_output_stream_write_all (
		stream, string, strlen (string), NULL, cancellable, NULL);

	g_object_unref (mime_part);

	return TRUE;
}
Ejemplo n.º 2
0
static void
write_message_to_stream_thread (GTask *task,
				gpointer source_object,
				gpointer task_data,
				GCancellable *cancellable)
{
	GOutputStream *output_stream;
	gssize bytes_written;
	GError *local_error = NULL;

	output_stream = task_data;

	bytes_written = camel_data_wrapper_decode_to_output_stream_sync (
		CAMEL_DATA_WRAPPER (source_object),
		output_stream, cancellable, &local_error);

	g_output_stream_close (output_stream, cancellable, local_error ? NULL : &local_error);

	if (local_error != NULL) {
		g_task_return_error (task, local_error);
	} else {
		g_task_return_int (task, bytes_written);
	}
}
Ejemplo n.º 3
0
static gboolean
emfe_image_format (EMailFormatterExtension *extension,
                   EMailFormatter *formatter,
                   EMailFormatterContext *context,
                   EMailPart *part,
                   GOutputStream *stream,
                   GCancellable *cancellable)
{
	gchar *content;
	CamelMimePart *mime_part;
	CamelDataWrapper *dw;
	GBytes *bytes;
	GOutputStream *raw_content;

	if (g_cancellable_is_cancelled (cancellable))
		return FALSE;

	mime_part = e_mail_part_ref_mime_part (part);
	dw = camel_medium_get_content (CAMEL_MEDIUM (mime_part));
	g_return_val_if_fail (dw, FALSE);

	raw_content = g_memory_output_stream_new_resizable ();
	camel_data_wrapper_decode_to_output_stream_sync (
		dw, raw_content, cancellable, NULL);
	g_output_stream_close (raw_content, NULL, NULL);

	bytes = g_memory_output_stream_steal_as_bytes (
		G_MEMORY_OUTPUT_STREAM (raw_content));

	if (context->mode == E_MAIL_FORMATTER_MODE_RAW) {

		if (!e_mail_formatter_get_animate_images (formatter)) {

			gchar *buff;
			gsize len;

			e_mail_part_animation_extract_frame (
				bytes, &buff, &len);

			g_output_stream_write_all (
				stream, buff, len, NULL, cancellable, NULL);

			g_free (buff);

		} else {
			gconstpointer data;
			gsize size;

			data = g_bytes_get_data (bytes, &size);

			g_output_stream_write_all (
				stream, data, size, NULL, cancellable, NULL);
		}

	} else {
		gchar *buffer;
		const gchar *mime_type;

		if (!e_mail_formatter_get_animate_images (formatter)) {

			gchar *buff;
			gsize len;

			e_mail_part_animation_extract_frame (
				bytes, &buff, &len);

			content = g_base64_encode ((guchar *) buff, len);
			g_free (buff);

		} else {
			gconstpointer data;
			gsize size;

			data = g_bytes_get_data (bytes, &size);
			content = g_base64_encode (data, size);
		}

		mime_type = e_mail_part_get_mime_type (part);
		if (mime_type == NULL)
			mime_type = "image/*";

		/* The image is already base64-encrypted so we can directly
		 * paste it to the output */
		buffer = g_strdup_printf (
			"<img src=\"data:%s;base64,%s\" "
			"     style=\"max-width: 100%%;\" />",
			mime_type, content);

		g_output_stream_write_all (
			stream, buffer, strlen (buffer),
			NULL, cancellable, NULL);

		g_free (buffer);
		g_free (content);
	}

	g_bytes_unref (bytes);

	g_object_unref (raw_content);

	g_object_unref (mime_part);

	return TRUE;
}