{ "format_version": 1, "id": "email", "name": "Email", "plural": "Emails", "builtin": true, "visibility": "owner", "date": "sent_at", "title": "subject", "columns": [ { "key": "thread_id", "name": "Conversation", "type": "link", "link_to": "email_thread", "required": true, "readonly": true, "contributes": false }, { "key": "external_id", "type": "text", "readonly": true }, { "key": "subject", "name": "Subject", "type": "text", "readonly": true }, { "key": "from_email", "name": "From address", "type": "text", "readonly": true }, { "key": "from_name", "name": "From", "type": "text", "readonly": true, "fact": true, "reading": "{value}" }, { "key": "recipients", "type": "longtext", "readonly": true }, { "key": "sent_at", "name": "Sent", "type": "date", "format": "calendar-datetime", "readonly": true, "fact": true, "reading": "{value}" }, { "key": "body", "type": "longtext", "readonly": true }, { "key": "snippet", "type": "text", "readonly": true }, { "key": "attachments", "type": "longtext", "readonly": true }, { "key": "gmail_id", "type": "text", "readonly": true }, { "key": "gmail_account", "type": "text", "readonly": true }, { "key": "labels", "type": "longtext", "readonly": true }, { "key": "unread", "type": "bool", "readonly": false }, { "key": "starred", "type": "bool", "readonly": false }, { "key": "in_inbox", "name": "In inbox", "type": "bool", "readonly": false }, { "key": "trashed_at", "name": "Binned", "type": "date", "readonly": true }, { "key": "sync_state", "type": "text", "readonly": true }, { "key": "account", "type": "text", "readonly": true }, { "key": "to_line", "name": "To", "type": "longtext", "readonly": true }, { "key": "cc_line", "name": "Cc", "type": "longtext", "readonly": true }, { "key": "media", "type": "file", "readonly": true, "presentation": "attachments" }, { "key": "direction", "type": "choice", "choices": [ "in", "out" ], "readonly": true }, { "key": "binned", "name": "In bin", "type": "bool", "readonly": true } ], "instructions": "Imported email archive. Ingest and Gmail sync run in Rust. Cotton has no send or reply verb. Never create imported mail as a substitute for delivery.", "tables": [ { "name": "cotton_emails", "columns": [ { "name": "id", "type": "TEXT", "default": null, "nullable": true, "primary_key": true, "declaration": "\n id TEXT PRIMARY KEY", "position": 0 }, { "name": "workspace_id", "type": "TEXT", "default": null, "nullable": false, "primary_key": false, "declaration": "\n workspace_id TEXT NOT NULL", "position": 1 }, { "name": "thread_id", "type": "TEXT", "default": null, "nullable": false, "primary_key": false, "declaration": "\n thread_id TEXT NOT NULL", "position": 2 }, { "name": "external_id", "type": "TEXT", "default": null, "nullable": false, "primary_key": false, "declaration": "\n external_id TEXT NOT NULL", "position": 3 }, { "name": "subject", "type": "TEXT", "default": null, "nullable": true, "primary_key": false, "declaration": "\n subject TEXT", "position": 4 }, { "name": "from_email", "type": "TEXT", "default": null, "nullable": false, "primary_key": false, "declaration": "\n from_email TEXT NOT NULL", "position": 5 }, { "name": "from_name", "type": "TEXT", "default": null, "nullable": true, "primary_key": false, "declaration": "\n from_name TEXT", "position": 6 }, { "name": "recipients", "type": "TEXT", "default": "'[]'", "nullable": false, "primary_key": false, "declaration": "\n recipients TEXT NOT NULL DEFAULT '[]'", "position": 7 }, { "name": "sent_at", "type": "TEXT", "default": null, "nullable": false, "primary_key": false, "declaration": "\n sent_at TEXT NOT NULL", "position": 8 }, { "name": "body", "type": "TEXT", "default": null, "nullable": true, "primary_key": false, "declaration": "\n body TEXT", "position": 9 }, { "name": "snippet", "type": "TEXT", "default": null, "nullable": true, "primary_key": false, "declaration": "\n snippet TEXT", "position": 10 }, { "name": "attachments", "type": "TEXT", "default": "'[]'", "nullable": false, "primary_key": false, "declaration": "\n attachments TEXT NOT NULL DEFAULT '[]'", "position": 11 }, { "name": "created_at", "type": "TEXT", "default": null, "nullable": false, "primary_key": false, "declaration": "\n created_at TEXT NOT NULL", "position": 12 }, { "name": "_hlc", "type": "TEXT", "default": "''", "nullable": false, "primary_key": false, "declaration": "\n _hlc TEXT NOT NULL DEFAULT ''", "position": 13 }, { "name": "gmail_id", "type": "TEXT", "default": null, "nullable": true, "primary_key": false, "declaration": " gmail_id TEXT", "position": 14 }, { "name": "gmail_account", "type": "TEXT", "default": null, "nullable": true, "primary_key": false, "declaration": " gmail_account TEXT", "position": 15 }, { "name": "labels", "type": "TEXT", "default": null, "nullable": true, "primary_key": false, "declaration": " labels TEXT CHECK (labels IS NULL OR json_type(labels) = 'array')", "position": 16 }, { "name": "unread", "type": "INTEGER", "default": "0", "nullable": false, "primary_key": false, "declaration": " unread INTEGER NOT NULL DEFAULT 0", "position": 17 }, { "name": "starred", "type": "INTEGER", "default": "0", "nullable": false, "primary_key": false, "declaration": " starred INTEGER NOT NULL DEFAULT 0", "position": 18 }, { "name": "in_inbox", "type": "INTEGER", "default": "1", "nullable": false, "primary_key": false, "declaration": " in_inbox INTEGER NOT NULL DEFAULT 1", "position": 19 }, { "name": "trashed_at", "type": "TEXT", "default": null, "nullable": true, "primary_key": false, "declaration": " trashed_at TEXT", "position": 20 }, { "name": "sync_state", "type": "TEXT", "default": null, "nullable": true, "primary_key": false, "declaration": " sync_state TEXT CHECK (sync_state IS NULL OR sync_state IN ('synced', 'pending'))", "position": 21 }, { "name": "_born", "type": "TEXT", "default": null, "nullable": true, "primary_key": false, "declaration": "\n _born TEXT", "position": 22 }, { "name": "account", "type": "TEXT", "default": null, "nullable": true, "primary_key": false, "declaration": "\n account TEXT", "position": 23 } ], "constraints": [ { "declaration": "\n UNIQUE (workspace_id, external_id)", "position": 24 }, { "declaration": "\n CHECK (length(external_id) > 0)", "position": 25 }, { "declaration": "\n CHECK (length(from_email) > 0)", "position": 26 }, { "declaration": "\n CHECK (json_type(recipients) = 'array')", "position": 27 }, { "declaration": "\n CHECK (json_type(attachments) = 'array')", "position": 28 }, { "declaration": "\n FOREIGN KEY (thread_id) REFERENCES cotton_email_threads(id)", "position": 29 }, { "declaration": "\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n ", "position": 30 } ], "prefix": "CREATE TABLE cotton_emails (", "suffix": ")", "indexes": [ "CREATE INDEX idx_cotton_emails_binned ON cotton_emails (workspace_id,trashed_at) WHERE trashed_at IS NOT NULL", "CREATE INDEX idx_cotton_emails_thread_sent ON cotton_emails (thread_id, sent_at DESC)", "CREATE INDEX idx_cotton_emails_workspace ON cotton_emails (workspace_id)", "CREATE INDEX idx_cotton_emails_account ON cotton_emails (workspace_id, account) WHERE account IS NOT NULL", "CREATE INDEX idx_cotton_emails_gmail_id ON cotton_emails (workspace_id, gmail_id)", "CREATE INDEX idx_cotton_emails_from ON cotton_emails (workspace_id, from_email)", "CREATE INDEX idx_cotton_emails_pending ON cotton_emails (workspace_id, sync_state)\n WHERE sync_state = 'pending'", "CREATE INDEX idx_cotton_emails_account_live ON cotton_emails (workspace_id, lower(coalesce(account, gmail_account)), trashed_at)", "CREATE INDEX idx_cotton_emails_thread_live ON cotton_emails (thread_id, trashed_at, in_inbox, starred, unread)", "CREATE INDEX IF NOT EXISTS idx_cotton_emails_author ON cotton_emails (substr(_hlc, 20), _hlc)" ], "full_text": [ "CREATE VIRTUAL TABLE fts_emails USING fts5(\n subject, body, content = 'cotton_emails', content_rowid = 'rowid',\n tokenize = 'unicode61 remove_diacritics 2'\n )", "CREATE VIRTUAL TABLE fts_mail USING fts5(\n subject, body, from_name, from_email, content = 'cotton_emails', content_rowid = 'rowid',\n tokenize = 'unicode61 remove_diacritics 2'\n )" ], "triggers": [ "CREATE TRIGGER fts_emails_ai AFTER INSERT ON cotton_emails WHEN new.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_emails'), 0) BEGIN\n INSERT INTO fts_emails (rowid, subject, body) VALUES (new.rowid, new.subject, new.body);\n END", "CREATE TRIGGER fts_emails_ad AFTER DELETE ON cotton_emails WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_emails'), 0) BEGIN\n INSERT INTO fts_emails (fts_emails, rowid, subject, body) VALUES ('delete', old.rowid, old.subject, old.body);\n END", "CREATE TRIGGER fts_emails_au AFTER UPDATE OF subject, body ON cotton_emails\n FOR EACH ROW WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_emails'), 0) AND (new.subject IS NOT old.subject OR new.body IS NOT old.body) BEGIN\n INSERT INTO fts_emails (fts_emails, rowid, subject, body) VALUES ('delete', old.rowid, old.subject, old.body);\n INSERT INTO fts_emails (rowid, subject, body) VALUES (new.rowid, new.subject, new.body);\n END", "CREATE TRIGGER fts_mail_ai AFTER INSERT ON cotton_emails WHEN new.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_mail'), 0) BEGIN\n INSERT INTO fts_mail (rowid, subject, body, from_name, from_email) VALUES (new.rowid, new.subject, new.body, new.from_name, new.from_email);\n END", "CREATE TRIGGER fts_mail_ad AFTER DELETE ON cotton_emails WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_mail'), 0) BEGIN\n INSERT INTO fts_mail (fts_mail, rowid, subject, body, from_name, from_email) VALUES ('delete', old.rowid, old.subject, old.body, old.from_name, old.from_email);\n END", "CREATE TRIGGER fts_mail_au AFTER UPDATE OF subject, body, from_name, from_email ON cotton_emails\n FOR EACH ROW WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_mail'), 0) AND (new.subject IS NOT old.subject OR new.body IS NOT old.body OR new.from_name IS NOT old.from_name OR new.from_email IS NOT old.from_email) BEGIN\n INSERT INTO fts_mail (fts_mail, rowid, subject, body, from_name, from_email) VALUES ('delete', old.rowid, old.subject, old.body, old.from_name, old.from_email);\n INSERT INTO fts_mail (rowid, subject, body, from_name, from_email) VALUES (new.rowid, new.subject, new.body, new.from_name, new.from_email);\n END" ] }, { "name": "cotton_email_participants", "columns": [ { "name": "id", "type": "TEXT", "default": null, "nullable": true, "primary_key": true, "declaration": "\n id TEXT PRIMARY KEY", "position": 0 }, { "name": "workspace_id", "type": "TEXT", "default": null, "nullable": false, "primary_key": false, "declaration": "\n workspace_id TEXT NOT NULL", "position": 1 }, { "name": "thread_id", "type": "TEXT", "default": null, "nullable": false, "primary_key": false, "declaration": "\n thread_id TEXT NOT NULL", "position": 2 }, { "name": "email", "type": "TEXT", "default": null, "nullable": false, "primary_key": false, "declaration": "\n email TEXT NOT NULL", "position": 3 }, { "name": "display_name", "type": "TEXT", "default": null, "nullable": true, "primary_key": false, "declaration": "\n display_name TEXT", "position": 4 }, { "name": "role", "type": "TEXT", "default": "'cc'", "nullable": false, "primary_key": false, "declaration": "\n role TEXT NOT NULL DEFAULT 'cc'", "position": 5 }, { "name": "created_at", "type": "TEXT", "default": null, "nullable": false, "primary_key": false, "declaration": "\n created_at TEXT NOT NULL", "position": 6 }, { "name": "updated_at", "type": "TEXT", "default": null, "nullable": false, "primary_key": false, "declaration": "\n updated_at TEXT NOT NULL", "position": 7 }, { "name": "_hlc", "type": "TEXT", "default": "''", "nullable": false, "primary_key": false, "declaration": "\n _hlc TEXT NOT NULL DEFAULT ''", "position": 8 }, { "name": "_born", "type": "TEXT", "default": null, "nullable": true, "primary_key": false, "declaration": "\n _born TEXT", "position": 9 } ], "constraints": [ { "declaration": "\n UNIQUE (thread_id, email)", "position": 10 }, { "declaration": "\n CHECK (length(email) > 0)", "position": 11 }, { "declaration": "\n CHECK (email = lower(email))", "position": 12 }, { "declaration": "\n CHECK (role IN ('from', 'to', 'cc'))", "position": 13 }, { "declaration": "\n FOREIGN KEY (thread_id) REFERENCES cotton_email_threads(id)", "position": 14 }, { "declaration": "\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n ", "position": 15 } ], "prefix": "CREATE TABLE cotton_email_participants (", "suffix": ")", "indexes": [ "CREATE INDEX idx_cotton_email_participants_email ON cotton_email_participants (workspace_id, email)", "CREATE INDEX idx_cotton_email_participants_thread ON cotton_email_participants (thread_id)", "CREATE INDEX IF NOT EXISTS idx_cotton_email_participants_author ON cotton_email_participants (substr(_hlc, 20), _hlc)" ], "full_text": [], "triggers": [] } ], "picture": null, "engine": "email", "project": null, "order": null, "slip": { "title": "subject", "subtitle": "from_name", "trailing": "sent_at", "photo": null, "toggle": null, "dye": "straw" }, "tile": { "face": "slip-list", "current": { "column": "sent_at", "days": 2 } }, "page": [ { "heading": null, "columns": [ "from_name", "sent_at" ], "role": "facts" }, { "heading": null, "columns": [ "body", "media" ] }, { "heading": "Details", "columns": [ "subject", "from_email", "to_line", "cc_line" ], "role": "side" }, { "heading": null, "columns": [ "trashed_at" ] } ], "add": false, "delete": false, "commands": [ { "id": "thread", "label": "Open thread", "kind": "open", "opens": "thread_id" } ], "card": { "face": "plain", "fields": [ { "slot": "title", "column": "subject" }, { "slot": "subtitle", "column": "from_name" }, { "slot": "body", "column": "body" }, { "slot": "facts", "column": "sent_at", "also": [ "from_email", "to_line", "cc_line" ] } ] }, "parts": { "shape": "desk", "head": { "facts": [ "from_name", "sent_at" ] }, "links": [], "body": "body", "lists": [], "acts": { "more": [ "thread" ] }, "strip": [ { "column": "media" }, { "column": "from_email" }, { "column": "to_line" }, { "column": "cc_line" } ], "opens": "body" } }