Closes #4499. Inline images will be shown in the message viewer.
This commit is contained in:
parent
0258a20ad9
commit
1200e477bf
2 changed files with 52 additions and 3 deletions
|
|
@ -755,7 +755,7 @@ public class MessageViewer : WebKit.WebView {
|
|||
string body_text = "";
|
||||
try {
|
||||
body_text = email.get_message().get_first_mime_part_of_content_type("text/html").to_string();
|
||||
body_text = insert_html_markup(body_text);
|
||||
body_text = insert_html_markup(body_text, email);
|
||||
} catch (Error err) {
|
||||
try {
|
||||
body_text = linkify_and_escape_plain_text(email.get_message().
|
||||
|
|
@ -765,7 +765,7 @@ public class MessageViewer : WebKit.WebView {
|
|||
debug("Could not get message text. %s", err2.message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Graft header and email body into the email container.
|
||||
try {
|
||||
WebKit.DOM.HTMLElement table_header =
|
||||
|
|
@ -1225,7 +1225,7 @@ public class MessageViewer : WebKit.WebView {
|
|||
return "<pre>" + set_up_quotes(message + signature) + "</pre>";
|
||||
}
|
||||
|
||||
private string insert_html_markup(string text) {
|
||||
private string insert_html_markup(string text, Geary.Email email) {
|
||||
try {
|
||||
// Create a workspace for manipulating the HTML.
|
||||
WebKit.DOM.Document document = get_dom_document();
|
||||
|
|
@ -1268,6 +1268,25 @@ public class MessageViewer : WebKit.WebView {
|
|||
// Now look for the signature.
|
||||
wrap_html_signature(ref container);
|
||||
|
||||
// Then get all inline images and replace them with data URLs.
|
||||
WebKit.DOM.NodeList inline_list = container.query_selector_all("img[src^=\"cid:\"]");
|
||||
for (int i = 0; i < inline_list.length; ++i) {
|
||||
// Get the MIME content for the image.
|
||||
WebKit.DOM.HTMLImageElement img = (WebKit.DOM.HTMLImageElement) inline_list.item(i);
|
||||
string mime_id = img.get_attribute("src").substring(4);
|
||||
Geary.Memory.AbstractBuffer image_content =
|
||||
email.get_message().get_content_by_mime_id(mime_id);
|
||||
uint8[] image_data = image_content.get_array();
|
||||
|
||||
// Get the content type.
|
||||
bool uncertain_content_type;
|
||||
string mimetype = ContentType.get_mime_type(ContentType.guess(null, image_data,
|
||||
out uncertain_content_type));
|
||||
|
||||
// Then set the source to a data url.
|
||||
set_data_url(img, mimetype, image_data);
|
||||
}
|
||||
|
||||
// Now return the whole message.
|
||||
return set_up_quotes(container.get_inner_html());
|
||||
} catch (Error e) {
|
||||
|
|
|
|||
|
|
@ -289,6 +289,36 @@ public class Geary.RFC822.Message : Object {
|
|||
return null;
|
||||
}
|
||||
|
||||
public Geary.Memory.AbstractBuffer get_content_by_mime_id(string mime_id) throws RFC822Error {
|
||||
GMime.Part? part = find_mime_part_by_mime_id(message.get_mime_part(), mime_id);
|
||||
if (part == null) {
|
||||
throw new RFC822Error.NOT_FOUND("Could not find a MIME part with content-id %s",
|
||||
mime_id);
|
||||
}
|
||||
return mime_part_to_memory_buffer(part);
|
||||
}
|
||||
|
||||
private GMime.Part? find_mime_part_by_mime_id(GMime.Object root, string mime_id) {
|
||||
// If this is a multipart container, check each of its children.
|
||||
if (root is GMime.Multipart) {
|
||||
GMime.Multipart multipart = root as GMime.Multipart;
|
||||
int count = multipart.get_count();
|
||||
for (int i = 0; i < count; ++i) {
|
||||
GMime.Part? child_part = find_mime_part_by_mime_id(multipart.get_part(i), mime_id);
|
||||
if (child_part != null) {
|
||||
return child_part;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise, check this part's content id.
|
||||
GMime.Part? part = root as GMime.Part;
|
||||
if (part != null && part.get_content_id() == mime_id) {
|
||||
return part;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
internal Gee.List<GMime.Part> get_attachments() throws RFC822Error {
|
||||
Gee.List<GMime.Part> attachments = new Gee.ArrayList<GMime.Part>();
|
||||
find_attachments( ref attachments, message.get_mime_part() );
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue