Improve external HTML content filtering
Balsa's HTML message display has the option to suppress loading images by using Webkit's auto-load-images
property, basically for protecting the user's privacy. This property is disabled whenever a regexp search of the HTML body indicates that images shall be loaded from a remote server. The user may select (or configure for a particular sender) to load the external images. If a message contains embedded images only, they are always displayed.
This approach has two disadvantages:
- if the message contains a mixture of embedded and external images, the embedded ones are not displayed, although this would be completely safe, and
- other external resources like fonts or style sheets which may also be used to track the recipient's activity are always loaded.
IMHO, a better solution is to catch the WebKitWebPage::send-request
signal and to decide whether an external resource shall be loaded or blocked. However, to this end a webkit web extension must be used, which is loaded from from a shared object in a specific folder (see this discussion thread).
I created a new branch html-filter which implements this approach. Some remarks:
- Webkit provides some methods for the communication between the main process (balsa) and the web page rendering process, but unfortunately no means for synchronisation. Therefore, when balsa's
WebKitWebContext
is initialised, a dummyWebKitWebView
is created as to trigger loading the filter extension, and the main process is delayed until this has been finished. If this fails for some reason, balsa falls back to the current filtering method. - balsa sends a
WebKitUserMessage
to the WebKitWebPage process when a newWebKitWebView
is created, and then simply sleeps for 1 millisecond. This seems to work for me, but it might be necessary to be extended. - Unfortunately, Webkit loads extensions from a single folder only. In order to enable testing it, I added the
#define WEB_EXT_CHECK_BUILDDIR
to libbalsa/html.c, line 54. Iff this define is set, balsa sets the extension folder to the build folder (tested with both autoconf and meson), falling back the the regular installation folder if the extension is not there. This, for a release build or packaging, this symbol should be undef'ed as to avoid leaking the build folder. I have no idea how this could be automated, though. - Filtered (missing) images are displayed as empty frame with a broken image icon in it. However, the size and/or aspect ratio of the frame may or may not be correct, no idea how I could fix that.
As always, any feedback will be highly appreciated!