This action requires saving a cookie to remember the page's state. You can read more about that on the cookies page.

 

Black theme for kmail content

Released on: 2020-09-17

Update: A few months after I released this; kmail released an update that stopped this functionality from having an effect. A month or so later; another update caused it to always crash on startup. I have not put time into solving these, and am no longer using kmail. This post remains up for interest only.

Kmail is a fully-featured email client that is native to KDE. It’s fast, configurable, and simply a pleasure to use.

Returning to kmail

A few years ago, I was doing a migration from an old laptop to a new one, and never quite got around to migrating kmail. I made do with Gmail for all of this time. But then a bug introduced last year, that still isn’t fixed, annoyed me enough that I explored kmail again… It was a breath of fresh air. How did I wait this long to get back in to it?!

In any case, I worked through testing all of my work flow.

The challenge

One aspect that was holding me back, was that HTML based email is much more common now. And that brings with it a wild west of formatting hacks that people do to try to stand out, but utterly destroy accessibility. Kmail does a really good job colouring sensibly formed content to the system theme, but falls apart when the email has colour hard-coded into the email. And even more so when only one of the background or foreground are set.

The solution

That’s where this project comes in. I started it as an isolated github project. But as I continued, it made sense to make it part of my existing colouredWeb project that I had previously discontinued. - I had already done the work of making CSS that works almost flawlessly, almost everywhere. So why re-invent the wheel?

But first let’s get a quick taste of what it can do:

A collection of screenshots showing different themes over the same content.
Above: A collection of screenshots showing different themes over the same content.

  • Bottom right: How the email original displayed. - They’ve coloured the background, but not the foreground.
  • Top right: The default theme that is installed when you install my project.
  • Left: A small sample of the many other themes currently available (there will be more!).

The continuum

There’s a continuum for how extreme we want to get in the pursuit of accessibility:

  • Display the email entirely as the author intended. - It might be pretty. But is absolutely useless for someone with more specific needs.
  • Kmail tries to re-colour the email to the system theme. - Works on a lot of basic content, but falls down on content where the author hasn’t taken accessibility into account (pretty much all commercial email, and notifications.)
  • Apply CSS from colouredWeb. - This got me a long way forwards. But still missed an annoying ~20% of email where values were hard-coded into the HTML.
  • Strip out hard-coded colour values. - This works on pretty much everything. The catch is when someone has highlighted something and expects that you can see it. That’s a terrible idea for accessibility anyway, and they shouldn’t do it. But they do, and this doesn’t currently handle that well.

I’m currently using it in it’s most extreme form, and loving it. Everything is readable, and pleasant on the eyes. For me, the trade-off of not seeing highlighted content is worth having everything easily readable. I recommened this approach for everyone. (If the content authors would like to use page-wide CSS, they will get a more predictable result that we can tune to be more accessible, without stripping out the meaning.)

But if you’d like a less heavy-handed approach. Those options are available as well.

How it works

Methods

CSS filter

This was my first idea, when I was supposed to be sleeping. Essentially, you

  • Create a custom filter that matches every email
  • Pipe it through a script that
    • matches against a loosely expected string
    • replaces that with the original, plus some code to include a stylesheet at an expected file path that has been placed during install time.

Yay! Job done. I can go back to sleep now.

Oh look, kmail inserts it’s own CSS to format the to/from box and a few other bits…. I can uuuuuuuse this!

CSS in-place

This simply appends the CSS to a CSS file that kmail inserts into the email.

It’s pretty reliable. It’s fast. It doesn’t need filters to be run, so works on old email without having to CTRL-J to run the filter.

But like the original CSS filter, when colours are hard coded into the HTML rather than using a stylesheet, things still get screwed up.

Rolls up sleeves.

This time it’s personal!

Filtering out colours

This is the point where the filter script went from pretty much being a one liner, to most definitely not being a one-liner. Although in fairness, that’s just to keep it readable and easy for other people to understand and modify. In reality, it would be pretty easy to run it in a one-liner still. Let’s not, though.

Essentially, this builds up a long list of search and replace regexes to strip out colour information. This is heavy-handed, but it works really well. At this point, it’s very rare that an email is not readable. The consequence is that now when someone has differentiated text solely by changing its colour (which they should never do), that information is lost, and communication assumptions may break. - You have been warned.

Where does the CSS come from?

One of the advantages of me building and using colouredWeb for so long is that it runs pretty well against pretty much everything. I’ve made a few tweaks to it. But largely, it’s just the way I left it several years ago, and it’s running fantastically. (There we go, some Apply-style marketing. :p )

In making all of this more approachable, I’ve switched to committing-in generated stylesheets rather than generating them on the fly. There’s more work I want to do on this, but it’s a start.

I’ve also made it generate previews of each theme, and made those directly viewable from rendered markdown, so that it’s viewable both from the main page on github, and the app page on github. My rationale for doing both is that people who come just for the app support, will get the previews for what they want to use straight away without needing to go somewhere else to choose. And people going to the main project itself will also see what it is able to generate.

Edge cases

When ever I’m discovering edge cases, I’m figuring out how to solve them. It’s been a week or so since I last discovered a new one (believe me, I’m looking!) I’m really pleased with how well this has come out.

Future apps

As you might have guessed from the directory structure, I have a growing list of apps that I want to add support for. This will take a whlie, but it will happen.

My end goal is to be able to

  • Run installs for individual apps.
  • Be able to detect which apps are installed, and automatically install themes for those apps without the user having to figure it out.

Current quality level

The current status of this is “works-for-me”.

If I see there is interest, I’ll put more time into making it easy for people to contribute improvements to it.

How you can show interest

Future clean up

Here are some near term goals

  • Improve documentation.
    • How to rebuild the themes.
    • How to add theme colours. - Done.
    • How to add theme shades. - Done.
    • Revisit how to install colouredWeb.
  • Make installing colouredWeb easier for those who only want to make themes and aren’t necessarily interested in developing colouredWeb itself.

Alternatives

ColouredWeb was originally just for web browsers. I put it down a few years ago because browser plugins were getting really good.

I’ve detailed some opinions of a couple of these in the Alternatives section of my original ColouredWeb blog post. I’m going to re-visit this soon, because the landscape has evolved quite a bit since then.

Last word

In the mean time. Please enjoy this. Pull request and issue welcome.

This post references

2020-06-28
This tag is for grouping the various projects that I do. These range from quick hardware hacks the provide some use, through to larger software projects. ...
1970-01-01
I've done a few software projects over the years. Here's a collection of some of them.

Posts using the same tags

An Android game like 2048, but 3D, and requiring a different strategy.
It was time for a much needed update to the resolution app. Here's what I've improved.
Why portrain-only designs on mobile devices are a bug. And why that matters.
Getting the information and access you need to your infrastructure quickly, so that you can get back to sleep.
It's time to blow the dust off machine learning, and apply it to a dataset that I know.
I've just released the biggest, most exciting, update since the first public release of handWavey. The learning curve is dramatically reduced!
The story of where Achel came from, and where it's going.
My CV had gained so much weight that it was hard to do anything with it any more, and it was hard to read. So I did something about it...
Control your computer using a Leap Motion controller, but with an every-day-quality implementation.
How much of your phone's screen resolution can you actually see? This app helps you quantify it.
An easy way to get a dark theme for kmail content, that reliably works on pretty much everything.
This is a continuation of An SRE's confession. P(12)])(confession). If you haven't read that yet, you should start there. 1. Site look and logic 1. An SRE's confession P(11) 1. **[An SRE's confession P(22) - You are here. 1. Under the hood. 1. Why I chose the tooling that I ...
FunnyHacks recently underwent an overhaul from top to bottom. I covered the front-end stuff on FunnyHacks.com and that was the right place for the post introducing the changes. But since RandomKSandom is where I'm going to be posting future content like this, this seemed like the right place to continue. ...
2020-06-28
This tag is for grouping the various projects that I do. These range from quick hardware hacks the provide some use, through to larger software projects. ...
calibrate multiple touch and non touch screens on a single linux system." This is to address the issue on multi-display Linux desktops where the touch panel is automatically calibrated to operate over all of the displays, and even if you get the calibration right, it's then wrong again when you ...
DoneIt is a time tracker for working out where your time is going. For me there were a few things I wanted to achieve with it - Be able to say what I've been doing all day. - See how much time is lost to time ...
Well over a year ago I introduced mass which is a tool for managing large numbers of servers. It's come along way in that time, and it's well and truly time for another look. From the users' point of view, the most interesting things are probably that you can now ...
Achel is a programming language that I have been working on for the past 13 years (I said 12 in the video, it has been a long time!) There has been growing interest in the programs I have been writing using it, so I have now released it as open ...
1970-01-01
I've done a few software projects over the years. Here's a collection of some of them.

More...

Home | About | Contact | Cookies