Skip to main content

Gefilte Fish GMail filter creator

Project description

Gefilte Fish automates the creation of GMail filters. You write a Python program using gefilte’s domain-specific language (DSL), run the program, and import the XML it creates.

Sample Python

Here’s an example of creating filters:

from gefilte import GefilteFish, GFilter

# Specialize GFilter for repo-specific GitHub notifications.
class GitHubFilter(GFilter):
    def repo(self, repo_name):
        org, repo = repo_name.split("/")
        return self.list_(f"{repo}.{org}.github.com")

# Make the filter-maker and use its DSL. All of the methods of GitHubFilter
# are now usable as global functions.
fish = GefilteFish(GitHubFilter)
with fish.dsl():

    # Google's spam moderation messages should never get sent to spam.
    with replyto("noreply-spamdigest@google.com"):
        never_spam()
        mark_important()

    # If the subject and body have these, label it "liked".
    with subject(exact("[Confluence]")).has(exact("liked this page")):
        label("liked")

    # We get a lot of notifications from GitHub,
    # we'll make a number of filters that apply.
    with from_("notifications@github.com"):

        # Skip the inbox (archive them).
        skip_inbox()

        # Notifications from some repos are special.
        with repo("myproject/tasks") as f:
            label("todo")
            with f.elif_(repo("otherproject/something")) as f:
                label("otherproject")
                with f.else_():
                    # But everything else goes into "Code reviews".
                    label("Code reviews")

        # Delete annoying bot messages.
        with from_("renovate[bot]"):
            delete()

        # GitHub sends to synthetic addresses to provide information.
        with to("author@noreply.github.com"):
            label("mine").star()

        with has('Merged, "into master"'):
            label("merged")

        # Data-driven filters. I'm mentoring these people
        # on these projects so make sure they get my attention.
        for who, where in [
            ("Joe Junior", "myproject/component1"),
            ("Francine Firstyear", "myproject/thing2"),
        ]:
            with from_(exact(who)).repo(where):
                label("mentee").star().mark_important()

    # Some inbound addresses come to me. Mark them so
    # I understand what I'm looking at in my inbox.
    for toaddr, the_label in [
        ("info@mycompany.com", "info@"),
        ("security@mycompany.com", "security@"),
        ("con2020@mycompany.com", "con20"),
        ("con2021@mycompany.com", "con21"),
    ]:
        with to(toaddr):
            label(the_label)

print(fish.xml())

The with clauses create nested contexts in which all of the enclosing filters apply. The elif_ and else_ structures are a little awkward, but easier than manually making filters with the same effect.

Installing filters

When you run your program, it will create XML output. Save that output in a file. In your browser, go to GMail - Settings - Filters and Blocked Addresses. Then “Import Filters”, “Choose File”, “Open File”, then “Create Filters”.

For more information about filtering in GMail, see Search operators you can use with Gmail.

License

The code in this repository is licensed under the Apache Software License 2.0 unless otherwise noted. See LICENSE.txt for details.

Changelog

0.5.1 — 2022-02-23

  • Removed unneeded vestigial XML elements from the output.

0.5.0 — 2021-03-28

First version.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gefilte-0.5.1.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gefilte-0.5.1-py2.py3-none-any.whl (8.7 kB view details)

Uploaded Python 2Python 3

File details

Details for the file gefilte-0.5.1.tar.gz.

File metadata

  • Download URL: gefilte-0.5.1.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.25.1 requests-toolbelt/0.9.1 urllib3/1.26.2 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for gefilte-0.5.1.tar.gz
Algorithm Hash digest
SHA256 974ec6ad0025280d6574a8f20d313b3ad80aa14c3aab0bff53f821c51e050651
MD5 07d96cc9a4ae172d5a4b57414132b0fc
BLAKE2b-256 66aaab9a70254ff38127a46b51f5de2df22538f7d70f20a7e375955585057579

See more details on using hashes here.

File details

Details for the file gefilte-0.5.1-py2.py3-none-any.whl.

File metadata

  • Download URL: gefilte-0.5.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.25.1 requests-toolbelt/0.9.1 urllib3/1.26.2 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for gefilte-0.5.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 8c4d0ac961e29a56a065914dce146d500c9ffbf72db3b50cc09f6c072e901d27
MD5 4883fb529aa85476a335333ba6d4d7c3
BLAKE2b-256 cf6ee1e8d697210bc583975213ce6c18047d4696c673bbcd8fd31f0a652b5af1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page