Skip to content

Commit

Permalink
Add dry run mode that does not move mails after classification (fixes #8
Browse files Browse the repository at this point in the history
)
  • Loading branch information
carlostrub committed Feb 3, 2018
1 parent 96a37e0 commit e7ac26f
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 12 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
# Release 1.2.0
## Added
- SISYPHUS_DRY_RUN flag to allow dry runs without moving files. In
fact, it does create missing folders, the database, learns, and
classifies mails. But, sisyphus does not move files between
folders. (#8)

## Changed
-

## Fixed
- Do not require config to get to help (#7)

## Known Issues
- There seems to be an issue with quotedprintable not properly reading in
malformed mails. Currently, such is likely to pass the filter.


# Release 1.1.1
## Added
-
Expand Down
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,21 @@ can put in your `$PATH`. (You can also take a look at `make install` to install
for you.)

## Usage
First, set the environment variables necessary for operation:
First, set the environment variable necessary for operation:
```
$ setenv SISYPHUS_DIRS PATHTOMAILDIR
$ setenv SISYPHUS_DURATION 24h
```
or
```
$ export SISYPHUS_DIRS=PATHTOMAILDIR
$ export SISYPHUS_DURATION=24h
```
or for Windows
```
$ set SISYPHUS_DIRS=PATHTOMAILDIR
$ set SISYPHUS_DURATION=24h
```


Sisyphus help can be started by running
For all other configuration options, please consult the help. It can
be started by running
```
$ sisyphus help
```
Expand Down
16 changes: 12 additions & 4 deletions classify.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,21 @@ func (m *Mail) Classify(db *bolt.DB, dir Maildir) (err error) {

// Move mail around if junk.
if junk {
err = os.Rename(filepath.Join(string(dir), "new", m.Key), filepath.Join(string(dir), ".Junk", "cur", m.Key))
if err != nil {
return err
if !m.DryRun {
err = os.Rename(filepath.Join(string(dir), "new", m.Key), filepath.Join(string(dir), ".Junk", "cur", m.Key))
if err != nil {
return err
}
}

var dryRun string
if m.DryRun {
dryRun = "-- dry run (nothing happened to this mail!)"
}

log.WithFields(log.Fields{
"mail": m.Key,
}).Info("Moved to Junk folder")
}).Info("Moved to Junk folder" + dryRun)
}

err = m.Unload(dir)
Expand Down
1 change: 1 addition & 0 deletions mail.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Mail struct {
Key string
Subject, Body *string
Junk, New bool
DryRun bool
}

// CreateDirs creates all the required dirs -- if not already there.
Expand Down
9 changes: 7 additions & 2 deletions sisyphus/sisyphus.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ func main() {
SISYPHUS_DIRS: Comma-separated list of maildirs,
e.g. ./Maildir,/home/JohnDoe/Maildir
SISYPHUS_DURATION: Interval between learning periods, e.g. 12h
SISYPHUS_DURATION: Interval between learning periods, e.g. 12h. Default is set to 24h.
SISYPHUS_DRY_RUN : If set, sisyphus will not move any mails around.
`,
}
}
Expand Down Expand Up @@ -143,8 +145,11 @@ COPYRIGHT:
case event := <-watcher.Events:
if event.Op&fsnotify.Create == fsnotify.Create {
path := strings.Split(event.Name, "/new/")

_, dryRun := os.LookupEnv("SISYPHUS_DRY_RUN")
m := sisyphus.Mail{
Key: path[1],
Key: path[1],
DryRun: dryRun,
}

err = m.Classify(dbs[sisyphus.Maildir(path[0])], sisyphus.Maildir(path[0]))
Expand Down

0 comments on commit e7ac26f

Please sign in to comment.