跳转到主要内容

Gefilte Fish GMail过滤器创建器

项目描述

Gefilte Fish自动化创建GMail过滤器。您使用gefilte的领域特定语言(DSL)编写Python程序,运行程序,然后导入它创建的XML。

Python示例

以下是一个创建过滤器的示例

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())

with子句在嵌套上下文中创建所有封装过滤器都适用的上下文。elif_和else_结构有些笨拙,但比手动创建具有相同效果的过滤器更容易。

安装过滤器

当您运行程序时,它将创建XML输出。将输出保存到文件中。在浏览器中,转到GMail - 设置 - 过滤器和阻止地址。然后“导入过滤器”,“选择文件”,“打开文件”,然后“创建过滤器”。

有关GMail过滤器的更多信息,请参阅 您可以在Gmail中使用的搜索运算符

许可协议

除非另有说明,否则此存储库中的代码根据Apache软件许可协议2.0许可。有关详细信息,请参阅LICENSE.txt

变更日志

0.5.1 — 2022-02-23

  • 从输出中删除了不必要的遗留XML元素。

0.5.0 — 2021-03-28

第一个版本。

项目详情


下载文件

下载您平台的文件。如果您不确定该选择哪个,请了解更多关于安装包的信息。

源代码分布

gefilte-0.5.1.tar.gz (8.4 kB 查看哈希值)

上传时间 源代码

构建分布

gefilte-0.5.1-py2.py3-none-any.whl (8.7 kB 查看哈希值)

上传时间 Python 2 Python 3

支持