mail-server/pepe.toml

92 lines
1.8 KiB
TOML
Raw Normal View History

2023-03-23 01:41:58 +08:00
I have the following SQLite table for storing email data:
CREATE TABLE email (
email_id INTEGER PRIMARY KEY,
blob_id TEXT NOT NULL,
thread_id INTEGER NOT NULL,
size INTEGER NOT NULL,
received_at TIMESTAMP NOT NULL,
message_id TEXT NOT NULL,
in_reply_to TEXT NOT NULL,
sender TEXT NOT NULL,
from TEXT NOT NULL,
to TEXT NOT NULL,
cc TEXT NOT NULL,
bcc TEXT NOT NULL,
reply_to TEXT NOT NULL,
subject TEXT NOT NULL,
sent_at TIMESTAMP NOT NULL,
has_attachment BOOL NOT NULL,
preview TEXT NOT NULL
);
The mailboxes and keywords for each message are stored in separate tables:
CREATE TABLE email_mailbox (
email_id INTEGER PRIMARY KEY,
mailbox_id INTEGER NOT NULL,
)
CREATE TABLE email_keyword (
email_id INTEGER PRIMARY KEY,
keyword TEXT NOT NULL
);
How would you write a SQLite query to list the email IDs of all the Emails with the subject "sales" sorted by messages that belong to the same Thread and have a the keyword "draft", then sorted by received at and then has attachment.
[email]
id: INT
blob_id: HASH
thread_id: INT
size: INT
received_at: TIMESTAMP
message_id: TEXT
in_reply_to: TEXT
sender: TEXT
from: TEXT
to: TEXT
cc: TEXT
bcc: TEXT
reply_to: TEXT
subject: TEXT
sent_at: TIMESTAMP
has_attachment: BOOL
preview: TEXT
[email_mailbox]
email_id: INT
mailbox_id: INT
imap_uid: INT
[email_keyword]
email_id: INT
keyword: TEXT
/*
o id
o blobId
o threadId
o mailboxIds
o keywords
o size
o receivedAt
o messageId
o inReplyTo
o sender
o from
o to
o cc
o bcc
o replyTo
o subject
o sentAt
o hasAttachment
o preview
[ "partId", "blobId", "size", "name", "type", "charset",
"disposition", "cid", "language", "location" ]
*/