static gboolean emfe_text_enriched_format (EMailFormatterExtension *extension, EMailFormatter *formatter, EMailFormatterContext *context, EMailPart *part, GOutputStream *stream, GCancellable *cancellable) { GOutputStream *filtered_stream; CamelMimeFilter *filter; const gchar *mime_type; const gchar *string; gchar *str; guint32 filter_flags = 0; if (g_cancellable_is_cancelled (cancellable)) return FALSE; mime_type = e_mail_part_get_mime_type (part); if (g_strcmp0 (mime_type, "text/richtext") == 0) filter_flags = CAMEL_MIME_FILTER_ENRICHED_IS_RICHTEXT; filter = camel_mime_filter_enriched_new (filter_flags); filtered_stream = camel_filter_output_stream_new (stream, filter); g_filter_output_stream_set_close_base_stream ( G_FILTER_OUTPUT_STREAM (filtered_stream), FALSE); g_object_unref (filter); str = g_strdup_printf ( "<div class=\"part-container -e-mail-formatter-frame-color %s" "-e-web-view-background-color -e-web-view-text-color\">" "<div class=\"part-container-inner-margin\">\n", e_mail_part_get_frame_security_style (part)); g_output_stream_write_all ( stream, str, strlen (str), NULL, cancellable, NULL); g_free (str); e_mail_formatter_format_text ( formatter, part, filtered_stream, cancellable); g_output_stream_flush (filtered_stream, cancellable, NULL); g_object_unref (filtered_stream); string = "</div></div>"; g_output_stream_write_all ( stream, string, strlen (string), NULL, cancellable, NULL); return TRUE; }
static void mail_formatter_quote_run (EMailFormatter *formatter, EMailFormatterContext *context, GOutputStream *stream, GCancellable *cancellable) { EMailFormatterQuote *qf; EMailFormatterQuoteContext *qf_context; GQueue queue = G_QUEUE_INIT; GList *head, *link; const gchar *string; if (g_cancellable_is_cancelled (cancellable)) return; qf = E_MAIL_FORMATTER_QUOTE (formatter); qf_context = (EMailFormatterQuoteContext *) context; qf_context->qf_flags = qf->priv->flags; g_seekable_seek ( G_SEEKABLE (stream), 0, G_SEEK_SET, NULL, NULL); e_mail_part_list_queue_parts (context->part_list, NULL, &queue); head = g_queue_peek_head_link (&queue); for (link = head; link != NULL; link = g_list_next (link)) { EMailPart *part = E_MAIL_PART (link->data); const gchar *mime_type; if (e_mail_part_id_has_suffix (part, ".headers") && !(qf_context->qf_flags & E_MAIL_FORMATTER_QUOTE_FLAG_HEADERS)) { continue; } if (e_mail_part_id_has_suffix (part, ".rfc822")) { link = e_mail_formatter_find_rfc822_end_iter (link); continue; } if (part->is_hidden) continue; if (e_mail_part_get_is_attachment (part)) continue; mime_type = e_mail_part_get_mime_type (part); e_mail_formatter_format_as ( formatter, context, part, stream, mime_type, cancellable); } while (!g_queue_is_empty (&queue)) g_object_unref (g_queue_pop_head (&queue)); /* Before we were inserting the BR elements and the credits in front of * the actual HTML code of the message. But this was wrong as when WebKit * was loading the given HTML code that looked like * <br>CREDITS<html>MESSAGE_CODE</html> WebKit parsed it like * <html><br>CREDITS</html><html>MESSAGE_CODE</html>. As no elements are * allowed outside of the HTML root element WebKit wrapped them into * another HTML root element. Afterwards the first root element was * treated as the primary one and all the elements from the second's root * HEAD and BODY elements were moved to the first one. * Thus the HTML that was loaded into composer contained the i.e. META * or STYLE definitions in the body. * So if we want to put something into the message we have to put it into * the special span element and it will be moved to body in EHTMLEditorView */ if (qf->priv->credits && *qf->priv->credits) { gchar *credits = g_strdup_printf ( "<span class=\"-x-evo-to-body\"><pre>%s</pre></span>", qf->priv->credits); g_output_stream_write_all ( stream, credits, strlen (credits), NULL, cancellable, NULL); g_free (credits); } /* If we want to cite the message we have to append the special span element * after the message and cite it in EHTMLEditorView because of reasons * mentioned above */ if (qf->priv->flags & E_MAIL_FORMATTER_QUOTE_FLAG_CITE) { string = "<span class=\"-x-evo-cite-body\"><span>"; g_output_stream_write_all ( stream, string, strlen (string), NULL, cancellable, NULL); } }
static void mail_formatter_print_run (EMailFormatter *formatter, EMailFormatterContext *context, GOutputStream *stream, GCancellable *cancellable) { GQueue queue = G_QUEUE_INIT; GQueue attachments = G_QUEUE_INIT; GList *head, *link; const gchar *string; context->mode = E_MAIL_FORMATTER_MODE_PRINTING; string = "<!DOCTYPE HTML>\n" "<html>\n" "<head>\n" "<meta name=\"generator\" content=\"Evolution Mail\" />\n" "<title>Evolution Mail Display</title>\n" "<link type=\"text/css\" rel=\"stylesheet\" " " media=\"print\" href=\"" STYLESHEET_URI "/>\n" "</head>\n" "<body style=\"background: #FFF; color: #000;\">"; g_output_stream_write_all ( stream, string, strlen (string), NULL, cancellable, NULL); e_mail_part_list_queue_parts (context->part_list, NULL, &queue); head = g_queue_peek_head_link (&queue); for (link = head; link != NULL; link = g_list_next (link)) { EMailPart *part = E_MAIL_PART (link->data); const gchar *mime_type; gboolean ok; if (g_cancellable_is_cancelled (cancellable)) break; if (part->is_hidden && !part->is_error) { if (e_mail_part_id_has_suffix (part, ".rfc822")) { link = e_mail_formatter_find_rfc822_end_iter (link); } continue; } mime_type = e_mail_part_get_mime_type (part); if (mime_type == NULL) continue; if (e_mail_part_get_is_attachment (part)) { if (e_mail_part_get_cid (part) != NULL) continue; g_queue_push_tail (&attachments, part); } ok = e_mail_formatter_format_as ( formatter, context, part, stream, mime_type, cancellable); /* If the written part was message/rfc822 then * jump to the end of the message, because content * of the whole message has been formatted by * message_rfc822 formatter */ if (ok && e_mail_part_id_has_suffix (part, ".rfc822")) { link = e_mail_formatter_find_rfc822_end_iter (link); continue; } } while (!g_queue_is_empty (&queue)) g_object_unref (g_queue_pop_head (&queue)); /* This consumes the attachments queue. */ if (!g_queue_is_empty (&attachments)) mail_formatter_print_write_attachments ( formatter, &attachments, stream, cancellable); string = "</body></html>"; g_output_stream_write_all ( stream, string, strlen (string), NULL, cancellable, NULL); }
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; }