Open-source News

Manage your Gmail filters from the Linux command line

opensource.com - Wed, 05/11/2022 - 15:00
Manage your Gmail filters from the Linux command line Kevin Sonney Wed, 05/11/2022 - 03:00 2 readers like this 2 readers like this

Automation is a hot topic right now. In my day job as an SRE part of my remit is to automate as many repeating tasks as possible. But how many of us do that in our daily, not-work, lives? This year, I am focused on automating away the toil so that we can focus on the things that are important.

Server-side mail rules are one of the most efficient ways to pre-sort and filter mail. Sadly, Gmail, the most popular mail service in the world, doesn't use any of the standard protocols to allow users to manage their rules. Adding, editing, or removing a single rule can be a time-consuming task in the web interface, depending on how many rules the user has in place. The options for editing them "out of band" as provided by the company are limited to an XML export and import.

I have 109 mail filters, so I know what a chore it can be to manage them using the provided methods. At least until I discovered gmailctl, the command-line tool for managing Gmail filters with a (relatively) simple standards-based configuration file.

$ gmailctl test
$ gmailctl diff
Filters:
--- Current
+++ TO BE APPLIED
@@ -1 +1,6 @@
+* Criteria:
+ from: @opensource.com
+ Actions:
+ mark as important
+ never mark as spam

$ gmailctl apply
You are going to apply the following changes to your settings:
Filters:
--- Current
+++ TO BE APPLIED
@@ -1 +1,6 @@
+* Criteria:
+ from: @opensource.com
+ Actions:
+ mark as important
+ never mark as spam
Do you want to apply them? [y/N]:

To define rules in a flexible manner gmailctl uses the jsonnet templating language. Using gmailctl also allows the user to export the existing rules for modification.

More Linux resources Linux commands cheat sheet Advanced Linux commands cheat sheet Free online course: RHEL technical overview Linux networking cheat sheet SELinux cheat sheet Linux common commands cheat sheet What are Linux containers? Our latest Linux articles

To get started, install gmailctl via your system's package manager, or install from source with go install github.com/mbrt/gmailctl/cmd/gmailctl@latest. Follow that with gmailctl init which will walk you through the process of setting up your credentials and the correct permissions in Google. If you already have rules in Gmail, I recommend running gmailctl download next, in order to backup the existing rules. These will be saved in the default configuration file ~/.gmailctl/config.jsonnet. Copy that file somewhere safe for future reference, or to restore your old rules just in case!

If you wish to start from a clean slate, or you don't have any rules yet, you need to create a new, empty ~/.gmailctl/config.jsonnet file. The most basic structure for this file is:

local lib = import 'gmailctl.libsonnet';
{
  version: "v1alpha3",
  author: {
    name: "OSDC User",
    email: "your-email@gmail.com"
  },
  rules: [
    {
      filter: {
        or: [
          { from: "@opensource.com" },
        ]
      },
      actions: {
        markRead: false,
        markSpam: false,
        markImportant: true
      },
    },
  ]
}

As you can see, this file format is similar to, but not as strict as JSON. This file sets up a simple rule to mark any mail from opensource.com as important, leave it unread, and not mark it as spam. It does this by defining the criteria in the filters section, and then the rules to apply in the actions section. Actions include the following boolean commands: markRead, markSpam,markImportant, and archive. You can also use actions to specify a category for the mail, and assign folders, which we will get to later in the article.

Once the file is saved, the configuration file format can be verified with gmailctl test. If everything is good, then you can use gmailctl diff to view what changes are going to be made, and gmailctl apply to upload your new rule to Gmail.

$ gmailctl diff
Filters:
---
Current
+++ TO BE APPLIED
@@ -1,6 +1,8 @@
* Criteria:
from: @opensource.com Actions:
+ archive
  mark as important
  never mark as spam
+ apply label: 1-Projects/2022-OSDC

$ gmailctl apply -y
You are going to apply the following changes to your settings:
Filters:
--- Current
+++ TO BE APPLIED
@@ -1,6 +1,8 @@
* Criteria:
  from: @opensource.com Actions:
+ archive
  mark as important
  never mark as spam
  apply label: 1-Projects/2022-OSDC

Applying the changes...

As mentioned previously, new mail messages can be auto-filed by setting labels in the configuration. I want to assign all mails from Opensource.com to a folder specifically for them, and remove them from the inbox (or archive in Gmail terms). To do that, I would change the actions section to be:

  actions: {
        markRead: false,
        markSpam: false,
        markImportant: true,
        archive: true,
        labels: [
          "1-Projects/2022-OSDC"
        ]
      },

As you can see in the image above, gmailctl diff now shows only what is going to change. To apply it, I used gmailctl apply -y to skip the confirmation prompt. If the label doesn't exist, then an error is given, since a filter cannot be made for a label that does not already exist.

You can also make more complex rules that target specific conditions or multiple emails. For example, the following rule uses an and condition to look for messages from Cloudflare that are not purchase confirmations.

filter: { and: [ { from: "noreply@notify.cloudflare.com" }, { subject: "[cloudflare]" }, { query: "-{Purchase Confirmation}" } ] },

In the case of a rule that performs the same action on multiple messages, you can use an or structure. I use that to file all emails relating to tabletop games to a single folder.

filter: { or: [ { from: "no-reply@obsidianportal.com" }, { from: "no-reply@roll20.net" }, { from: "team@arcanegoods.com" }, { from: "team@dndbeyond.com" }, { from: "noreply@forge-vtt.com" }, { from: "@elventower.com" }, { from: "no-reply@dmsguild.com"}, { from: "info@goodman-games.com" }, { from: "contact@mg.ndhobbies.com" }, { from: "@monkeyblooddesign.co.uk" }, ] },

For people with multiple Gmail accounts that need their own sets of rules, you can specify a unique configuration file for them with the --config command line parameter. For example, my work uses Gmail, and I have a whole other set of rules for that. I can create a new gmailctl directory, and use that for the work configuration, like so:

$ gmailctl --config ~/.gmailctl-work/ diff

To make this easier on myself, I have two shell aliases to make it clear which configuration I'm using.

alias gmailctl-home="gmailctl --config $HOME/.gmailctl" alias gmailctl-work="gmailctl --config $HOME/.gmailctl-work"

The one drawback gmailctl has is that it will not apply a new filter to existing messages, so you still have to manually do things for mail received before doing gmailctl apply. I hope they are able to sort that out in the future. Other than that, gmailctl has allowed me to make adding and updating Gmail filters fast and almost completely automatic, and I can use my favorite email client without having to constantly go back to the web UI to change or update a filter.

The gmailctl command-line tool manages email filters with a simple standards-based configuration file.

Image by:

Ribkahn via Pixabay, CCO

Email Command line Linux What to read next 5 open source alternatives to Gmail This work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License. Register or Login to post a comment.

Open-Source Firmware For The MSI Alder Lake Motherboard Taking Shape

Phoronix - Wed, 05/11/2022 - 15:00
Last month was the surprising news of open-source Coreboot working on a readily available Intel Alder Lake motherboard. That work for the MSI PRO Z690-A WiFi DDR4 motherboard is being carried out by independent firmware consulting firm 3mdeb and using the Dasharo open-source firmware distribution with Coreboot...

Catalyzing an ecosystem of co-creators for the cloud

Red Hat News - Wed, 05/11/2022 - 12:00

There is no doubt that cloud has transformed the IT industry. This transformation has only accelerated due to the global pandemic, with many organizations leaning on hybrid clouds to achieve the necessary balance of speed, efficiency and scale offered by cloud-native technologies and the reliability of existing on-premises infrastructure. As a result, how customers access cloud technology and services has evolved.

How CIOs can build the future they want with open source

Red Hat News - Wed, 05/11/2022 - 12:00

The following is an excerpt from my Red Hat Summit keynote today.

 

Just over a decade ago, Marc Andreessen pointed out that software was eating the world. We can definitively update his quote to be more accurate: "Software ate the world." Software has taken over our businesses and how you create value for your customers.

Intel oneAPI Level Zero Loader 1.8 Released For Supporting New L0 Features

Phoronix - Wed, 05/11/2022 - 12:00
Another Intel (open-source) software update coinciding with the company's Vision 2022 conference is a new oneAPI Level Zero Loader release...

RHEL9 Reaching GA Shortly, RHIVOS Woos GM For Software-Defined Vehicles

Phoronix - Wed, 05/11/2022 - 06:05
Today at the Red Hat Summit is word of Red Hat Enterprise Linux 9 reaching general availability status in the coming weeks...

Intel Releases New CPU Microcode For Latest Security Advisory (CVE-2022-21151)

Phoronix - Wed, 05/11/2022 - 02:30
In addition to all the product announcements made for Intel Vision 2022 in Texas, today marks patch Tuesday with a new round of security disclosures from Intel. This month there are 16 new advisories for addressing 41 vulnerabilities affecting their software and hardware. 76% of these vulnerabilities were found by Intel engineers...

In Memory of Shubhra Kar

The Linux Foundation - Wed, 05/11/2022 - 01:45

This past week, we lost our dear friend, colleague, and a true champion of the open source community. Our CTO, Shubhra Kar, passed away suddenly while he was with his entire LF family at our first in-person, all-hands gathering since before the pandemic. 

Those who had the honor to work with him will know, he was a special leader and a wonderful human being.  Above all, Shubhra was the kind of leader who quickly passed the credit for accomplishments to his team over himself. His humble spirit and ever-present smile was admired by all around him. He was so proud of the world class team he had built here, and did that in part with engineers who followed him from one organization to another throughout his career.

We also knew Shubhra as a selfless leader – one who was more interested in the work than the reward. At the same time, he was incredibly ambitious – wanting to build a platform that would not only transform The Linux Foundation but support open source development communities around the world.  This was the week his team unveiled significant new enhancements across the LFX platform. It was a project he led from vision to reality, after many – even members of his own team – had told him the path to success was impossible. He was a transformational leader that has left his legacy here.

While he was passionate about his work and his team, he loved his family even more. In fact, his children were often spotted behind him during video calls throughout the day. He was a fantastic husband and father, and we are so grateful for his wife, son, and daughter sharing him with us. 

Sharing Memories

Our thoughts and prayers remain with Shubhra’s family in this incredibly difficult time. If you would like to leave a memorial message for Shubhra, please submit a pull request on GitHub here. His family would love to hear from you and especially appreciates stories that are shared of his life and career.

Memorial Fund

The Linux Foundation has made arrangements with the family to establish Shubhra’s memorial fund that will provide support for his family and his children’s education.  Donations can be made to the family here.


.avia-image-container.av-l30eojwa-6b98ca1039ffe435dfb5ce6c0cc79c46 .av-image-caption-overlay-center{ color:#ffffff; }

The post In Memory of Shubhra Kar appeared first on Linux Foundation.

Vulkan 1.3.213 Released With Minor Ray-Tracing Update, Other New Extensions

Phoronix - Wed, 05/11/2022 - 01:19
Vulkan 1.3.213 is out today that on top of the usual specification clarifications/corrections are also four new extensions, including VK_KHR_ray_tracing_maintenance1...

Pages