Add dry run mode that does not move mails after classification (fixes #8)

master
Carlo Strub 6 years ago
parent 96a37e0439
commit e7ac26f264
No known key found for this signature in database
GPG Key ID: 34EF3FF33C29811A

@ -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
-

@ -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
```

@ -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)

@ -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.

@ -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.
`,
}
}
@ -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]))

Loading…
Cancel
Save