Git Product home page Git Product logo

gmailfilters's Introduction

gmailfilters

make-all make-image GoDoc Github All Releases

A tool to sync Gmail filters from a config file to your account.

NOTE: This makes it so the single configuration file is the only way to add filters to your account, meaning if you add a filter via the UI and do not also add it in your config file, the next time you run this tool on your outdated config, the filter you added only in the UI will be deleted.

Table of Contents

Installation

Binaries

For installation instructions from binaries please visit the Releases Page.

Via Go

$ go get github.com/jessfraz/gmailfilters

Usage

$ gmailfilters -h
gmailfilters -  A tool to sync Gmail filters from a config file to your account.

Usage: gmailfilters <command>

Flags:

  -d, --debug       enable debug logging (default: false)
  -e, --export      export existing filters (default: false)
  -f, --creds-file  Gmail credential file (or env var GMAIL_CREDENTIAL_FILE) (default: <none>)
  -t, --token-file  Gmail oauth token file (default: /tmp/token.json)

Commands:

  version  Show the version information.

Example Filter File

[[filter]]
query = "to:[email protected]"
archive = true
read = true

[[filter]]
query = "from:[email protected] LGTM"
label = "github/LGTM"

[[filter]]
query = """
(-to:[email protected] \
(from:([email protected]) AND (@jfrazelle OR @jessfraz OR to:[email protected] OR to:[email protected] OR to:[email protected])))
"""
label = "github/mentions"

[[filter]]
query = """
to:[email protected] \
-to:[email protected] \
-to:[email protected] \
-to:[email protected]
"""
label = "github/team-mention"

[[filter]]
query = """
from:[email protected] \
-to:[email protected] \
-to:[email protected] \
-to:[email protected] \
-to:[email protected]
"""
archive = true

[[filter]]
query = "(from:me AND to:[email protected])"
label = "github/mentions"

[[filter]]
query = "(from:[email protected])"
label = "github"

[[filter]]
queryOr = [
"to:[email protected]",
"to:[email protected]",
"to:[email protected]",
"to:[email protected]"
]
delete = true

[[filter]]
queryOr = [
"from:[email protected]",
"from:[email protected]",
"from:[email protected]"
]
label = "to-be-deleted"

[[filter]]
query = "[email protected] OR (subject:\"Invitation to comment\" AND from:me ) OR from:(*@docs.google.com)"
label = "to-be-deleted"

[[filter]]
query = "(from:(-me) {filename:vcs filename:ics} has:attachment) OR (subject:(\"invitation\" OR \"accepted\" OR \"tentatively accepted\" OR \"rejected\" OR \"updated\" OR \"canceled event\" OR \"declined\") when where calendar who organizer)"
label = "to-be-deleted"

[[filter]]
query = "list:[email protected]"
label = "Mailing Lists/coreos-dev"
archiveUnlessToMe = true

[[filter]]
queryOr = [
"list:[email protected]",
"list:[email protected]"
]
label = "Mailing Lists/xdg-apps"
archiveUnlessToMe = true

Setup

Gmail

  1. Enable the API: To get started using Gmail API, you need to first create a project in the Google API Console, enable the API, and create credentials.

    Follow the instructions for step enabling the API here.

gmailfilters's People

Contributors

github-actions[bot] avatar jessfraz avatar jnsn avatar toc-me[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gmailfilters's Issues

From: filters are not correctly represented

Gmail filters matched only on from: queries are not correctly represented by the program.

Given a filter with only a from criteria
image
I would expect a corresponding entry in the file produced by --export; however, only empty filter sets are produced:

[[Filter]]
Query = ""
Archive = false
Read = false
Delete = false
ToMe = false
ArchiveUnlessToMe = false
Label = ""
ForwardTo = ""

I suspect this is an issue because other criteria do generate values in the export file, such as compound criteria. example:

[[Filter]]
Query = "from:(\"wafflebot[bot]\") OR subject:(Apply fixes from StyleCI)"
Archive = false
Read = false
Delete = false
ToMe = false
ArchiveUnlessToMe = false
Label = "P1/00A2 - Github/Auto"
ForwardTo = ""

"Sensitive scope" api permissions issues

Hi folks,

I'm unable to generate creds that don't generate an error 403(insufficient permissions) due to the needed modification scope on the application. Anyone found a way around this? thanks!

App doesn't work on Windows, can't save oauth token as /tmp/ doesn't exist

By default, gmailfilters doesn't work on Windows, neither when using go get, nor with the Windows release builds.

The culprit is the save location of the authentication token file. The default is set to /tmp/token.json.

tokenFile = "/tmp/token.json"

It might be better if this is constructed using the https://golang.org/pkg/os/#TempDir method to get a system independent temp folder.

Label color

Hi,

It will be more convenient if the labels can be colored.

Negated query support.

It noticed that we are missing Negated Query support. I added the negated support in my PR #2. Do you feel I should cherry pick the commit or is there a better way to handle this?

pryorda@843dbff

Evaluate Individual Filter Usefulness

Enumerate "hits" on each filter for specified time-ranges.

Export these filter-hit-time ranges to a portable spreadsheet so that filters can be evaluated for usefulness / adjusted / removed accordingly.

Runtime error

Hello, I am trying to run the software in an Ubuntu box, but I am getting this error:

`lorenzo@kwaremont:~$ gmailfilters -f Scaricati/credentials.json -t token.json -e test.conf
exporting existing filters...
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x6c053f]

goroutine 1 [running]:
main.getExistingFilters(0x7e3720, 0xc000010018, 0xc0000d1b10, 0x1, 0x1)
/home/lorenzo/go/src/github.com/jessfraz/gmailfilters/filter.go:223 +0x27f
main.exportExistingFilters(0x7ffd875003cf, 0x9, 0xc000062720, 0x1)
/home/lorenzo/go/src/github.com/jessfraz/gmailfilters/filter.go:155 +0x9b
main.main.func2(0x7e94a0, 0xc000076ea0, 0xc0000120d0, 0x1, 0x1, 0x0, 0x0)
/home/lorenzo/go/src/github.com/jessfraz/gmailfilters/main.go:124 +0x4cb
github.com/jessfraz/gmailfilters/vendor/github.com/genuinetools/pkg/cli.(*Program).run(0xc0000c6000, 0x7e94a0, 0xc000076ea0, 0xc000012070, 0x7, 0x7, 0xf, 0xc00001c4a0)
/home/lorenzo/go/src/github.com/jessfraz/gmailfilters/vendor/github.com/genuinetools/pkg/cli/cli.go:179 +0x243
github.com/jessfraz/gmailfilters/vendor/github.com/genuinetools/pkg/cli.(*Program).Run(0xc0000c6000)
/home/lorenzo/go/src/github.com/jessfraz/gmailfilters/vendor/github.com/genuinetools/pkg/cli/cli.go:89 +0x61
main.main()
/home/lorenzo/go/src/github.com/jessfraz/gmailfilters/main.go:157 +0x644
lorenzo@kwaremont:~$
`

How can I solve this problem?

Support "Mark as important" in filters

When exporting filters, it appears that IMPORTANT is treated as one of the special label IDs, alongside INBOX, UNREAD, and TRASH.

The gmail filter UI appears to support IMPORTANT in two ways:

  1. Always mark the email as important (add label)
  2. Never mark the email as important (remove label)

We should therefore support the following:

  1. AlwaysMarkImportant
  2. NeverMarkImportant

Improve credentials creation documentation

Hi! As we discussed on Twitter, I've been trying to use this tool but no matter what combination of things I click on the console for creating the credentials, I always end up with the following message:

parsing client secret file to config failed: oauth2/google: no credentials found

After enabling the Gmail API from the console, I click on Create Credentials and I'm being present with a form. First question is from where am I going to use the API:

image

Next question is whether I want to give access to User data or Application data, so I've chosen the latter:

image

Then I proceed to click on What credentials do I need? and I'm presented with the following:

image

Here is where it gets tricky, as none of the roles seem to match the Gmail labels notion that I was expecting. I've chosen different things but when the JSON file is downloaded and I pass it to gmailfilters it always fails when parsing the file.

Thank you very much for your time and for all the great tools you've written so far!

All available configs

Hi! Thanks for this great piece of software ❤️

I wanted to know what are all the configs available for each filter. From the README I can see for example query, archiveUnlessToMe, label, queryOr, etc.

Although, I noticed that I want something like markAsImportant = false or similar because when the email matches one of my filters and it has archive = true GMail puts it on the Inbox anyway because their smart algorithm marks it as important :(

Is there an option for this case? Thanks!

Download existing Filters

Thanks for creating this automation script, @jessfraz!

I can't use this awesome script because I have hundreds of filters created in the UI. I wish there could be a downloader for these settings that downloads/converts the existing filters to a file.

Feature request.

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.