Skip to content

Commit

Permalink
Add README
Browse files Browse the repository at this point in the history
  • Loading branch information
foxcpp committed Feb 6, 2022
1 parent 6e2ac7f commit 44be6d3
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
go-sieve
====================

Sieve email filtering language ([RFC 5228][rfc5228])
implementation in Go.

## Extensions

- envelope (RFC 5228)
- fileinto (RFC 5228)

## Example

```go
package main

import (
"context"
"strings"

"github.com/foxcpp/go-sieve"
"github.com/foxcpp/go-sieve/interp"
)

func main() {
const script = `
require "fileinto";
if header :contains "subject" "rich" {
fileinto "Junk";
}
`

parsed, _ := sieve.Load(strings.NewReader(script), sieve.DefaultOptions())
data := interp.NewRuntimeData(
parsed,
interp.Callback{},
)
parsed.Execute(context.Background(), data)
// inspect RuntimeData for results
}

```

[rfc5228]: https://datatracker.ietf.org/doc/html/rfc5228
10 changes: 7 additions & 3 deletions cmd/sieve-run/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"context"
"flag"
"fmt"
"log"
"net/textproto"
"os"
Expand Down Expand Up @@ -65,11 +66,14 @@ func main() {
data.SMTP.To = *envTo

ctx := context.Background()
start = time.Now()
if err := loadedScript.Execute(ctx, data); err != nil {
log.Fatalln(err)
}
end = time.Now()
log.Println("script executed in", end.Sub(start))

log.Println("redirect:", data.RedirectAddr)
log.Println("fileinfo:", data.Mailboxes)
log.Println("keep:", data.ImplicitKeep || data.Keep)
fmt.Println("redirect:", data.RedirectAddr)
fmt.Println("fileinfo:", data.Mailboxes)
fmt.Println("keep:", data.ImplicitKeep || data.Keep)
}

0 comments on commit 44be6d3

Please sign in to comment.