About Archive Tags RSS Feed


procmail for gmail?

24 January 2020 12:20

After 10+ years I'm in the process of retiring my mail-host. In the future I'll no longer be running exim4/dovecot/similar, and handling my own mail. Instead it'll all go to a (paid) Google account.

It feels like the end of an era, as it means a lot of my daily life will not be spent inside a single host no longer will I run:

ssh steve@mail.steve.org.uk

I'm still within my Gsuite trial, but I've mostly finished importing my vast mail archive, via mbsync.

The only outstanding thing I need is some scripting for the mail. Since my mail has been self-hosted I've evolved a large and complex procmail configuration file which sorted incoming messages into Maildir folders.

Having a quick look around last night I couldn't find anything similar for the brave new world of Google Mail. So I hacked up a quick script which will automatically add labels to new messages that don't have any.

Finding messages which are new/unread and which don't have labels is a matter of searching for:

is:unread -has:userlabels

From there adding labels is pretty simple, if you decide what you want. For the moment I'm keeping it simple:

  • If a message comes from "Bob Smith" <bob.smith@example.com>
    • I add the label "bob.smith".
    • I add the label "example.com".

Both labels will be created if they don't already exist, and the actual coding part was pretty simple. To be more complex/flexible I would probably need to integrate a scripting language (oh, I have one of those), and let the user decide what to do for each message.

The biggest annoyance is setting up the Google project, and all the OAUTH magic. I've documented briefly what I did but I don't actually know if anybody else could run the damn thing - there's just too much "magic" involved in these APIs.

Anyway procmail-lite for gmail. Job done.



Comments on this entry

icon Al at 13:49 on 24 January 2020

Most people degoogle. Specially those who can

Hope you share your motivations which is more interesting that how you label mails which is mostly unnecessary, since you can just search for them:

from:bob.smith@ from:@example.com

icon Steve Kemp at 20:11 on 24 January 2020

I think the scripting facility I have now is worth demonstrating:

// Prove we can do "complex" things too - by adding a label
// conditionally, depending upon the contents of the Subject-header.
if ( Subject ~= /attic: backup/ ) {
   add( "backups" );

   // Remove the "UNREAD" label, which will mark the
   // message as having been read.
   // Gmail is weird :)
   remove( "UNREAD" );

Of course that can be done via the UI, but it's a pain if you have complex rules.

Anyway I take the point that a lot of people are vocal with their anti-Google crusades, even if I suspect a lot of them don't actually follow-through as much as they pretend.

My personal goal for 2020 is to cancel every single server, virtual machine, and host I maintain. That means moving email to a commercial provider, moving websites to netlify/S3/etc.

I went through a trial of fastmail, didn't like it. I'm still in my trial of Gsuite and find it works well. I see no reason to avoid Google per se.

I did remove google analytics from all my sites, but that was because with ad-blocking the stats were broken. I also removed all (adsense) adverts from my sites, but that is also because adblocking made them pointless.

In short I'll rely on Google for email (which I'm paying for), and I'll continue to love Google Translate - since I live in a country which has a language I don't fully understand. I'm not going to boycot them, and if you are then I'll wish you luck.

icon Jonathan at 00:15 on 25 January 2020

My personal goal for 2020 is to cancel every single server, virtual machine, and host I maintain. That means moving email to a commercial provider, moving websites to netlify/S3/etc.

I'd be interested if you'd expand on your reasoning here. Not that I'm questioning it, but I'd be interested in your perspective.

icon Leandro Penz at 13:58 on 25 January 2020

You can get something that works with imap - I was able to get quite a lot of mileage out of imapfilter, FWIW. It's programmable in lua.

icon Steve Kemp at 19:39 on 25 January 2020

For servers I just find I don't have the patience any more for looking after them. Nothing specific is a problem, as I'm used to dealing with lots of hosts, but I can live without it.

IMAP-access is something I tried experimenting with, Leandro, but I couldn't make too many changes without getting surprised - and it impacted the IMAPsync I was running to migrate over.

A standard approach would be better than being tied to the API, though I guess being tied to a specific provider in the first place is just the same thing ..