From b74fe83ee63ae97566d71b651cbe9cde33c8732e Mon Sep 17 00:00:00 2001 From: Amnay Date: Wed, 14 Dec 2016 17:04:35 +0100 Subject: [PATCH 1/2] add `orig_to` to logPattern (non-capturing) some bounce logs may contain the `orig_to` field: http://pastebin.com/0cVp0iuC --- postfixutil/postfixutil.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/postfixutil/postfixutil.go b/postfixutil/postfixutil.go index e17b1d2..936b354 100644 --- a/postfixutil/postfixutil.go +++ b/postfixutil/postfixutil.go @@ -11,7 +11,8 @@ import "regexp" const ( softDSN string = "5.2.0 5.2.1 5.2.2 5.3.1 5.4.5 5.5.3" queueIDPattern string = "\\]:\\s([A-Z0-9]+):" - logPattern string = "^([A-Za-z]{3}\\s+\\d+ [0-9:]{8}) .*? .*?: ([A-Z0-9]+): to=<(.*?)>, relay=(.*?), delay=(.*?), delays=(.*?), dsn=(.*?), status=(.*?)$" + logPattern string = "^([A-Za-z]{3}\\s+\\d+ [0-9:]{8}) .*? .*?: ([A-Z0-9]+): to=<(.*?)>, (?:orig_to=<.*?>, )?relay=(.*?), delay=(.*?), delays=(.*?), dsn=(.*?), status=(.*?)$" + ) type Bounce struct { From 23d4acc02918cabecd0c572013c0689766e536fe Mon Sep 17 00:00:00 2001 From: Amnay Mokhtari Date: Tue, 27 Dec 2016 18:17:43 +0100 Subject: [PATCH 2/2] formatting --- bounce2db.go | 15 +++++++++------ postfixutil/postfixutil.go | 17 ++++++++--------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/bounce2db.go b/bounce2db.go index 3f8f986..5295499 100644 --- a/bounce2db.go +++ b/bounce2db.go @@ -1,11 +1,14 @@ package main -import "log" -import "os" -import "flag" -import "./postfixutil" -import "encoding/json" -import "gopkg.in/mgo.v2" +import ( + "encoding/json" + "flag" + "log" + "os" + + "github.com/amnay-mo/postfix-bounce/postfixutil" + "gopkg.in/mgo.v2" +) const ( BounceCollection string = "bounces" diff --git a/postfixutil/postfixutil.go b/postfixutil/postfixutil.go index 936b354..1c5a91f 100644 --- a/postfixutil/postfixutil.go +++ b/postfixutil/postfixutil.go @@ -9,22 +9,21 @@ import "time" import "regexp" const ( - softDSN string = "5.2.0 5.2.1 5.2.2 5.3.1 5.4.5 5.5.3" + softDSN string = "5.2.0 5.2.1 5.2.2 5.3.1 5.4.5 5.5.3" queueIDPattern string = "\\]:\\s([A-Z0-9]+):" logPattern string = "^([A-Za-z]{3}\\s+\\d+ [0-9:]{8}) .*? .*?: ([A-Z0-9]+): to=<(.*?)>, (?:orig_to=<.*?>, )?relay=(.*?), delay=(.*?), delays=(.*?), dsn=(.*?), status=(.*?)$" - ) type Bounce struct { // ID string - Date time.Time + Date time.Time QueueID string - To string - Relay string - Delay string - Delays string - DSN string - Status string + To string + Relay string + Delay string + Delays string + DSN string + Status string } func (b *Bounce) IsHard() bool {