feat: show who really wrote a held message in the CLI and the UI
- Add SENDER and FROM columns to held ls, flagging a From header that differs from the sender - Show the From header and a badge in the Held tab; keep the envelope sender visible
This commit is contained in:
parent
1e46be79b0
commit
bcca031ea3
6 changed files with 80 additions and 5 deletions
|
|
@ -30,6 +30,10 @@ export interface Held {
|
|||
created_at: string
|
||||
/** Why the message was held, for the admin. */
|
||||
reason: string
|
||||
/** The From header as received: the author readers will see. */
|
||||
from: string
|
||||
/** The From header names someone other than the envelope sender, or nobody usable. */
|
||||
mismatch: boolean
|
||||
}
|
||||
|
||||
export interface Message {
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ describe('list page', () => {
|
|||
installFakeApi(
|
||||
newState({
|
||||
lists: [dev()],
|
||||
held: { 1: [{ id: 5, sender: 'a@x.com', subject: 's', size: 10, created_at: '2030-01-01T00:00:00Z', reason: '' }] },
|
||||
held: { 1: [{ id: 5, sender: 'a@x.com', subject: 's', size: 10, created_at: '2030-01-01T00:00:00Z', reason: '', from: 'a@x.com', mismatch: false }] },
|
||||
}),
|
||||
)
|
||||
renderApp('/lists/1', { token: 'good' })
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@ const held = (id: number, over: Partial<Held> = {}): Held => ({
|
|||
size: 2048,
|
||||
created_at: '2030-01-02T03:04:05Z',
|
||||
reason: 'the list is moderated',
|
||||
from: `Sender ${id} <s${id}@example.com>`,
|
||||
mismatch: false,
|
||||
...over,
|
||||
})
|
||||
|
||||
|
|
@ -46,6 +48,29 @@ describe('held tab', () => {
|
|||
expect(screen.getByRole('columnheader', { name: /reason/i })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('shows the author readers will see, and flags a From header that is not the sender', async () => {
|
||||
await setup([
|
||||
held(1),
|
||||
held(2, { sender: 'bob@example.com', from: 'Eve <eve@example.com>', mismatch: true }),
|
||||
held(3, { sender: 'bob@example.com', from: '', mismatch: true }),
|
||||
])
|
||||
const honest = (await screen.findByText('Subject 1')).closest('tr')!
|
||||
expect(within(honest).getByText('Sender 1 <s1@example.com>')).toBeInTheDocument()
|
||||
expect(within(honest).getByText('s1@example.com')).toBeInTheDocument()
|
||||
expect(within(honest).queryByText(/differs from the sender/i)).not.toBeInTheDocument()
|
||||
|
||||
const passing = screen.getByText('Subject 2').closest('tr')!
|
||||
expect(within(passing).getByText('Eve <eve@example.com>')).toBeInTheDocument()
|
||||
expect(within(passing).getByText('bob@example.com')).toBeInTheDocument() // who really sent it
|
||||
expect(within(passing).getByText(/differs from the sender/i)).toBeInTheDocument()
|
||||
|
||||
const noFrom = screen.getByText('Subject 3').closest('tr')!
|
||||
expect(within(noFrom).getByText(/differs from the sender/i)).toBeInTheDocument()
|
||||
expect(within(noFrom).getByText('(none)')).toBeInTheDocument()
|
||||
expect(screen.getByRole('columnheader', { name: /^from \(header\)$/i })).toBeInTheDocument()
|
||||
expect(screen.getByRole('columnheader', { name: /^sender$/i })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('says nothing is waiting', async () => {
|
||||
await setup([])
|
||||
expect(await screen.findByText(/nothing is waiting/i)).toBeInTheDocument()
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import {
|
|||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from '@/components/ui/alert-dialog'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table'
|
||||
import { api, type Held, type List } from '@/lib/api'
|
||||
|
|
@ -60,7 +61,8 @@ export function HeldTab() {
|
|||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Subject</TableHead>
|
||||
<TableHead>From</TableHead>
|
||||
<TableHead>From (header)</TableHead>
|
||||
<TableHead>Sender</TableHead>
|
||||
<TableHead>Received</TableHead>
|
||||
<TableHead>Size</TableHead>
|
||||
<TableHead>Reason</TableHead>
|
||||
|
|
@ -71,6 +73,14 @@ export function HeldTab() {
|
|||
{items.map((h) => (
|
||||
<TableRow key={h.id}>
|
||||
<TableCell className="font-medium">{h.subject || '(no subject)'}</TableCell>
|
||||
<TableCell className="whitespace-normal">
|
||||
{h.from || <span className="text-muted-foreground">(none)</span>}
|
||||
{h.mismatch && (
|
||||
<Badge variant="destructive" className="ml-2">
|
||||
Differs from the sender
|
||||
</Badge>
|
||||
)}
|
||||
</TableCell>
|
||||
<TableCell>{h.sender}</TableCell>
|
||||
<TableCell>{formatDate(h.created_at)}</TableCell>
|
||||
<TableCell>{formatBytes(h.size)}</TableCell>
|
||||
|
|
|
|||
|
|
@ -319,7 +319,7 @@ func TestHeldQueue(t *testing.T) {
|
|||
id2, _ := e.s.HoldMessage(l.ID, "eve@x.com", []byte("Subject: Second held\r\n\r\nbody"), "")
|
||||
id3, _ := e.s.HoldMessage(l.ID, "anon@x.com", []byte("From: anon@x.com\r\n\r\nno subject here"), "")
|
||||
out := e.ok(t, "held", "ls", "dev@example.org")
|
||||
for _, want := range []string{"ID", "FROM", "SUBJECT", "SIZE", "REASON", "bob@x.com", "First held", "eve@x.com", "Second held", "(no subject)", "the list is moderated"} {
|
||||
for _, want := range []string{"ID", "SENDER", "FROM", "SUBJECT", "SIZE", "REASON", "bob@x.com", "First held", "eve@x.com", "Second held", "(no subject)", "the list is moderated"} {
|
||||
if !strings.Contains(out, want) {
|
||||
t.Fatalf("held ls lacks %q:\n%s", want, out)
|
||||
}
|
||||
|
|
@ -797,3 +797,30 @@ func TestQueueShowsFailedDeliveries(t *testing.T) {
|
|||
t.Fatalf("a failed delivery can be cleared:\n%s", out)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHeldListingWarnsWhenTheHeaderDiffersFromTheSender(t *testing.T) {
|
||||
e := newEnv(t)
|
||||
e.ok(t, "list", "add", "dev@example.org")
|
||||
l, _ := e.s.FindList("dev@example.org")
|
||||
e.s.HoldMessage(l.ID, "bob@x.com", []byte("From: Bob <bob@x.com>\r\nSubject: honest\r\n\r\nb"), "r")
|
||||
e.s.HoldMessage(l.ID, "bob@x.com", []byte("From: Eve <eve@x.com>\r\nSubject: passing as eve\r\n\r\nb"), "r")
|
||||
e.s.HoldMessage(l.ID, "bob@x.com", []byte("Subject: no from\r\n\r\nb"), "r")
|
||||
out := e.ok(t, "held", "ls", "dev@example.org")
|
||||
lines := map[string]string{}
|
||||
for _, l := range strings.Split(out, "\n") {
|
||||
for _, key := range []string{"honest", "passing as eve", "no from"} {
|
||||
if strings.Contains(l, key) {
|
||||
lines[key] = l
|
||||
}
|
||||
}
|
||||
}
|
||||
if strings.Contains(lines["honest"], "differs") {
|
||||
t.Fatalf("a matching header is not flagged: %q", lines["honest"])
|
||||
}
|
||||
if !strings.Contains(lines["passing as eve"], "Eve <eve@x.com>") || !strings.Contains(lines["passing as eve"], "differs") {
|
||||
t.Fatalf("the author readers will see is shown and flagged: %q", lines["passing as eve"])
|
||||
}
|
||||
if !strings.Contains(lines["no from"], "differs") {
|
||||
t.Fatalf("no usable From is flagged too: %q", lines["no from"])
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -375,6 +375,8 @@ func (c *cmd) heldLs(args []string) int {
|
|||
Size int `json:"size"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
Reason string `json:"reason"`
|
||||
From string `json:"from"`
|
||||
Mismatch bool `json:"mismatch"`
|
||||
}
|
||||
if err := json.Unmarshal(raw, &hs); err != nil {
|
||||
return c.fail(err)
|
||||
|
|
@ -383,13 +385,20 @@ func (c *cmd) heldLs(args []string) int {
|
|||
fmt.Fprintln(c.io.Out, "Nothing is held for moderation.")
|
||||
return 0
|
||||
}
|
||||
rows := [][]string{{"ID", "RECEIVED", "FROM", "SUBJECT", "SIZE", "REASON"}}
|
||||
rows := [][]string{{"ID", "RECEIVED", "SENDER", "FROM", "SUBJECT", "SIZE", "REASON"}}
|
||||
for _, h := range hs {
|
||||
subject := h.Subject
|
||||
if subject == "" {
|
||||
subject = "(no subject)"
|
||||
}
|
||||
rows = append(rows, []string{strconv.FormatInt(h.ID, 10), formatDate(h.CreatedAt), h.Sender, subject, formatBytes(h.Size), h.Reason})
|
||||
from := h.From
|
||||
if from == "" {
|
||||
from = "-"
|
||||
}
|
||||
if h.Mismatch {
|
||||
from += " (differs)" // readers would see someone other than the sender
|
||||
}
|
||||
rows = append(rows, []string{strconv.FormatInt(h.ID, 10), formatDate(h.CreatedAt), h.Sender, from, subject, formatBytes(h.Size), h.Reason})
|
||||
}
|
||||
c.table(rows)
|
||||
return 0
|
||||
|
|
|
|||
Loading…
Reference in a new issue