Skip to content

Commit

Permalink
Enhancedstatuscodes backend (flashmob#55)
Browse files Browse the repository at this point in the history
* Added support for ENHANCEDSTATUSCODES

Support for ENHANCEDSTATUSCODES (rfc3463) - Issue flashmob#34

* Backend missing new Enhanced Status Codes

* Added Response Test to travis

* Expect Enhanced Status code in response
  • Loading branch information
phires authored and flashmob committed Jan 24, 2017
1 parent 100f9bb commit 9d9d864
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ script:
- make guerrillad
- go test ./tests
- go test
- go test ./cmd/guerrillad
- go test ./cmd/guerrillad
- go test ./response
14 changes: 8 additions & 6 deletions backends/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package backends
import (
"errors"
"fmt"
log "github.com/Sirupsen/logrus"
"github.com/flashmob/go-guerrilla/envelope"
"strconv"
"strings"
"sync"
"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,
Expand Down Expand Up @@ -129,7 +131,7 @@ func New(backendName string, backendConfig BackendConfig) (Backend, error) {
// Distributes an envelope to one of the backend workers
func (gw *BackendGateway) Process(e *envelope.Envelope) BackendResult {
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
Expand All @@ -144,12 +146,12 @@ func (gw *BackendGateway) Process(e *envelope.Envelope) BackendResult {
select {
case status := <-savedNotify:
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):
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 {
Expand Down
2 changes: 1 addition & 1 deletion tests/guerrilla_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ func TestDataCommand(t *testing.T) {
bufin,
email+"\r\n.\r\n")
//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 {
t.Error("Server did not respond with", expected, ", it said:"+response, err)
}
Expand Down

0 comments on commit 9d9d864

Please sign in to comment.