chore(email): name the server, encryption and attachment size on a send failure

"An existing connection was forcibly closed by the remote host" during DATA
reads the same whether the server refused the SIZE, hit an hourly quota, or
simply dropped the socket — and only the first is something an operator can act
on. The message now carries host:port, the encryption in use and the total
attachment size, so the size can be ruled in or out without a second attempt.

A path that does not exist is not counted: the mail library skips it, so
reporting it would describe a message that was never sent.
This commit is contained in:
2026-08-13 12:09:57 +02:00
parent eba54344b0
commit 2695747db6
2 changed files with 61 additions and 1 deletions
+34
View File
@@ -0,0 +1,34 @@
package email
import (
"os"
"path/filepath"
"testing"
)
// "An existing connection was forcibly closed" during DATA reads the same
// whether the server refused the SIZE, hit a quota, or just dropped the socket
// — and only the first is something the operator can act on. Naming the size in
// the error rules it in or out without a second attempt.
func TestDescribeSize(t *testing.T) {
dir := t.TempDir()
a := filepath.Join(dir, "card.jpg")
if err := os.WriteFile(a, make([]byte, 2048), 0o644); err != nil {
t.Fatal(err)
}
if got := describeSize(nil); got != "no attachment" {
t.Errorf("no attachment = %q", got)
}
if got := describeSize([]string{""}); got != "no attachment" {
t.Errorf("blank path = %q, want it ignored", got)
}
if got := describeSize([]string{a}); got != "1 attachment(s), 2 KB" {
t.Errorf("one file = %q", got)
}
// A path that does not exist must not be counted — the mail library skips it,
// so reporting it would describe a message that was never sent.
if got := describeSize([]string{a, filepath.Join(dir, "gone.jpg")}); got != "1 attachment(s), 2 KB" {
t.Errorf("missing file counted: %q", got)
}
}