1 parent
0421994fe6
commit
425ea7449b
138 files changed
+5705
-1012
No files matched your search
@@ -0,0 +1,486 @@
|
||||
pub mod auth_user_data {
|
||||
pub const Q_001: &str = "SELECT value FROM user_meta WHERE key = 'schema_version'";
|
||||
}
|
||||
|
||||
pub mod db_calendar {
|
||||
pub const EVENT_SELECT_COLS: &str = "id, title, description, location, start_time, end_time, \
|
||||
all_day, recurrence_rule, attendees, organizer, status, source, source_uid, \
|
||||
source_message_uid, source_message_folder, meeting_url, color, reminder_minutes, \
|
||||
created_at, updated_at";
|
||||
pub const SETTINGS_SELECT_COLS: &str = "default_view, week_starts_on, working_hours_start, \
|
||||
working_hours_end, time_format, zoom_link, teams_link, meet_link, caldav_url, \
|
||||
caldav_username, caldav_enabled, updated_at";
|
||||
pub const Q_001: &str = "SELECT CURRENT_TIMESTAMP";
|
||||
pub const Q_002: &str = "INSERT INTO calendar_events
|
||||
(id, title, description, location, start_time, end_time, all_day,
|
||||
recurrence_rule, attendees, organizer, status, source, source_uid,
|
||||
source_message_uid, source_message_folder, meeting_url, color,
|
||||
reminder_minutes, created_at, updated_at)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20)";
|
||||
pub const Q_003: &str = "DELETE FROM calendar_events WHERE id = $1";
|
||||
pub const Q_004: &str = "INSERT OR IGNORE INTO calendar_settings (id) VALUES (1)";
|
||||
pub const Q_005: &str = "INSERT OR IGNORE INTO calendar_settings (id) VALUES (1)";
|
||||
pub const Q_006: &str = "SELECT id, name, url_template, icon, is_default, created_at
|
||||
FROM meeting_templates ORDER BY is_default DESC, name ASC";
|
||||
pub const Q_007: &str =
|
||||
"INSERT INTO meeting_templates (name, url_template, icon) VALUES ($1, $2, $3)";
|
||||
pub const Q_008: &str = "SELECT id, name, url_template, icon, is_default, created_at
|
||||
FROM meeting_templates WHERE id = $1";
|
||||
pub const Q_009: &str = "DELETE FROM meeting_templates WHERE id = $1";
|
||||
pub const FORMAT_001: &str = "SELECT {EVENT_SELECT_COLS} FROM calendar_events
|
||||
WHERE end_time >= $1 AND start_time <= $2
|
||||
ORDER BY start_time ASC";
|
||||
pub const FORMAT_002: &str =
|
||||
"SELECT {EVENT_SELECT_COLS} FROM calendar_events ORDER BY start_time ASC, title ASC";
|
||||
pub const FORMAT_003: &str = "SELECT {EVENT_SELECT_COLS} FROM calendar_events WHERE id = $1";
|
||||
pub const FORMAT_004: &str = "UPDATE calendar_events SET {} WHERE id = ${idx}";
|
||||
pub const FORMAT_005: &str =
|
||||
"SELECT {EVENT_SELECT_COLS} FROM calendar_events WHERE source_uid = $1";
|
||||
pub const FORMAT_006: &str =
|
||||
"SELECT {SETTINGS_SELECT_COLS} FROM calendar_settings WHERE id = 1";
|
||||
pub const FORMAT_007: &str = "UPDATE calendar_settings SET {} WHERE id = 1";
|
||||
}
|
||||
|
||||
pub mod db_contact_groups {
|
||||
pub const Q_001: &str = "INSERT INTO contact_groups (id, name) VALUES ($1, $2)";
|
||||
pub const Q_002: &str = "SELECT g.id, g.name, g.created_at, g.updated_at,
|
||||
(SELECT COUNT(*) FROM contact_group_members m WHERE m.group_id = g.id) AS member_count
|
||||
FROM contact_groups g
|
||||
ORDER BY g.name ASC";
|
||||
pub const Q_003: &str =
|
||||
"UPDATE contact_groups SET name = $1, updated_at = CURRENT_TIMESTAMP WHERE id = $2";
|
||||
pub const Q_004: &str = "DELETE FROM contact_groups WHERE id = $1";
|
||||
pub const Q_005: &str =
|
||||
"INSERT OR IGNORE INTO contact_group_members (group_id, contact_id) VALUES ($1, $2)";
|
||||
pub const Q_006: &str =
|
||||
"DELETE FROM contact_group_members WHERE group_id = $1 AND contact_id = $2";
|
||||
pub const Q_007: &str = "SELECT c.id, c.email, c.name, c.company, c.notes, c.phone, c.job_title, c.address, c.website, c.birthday, c.is_favorite,
|
||||
c.last_contacted, c.contact_count, c.source, c.created_at, c.updated_at, c.emails_json, c.phones_json, c.addresses_json, EXISTS(SELECT 1 FROM contact_photos p WHERE p.contact_id = c.id) AS has_photo
|
||||
FROM contacts c
|
||||
JOIN contact_group_members m ON m.contact_id = c.id
|
||||
WHERE m.group_id = $1
|
||||
ORDER BY c.name ASC";
|
||||
pub const Q_008: &str = "SELECT g.id, g.name, g.created_at, g.updated_at,
|
||||
(SELECT COUNT(*) FROM contact_group_members m2 WHERE m2.group_id = g.id) AS member_count
|
||||
FROM contact_groups g
|
||||
JOIN contact_group_members m ON m.group_id = g.id
|
||||
WHERE m.contact_id = $1
|
||||
ORDER BY g.name ASC";
|
||||
}
|
||||
|
||||
pub mod db_contacts {
|
||||
pub const CONTACT_SELECT_COLS: &str = "id, email, name, company, notes, phone, job_title, address, website, birthday, is_favorite, last_contacted, contact_count, source, created_at, updated_at, emails_json, phones_json, addresses_json, EXISTS(SELECT 1 FROM contact_photos p WHERE p.contact_id = contacts.id) AS has_photo";
|
||||
pub const Q_001: &str = "INSERT INTO contacts
|
||||
(id, email, name, company, notes, phone, job_title, address, website, birthday, is_favorite, last_contacted,
|
||||
contact_count, source, created_at, updated_at, emails_json, phones_json, addresses_json)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19)
|
||||
ON CONFLICT(id) DO UPDATE SET
|
||||
email=excluded.email, name=excluded.name, company=excluded.company, notes=excluded.notes,
|
||||
phone=excluded.phone, job_title=excluded.job_title, address=excluded.address, website=excluded.website, birthday=excluded.birthday,
|
||||
is_favorite=excluded.is_favorite, last_contacted=excluded.last_contacted, contact_count=excluded.contact_count,
|
||||
source=excluded.source, updated_at=excluded.updated_at, emails_json=excluded.emails_json,
|
||||
phones_json=excluded.phones_json, addresses_json=excluded.addresses_json";
|
||||
pub const Q_002: &str = "DELETE FROM contacts WHERE id = $1";
|
||||
pub const Q_003: &str = r#"
|
||||
SELECT email, name
|
||||
FROM known_addresses
|
||||
WHERE (email LIKE $1 ESCAPE '\' OR name LIKE $1 ESCAPE '\')
|
||||
AND email NOT IN (SELECT email FROM contacts)
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM contacts c, json_each(c.emails_json) alt
|
||||
WHERE lower(alt.value) = lower(known_addresses.email)
|
||||
)
|
||||
ORDER BY email ASC
|
||||
LIMIT $2
|
||||
"#;
|
||||
pub const Q_004: &str = "INSERT INTO known_addresses (email, name) VALUES ($1, $2)
|
||||
ON CONFLICT(email) DO UPDATE SET name = excluded.name WHERE excluded.name != ''";
|
||||
pub const Q_005: &str = "INSERT INTO known_addresses (email, name) VALUES ($1, $2)
|
||||
ON CONFLICT(email) DO UPDATE SET name = excluded.name WHERE excluded.name != ''";
|
||||
pub const Q_006: &str = "UPDATE contacts
|
||||
SET contact_count = contact_count + 1,
|
||||
last_contacted = CURRENT_TIMESTAMP,
|
||||
updated_at = CURRENT_TIMESTAMP
|
||||
WHERE email = $1";
|
||||
pub const Q_007: &str = "INSERT OR IGNORE INTO contacts (id, email, name, source)
|
||||
VALUES ($1, $2, $3, 'auto')";
|
||||
pub const Q_008: &str = "INSERT INTO contact_photos (contact_id, content_type, data, updated_at) VALUES ($1, $2, $3, CURRENT_TIMESTAMP) ON CONFLICT(contact_id) DO UPDATE SET content_type=excluded.content_type, data=excluded.data, updated_at=CURRENT_TIMESTAMP";
|
||||
pub const Q_009: &str = "SELECT content_type, data FROM contact_photos WHERE contact_id = $1";
|
||||
pub const Q_010: &str = "DELETE FROM contact_photos WHERE contact_id = $1";
|
||||
pub const FORMAT_001: &str = "SELECT {CONTACT_SELECT_COLS} FROM contacts WHERE id = $1";
|
||||
pub const FORMAT_002: &str = "SELECT {CONTACT_SELECT_COLS} FROM contacts \
|
||||
WHERE lower(email) = lower($1) \
|
||||
OR EXISTS (SELECT 1 FROM json_each(contacts.emails_json) WHERE lower(value) = lower($1))";
|
||||
pub const FORMAT_003: &str = "SELECT {CONTACT_SELECT_COLS} FROM contacts
|
||||
WHERE name LIKE $1 ESCAPE '\\' OR email LIKE $1 ESCAPE '\\' OR emails_json LIKE $1 ESCAPE '\\'
|
||||
ORDER BY name ASC
|
||||
LIMIT $2 OFFSET $3";
|
||||
pub const FORMAT_004: &str = "SELECT {CONTACT_SELECT_COLS} FROM contacts
|
||||
ORDER BY name ASC
|
||||
LIMIT $1 OFFSET $2";
|
||||
pub const FORMAT_005: &str = "SELECT {CONTACT_SELECT_COLS} FROM contacts
|
||||
WHERE name LIKE $1 ESCAPE '\\' OR email LIKE $1 ESCAPE '\\' OR emails_json LIKE $1 ESCAPE '\\'
|
||||
ORDER BY name ASC
|
||||
LIMIT $2";
|
||||
}
|
||||
|
||||
pub mod db_display_preferences {
|
||||
pub const Q_001: &str = "SELECT density, theme, language, compose_format, deep_index, animation_mode, preview_pane, ui_scale, color_preset, accent_color, background_color, panel_color, text_color, font_family, font_size, row_height, folder_pane_width, message_pane_width, border_radius, contrast, show_avatars, show_attachment_icons, show_flags, reduce_motion, date_format, time_format, compose_autosave_ms, default_priority, request_mdn_default, attachment_reminder, icon_size, toolbar_density, sidebar_item_height, reader_max_width, composer_width, selection_color, unread_font_weight, unread_badge_style, compact_headers, show_borders, scrollbar_density, monochrome, folder_background, message_background, reader_background, compose_font_family, reply_position, quote_style, forward_mode, spellcheck_enabled, interface_skin, preset_scale_unlocked, updated_at FROM display_preferences WHERE id = 1";
|
||||
pub const Q_002: &str = "INSERT OR IGNORE INTO display_preferences (id) VALUES (1)";
|
||||
pub const FORMAT_001: &str = "UPDATE display_preferences SET {} WHERE id = ${}";
|
||||
}
|
||||
|
||||
pub mod db_drafts {
|
||||
pub const Q_001: &str = "INSERT INTO drafts (id, to_addresses, cc_addresses, bcc_addresses, subject, text_body, html_body, in_reply_to, references_header, request_mdn, priority, compose_format, pgp_mode, pgp_inline, pgp_attach_public_key, pgp_attach_recipient_keys, updated_at)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, CURRENT_TIMESTAMP)
|
||||
ON CONFLICT(id) DO UPDATE SET
|
||||
to_addresses = excluded.to_addresses,
|
||||
cc_addresses = excluded.cc_addresses,
|
||||
bcc_addresses = excluded.bcc_addresses,
|
||||
subject = excluded.subject,
|
||||
text_body = excluded.text_body,
|
||||
html_body = excluded.html_body,
|
||||
in_reply_to = excluded.in_reply_to,
|
||||
references_header = excluded.references_header,
|
||||
request_mdn = excluded.request_mdn,
|
||||
priority = excluded.priority,
|
||||
compose_format = excluded.compose_format,
|
||||
pgp_mode = excluded.pgp_mode,
|
||||
pgp_inline = excluded.pgp_inline,
|
||||
pgp_attach_public_key = excluded.pgp_attach_public_key,
|
||||
pgp_attach_recipient_keys = excluded.pgp_attach_recipient_keys,
|
||||
updated_at = CURRENT_TIMESTAMP";
|
||||
pub const Q_002: &str = "SELECT id, to_addresses, cc_addresses, bcc_addresses, subject, text_body, html_body, in_reply_to, references_header, request_mdn, priority, compose_format, pgp_mode, pgp_inline, pgp_attach_public_key, pgp_attach_recipient_keys, remote_folder, remote_uid, remote_uid_validity, created_at, updated_at
|
||||
FROM drafts WHERE id = $1";
|
||||
pub const Q_003: &str = "SELECT id, to_addresses, cc_addresses, bcc_addresses, subject, text_body, html_body, in_reply_to, references_header, request_mdn, priority, compose_format, pgp_mode, pgp_inline, pgp_attach_public_key, pgp_attach_recipient_keys, remote_folder, remote_uid, remote_uid_validity, created_at, updated_at
|
||||
FROM drafts ORDER BY updated_at DESC";
|
||||
pub const Q_004: &str = "UPDATE drafts SET remote_folder = $2, remote_uid = $3, remote_uid_validity = $4 WHERE id = $1";
|
||||
pub const Q_005: &str = "DELETE FROM drafts WHERE id = $1";
|
||||
pub const Q_006: &str =
|
||||
"INSERT INTO draft_attachments (id, draft_id, filename, content_type, size, file_path)
|
||||
VALUES ($1, $2, $3, $4, $5, $6)";
|
||||
pub const Q_007: &str =
|
||||
"SELECT id, draft_id, filename, content_type, size, file_path, created_at
|
||||
FROM draft_attachments WHERE draft_id = $1 ORDER BY created_at ASC";
|
||||
pub const Q_008: &str = "DELETE FROM draft_attachments WHERE id = $1";
|
||||
}
|
||||
|
||||
pub mod db_folder_preferences {
|
||||
pub const Q_001: &str = "SELECT flagged_on_top FROM folder_preferences WHERE folder_name = $1";
|
||||
pub const Q_002: &str = "SELECT flagged_on_top FROM mail_preferences WHERE id = 1";
|
||||
pub const Q_003: &str = "SELECT EXISTS(SELECT 1 FROM folders WHERE name = $1)";
|
||||
pub const Q_004: &str = "SELECT flagged_on_top FROM mail_preferences WHERE id = 1";
|
||||
pub const Q_005: &str = "SELECT EXISTS(SELECT 1 FROM folders WHERE name = $1)";
|
||||
pub const Q_006: &str = "INSERT INTO folder_preferences(folder_name, flagged_on_top, updated_at) VALUES($1, $2, CURRENT_TIMESTAMP)\n ON CONFLICT(folder_name) DO UPDATE SET flagged_on_top = excluded.flagged_on_top, updated_at = CURRENT_TIMESTAMP";
|
||||
pub const Q_007: &str = "DELETE FROM folder_preferences WHERE folder_name = $1";
|
||||
}
|
||||
|
||||
pub mod db_folders {
|
||||
pub const Q_001: &str = "INSERT OR REPLACE INTO folders
|
||||
(name, delimiter, parent, flags, is_subscribed,
|
||||
total_count, unread_count, uid_validity, highest_modseq, updated_at)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, CURRENT_TIMESTAMP)";
|
||||
pub const Q_002: &str = "INSERT OR IGNORE INTO folders
|
||||
(name, delimiter, flags, is_subscribed, updated_at)
|
||||
VALUES ($1, $2, $3, 1, CURRENT_TIMESTAMP)";
|
||||
pub const Q_003: &str = "SELECT name, delimiter, parent, flags, is_subscribed,
|
||||
total_count, unread_count, uid_validity, highest_modseq
|
||||
FROM folders
|
||||
ORDER BY name";
|
||||
pub const Q_004: &str = "DELETE FROM folders";
|
||||
pub const Q_005: &str = "UPDATE folders SET updated_at = CURRENT_TIMESTAMP";
|
||||
pub const Q_006: &str = "UPDATE folders SET uid_validity = $1, total_count = $2, messages_updated_at = CURRENT_TIMESTAMP
|
||||
WHERE name = $3";
|
||||
pub const Q_007: &str =
|
||||
"UPDATE folders SET uid_validity = $1, total_count = $2, highest_modseq = $3
|
||||
WHERE name = $4";
|
||||
pub const Q_008: &str =
|
||||
"SELECT COUNT(*) FROM messages WHERE folder = $1 AND flags NOT LIKE '%\\Seen%'";
|
||||
pub const Q_009: &str = "UPDATE folders SET unread_count = $1 WHERE name = $2";
|
||||
pub const Q_010: &str = "UPDATE folders SET unread_count = GREATEST(0, CAST(unread_count AS INTEGER) + $1) WHERE name = $2";
|
||||
pub const Q_011: &str = "SELECT EXISTS(
|
||||
SELECT 1 FROM folders
|
||||
WHERE updated_at > datetime('now', $1)
|
||||
)";
|
||||
pub const Q_012: &str = "SELECT EXISTS(
|
||||
SELECT 1 FROM folders
|
||||
WHERE name = $1 AND messages_updated_at > datetime('now', $2)
|
||||
)";
|
||||
pub const Q_013: &str = "SELECT messages_updated_at IS NULL FROM folders WHERE name = $1";
|
||||
pub const Q_014: &str = "UPDATE folders SET messages_updated_at = NULL WHERE name = $1";
|
||||
pub const Q_015: &str = "SELECT name, delimiter, parent, flags, is_subscribed,
|
||||
total_count, unread_count, uid_validity, highest_modseq
|
||||
FROM folders
|
||||
WHERE name = $1";
|
||||
pub const Q_016: &str = "DELETE FROM messages WHERE folder = $1";
|
||||
pub const Q_017: &str = "DELETE FROM folders WHERE name = $1";
|
||||
pub const Q_018: &str = "PRAGMA defer_foreign_keys = ON;";
|
||||
pub const Q_019: &str = "INSERT INTO folders (name, delimiter, parent, flags, is_subscribed, total_count, unread_count, uid_validity, highest_modseq, updated_at, messages_updated_at)
|
||||
SELECT $1, delimiter, parent, flags, is_subscribed, total_count, unread_count, uid_validity, highest_modseq, CURRENT_TIMESTAMP, messages_updated_at
|
||||
FROM folders WHERE name = $2";
|
||||
pub const Q_020: &str = "UPDATE messages SET folder = $1 WHERE folder = $2";
|
||||
pub const Q_021: &str = "UPDATE message_tags SET message_folder = $1 WHERE message_folder = $2";
|
||||
pub const Q_022: &str =
|
||||
"UPDATE calendar_events SET source_message_folder = $1 WHERE source_message_folder = $2";
|
||||
pub const Q_023: &str = "UPDATE folders SET parent = $1 WHERE parent = $2";
|
||||
pub const Q_024: &str = "DELETE FROM folders WHERE name = $1";
|
||||
pub const Q_025: &str = "SELECT name FROM folders WHERE flags LIKE '%' || $1 || '%' LIMIT 1";
|
||||
pub const Q_026: &str =
|
||||
"UPDATE folders SET messages_updated_at = '2000-01-01 00:00:00' WHERE name = 'Sent'";
|
||||
pub const Q_027: &str = "SELECT messages_updated_at FROM folders WHERE name = 'Sent'";
|
||||
pub const FORMAT_001: &str = "DELETE FROM folders WHERE name NOT IN ({})";
|
||||
}
|
||||
|
||||
pub mod db_header_sync {
|
||||
pub const Q_001: &str = "SELECT value FROM user_meta WHERE key = 'header_sync_generation'";
|
||||
pub const Q_002: &str =
|
||||
"INSERT INTO user_meta (key, value) VALUES ('header_sync_generation', '1')
|
||||
ON CONFLICT(key) DO UPDATE SET value = CAST(value AS INTEGER) + 1";
|
||||
}
|
||||
|
||||
pub mod db_identities {
|
||||
pub const IDENTITY_SELECT_COLS: &str = "id, display_name, email, signature_html, is_default, created_at, updated_at, reply_to, bcc, organization, signature_text, signature_new, signature_reply, signature_forward, signature_position, pgp_fingerprint, pgp_sign_default, pgp_encrypt_default, pgp_inline_default";
|
||||
pub const Q_001: &str = "INSERT INTO identities (display_name,email,signature_html,is_default,reply_to,bcc,organization,signature_text,signature_new,signature_reply,signature_forward,signature_position,pgp_fingerprint,pgp_sign_default,pgp_encrypt_default,pgp_inline_default) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16)";
|
||||
pub const Q_002: &str = "DELETE FROM identities WHERE id = $1";
|
||||
pub const Q_003: &str = "SELECT COUNT(*) FROM identities";
|
||||
pub const Q_004: &str =
|
||||
"UPDATE identities SET is_default = 0, updated_at = CURRENT_TIMESTAMP WHERE is_default = 1";
|
||||
pub const FORMAT_001: &str =
|
||||
"SELECT {IDENTITY_SELECT_COLS} FROM identities ORDER BY is_default DESC, email ASC";
|
||||
pub const FORMAT_002: &str = "SELECT {IDENTITY_SELECT_COLS} FROM identities WHERE id = $1";
|
||||
pub const FORMAT_003: &str =
|
||||
"SELECT {IDENTITY_SELECT_COLS} FROM identities WHERE is_default = 1 LIMIT 1";
|
||||
pub const FORMAT_004: &str = "UPDATE identities SET {} WHERE id = ${}";
|
||||
}
|
||||
|
||||
pub mod db_mail_preferences {
|
||||
pub const Q_001: &str = "SELECT messages_per_page, mark_read_delay_ms, remote_images, preferred_body, thread_mode, collapse_quotes, show_snippets, default_sort, flagged_on_top, sync_imap_keywords, updated_at FROM mail_preferences WHERE id = 1";
|
||||
pub const Q_002: &str = "INSERT OR IGNORE INTO mail_preferences (id) VALUES (1)";
|
||||
pub const Q_003: &str = "UPDATE mail_preferences SET messages_per_page = $1, mark_read_delay_ms = $2, remote_images = $3, preferred_body = $4, thread_mode = $5, collapse_quotes = $6, show_snippets = $7, default_sort = $8, flagged_on_top = $9, sync_imap_keywords = $10, updated_at = CURRENT_TIMESTAMP WHERE id = 1";
|
||||
}
|
||||
|
||||
pub mod db_messages {
|
||||
pub const MSG_SELECT_COLS: &str = "uid, folder, message_id, in_reply_to, references_header, subject, from_address, from_name, to_addresses, cc_addresses, date, flags, size, has_attachments, snippet, reaction";
|
||||
pub const Q_001: &str = "INSERT OR REPLACE INTO messages
|
||||
(uid, folder, message_id, in_reply_to, references_header,
|
||||
subject, from_address, from_name, to_addresses, cc_addresses,
|
||||
date, flags, size, has_attachments, snippet, date_epoch, reaction)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17)";
|
||||
pub const Q_002: &str = "DELETE FROM messages WHERE folder = $1";
|
||||
pub const Q_003: &str = "SELECT COALESCE(MAX(uid), 0) FROM messages WHERE folder = $1";
|
||||
pub const Q_004: &str = "SELECT uid, folder, subject, from_address, from_name, to_addresses, \
|
||||
COALESCE(NULLIF(body_text, ''), snippet, ''), date_epoch, has_attachments \
|
||||
FROM messages ORDER BY folder, uid";
|
||||
pub const Q_005: &str = "SELECT COUNT(*) FROM messages WHERE folder = $1";
|
||||
pub const Q_006: &str = "SELECT COUNT(*) FROM messages";
|
||||
pub const Q_007: &str = "UPDATE messages SET flags = $1 WHERE folder = $2 AND uid = $3";
|
||||
pub const Q_008: &str = "UPDATE messages
|
||||
SET body_html = $1, body_text = $2, body_cached = 1,
|
||||
attachments_json = $3, raw_headers = $4, email_theme = $5
|
||||
WHERE folder = $6 AND uid = $7";
|
||||
pub const Q_009: &str = "UPDATE messages SET email_theme = $1 WHERE folder = $2 AND uid = $3";
|
||||
pub const Q_010: &str =
|
||||
"SELECT body_cached, body_html, body_text, attachments_json, raw_headers, email_theme
|
||||
FROM messages
|
||||
WHERE folder = $1 AND uid = $2";
|
||||
pub const Q_011: &str = "DELETE FROM messages WHERE folder = $1 AND uid = $2";
|
||||
pub const Q_012: &str = "SELECT folder, uid FROM messages
|
||||
WHERE body_cached = 0
|
||||
ORDER BY date_epoch DESC
|
||||
LIMIT $1";
|
||||
pub const Q_013: &str = "SELECT uid, flags FROM messages WHERE folder = $1";
|
||||
pub const Q_014: &str = "SELECT SUM(size) FROM messages";
|
||||
pub const FORMAT_001: &str = "SELECT {MSG_SELECT_COLS}
|
||||
FROM messages
|
||||
WHERE folder = $1
|
||||
ORDER BY date_epoch DESC
|
||||
LIMIT $2 OFFSET $3";
|
||||
pub const FORMAT_002: &str = "SELECT {MSG_SELECT_COLS}
|
||||
FROM messages
|
||||
WHERE folder = $1
|
||||
ORDER BY {order_by}
|
||||
LIMIT $2 OFFSET $3";
|
||||
pub const FORMAT_003: &str = "SELECT {MSG_SELECT_COLS}
|
||||
FROM messages
|
||||
WHERE folder = $1 AND uid = $2";
|
||||
pub const FORMAT_004: &str = "SELECT {MSG_SELECT_COLS}
|
||||
FROM messages
|
||||
WHERE message_id = $1
|
||||
OR in_reply_to = $1
|
||||
OR references_header LIKE $2 ESCAPE '\\'
|
||||
ORDER BY date_epoch ASC";
|
||||
pub const FORMAT_005: &str = "SELECT {MSG_SELECT_COLS}
|
||||
FROM messages
|
||||
{where_clause}
|
||||
ORDER BY date_epoch DESC
|
||||
LIMIT ${}";
|
||||
}
|
||||
|
||||
pub mod db_notification_preferences {
|
||||
pub const Q_001: &str = "SELECT enabled, sound, folders, dnd_enabled, dnd_start, dnd_end, updated_at FROM notification_preferences WHERE id = 1";
|
||||
pub const Q_002: &str = "INSERT OR IGNORE INTO notification_preferences (id) VALUES (1)";
|
||||
pub const FORMAT_001: &str =
|
||||
"UPDATE notification_preferences SET {set_clause} WHERE id = ${idx}";
|
||||
}
|
||||
|
||||
pub mod db_pgp {
|
||||
pub const KEY_COLS: &str = "fingerprint,key_id,email,user_id,public_key_armor,secret_key_path,has_secret,trust,source,created_at,updated_at";
|
||||
pub const Q_001: &str = "INSERT INTO pgp_keys (fingerprint,key_id,email,user_id,public_key_armor,secret_key_path,has_secret,trust,source) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9)\n ON CONFLICT(fingerprint) DO UPDATE SET key_id=excluded.key_id,email=CASE WHEN excluded.email='' THEN pgp_keys.email ELSE excluded.email END,user_id=CASE WHEN excluded.user_id='' THEN pgp_keys.user_id ELSE excluded.user_id END,public_key_armor=excluded.public_key_armor,secret_key_path=COALESCE(excluded.secret_key_path,pgp_keys.secret_key_path),has_secret=MAX(pgp_keys.has_secret,excluded.has_secret),trust=excluded.trust,source=excluded.source,updated_at=CURRENT_TIMESTAMP";
|
||||
pub const Q_002: &str = "DELETE FROM pgp_keys WHERE replace(upper(fingerprint),' ','')=$1";
|
||||
pub const Q_003: &str = "UPDATE pgp_keys SET trust=$2,updated_at=CURRENT_TIMESTAMP WHERE replace(upper(fingerprint),' ','')=$1";
|
||||
pub const Q_004: &str =
|
||||
"SELECT wkd_enabled,hkp_enabled,require_trusted_encryption FROM pgp_preferences WHERE id=1";
|
||||
pub const Q_005: &str = "UPDATE pgp_preferences SET wkd_enabled=$1,hkp_enabled=$2,require_trusted_encryption=$3,updated_at=CURRENT_TIMESTAMP WHERE id=1";
|
||||
pub const FORMAT_001: &str =
|
||||
"SELECT {KEY_COLS} FROM pgp_keys ORDER BY has_secret DESC, lower(email), fingerprint";
|
||||
pub const FORMAT_002: &str =
|
||||
"SELECT {KEY_COLS} FROM pgp_keys WHERE replace(upper(fingerprint),' ','')=$1";
|
||||
pub const FORMAT_003: &str = "SELECT {KEY_COLS} FROM pgp_keys WHERE lower(email)=lower($1) ORDER BY CASE trust WHEN 'verified' THEN 0 WHEN 'trusted' THEN 1 WHEN 'unknown' THEN 2 ELSE 3 END, has_secret DESC";
|
||||
pub const FORMAT_004: &str = "SELECT {KEY_COLS} FROM pgp_keys WHERE lower(email)=lower($1) ORDER BY CASE trust WHEN 'verified' THEN 0 WHEN 'trusted' THEN 1 WHEN 'unknown' THEN 2 ELSE 3 END, has_secret DESC LIMIT 1";
|
||||
pub const FORMAT_005: &str = "SELECT {KEY_COLS} FROM pgp_keys WHERE has_secret=1 AND secret_key_path IS NOT NULL ORDER BY lower(email), fingerprint";
|
||||
}
|
||||
|
||||
pub mod db_pool {
|
||||
pub const Q_001: &str = "SELECT 0";
|
||||
pub const Q_002: &str = "SELECT CURRENT_TIMESTAMP";
|
||||
pub const Q_003: &str = "SELECT 1";
|
||||
pub const Q_004: &str = "SELECT 1";
|
||||
pub const Q_005: &str = "SELECT tablename FROM pg_catalog.pg_tables WHERE schemaname = current_schema() ORDER BY tablename";
|
||||
pub const Q_006: &str = "SELECT 1";
|
||||
}
|
||||
|
||||
pub mod db_response_templates {
|
||||
pub const Q_001: &str =
|
||||
"SELECT id,name,body,format,created_at,updated_at FROM response_templates ORDER BY name ";
|
||||
pub const Q_002: &str =
|
||||
"SELECT id,name,body,format,created_at,updated_at FROM response_templates WHERE id=$1";
|
||||
pub const Q_003: &str = "INSERT INTO response_templates(name,body,format) VALUES ($1,$2,$3)";
|
||||
pub const Q_004: &str = "UPDATE response_templates SET name=$1,body=$2,format=$3,updated_at=CURRENT_TIMESTAMP WHERE id=$4";
|
||||
pub const Q_005: &str = "DELETE FROM response_templates WHERE id=$1";
|
||||
}
|
||||
|
||||
pub mod db_saved_searches {
|
||||
pub const Q_001: &str =
|
||||
"SELECT id,name,query_string,created_at,updated_at FROM saved_searches ORDER BY name ";
|
||||
pub const Q_002: &str = "INSERT INTO saved_searches(name,query_string) VALUES ($1,$2)";
|
||||
pub const Q_003: &str = "UPDATE saved_searches SET name=$1,query_string=$2,updated_at=CURRENT_TIMESTAMP WHERE id=$3";
|
||||
pub const Q_004: &str =
|
||||
"SELECT id,name,query_string,created_at,updated_at FROM saved_searches WHERE id=$1";
|
||||
pub const Q_005: &str = "DELETE FROM saved_searches WHERE id=$1";
|
||||
}
|
||||
|
||||
pub mod db_special_folders {
|
||||
pub const Q_001: &str = "SELECT folder_name FROM special_folders WHERE role = $1";
|
||||
pub const Q_002: &str = "SELECT EXISTS(SELECT 1 FROM folders WHERE name = $1)";
|
||||
pub const Q_003: &str = "INSERT INTO special_folders(role, folder_name, updated_at) VALUES($1, $2, CURRENT_TIMESTAMP)\n ON CONFLICT(role) DO UPDATE SET folder_name = excluded.folder_name, updated_at = CURRENT_TIMESTAMP";
|
||||
pub const Q_004: &str = "DELETE FROM special_folders WHERE role = $1";
|
||||
pub const Q_005: &str = "UPDATE special_folders SET folder_name = $1, updated_at = CURRENT_TIMESTAMP WHERE folder_name = $2";
|
||||
pub const Q_006: &str = "DELETE FROM special_folders WHERE folder_name = $1";
|
||||
}
|
||||
|
||||
pub mod db_tags {
|
||||
pub const Q_001: &str =
|
||||
"INSERT INTO tags (id, name, color, imap_keyword) VALUES ($1, $2, $3, $4)";
|
||||
pub const Q_002: &str =
|
||||
"SELECT t.id, t.name, t.color, t.imap_keyword, t.created_at, t.updated_at,
|
||||
(SELECT COUNT(*) FROM message_tags mt WHERE mt.tag_id = t.id) AS message_count
|
||||
FROM tags t
|
||||
ORDER BY t.name ASC";
|
||||
pub const Q_003: &str =
|
||||
"SELECT message_uid, message_folder FROM message_tags WHERE tag_id = $1";
|
||||
pub const Q_004: &str =
|
||||
"UPDATE tags SET name = $1, color = $2, updated_at = CURRENT_TIMESTAMP WHERE id = $3";
|
||||
pub const Q_005: &str = "DELETE FROM tags WHERE id = $1";
|
||||
pub const Q_006: &str = "INSERT OR IGNORE INTO message_tags (tag_id, message_uid, message_folder) VALUES ($1, $2, $3)";
|
||||
pub const Q_007: &str =
|
||||
"DELETE FROM message_tags WHERE tag_id = $1 AND message_uid = $2 AND message_folder = $3";
|
||||
pub const Q_008: &str = "SELECT t.id, t.name, t.color
|
||||
FROM tags t
|
||||
JOIN message_tags mt ON mt.tag_id = t.id
|
||||
WHERE mt.message_uid = $1 AND mt.message_folder = $2
|
||||
ORDER BY t.name ASC";
|
||||
pub const Q_009: &str =
|
||||
"SELECT m.uid, m.folder, m.message_id, m.in_reply_to, m.references_header,
|
||||
m.subject, m.from_address, m.from_name, m.to_addresses, m.cc_addresses,
|
||||
m.date, m.flags, m.size, m.has_attachments, m.snippet, m.reaction
|
||||
FROM messages m
|
||||
JOIN message_tags mt ON mt.message_uid = m.uid AND mt.message_folder = m.folder
|
||||
WHERE mt.tag_id = $1
|
||||
ORDER BY m.date_epoch DESC
|
||||
LIMIT $2 OFFSET $3";
|
||||
pub const Q_010: &str = "SELECT COUNT(*) FROM message_tags WHERE tag_id = $1";
|
||||
pub const Q_011: &str = "INSERT OR IGNORE INTO folders (name) VALUES ($1)";
|
||||
pub const Q_012: &str = "INSERT INTO messages (uid, folder, subject, from_address, from_name, to_addresses, date, flags, size, has_attachments, snippet)
|
||||
VALUES ($1, $2, 'Test', 'test@ex.com', 'Test', '[]', '2024-01-01', '', 100, 0, '')";
|
||||
pub const FORMAT_001: &str = "SELECT mt.message_uid, mt.message_folder, t.id, t.name, t.color
|
||||
FROM message_tags mt
|
||||
JOIN tags t ON t.id = mt.tag_id
|
||||
WHERE {}
|
||||
ORDER BY t.name ASC";
|
||||
}
|
||||
|
||||
pub mod db_trusted_senders {
|
||||
pub const Q_001: &str = "SELECT email FROM trusted_senders ORDER BY lower(email)";
|
||||
pub const Q_002: &str = "INSERT OR IGNORE INTO trusted_senders(email) VALUES($1)";
|
||||
pub const Q_003: &str = "DELETE FROM trusted_senders WHERE email = $1 ";
|
||||
}
|
||||
|
||||
pub mod routes_contacts {
|
||||
pub const Q_001: &str = "SELECT CURRENT_TIMESTAMP";
|
||||
pub const Q_002: &str = "SELECT CURRENT_TIMESTAMP";
|
||||
pub const Q_003: &str = "SELECT CURRENT_TIMESTAMP";
|
||||
}
|
||||
|
||||
pub mod routes_diagnostics {
|
||||
pub const Q_001: &str = "SELECT COUNT(*),
|
||||
COALESCE(SUM(CASE WHEN messages_updated_at IS NULL THEN 1 ELSE 0 END), 0),
|
||||
CASE WHEN MAX(updated_at) IS NULL THEN NULL ELSE replace(MAX(updated_at), ' ', 'T') || 'Z' END,
|
||||
CASE WHEN MAX(messages_updated_at) IS NULL THEN NULL ELSE replace(MAX(messages_updated_at), ' ', 'T') || 'Z' END
|
||||
FROM folders";
|
||||
pub const Q_002: &str = "SELECT COUNT(*) FROM messages";
|
||||
pub const Q_003: &str = "SELECT COUNT(*) FROM messages WHERE body_cached = 1";
|
||||
}
|
||||
|
||||
pub mod routes_folder_mgmt {
|
||||
pub const Q_001: &str = "UPDATE messages SET flags = CASE WHEN flags = '' THEN $2 ELSE flags || ',' || $2 END WHERE folder = $1 AND instr(flags, $2) = 0";
|
||||
pub const Q_002: &str = "UPDATE folders SET unread_count = 0 WHERE name = $1";
|
||||
pub const Q_003: &str = "SELECT uid FROM messages WHERE folder = $1";
|
||||
pub const Q_004: &str = "UPDATE folders SET total_count = 0, unread_count = 0, messages_updated_at = CURRENT_TIMESTAMP WHERE name = $1";
|
||||
}
|
||||
|
||||
pub mod routes_messages_mod {
|
||||
pub const Q_001: &str = "SELECT flags FROM messages WHERE folder = $1 AND uid = $2";
|
||||
}
|
||||
|
||||
pub mod routes_pgp {
|
||||
pub const Q_001: &str = "UPDATE identities SET pgp_fingerprint=NULL,pgp_sign_default=0,pgp_encrypt_default=0,pgp_inline_default=0 WHERE replace(upper(COALESCE(pgp_fingerprint,'')),' ','')=$1";
|
||||
}
|
||||
|
||||
pub mod routes_special_folders {
|
||||
pub const Q_001: &str = "SELECT EXISTS(SELECT 1 FROM folders WHERE name = $1)";
|
||||
}
|
||||
|
||||
pub mod sessions {
|
||||
pub const UPSERT: &str = r#"INSERT INTO sessions (
|
||||
token, account_id, browser_id, email, password_ciphertext, user_hash,
|
||||
imap_host, imap_port, imap_tls, imap_tls_verify, smtp_host, smtp_port,
|
||||
smtp_tls, smtp_tls_verify, timeout_secs, created_at_unix, last_accessed_unix, user_agent
|
||||
) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18)
|
||||
ON CONFLICT(token) DO UPDATE SET
|
||||
account_id=EXCLUDED.account_id, browser_id=EXCLUDED.browser_id, email=EXCLUDED.email,
|
||||
password_ciphertext=EXCLUDED.password_ciphertext, user_hash=EXCLUDED.user_hash,
|
||||
imap_host=EXCLUDED.imap_host, imap_port=EXCLUDED.imap_port, imap_tls=EXCLUDED.imap_tls,
|
||||
imap_tls_verify=EXCLUDED.imap_tls_verify, smtp_host=EXCLUDED.smtp_host, smtp_port=EXCLUDED.smtp_port,
|
||||
smtp_tls=EXCLUDED.smtp_tls, smtp_tls_verify=EXCLUDED.smtp_tls_verify, timeout_secs=EXCLUDED.timeout_secs,
|
||||
last_accessed_unix=EXCLUDED.last_accessed_unix, user_agent=EXCLUDED.user_agent"#;
|
||||
pub const BY_TOKEN: &str = "SELECT * FROM sessions WHERE token = $1";
|
||||
pub const BY_BROWSER: &str =
|
||||
"SELECT * FROM sessions WHERE browser_id = $1 ORDER BY created_at_unix";
|
||||
pub const BY_USER: &str =
|
||||
"SELECT * FROM sessions WHERE user_hash = $1 ORDER BY last_accessed_unix DESC";
|
||||
pub const BROWSER_EXISTS: &str = "SELECT COUNT(*) FROM sessions WHERE browser_id = $1";
|
||||
pub const DELETE_ACCOUNT: &str = "DELETE FROM sessions WHERE account_id = $1";
|
||||
pub const DELETE_BROWSER: &str = "DELETE FROM sessions WHERE browser_id = $1";
|
||||
pub const DELETE_EXPIRED: &str =
|
||||
"DELETE FROM sessions WHERE last_accessed_unix + timeout_secs < $1";
|
||||
}
|
||||
Reference in new issue
Block a user