litehtml::tstring url;
make_url(bg.image.c_str(), bg.baseurl.c_str(), url);
- lock_images_cache();
- bool found = false;
const image *img_i = NULL;
+ lock_images_cache();
+
for (auto ii = m_images.cbegin(); ii != m_images.cend(); ++ii) {
const image *i = &(*ii);
if (i->first == url) {
img_i = i;
- found = true;
break;
}
}
void add_image_to_cache(const gchar *url, GdkPixbuf *image);
virtual void redraw(gboolean force_render) = 0;
+ virtual GdkPixbuf *get_local_image(const litehtml::tstring url) const = 0;
protected:
virtual void draw_ellipse(cairo_t* cr, int x, int y, int width, int height, const litehtml::web_color& color, int line_width);
GdkPixbuf *pixbuf = NULL;
http* http_loader = NULL;
- if (!lh_prefs_get()->enable_remote_content) {
- debug_print("blocking download of image from '%s'\n", url);
- return NULL;
- }
-
- debug_print("allowing download of image from '%s'\n", url);
-
http_loader = new http();
GInputStream *image = http_loader->load_url(url, &error);
unlock_images_cache();
- if(!found) {
+ if (!found) {
struct FetchCtx *ctx = g_new(struct FetchCtx, 1);
+
+ /* Attached images can be loaded into cache right here. */
+ if (!strncmp(src, "cid:", 4)) {
+ GdkPixbuf *pixbuf = get_local_image(src);
+
+ if (pixbuf != NULL)
+ add_image_to_cache(src, pixbuf);
+
+ return;
+ }
+
+ if (!lh_prefs_get()->enable_remote_content) {
+ debug_print("blocking download of image from '%s'\n", src);
+ return;
+ }
+
+ debug_print("allowing download of image from '%s'\n", src);
+
ctx->url = g_strdup(url.c_str());
ctx->container = this;
return;
}
+ lh_widget_set_partinfo(viewer->widget, partinfo);
lh_widget_open_html(viewer->widget, utf8);
g_free(utf8);
}
m_font_name = NULL;
m_font_size = 0;
+ m_partinfo = NULL;
+
gtk_widget_set_events(m_drawing_area,
GDK_BUTTON_RELEASE_MASK
| GDK_BUTTON_PRESS_MASK
return _t(url);
}
+void lh_widget::set_partinfo(MimeInfo *partinfo)
+{
+ m_partinfo = partinfo;
+}
+
+GdkPixbuf *lh_widget::get_local_image(const litehtml::tstring url) const
+{
+ GdkPixbuf *pixbuf;
+ const gchar *name;
+ MimeInfo *p = m_partinfo;
+
+ if (strncmp(url.c_str(), "cid:", 4) != 0) {
+ debug_print("lh_widget::get_local_image: '%s' is not a local URI, ignoring\n", url.c_str());
+ return NULL;
+ }
+
+ name = url.c_str() + 4;
+ debug_print("getting message part '%s'\n", name);
+
+ while ((p = procmime_mimeinfo_next(p)) != NULL) {
+ size_t len = strlen(name);
+
+ /* p->id is in format "<partname>" */
+ if (!strncasecmp(name, p->id + 1, len) &&
+ strlen(p->id) >= len + 2 &&
+ *(p->id + len + 1) == '>') {
+ GInputStream *stream;
+ GError *error = NULL;
+
+ stream = procmime_get_part_as_inputstream(p, &error);
+ if (error != NULL) {
+ g_warning("Couldn't get image MIME part: %s\n", error->message);
+ g_error_free(error);
+ return NULL;
+ }
+
+ pixbuf = gdk_pixbuf_new_from_stream(stream, NULL, &error);
+ g_object_unref(stream);
+ if (error != NULL) {
+ g_warning("Couldn't load image: %s\n", error->message);
+ g_error_free(error);
+ return NULL;
+ }
+
+ return pixbuf;
+ }
+ }
+
+ /* MIME part with requested name was not found */
+ return NULL;
+}
+
////////////////////////////////////////////////
static gboolean expose_event_cb(GtkWidget *widget, GdkEvent *event,
gpointer user_data)
w->print();
}
+void lh_widget_set_partinfo(lh_widget_wrapped *w, MimeInfo *partinfo)
+{
+ w->set_partinfo(partinfo);
+}
+
} /* extern "C" */
#include <glib.h>
#include <gio/gio.h>
+#include "procmime.h"
+
#include "container_linux.h"
struct pango_font
void popup_context_menu(const litehtml::tchar_t *url, GdkEventButton *event);
const litehtml::tstring fullurl(const litehtml::tchar_t *url) const;
+ void set_partinfo(MimeInfo *partinfo);
+ GdkPixbuf *get_local_image(const litehtml::tstring url) const;
+
litehtml::document::ptr m_html;
litehtml::tstring m_clicked_url;
litehtml::tstring m_base_url;
litehtml::context m_context;
gint m_height;
litehtml::tstring m_cursor;
+ MimeInfo *m_partinfo;
litehtml::tchar_t *m_font_name;
int m_font_size;
void lh_widget_statusbar_push(const gchar* msg);
void lh_widget_statusbar_pop();
void lh_widget_print(lh_widget_wrapped *w);
+void lh_widget_set_partinfo(lh_widget_wrapped *w, MimeInfo *partinfo);
#ifdef __cplusplus
} /* extern "C" */