Browse Source

- remove /sloonz/go-qprintable and replace with go stdlib equivalent
- update glide
- add envelope.go tests

flashmob 8 years ago
parent
commit
b532c91122
6 changed files with 57 additions and 23 deletions
  1. 1 0
      Makefile
  2. 1 1
      cmd/guerrillad/serve_test.go
  3. 3 12
      glide.lock
  4. 0 6
      glide.yaml
  5. 2 4
      mail/envelope.go
  6. 50 0
      mail/envelope_test.go

+ 1 - 0
Makefile

@@ -30,6 +30,7 @@ test: *.go */*.go */*/*.go
 	$(GO_VARS) $(GO) test -v ./cmd/guerrillad
 	$(GO_VARS) $(GO) test -v ./cmd/guerrillad
 	$(GO_VARS) $(GO) test -v ./response
 	$(GO_VARS) $(GO) test -v ./response
 	$(GO_VARS) $(GO) test -v ./backends
 	$(GO_VARS) $(GO) test -v ./backends
+	$(GO_VARS) $(GO) test -v ./mail
 
 
 testrace: *.go */*.go */*/*.go
 testrace: *.go */*.go */*/*.go
 	$(GO_VARS) $(GO) test -v . -race
 	$(GO_VARS) $(GO) test -v . -race

+ 1 - 1
cmd/guerrillad/serve_test.go

@@ -228,7 +228,7 @@ var configJsonE = `
     ],
     ],
     "backend_config" :
     "backend_config" :
         {
         {
-            "process_stack_old": "HeadersParser|Debugger|Hasher|Header|Compressor|Redis|MySql",
+            "save_process_old": "HeadersParser|Debugger|Hasher|Header|Compressor|Redis|MySql",
             "save_process": "GuerrillaRedisDB",
             "save_process": "GuerrillaRedisDB",
             "log_received_mails" : true,
             "log_received_mails" : true,
             "mysql_db":"gmail_mail",
             "mysql_db":"gmail_mail",

+ 3 - 12
glide.lock

@@ -1,5 +1,5 @@
-hash: 1a8fddacae80af03b3cb67287a2a39396a4b38a0c7f805f63325293a19230853
-updated: 2017-02-01T09:34:30.442747666+11:00
+hash: edbacc9b8ae3fcad4c01969c3efc5d815d79ffdc544d0bd56c501018696c2285
+updated: 2017-03-11T23:00:44.323885211+11:00
 imports:
 imports:
 - name: github.com/asaskevich/EventBus
 - name: github.com/asaskevich/EventBus
   version: ab9e5ceb2cc1ca6f36a5813c928c534e837681c2
   version: ab9e5ceb2cc1ca6f36a5813c928c534e837681c2
@@ -13,20 +13,11 @@ imports:
 - name: github.com/inconshreveable/mousetrap
 - name: github.com/inconshreveable/mousetrap
   version: 76626ae9c91c4f2a10f34cad8ce83ea42c93bb75
   version: 76626ae9c91c4f2a10f34cad8ce83ea42c93bb75
 - name: github.com/Sirupsen/logrus
 - name: github.com/Sirupsen/logrus
-  version: d26492970760ca5d33129d2d799e34be5c4782eb
-- name: github.com/sloonz/go-qprintable
-  version: 775b3a4592d5bfc47b0ba398ec0d4dba018e5926
+  version: 0208149b40d863d2c1a2f8fe5753096a9cf2cc8b
 - name: github.com/spf13/cobra
 - name: github.com/spf13/cobra
   version: b62566898a99f2db9c68ed0026aa0a052e59678d
   version: b62566898a99f2db9c68ed0026aa0a052e59678d
 - name: github.com/spf13/pflag
 - name: github.com/spf13/pflag
   version: 25f8b5b07aece3207895bf19f7ab517eb3b22a40
   version: 25f8b5b07aece3207895bf19f7ab517eb3b22a40
-- name: github.com/ziutek/mymysql
-  version: e08c2f35356576b3c3690c252fe5dca728ae9292
-  subpackages:
-  - autorc
-  - godrv
-  - mysql
-  - native
 - name: golang.org/x/sys
 - name: golang.org/x/sys
   version: 478fcf54317e52ab69f40bb4c7a1520288d7f7ea
   version: 478fcf54317e52ab69f40bb4c7a1520288d7f7ea
   subpackages:
   subpackages:

+ 0 - 6
glide.yaml

@@ -6,13 +6,7 @@ import:
   version: ~1.0.0
   version: ~1.0.0
   subpackages:
   subpackages:
   - redis
   - redis
-- package: github.com/sloonz/go-qprintable
 - package: github.com/spf13/cobra
 - package: github.com/spf13/cobra
-- package: github.com/ziutek/mymysql
-  version: ~1.5.4
-  subpackages:
-  - autorc
-  - godrv
 - package: gopkg.in/iconv.v1
 - package: gopkg.in/iconv.v1
   version: ~1.1.1
   version: ~1.1.1
 - package: github.com/asaskevich/EventBus
 - package: github.com/asaskevich/EventBus

+ 2 - 4
mail/envelope.go

@@ -7,10 +7,10 @@ import (
 	"encoding/base64"
 	"encoding/base64"
 	"errors"
 	"errors"
 	"fmt"
 	"fmt"
-	"github.com/sloonz/go-qprintable"
 	"gopkg.in/iconv.v1"
 	"gopkg.in/iconv.v1"
 	"io"
 	"io"
 	"io/ioutil"
 	"io/ioutil"
+	"mime/quotedprintable"
 	"net/textproto"
 	"net/textproto"
 	"regexp"
 	"regexp"
 	"strings"
 	"strings"
@@ -238,9 +238,7 @@ func fromBase64(data string) string {
 }
 }
 
 
 func fromQuotedP(data string) string {
 func fromQuotedP(data string) string {
-	buf := bytes.NewBufferString(data)
-	decoder := qprintable.NewDecoder(qprintable.BinaryEncoding, buf)
-	res, _ := ioutil.ReadAll(decoder)
+	res, _ := ioutil.ReadAll(quotedprintable.NewReader(strings.NewReader(data)))
 	return string(res)
 	return string(res)
 }
 }
 
 

+ 50 - 0
mail/envelope_test.go

@@ -0,0 +1,50 @@
+package mail
+
+import (
+	"io/ioutil"
+	"strings"
+	"testing"
+)
+
+func TestMimeHeaderDecode(t *testing.T) {
+	str := MimeHeaderDecode("=?ISO-2022-JP?B?GyRCIVo9dztSOWJAOCVBJWMbKEI=?=")
+	if i := strings.Index(str, "【女子高生チャ"); i != 0 {
+		t.Error("expecting 【女子高生チャ, got:", str)
+	}
+	str = MimeHeaderDecode("=?ISO-8859-1?Q?Andr=E9?= Pirard <[email protected]>")
+	if strings.Index(str, "André Pirard") != 0 {
+		t.Error("expecting André Pirard, got:", str)
+	}
+}
+
+func TestEnvelope(t *testing.T) {
+	e := NewEnvelope("127.0.0.1", 22)
+
+	e.QueuedId = "abc123"
+	e.Helo = "helo.example.com"
+	e.MailFrom = Address{User: "test", Host: "example.com"}
+	e.TLS = true
+	e.RemoteIP = "222.111.233.121"
+	to := Address{User: "test", Host: "example.com"}
+	e.PushRcpt(to)
+	if to.String() != "[email protected]" {
+		t.Error("to does not equal [email protected], it was:", to.String())
+	}
+	e.Data.WriteString("Subject: Test\n\nThis is a test nbnb nbnb hgghgh nnnbnb nbnbnb nbnbn.")
+
+	addHead := "Delivered-To: " + to.String() + "\n"
+	addHead += "Received: from " + e.Helo + " (" + e.Helo + "  [" + e.RemoteIP + "])\n"
+	e.DeliveryHeader = addHead
+
+	r := e.NewReader()
+
+	data, _ := ioutil.ReadAll(r)
+	if len(data) != e.Len() {
+		t.Error("e.Len() is inccorrect, it shown ", e.Len(), " but we wanted ", len(data))
+	}
+	e.ParseHeaders()
+	if e.Subject != "Test" {
+		t.Error("Subject expecting: Test, got:", e.Subject)
+	}
+
+}