feat(protocols): trusted senders are not filed as spam, when the message proves its sender
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b536ed13e7
commit
d7f9659b5e
7 files changed
+226
No files matched your search
@@ -0,0 +1,32 @@
|
||||
package postgres
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
)
|
||||
|
||||
// TrustedSenders reads the senders a mailbox trusts. The webmail writes them
|
||||
// through the auth service; delivery only ever asks.
|
||||
type TrustedSenders struct {
|
||||
pool *pgxpool.Pool
|
||||
}
|
||||
|
||||
func NewTrustedSenders(pool *pgxpool.Pool) *TrustedSenders {
|
||||
return &TrustedSenders{pool: pool}
|
||||
}
|
||||
|
||||
func (t *TrustedSenders) IsTrusted(ctx context.Context, mailboxID uuid.UUID, address string) (bool, error) {
|
||||
var trusted bool
|
||||
err := t.pool.QueryRow(ctx, `
|
||||
SELECT EXISTS (
|
||||
SELECT 1 FROM trusted_senders WHERE mailbox_id = $1 AND address = $2
|
||||
)
|
||||
`, mailboxID, address).Scan(&trusted)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("look up a trusted sender: %w", err)
|
||||
}
|
||||
return trusted, nil
|
||||
}
|
||||
Reference in new issue
Block a user