353
353
if (message_is_html) {
354
354
web_view.load_html (message_content);
356
web_view.load_plain_text (message_content);
357
* Instead of calling web_view.load_plain_text, use Camel's ToHTML
358
* filter to convert text to HTML. This gives us some niceties like
359
* clickable URLs and email addresses for free.
361
* Explanation of MimeFilterToHTMLFlags:
362
* https://wiki.gnome.org/Apps/Evolution/Camel.MimeFilter#Camel.MimeFilterToHtml
364
var flags = Camel.MimeFilterToHTMLFlags.CONVERT_NL |
365
Camel.MimeFilterToHTMLFlags.CONVERT_SPACES |
366
Camel.MimeFilterToHTMLFlags.CONVERT_URLS |
367
Camel.MimeFilterToHTMLFlags.CONVERT_ADDRESSES;
368
var html = Camel.text_to_html (message_content, flags, 0);
369
web_view.load_html (html);
360
private async void parse_mime_content (Camel.DataWrapper message_content) {
361
if (message_content is Camel.Multipart) {
362
var content = message_content as Camel.Multipart;
373
private async void parse_mime_content (Camel.DataWrapper mime_content) {
374
if (mime_content is Camel.Multipart) {
375
var content = mime_content as Camel.Multipart;
363
376
for (uint i = 0; i < content.get_number (); i++) {
364
377
var part = content.get_part (i);
365
378
var field = part.get_mime_type_field ();
391
message_content = (string) os.steal_data ();
404
// Convert the message to UTF-8 to ensure we have a valid GLib string.
405
message_content = convert_to_utf8 (os, field.param ("charset"));
392
407
if (field.subtype == "html") {
393
408
message_is_html = true;
413
private static string convert_to_utf8 (GLib.MemoryOutputStream os, string? encoding) {
414
var num_bytes = (int) os.get_data_size ();
415
var bytes = (string) os.steal_data ();
419
if (encoding != null) {
420
string? iconv_encoding = Camel.iconv_charset_name (encoding);
421
if (iconv_encoding != null) {
423
utf8 = GLib.convert (bytes, num_bytes, "UTF-8", iconv_encoding);
424
} catch (ConvertError e) {
425
// Nothing to do - result will be assigned below.
430
if (utf8 == null || !utf8.validate ()) {
432
* If message_content is not valid UTF-8 at this point, assume that
433
* it is ISO-8859-1 encoded by default, and convert it to UTF-8.
436
utf8 = GLib.convert (bytes, num_bytes, "UTF-8", "ISO-8859-1");
437
} catch (ConvertError e) {
438
critical ("Every string should be valid ISO-8859-1. ConvertError: %s", e.message);
398
446
private async void handle_inline_mime (Camel.MimePart part) {
399
447
var byte_array = new ByteArray ();
400
448
var os = new Camel.StreamMem ();
410
bytes = ByteArray.free_to_bytes (byte_array);
457
Bytes bytes = ByteArray.free_to_bytes (byte_array);
411
458
var inline_stream = new MemoryInputStream.from_bytes (bytes);
412
459
web_view.add_internal_resource (part.get_content_id (), inline_stream);