diff --git a/lib/gmail/gmail.go b/lib/gmail/gmail.go index 14eb9fe..da46c8f 100644 --- a/lib/gmail/gmail.go +++ b/lib/gmail/gmail.go @@ -62,18 +62,20 @@ var ( // Gmail represents a Gmail client. type Gmail struct { - label string - labelId string - cache gmailCache - svc gmailService - dir maildir.Maildir - progress chan<- lib.Progress + label string + labelId string + excludeLabels []string + cache gmailCache + svc gmailService + dir maildir.Maildir + progress chan<- lib.Progress } // Creates a new Gmail synchronizer. -func NewGmail(dir string, label string) (*Gmail, error) { +func NewGmail(dir string, label string, excludedLabels []string) (*Gmail, error) { g := Gmail{ - label: label, + label: label, + excludeLabels: excludedLabels, } f := path.Join(dir, cacheFile) if c, err := lib.NewBoltCache(f); err != nil { @@ -300,6 +302,14 @@ func (g *Gmail) handleNewMsg(id string) msgOp { o.Error = err return o } + for _, el := range g.excludeLabels { + for _, ml := range o.Labels { + if ml == el { + // Skip messages with excluded labels. + return o + } + } + } if g.labelsChanged(id, o.Labels) && exists { // Have to fetch body. m, c, err := g.getMaildirMessage(k) diff --git a/main.go b/main.go index e6cb345..74944b5 100644 --- a/main.go +++ b/main.go @@ -2,9 +2,9 @@ package main import ( "fmt" - "github.com/codegangsta/cli" "github.com/danmarg/outtake/lib" "github.com/danmarg/outtake/lib/gmail" + "github.com/urfave/cli" "os" "time" ) @@ -17,7 +17,7 @@ func main() { app := cli.NewApp() app.Name = "outtake" app.Usage = "Export Gmail to Maildir...efficiently!" - app.Version = "0.0.1" + app.Version = "0.0.2" app.Author = "dan@af0.net" app.Flags = []cli.Flag{ cli.StringFlag{ @@ -32,6 +32,10 @@ func main() { Name: "label", Usage: "Label to sync", }, + cli.StringSliceFlag{ + Name: "exclude_label", + Usage: "Skip messages with these labels if present", + }, cli.IntFlag{ Name: "buffer", Usage: "Download buffer size", @@ -61,7 +65,7 @@ func main() { fmt.Printf("Error: %d exists and is not a directory\n", d) return } - g, err := gmail.NewGmail(d, ctx.String("label")) + g, err := gmail.NewGmail(d, ctx.String("label"), ctx.StringSlice("exclude_label")) gmail.MessageBufferSize = ctx.Int("buffer") gmail.ConcurrentDownloads = ctx.Int("parallel") if err != nil {