summary refs log tree commit diff stats
path: root/config/config.go
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2019-03-31 14:42:18 -0400
committerDrew DeVault <sir@cmpwn.com>2019-03-31 14:42:18 -0400
commit8e5ed2a161bf654888a8b48af2d9fdf6fbc0c7e0 (patch)
tree9a83cf70c8c7e1491005cfc1bab1d7e2e6cbe92d /config/config.go
parentf9262e4b0600fcc83ddac642412769c2bce05c5c (diff)
downloadaerc-8e5ed2a161bf654888a8b48af2d9fdf6fbc0c7e0.tar.gz
Implement header-regex-match filters
Diffstat (limited to 'config/config.go')
-rw-r--r--config/config.go22
1 files changed, 18 insertions, 4 deletions
diff --git a/config/config.go b/config/config.go
index 8d460ca..bff188e 100644
--- a/config/config.go
+++ b/config/config.go
@@ -4,6 +4,7 @@ import (
 	"errors"
 	"fmt"
 	"path"
+	"regexp"
 	"strings"
 	"unicode"
 
@@ -25,7 +26,6 @@ type UIConfig struct {
 const (
 	FILTER_MIMETYPE = iota
 	FILTER_HEADER
-	FILTER_HEADER_REGEX
 )
 
 type AccountConfig struct {
@@ -48,6 +48,8 @@ type FilterConfig struct {
 	FilterType int
 	Filter     string
 	Command    string
+	Header     string
+	Regex      *regexp.Regexp
 }
 
 type ViewerConfig struct {
@@ -161,10 +163,22 @@ func LoadConfig(root *string) (*AercConfig, error) {
 				Command: cmd,
 				Filter:  match,
 			}
-			if strings.Contains(match, "~:") {
-				filter.FilterType = FILTER_HEADER_REGEX
-			} else if strings.ContainsRune(match, ':') {
+			fmt.Println(match)
+			if strings.Contains(match, ",~") {
 				filter.FilterType = FILTER_HEADER
+				header := filter.Filter[:strings.Index(filter.Filter, ",")]
+				regex := filter.Filter[strings.Index(filter.Filter, "~")+1:]
+				filter.Header = strings.ToLower(header)
+				filter.Regex, err = regexp.Compile(regex)
+				if err != nil {
+					panic(err)
+				}
+			} else if strings.ContainsRune(match, ',') {
+				filter.FilterType = FILTER_HEADER
+				header := filter.Filter[:strings.Index(filter.Filter, ",")]
+				value := filter.Filter[strings.Index(filter.Filter, ",")+1:]
+				filter.Header = strings.ToLower(header)
+				filter.Regex, err = regexp.Compile(regexp.QuoteMeta(value))
 			} else {
 				filter.FilterType = FILTER_MIMETYPE
 			}