feat: store email attachments in R2 and expose as RSS enclosures

Attachments from incoming emails are uploaded to an optional Cloudflare R2
bucket and exposed as <enclosure> elements in RSS and <link rel="enclosure">
in Atom feeds, served at /files/{id}/{filename} with immutable caching.

R2 is opt-in: if ATTACHMENT_BUCKET is not bound the feature is a no-op.
Attachments are cleaned up from R2 on email/feed deletion and during
size-based feed trimming. Adds MockR2 to the test setup.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Julien Herr
2026-05-21 09:09:37 +02:00
parent 3e28246c61
commit e93bbb8d3e
15 changed files with 615 additions and 19 deletions
+11
View File
@@ -3,11 +3,20 @@ export interface Env {
EMAIL_STORAGE: KVNamespace;
ADMIN_PASSWORD: string;
DOMAIN: string;
ATTACHMENT_BUCKET?: R2Bucket;
FEED_MAX_SIZE_BYTES?: string;
PROXY_TRUSTED_IPS?: string;
PROXY_AUTH_SECRET?: string;
}
// Stored attachment metadata (bytes live in R2, keyed by id)
export interface AttachmentData {
id: string;
filename: string;
contentType: string;
size: number;
}
// Email interface for stored emails
export interface EmailData {
subject: string;
@@ -15,6 +24,7 @@ export interface EmailData {
content: string;
receivedAt: number;
headers: Record<string, string>;
attachments?: AttachmentData[];
}
// Feed configuration interface
@@ -41,6 +51,7 @@ export interface EmailMetadata {
subject: string;
receivedAt: number;
size?: number;
attachmentIds?: string[];
}
// Feed list interface