Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions lib/gmail/gmail.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 7 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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{
Expand All @@ -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",
Expand Down Expand Up @@ -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 {
Expand Down