Giter Club home page Giter Club logo

sieve-generator's Introduction

sieve-generator

This is a CLI used to generate .sieve email filter allowlist for different folders based on the receiver email address, configured with a JSON file. I have a catch-all email domain and use it automates the allowlist creating process whenever I use a new email. (e.g. [email protected] filtered to something folder)

Installation

cargo install sieve-generator or download the binary, only tested on Linux.

Usage

Let say we have JSON config file like this

{
    "domain.com": {
        "options": { // Global options
            // If every folder should be a sub-folder of a domain named folder
            "domain-as-first-folder": false,
        },
        "Newsletter": {
            "Software": ["google", "facebook"],
            "Business": "wallstreet"
        },
        "Utilities": {
            "self": ["electricity"],
            "Grocery": {
                "localparts": "market",
                // If title or sender contains keyword then go to label
                // By default every labeled mail will not be marked read
                // even if mark-as-read is set
                "labels": {
                    "label": "keyword",
                    "label2": ["keyword2"]
                },
                "options": {
                    // The generic filter here will be utilities.grocery.secret
                    // not grocery.secret
                    "fullpath": true,
                    // Mark all email of this folder as read
                    "mark-as-read": true,
                    // Not generate generic filter for this folder
                    "generic": false
                }
            }
        }
    }
}

A .sieve filter allowlist will be generated in which

  • It applies to all email sent to *@domain.com
  • [email protected] will be filtered to Business folder of Newsletter parent folder and so on.
  • The filter for a parent folder with children (e.g. Utilities) is set using self keyword.
  • There are short form filter (e.g. Business folder) and full form (e.g. Grocery) that allows to specify options and a label rule.
  • There is a generic filter generated for each in the folder tree, e.g. newsletter.business.*@domain.com (fullpath option == true) is filtered to Business folder.
  • Every mails that are not allowlisted will be put in an Unknown folder by default.
  • Unknown is a special folder, everything go there will be silent, even if explicitly configured.

The JSON above will produce

# @domain.com
if envelope :domain :is "to" "domain.com" {
    # Custom filters
    if envelope :localpart :matches "to" ["market"] {
        if header :contains ["from","subject"] ["keyword","keyword2"] {
            if header :contains ["from","subject"] ["keyword"] {
                fileinto "label";
            }
            if header :contains ["from","subject"] ["keyword2"] {
                fileinto "label2";
            }
        } else {
            addflag "\\Seen";
            fileinto "unread";
        }
        fileinto "Utilities";
        fileinto "Utilities/Grocery";
    } elsif envelope :localpart :matches "to" ["electricity"] {
        fileinto "Utilities";
    } elsif envelope :localpart :matches "to" ["google","facebook"] {
        fileinto "Newsletter";
        fileinto "Newsletter/Software";
    } elsif envelope :localpart :matches "to" ["wallstreet"] {
        fileinto "Newsletter";
        fileinto "Newsletter/Business";
    }
    # Generic filters
    elsif envelope :localpart :matches "to" ["utilities","utilities.*"] {
        fileinto "Utilities";
    } elsif envelope :localpart :matches "to" ["software","software.*"] {
        fileinto "Newsletter";
        fileinto "Newsletter/Software";
    } elsif envelope :localpart :matches "to" ["business","business.*"] {
        fileinto "Newsletter";
        fileinto "Newsletter/Business";
    } elsif envelope :localpart :matches "to" ["newsletter","newsletter.*"] {
        fileinto "Newsletter";
    } else {
        addflag "\\Seen";
        fileinto "Unknown";
    }
}

sieve-generator's People

Contributors

haoadoreorange avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.