Skip to content

About the author of Daydream Drift

Tomasz Niezgoda (LinkedIn/tomaszniezgoda & GitHub/tniezg) is the author of this blog. It contains original content written with care.

Please link back to this website when referencing any of the materials.

Author:

Force GMail To Filter Incoming Messages

Published

Based on my recent experience, automatic filtering of incoming messages in GMail is broken. Filters don't fire automatically when their job is to label unread messages and remove them from the inbox. This issue has been discussed multiple times on the web and many solutions proposed, except none of them worked for me. Supposedly, GMail may skip running some automatic filters if messages are modified in multiple ways, such as marked as important. However, after reconfiguring GMail multiple times filters still wouldn't function on their own.

So, in the end I created a Docker image that solves this issue by leveraging GMail's API. Every few seconds, it applies a filter to a GMail account. It removes unread messages from the Inbox that correspond to one of supplied senders' addresses and labels them. There's no concept of folders in GMail but labels have the same end effect - they group messages together. For example, I use this mechanism to move messages from meetup.com away from the inbox and group them under the "events" label.

Limitations

While the Docker image has never crashed for me, even after running for many weeks non-stop and has been correctly filtering messages, it doesn't have the exact same effect on the inbox as would be expected from a "native" and automatic GMail filter.

Since messages are filtered every few seconds and e-mail clients such as GMail for Android and Mail for macOS usually check GMail for new messages just as often, chances are some of those clients will notify of unread messages shortly before they get moved out of the inbox by the Docker image. This can mean a visual notification, a sound or vibration of the phone. Many e-mail clients will then synchronize notifications with GMail's newest state and remove notifications about messages that were moved.

How to use

GMail's API is free up to a certain point, which shouldn't be a problem when running the filter for a single account. The image can be found on Docker Hub. Setting up the image is a few minute process, mostly because it requires access to the GMail account to modify messages.