Repository: emersion/go-smtp
Pull request #78 (2019-11-29 23:20:05)

server: Add missing BODY argument case

codecov[bot]: # [Codecov](https://codecov.io/gh/emersion/go-smtp/pull/78?src=pr&el=h1) Report
> Merging [#78](https://codecov.io/gh/emersion/go-smtp/pull/78?src=pr&el=desc) into [master](https://codecov.io/gh/emersion/go-smtp/commit/a6972aed0ad8e6ef86c5e581060d91b77ac9759e?src=pr&el=desc) will **increase** coverage by `0.24%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/emersion/go-smtp/pull/78/graphs/tree.svg?width=650&token=vj7HO8ABwC&height=150&src=pr)](https://codecov.io/gh/emersion/go-smtp/pull/78?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master      #78      +/-   ##
==========================================
+ Coverage   63.26%   63.51%   +0.24%     
==========================================
  Files           8        8              
  Lines         882      888       +6     
==========================================
+ Hits          558      564       +6     
  Misses        238      238              
  Partials       86       86
```


| [Impacted Files](https://codecov.io/gh/emersion/go-smtp/pull/78?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [conn.go](https://codecov.io/gh/emersion/go-smtp/pull/78/diff?src=pr&el=tree#diff-Y29ubi5nbw==) | `63.03% <100%> (+0.57%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/emersion/go-smtp/pull/78?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/emersion/go-smtp/pull/78?src=pr&el=footer). Last update [a6972ae...e32d416](https://codecov.io/gh/emersion/go-smtp/pull/78?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/conn.go b/conn.go
index 3e71955..40e6556 100644
--- a/conn.go
+++ b/conn.go
@@ -329,6 +329,13 @@ func (c *Conn) handleMail(arg string) {
 					return
 				}
 				opts.RequireTLS = true
+			case "BODY":
+				switch value {
+				case "7BIT", "8BITMIME":
+				default:
+					c.WriteResponse(500, EnhancedCode{5, 5, 4}, "Unknown BODY value")
+					return
+				}
 			default:
 				c.WriteResponse(500, EnhancedCode{5, 5, 4}, "Unknown MAIL FROM argument")
 				return


Test patch:
diff --git a/server_test.go b/server_test.go
index ed66927..b575c7d 100644
--- a/server_test.go
+++ b/server_test.go
@@ -314,6 +314,34 @@ func TestServerSMTPUTF8_Disabled(t *testing.T) {
 	return
 }
 
+func TestServer8BITMIME(t *testing.T) {
+	_, s, c, scanner := testServerAuthenticated(t)
+	defer s.Close()
+	defer c.Close()
+
+	io.WriteString(c, "MAIL FROM:<alice@wonderland.book> BODY=8BITMIME\r\n")
+	scanner.Scan()
+	if !strings.HasPrefix(scanner.Text(), "250 ") {
+		t.Fatal("Invalid MAIL response:", scanner.Text())
+	}
+
+	return
+}
+
+func TestServer_BODYInvalidValue(t *testing.T) {
+	_, s, c, scanner := testServerAuthenticated(t)
+	defer s.Close()
+	defer c.Close()
+
+	io.WriteString(c, "MAIL FROM:<alice@wonderland.book> BODY=RABIIT\r\n")
+	scanner.Scan()
+	if strings.HasPrefix(scanner.Text(), "250 ") {
+		t.Fatal("Invalid MAIL response:", scanner.Text())
+	}
+
+	return
+}
+
 func TestServerUnknownArg(t *testing.T) {
 	_, s, c, scanner := testServerAuthenticated(t)
 	defer s.Close()