|
@@ -535,6 +535,199 @@ func TestRFC2821LimitDomain(t *testing.T) {
|
|
|
logIn.Reset(&logBuffer)
|
|
|
}
|
|
|
|
|
|
+// Test several different inputs to MAIL FROM command
|
|
|
+func TestMailFromCmd(t *testing.T) {
|
|
|
+ if initErr != nil {
|
|
|
+ t.Error(initErr)
|
|
|
+ t.FailNow()
|
|
|
+ }
|
|
|
+ if startErrors := app.Start(); startErrors == nil {
|
|
|
+ conn, bufin, err := Connect(config.Servers[0], 20)
|
|
|
+ if err != nil {
|
|
|
+ // handle error
|
|
|
+ t.Error(err.Error(), config.Servers[0].ListenInterface)
|
|
|
+ t.FailNow()
|
|
|
+ } else {
|
|
|
+ // client goes into command state
|
|
|
+ if _, err := Command(conn, bufin, "HELO localtester"); err != nil {
|
|
|
+ t.Error("Hello command failed", err.Error())
|
|
|
+ }
|
|
|
+ // Basic valid address
|
|
|
+ response, err := Command(conn, bufin, "MAIL FROM:[email protected]")
|
|
|
+ if err != nil {
|
|
|
+ t.Error("command failed", err.Error())
|
|
|
+ }
|
|
|
+ expected := "250 2.1.0 OK"
|
|
|
+ if strings.Index(response, expected) != 0 {
|
|
|
+ t.Error("Server did not respond with", expected, ", it said:"+response)
|
|
|
+ }
|
|
|
+
|
|
|
+ // Reset
|
|
|
+ response, err = Command(conn, bufin, "RSET")
|
|
|
+ if err != nil {
|
|
|
+ t.Error("command failed", err.Error())
|
|
|
+ }
|
|
|
+ expected = "250 2.1.0 OK"
|
|
|
+ if strings.Index(response, expected) != 0 {
|
|
|
+ t.Error("Server did not respond with", expected, ", it said:"+response)
|
|
|
+ }
|
|
|
+
|
|
|
+ // Basic valid address (RfC)
|
|
|
+ response, err = Command(conn, bufin, "MAIL FROM:<[email protected]>")
|
|
|
+ if err != nil {
|
|
|
+ t.Error("command failed", err.Error())
|
|
|
+ }
|
|
|
+ expected = "250 2.1.0 OK"
|
|
|
+ if strings.Index(response, expected) != 0 {
|
|
|
+ t.Error("Server did not respond with", expected, ", it said:"+response)
|
|
|
+ }
|
|
|
+
|
|
|
+ // Reset
|
|
|
+ response, err = Command(conn, bufin, "RSET")
|
|
|
+ if err != nil {
|
|
|
+ t.Error("command failed", err.Error())
|
|
|
+ }
|
|
|
+ expected = "250 2.1.0 OK"
|
|
|
+ if strings.Index(response, expected) != 0 {
|
|
|
+ t.Error("Server did not respond with", expected, ", it said:"+response)
|
|
|
+ }
|
|
|
+
|
|
|
+ // Bounce
|
|
|
+ response, err = Command(conn, bufin, "MAIL FROM:<>")
|
|
|
+ if err != nil {
|
|
|
+ t.Error("command failed", err.Error())
|
|
|
+ }
|
|
|
+ expected = "250 2.1.0 OK"
|
|
|
+ if strings.Index(response, expected) != 0 {
|
|
|
+ t.Error("Server did not respond with", expected, ", it said:"+response)
|
|
|
+ }
|
|
|
+
|
|
|
+ // Reset
|
|
|
+ response, err = Command(conn, bufin, "RSET")
|
|
|
+ if err != nil {
|
|
|
+ t.Error("command failed", err.Error())
|
|
|
+ }
|
|
|
+ expected = "250 2.1.0 OK"
|
|
|
+ if strings.Index(response, expected) != 0 {
|
|
|
+ t.Error("Server did not respond with", expected, ", it said:"+response)
|
|
|
+ }
|
|
|
+
|
|
|
+ // What?
|
|
|
+ response, err = Command(conn, bufin, "MAIL FROM:<<>>")
|
|
|
+ if err != nil {
|
|
|
+ t.Error("command failed", err.Error())
|
|
|
+ }
|
|
|
+ expected = "501 5.5.4 Invalid address"
|
|
|
+ if strings.Index(response, expected) != 0 {
|
|
|
+ t.Error("Server did not respond with", expected, ", it said:"+response)
|
|
|
+ }
|
|
|
+
|
|
|
+ // Reset
|
|
|
+ response, err = Command(conn, bufin, "RSET")
|
|
|
+ if err != nil {
|
|
|
+ t.Error("command failed", err.Error())
|
|
|
+ }
|
|
|
+ expected = "250 2.1.0 OK"
|
|
|
+ if strings.Index(response, expected) != 0 {
|
|
|
+ t.Error("Server did not respond with", expected, ", it said:"+response)
|
|
|
+ }
|
|
|
+
|
|
|
+ // Invalid address?
|
|
|
+ response, err = Command(conn, bufin, "MAIL FROM:<justatest>")
|
|
|
+ if err != nil {
|
|
|
+ t.Error("command failed", err.Error())
|
|
|
+ }
|
|
|
+ expected = "501 5.5.4 Invalid address"
|
|
|
+ if strings.Index(response, expected) != 0 {
|
|
|
+ t.Error("Server did not respond with", expected, ", it said:"+response)
|
|
|
+ }
|
|
|
+
|
|
|
+ // Reset
|
|
|
+ response, err = Command(conn, bufin, "RSET")
|
|
|
+ if err != nil {
|
|
|
+ t.Error("command failed", err.Error())
|
|
|
+ }
|
|
|
+ expected = "250 2.1.0 OK"
|
|
|
+ if strings.Index(response, expected) != 0 {
|
|
|
+ t.Error("Server did not respond with", expected, ", it said:"+response)
|
|
|
+ }
|
|
|
+
|
|
|
+ // SMTPUTF8 not implemented for now, currently still accepted
|
|
|
+ response, err = Command(conn, bufin, "MAIL FROM:<anö[email protected]>")
|
|
|
+ if err != nil {
|
|
|
+ t.Error("command failed", err.Error())
|
|
|
+ }
|
|
|
+ expected = "250 2.1.0 OK"
|
|
|
+ if strings.Index(response, expected) != 0 {
|
|
|
+ t.Error("Server did not respond with", expected, ", it said:"+response)
|
|
|
+ }
|
|
|
+
|
|
|
+ // Reset
|
|
|
+ response, err = Command(conn, bufin, "RSET")
|
|
|
+ if err != nil {
|
|
|
+ t.Error("command failed", err.Error())
|
|
|
+ }
|
|
|
+ expected = "250 2.1.0 OK"
|
|
|
+ if strings.Index(response, expected) != 0 {
|
|
|
+ t.Error("Server did not respond with", expected, ", it said:"+response)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 8BITMIME (RfC 6152)
|
|
|
+ response, err = Command(conn, bufin, "MAIL FROM:<[email protected]> BODY=8BITMIME")
|
|
|
+ if err != nil {
|
|
|
+ t.Error("command failed", err.Error())
|
|
|
+ }
|
|
|
+ expected = "250 2.1.0 OK"
|
|
|
+ if strings.Index(response, expected) != 0 {
|
|
|
+ t.Error("Server did not respond with", expected, ", it said:"+response)
|
|
|
+ }
|
|
|
+
|
|
|
+ // Reset
|
|
|
+ response, err = Command(conn, bufin, "RSET")
|
|
|
+ if err != nil {
|
|
|
+ t.Error("command failed", err.Error())
|
|
|
+ }
|
|
|
+ expected = "250 2.1.0 OK"
|
|
|
+ if strings.Index(response, expected) != 0 {
|
|
|
+ t.Error("Server did not respond with", expected, ", it said:"+response)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 8BITMIME (RfC 6152) Bounce
|
|
|
+ response, err = Command(conn, bufin, "MAIL FROM:<> BODY=8BITMIME")
|
|
|
+ if err != nil {
|
|
|
+ t.Error("command failed", err.Error())
|
|
|
+ }
|
|
|
+ expected = "250 2.1.0 OK"
|
|
|
+ if strings.Index(response, expected) != 0 {
|
|
|
+ t.Error("Server did not respond with", expected, ", it said:"+response)
|
|
|
+ }
|
|
|
+
|
|
|
+ // Reset
|
|
|
+ response, err = Command(conn, bufin, "RSET")
|
|
|
+ if err != nil {
|
|
|
+ t.Error("command failed", err.Error())
|
|
|
+ }
|
|
|
+ expected = "250 2.1.0 OK"
|
|
|
+ if strings.Index(response, expected) != 0 {
|
|
|
+ t.Error("Server did not respond with", expected, ", it said:"+response)
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ conn.Close()
|
|
|
+ app.Shutdown()
|
|
|
+ } else {
|
|
|
+ if startErrors := app.Start(); startErrors != nil {
|
|
|
+ t.Error(startErrors)
|
|
|
+ app.Shutdown()
|
|
|
+ t.FailNow()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ logOut.Flush()
|
|
|
+ // don't forget to reset
|
|
|
+ logBuffer.Reset()
|
|
|
+ logIn.Reset(&logBuffer)
|
|
|
+}
|
|
|
+
|
|
|
// It should error when MAIL FROM was given twice
|
|
|
func TestNestedMailCmd(t *testing.T) {
|
|
|
if initErr != nil {
|