Giter VIP home page Giter VIP logo

Comments (11)

lutzky avatar lutzky commented on September 21, 2024 1

Yep, my process definitely started with "I'll just send a pull request" and quickly turned into "this is nontrivial and should be a feature request".

from gmailctl.

mbrt avatar mbrt commented on September 21, 2024

This is not easy to do, because the diff is done at the lowest level of filters, where all the fields are simple strings. This allows for easy comparison with whatever is currently set in Gmail, without having to parse and back-translate upstream filters to higher level representations.

The line you report (to: {[email protected] .... }) is effectively just a string, so the cmp package would report the same result.

from gmailctl.

lutzky avatar lutzky commented on September 21, 2024

Is there a reasonable place to say "here are all the filters before, here are all the filters after, throw it at cmp.Diff and see how bad it looks"? Should serve as a reasonable starting point.

from gmailctl.

lutzky avatar lutzky commented on September 21, 2024

Alright, I found a place and ran it, lutzky@f3264ab. The output doesn't look great.

from gmailctl.

mbrt avatar mbrt commented on September 21, 2024

Yeah indeed. It's a bunch of strings not very different from what's existing. To make it better you really need a parser for Gmail filter expressions.

from gmailctl.

lutzky avatar lutzky commented on September 21, 2024

Yep. Now, even if I were to write such a parser, the output for cmp.Diff on imagined parsed filters doesn't look great:

 main.FilterNode{
  	And: []main.FilterNode{
  		{
  			And: nil,
  			Or: []main.FilterNode{
  				{From: "person1"},
  				{From: "person2"},
- 				{From: "person3"},
  				{From: "person4"},
  			},
  			Not:  nil,
  			From: "",
  		},
  		{
  			And: nil,
  			Or:  nil,
  			Not: &main.FilterNode{
  				And: nil,
  				Or: []main.FilterNode{
  					{From: "person5"},
  					{
  						And:  nil,
  						Or:   nil,
  						Not:  nil,
- 						From: "person6",
+ 						From: "person7",
  					},
  				},
  				Not:  nil,
  				From: "",
  			},
  			From: "",
  		},
  	},
  	Or:   nil,
  	Not:  nil,
  	From: "",
  }

Even if we hide all the nil and "" entries, what we actually want is more like this:

before: {person1 person2 person3 person4} -{person5 person6}
after:  {person1 person2 person4} -{person5 person7}
diff:
 {
   person1
   person2
-  person3
   person4
 }
 -{
   person5
-  person6
+  person7
  }

So, essentially, it's a matter of adding newlines and indentation in a few places, and running a traditional diff. I'll see if I can mock something up.

from gmailctl.

lutzky avatar lutzky commented on September 21, 2024

It's quick-and-dirty, but perhaps not entirely useless: https://go.dev/play/p/EREXFY8gTwR

from gmailctl.

mbrt avatar mbrt commented on September 21, 2024

It's certainly a start. There are a lot more cases to consider though. From the top of my head:

  • quotes: from:"foo bar"
  • parenthesis: (a b) subject:(foo bar)
  • nested expressions: -(x {y -z} k)

And combinations of those.

from gmailctl.

github-actions avatar github-actions commented on September 21, 2024

This issue is stale because it has been open for 30 days without activity.
This will be closed in 7 days, unless you add the 'lifecycle/keep-alive' label or comment.

from gmailctl.

lutzky avatar lutzky commented on September 21, 2024

Tweaked it a bit to handle your example cases: https://go.dev/play/p/qNFzmtFEWCo

WDYT?

from gmailctl.

mbrt avatar mbrt commented on September 21, 2024

Cool! I tried a couple more nasty cases (colons outside operators) and the results still seem good! https://go.dev/play/p/LtIy47e5eY7.

from gmailctl.

Related Issues (20)

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.