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
4 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>
|
||||
|
|
|
|||
Loading…
Reference in a new issue