package web
// The mail page and attachment download (novox/hq ADR 0440 ยง5, issue 1266).
import (
"context"
"encoding/base64"
"encoding/json"
"errors"
"net/http"
"net/http/httptest"
"strings"
"testing"
)
// 1266/AC1, AC2: a mail whose body holds and
shows that
// text escaped, carries no script or img element, and nothing on the page names another origin.
func TestMailPageEscapesScriptAndRemoteImageInTheBody(t *testing.T) {
raw, _ := json.Marshal(map[string]any{
"account": "mesh", "folder": "INBOX", "uid": 7, "subject": "hi", "date": "2026-01-01T00:00:00Z",
"from": []map[string]any{{"address": "bob@example.org"}}, "to": []map[string]any{{"address": "me@example.org"}},
"text": ` and
`,
})
b := &Bundle{Read: func(context.Context, map[string]any) (json.RawMessage, error) { return raw, nil }}
w := httptest.NewRecorder()
r := httptest.NewRequest(http.MethodGet, "/mail?account=mesh&folder=INBOX&uid=7", nil)
b.mailPage(w, r)
body := w.Body.String()
if strings.Contains(body, "