Bläddra i källkod

Enhancedstatuscodes backend (#55)

* Added support for ENHANCEDSTATUSCODES

Support for ENHANCEDSTATUSCODES (rfc3463) - Issue #34

* Backend missing new Enhanced Status Codes

* Added Response Test to travis

* Expect Enhanced Status code in response
Philipp Resch 8 år sedan
förälder
incheckning
9d9d864567
3 ändrade filer med 11 tillägg och 8 borttagningar
  1. 2 1
      .travis.yml
  2. 8 6
      backends/backend.go
  3. 1 1
      tests/guerrilla_test.go

+ 2 - 1
.travis.yml

@@ -17,4 +17,5 @@ script:
   - make guerrillad
   - make guerrillad
   - go test ./tests
   - go test ./tests
   - go test
   - go test
-  - go test ./cmd/guerrillad
+  - go test ./cmd/guerrillad
+  - go test ./response

+ 8 - 6
backends/backend.go

@@ -3,12 +3,14 @@ package backends
 import (
 import (
 	"errors"
 	"errors"
 	"fmt"
 	"fmt"
-	log "github.com/Sirupsen/logrus"
-	"github.com/flashmob/go-guerrilla/envelope"
 	"strconv"
 	"strconv"
 	"strings"
 	"strings"
 	"sync"
 	"sync"
 	"time"
 	"time"
+
+	log "github.com/Sirupsen/logrus"
+	"github.com/flashmob/go-guerrilla/envelope"
+	"github.com/flashmob/go-guerrilla/response"
 )
 )
 
 
 // Backends process received mail. Depending on the implementation, they can store mail in the database,
 // Backends process received mail. Depending on the implementation, they can store mail in the database,
@@ -129,7 +131,7 @@ func New(backendName string, backendConfig BackendConfig) (Backend, error) {
 // Distributes an envelope to one of the backend workers
 // Distributes an envelope to one of the backend workers
 func (gw *BackendGateway) Process(e *envelope.Envelope) BackendResult {
 func (gw *BackendGateway) Process(e *envelope.Envelope) BackendResult {
 	if gw.State != BackendStateRunning {
 	if gw.State != BackendStateRunning {
-		return NewBackendResult("554 Transaction failed - backend not running" + strconv.Itoa(gw.State))
+		return NewBackendResult(response.CustomString(response.OtherOrUndefinedProtocolStatus, 554, response.ClassPermanentFailure, "Transaction failed - backend not running "+strconv.Itoa(gw.State)))
 	}
 	}
 
 
 	to := e.RcptTo
 	to := e.RcptTo
@@ -144,12 +146,12 @@ func (gw *BackendGateway) Process(e *envelope.Envelope) BackendResult {
 	select {
 	select {
 	case status := <-savedNotify:
 	case status := <-savedNotify:
 		if status.err != nil {
 		if status.err != nil {
-			return NewBackendResult("554 Error: " + status.err.Error())
+			return NewBackendResult(response.CustomString(response.OtherOrUndefinedProtocolStatus, 554, response.ClassPermanentFailure, "Error: "+status.err.Error()))
 		}
 		}
-		return NewBackendResult(fmt.Sprintf("250 OK : queued as %s", status.hash))
+		return NewBackendResult(response.CustomString(response.OtherStatus, 250, response.ClassSuccess, fmt.Sprintf("OK : queued as %s", status.hash)))
 	case <-time.After(time.Second * 30):
 	case <-time.After(time.Second * 30):
 		log.Infof("Backend has timed out")
 		log.Infof("Backend has timed out")
-		return NewBackendResult("554 Error: transaction timeout")
+		return NewBackendResult(response.CustomString(response.OtherOrUndefinedProtocolStatus, 554, response.ClassPermanentFailure, "Error: transaction timeout"))
 	}
 	}
 }
 }
 func (gw *BackendGateway) Shutdown() error {
 func (gw *BackendGateway) Shutdown() error {

+ 1 - 1
tests/guerrilla_test.go

@@ -796,7 +796,7 @@ func TestDataCommand(t *testing.T) {
 				bufin,
 				bufin,
 				email+"\r\n.\r\n")
 				email+"\r\n.\r\n")
 			//expected := "500 Line too long"
 			//expected := "500 Line too long"
-			expected := "250 OK : queued as s0m3l337Ha5hva1u3LOL"
+			expected := "250 2.0.0 OK : queued as s0m3l337Ha5hva1u3LOL"
 			if strings.Index(response, expected) != 0 {
 			if strings.Index(response, expected) != 0 {
 				t.Error("Server did not respond with", expected, ", it said:"+response, err)
 				t.Error("Server did not respond with", expected, ", it said:"+response, err)
 			}
 			}