CREATE TABLE IF NOT EXISTS emails (
    id BIGINT AUTO_INCREMENT PRIMARY KEY,
    recipient VARCHAR(255) NOT NULL,
    sender VARCHAR(255) NOT NULL,
    subject VARCHAR(512),
    body TEXT,
    received_at DATETIME,
    raw MEDIUMBLOB
);

CREATE TABLE IF NOT EXISTS email_attachments (
    id BIGINT AUTO_INCREMENT PRIMARY KEY,
    email_id BIGINT NOT NULL,
    filename VARCHAR(255),
    content_type VARCHAR(128),
    content LONGBLOB,
    FOREIGN KEY (email_id) REFERENCES emails(id) ON DELETE CASCADE
);
