1 parent
0421994fe6
commit
425ea7449b
138 files changed
+5705
-1012
No files matched your search
@@ -0,0 +1,487 @@
|
||||
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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
pub const Q_003: &str = "DELETE FROM calendar_events WHERE id = ?";
|
||||
pub const Q_004: &str = "INSERT IGNORE INTO calendar_settings (id) VALUES (1)";
|
||||
pub const Q_005: &str = "INSERT 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 (?, ?, ?)";
|
||||
pub const Q_008: &str = "SELECT id, name, url_template, icon, is_default, created_at
|
||||
FROM meeting_templates WHERE id = ?";
|
||||
pub const Q_009: &str = "DELETE FROM meeting_templates WHERE id = ?";
|
||||
pub const FORMAT_001: &str = "SELECT {EVENT_SELECT_COLS} FROM calendar_events
|
||||
WHERE end_time >= ? AND start_time <= ?
|
||||
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 = ?";
|
||||
pub const FORMAT_004: &str = "UPDATE calendar_events SET {} WHERE id = ?";
|
||||
pub const FORMAT_005: &str =
|
||||
"SELECT {EVENT_SELECT_COLS} FROM calendar_events WHERE source_uid = ?";
|
||||
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 (?, ?)";
|
||||
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 = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ?";
|
||||
pub const Q_004: &str = "DELETE FROM contact_groups WHERE id = ?";
|
||||
pub const Q_005: &str =
|
||||
"INSERT IGNORE INTO contact_group_members (group_id, contact_id) VALUES (?, ?)";
|
||||
pub const Q_006: &str =
|
||||
"DELETE FROM contact_group_members WHERE group_id = ? AND contact_id = ?";
|
||||
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 = ?
|
||||
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 = ?
|
||||
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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
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 = ?";
|
||||
pub const Q_003: &str = r#"
|
||||
SELECT email, name
|
||||
FROM known_addresses
|
||||
WHERE (email LIKE ? ESCAPE '\' OR name LIKE ? 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 ?
|
||||
"#;
|
||||
pub const Q_004: &str = "INSERT INTO known_addresses (email, name) VALUES (?, ?)
|
||||
ON CONFLICT(email) DO UPDATE SET name = excluded.name WHERE excluded.name != ''";
|
||||
pub const Q_005: &str = "INSERT INTO known_addresses (email, name) VALUES (?, ?)
|
||||
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 = ?";
|
||||
pub const Q_007: &str = "INSERT IGNORE INTO contacts (id, email, name, source)
|
||||
VALUES (?, ?, ?, 'auto')";
|
||||
pub const Q_008: &str = "INSERT INTO contact_photos (contact_id, content_type, data, updated_at) VALUES (?, ?, ?, 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 = ?";
|
||||
pub const Q_010: &str = "DELETE FROM contact_photos WHERE contact_id = ?";
|
||||
pub const FORMAT_001: &str = "SELECT {CONTACT_SELECT_COLS} FROM contacts WHERE id = ?";
|
||||
pub const FORMAT_002: &str = "SELECT {CONTACT_SELECT_COLS} FROM contacts \
|
||||
WHERE lower(email) = lower(?) \
|
||||
OR EXISTS (SELECT 1 FROM json_each(contacts.emails_json) WHERE lower(value) = lower(?))";
|
||||
pub const FORMAT_003: &str = "SELECT {CONTACT_SELECT_COLS} FROM contacts
|
||||
WHERE name LIKE ? ESCAPE '\\' OR email LIKE ? ESCAPE '\\' OR emails_json LIKE ? ESCAPE '\\'
|
||||
ORDER BY name ASC
|
||||
LIMIT ? OFFSET ?";
|
||||
pub const FORMAT_004: &str = "SELECT {CONTACT_SELECT_COLS} FROM contacts
|
||||
ORDER BY name ASC
|
||||
LIMIT ? OFFSET ?";
|
||||
pub const FORMAT_005: &str = "SELECT {CONTACT_SELECT_COLS} FROM contacts
|
||||
WHERE name LIKE ? ESCAPE '\\' OR email LIKE ? ESCAPE '\\' OR emails_json LIKE ? ESCAPE '\\'
|
||||
ORDER BY name ASC
|
||||
LIMIT ?";
|
||||
}
|
||||
|
||||
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 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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 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 = ?";
|
||||
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 = ?, remote_uid = ?, remote_uid_validity = ? WHERE id = ?";
|
||||
pub const Q_005: &str = "DELETE FROM drafts WHERE id = ?";
|
||||
pub const Q_006: &str =
|
||||
"INSERT INTO draft_attachments (id, draft_id, filename, content_type, size, file_path)
|
||||
VALUES (?, ?, ?, ?, ?, ?)";
|
||||
pub const Q_007: &str =
|
||||
"SELECT id, draft_id, filename, content_type, size, file_path, created_at
|
||||
FROM draft_attachments WHERE draft_id = ? ORDER BY created_at ASC";
|
||||
pub const Q_008: &str = "DELETE FROM draft_attachments WHERE id = ?";
|
||||
}
|
||||
|
||||
pub mod db_folder_preferences {
|
||||
pub const Q_001: &str = "SELECT flagged_on_top FROM folder_preferences WHERE folder_name = ?";
|
||||
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 = ?)";
|
||||
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 = ?)";
|
||||
pub const Q_006: &str = "INSERT INTO folder_preferences(folder_name, flagged_on_top, updated_at) VALUES(?, ?, 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 = ?";
|
||||
}
|
||||
|
||||
pub mod db_folders {
|
||||
pub const Q_001: &str = "REPLACE INTO folders
|
||||
(name, delimiter, parent, flags, is_subscribed,
|
||||
total_count, unread_count, uid_validity, highest_modseq, updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP)";
|
||||
pub const Q_002: &str = "INSERT IGNORE INTO folders
|
||||
(name, delimiter, flags, is_subscribed, updated_at)
|
||||
VALUES (?, ?, ?, 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 = ?, total_count = ?, messages_updated_at = CURRENT_TIMESTAMP
|
||||
WHERE name = ?";
|
||||
pub const Q_007: &str =
|
||||
"UPDATE folders SET uid_validity = ?, total_count = ?, highest_modseq = ?
|
||||
WHERE name = ?";
|
||||
pub const Q_008: &str =
|
||||
"SELECT COUNT(*) FROM messages WHERE folder = ? AND flags NOT LIKE '%\\Seen%'";
|
||||
pub const Q_009: &str = "UPDATE folders SET unread_count = ? WHERE name = ?";
|
||||
pub const Q_010: &str = "UPDATE folders SET unread_count = GREATEST(0, CAST(unread_count AS SIGNED) + ?) WHERE name = ?";
|
||||
pub const Q_011: &str = "SELECT EXISTS(
|
||||
SELECT 1 FROM folders
|
||||
WHERE updated_at > datetime('now', ?)
|
||||
)";
|
||||
pub const Q_012: &str = "SELECT EXISTS(
|
||||
SELECT 1 FROM folders
|
||||
WHERE name = ? AND messages_updated_at > datetime('now', ?)
|
||||
)";
|
||||
pub const Q_013: &str = "SELECT messages_updated_at IS NULL FROM folders WHERE name = ?";
|
||||
pub const Q_014: &str = "UPDATE folders SET messages_updated_at = NULL WHERE name = ?";
|
||||
pub const Q_015: &str = "SELECT name, delimiter, parent, flags, is_subscribed,
|
||||
total_count, unread_count, uid_validity, highest_modseq
|
||||
FROM folders
|
||||
WHERE name = ?";
|
||||
pub const Q_016: &str = "DELETE FROM messages WHERE folder = ?";
|
||||
pub const Q_017: &str = "DELETE FROM folders WHERE name = ?";
|
||||
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 ?, delimiter, parent, flags, is_subscribed, total_count, unread_count, uid_validity, highest_modseq, CURRENT_TIMESTAMP, messages_updated_at
|
||||
FROM folders WHERE name = ?";
|
||||
pub const Q_020: &str = "UPDATE messages SET folder = ? WHERE folder = ?";
|
||||
pub const Q_021: &str = "UPDATE message_tags SET message_folder = ? WHERE message_folder = ?";
|
||||
pub const Q_022: &str =
|
||||
"UPDATE calendar_events SET source_message_folder = ? WHERE source_message_folder = ?";
|
||||
pub const Q_023: &str = "UPDATE folders SET parent = ? WHERE parent = ?";
|
||||
pub const Q_024: &str = "DELETE FROM folders WHERE name = ?";
|
||||
pub const Q_025: &str = "SELECT name FROM folders WHERE flags LIKE CONCAT('%', ?, '%') 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 (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
|
||||
pub const Q_002: &str = "DELETE FROM identities WHERE id = ?";
|
||||
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 = ?";
|
||||
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 IGNORE INTO mail_preferences (id) VALUES (1)";
|
||||
pub const Q_003: &str = "UPDATE mail_preferences SET 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 = 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 = "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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
pub const Q_002: &str = "DELETE FROM messages WHERE folder = ?";
|
||||
pub const Q_003: &str = "SELECT COALESCE(MAX(uid), 0) FROM messages WHERE folder = ?";
|
||||
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 = ?";
|
||||
pub const Q_006: &str = "SELECT COUNT(*) FROM messages";
|
||||
pub const Q_007: &str = "UPDATE messages SET flags = ? WHERE folder = ? AND uid = ?";
|
||||
pub const Q_008: &str = "UPDATE messages
|
||||
SET body_html = ?, body_text = ?, body_cached = 1,
|
||||
attachments_json = ?, raw_headers = ?, email_theme = ?
|
||||
WHERE folder = ? AND uid = ?";
|
||||
pub const Q_009: &str = "UPDATE messages SET email_theme = ? WHERE folder = ? AND uid = ?";
|
||||
pub const Q_010: &str =
|
||||
"SELECT body_cached, body_html, body_text, attachments_json, raw_headers, email_theme
|
||||
FROM messages
|
||||
WHERE folder = ? AND uid = ?";
|
||||
pub const Q_011: &str = "DELETE FROM messages WHERE folder = ? AND uid = ?";
|
||||
pub const Q_012: &str = "SELECT folder, uid FROM messages
|
||||
WHERE body_cached = 0
|
||||
ORDER BY date_epoch DESC
|
||||
LIMIT ?";
|
||||
pub const Q_013: &str = "SELECT uid, flags FROM messages WHERE folder = ?";
|
||||
pub const Q_014: &str = "SELECT SUM(size) FROM messages";
|
||||
pub const FORMAT_001: &str = "SELECT {MSG_SELECT_COLS}
|
||||
FROM messages
|
||||
WHERE folder = ?
|
||||
ORDER BY date_epoch DESC
|
||||
LIMIT ? OFFSET ?";
|
||||
pub const FORMAT_002: &str = "SELECT {MSG_SELECT_COLS}
|
||||
FROM messages
|
||||
WHERE folder = ?
|
||||
ORDER BY {order_by}
|
||||
LIMIT ? OFFSET ?";
|
||||
pub const FORMAT_003: &str = "SELECT {MSG_SELECT_COLS}
|
||||
FROM messages
|
||||
WHERE folder = ? AND uid = ?";
|
||||
pub const FORMAT_004: &str = "SELECT {MSG_SELECT_COLS}
|
||||
FROM messages
|
||||
WHERE message_id = ?
|
||||
OR in_reply_to = ?
|
||||
OR references_header LIKE ? 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 IGNORE INTO notification_preferences (id) VALUES (1)";
|
||||
pub const FORMAT_001: &str = "UPDATE notification_preferences SET {set_clause} WHERE id = ?";
|
||||
}
|
||||
|
||||
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 (?,?,?,?,?,?,?,?,?)\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),' ','')=?";
|
||||
pub const Q_003: &str = "UPDATE pgp_keys SET trust=?,updated_at=CURRENT_TIMESTAMP WHERE replace(upper(fingerprint),' ','')=?";
|
||||
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=?,hkp_enabled=?,require_trusted_encryption=?,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),' ','')=?";
|
||||
pub const FORMAT_003: &str = "SELECT {KEY_COLS} FROM pgp_keys WHERE lower(email)=lower(?) 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(?) 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 = "SHOW TABLES";
|
||||
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=?";
|
||||
pub const Q_003: &str = "INSERT INTO response_templates(name,body,format) VALUES (?,?,?)";
|
||||
pub const Q_004: &str = "UPDATE response_templates SET name=?,body=?,format=?,updated_at=CURRENT_TIMESTAMP WHERE id=?";
|
||||
pub const Q_005: &str = "DELETE FROM response_templates WHERE id=?";
|
||||
}
|
||||
|
||||
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 (?,?)";
|
||||
pub const Q_003: &str =
|
||||
"UPDATE saved_searches SET name=?,query_string=?,updated_at=CURRENT_TIMESTAMP WHERE id=?";
|
||||
pub const Q_004: &str =
|
||||
"SELECT id,name,query_string,created_at,updated_at FROM saved_searches WHERE id=?";
|
||||
pub const Q_005: &str = "DELETE FROM saved_searches WHERE id=?";
|
||||
}
|
||||
|
||||
pub mod db_special_folders {
|
||||
pub const Q_001: &str = "SELECT folder_name FROM special_folders WHERE role = ?";
|
||||
pub const Q_002: &str = "SELECT EXISTS(SELECT 1 FROM folders WHERE name = ?)";
|
||||
pub const Q_003: &str = "INSERT INTO special_folders(role, folder_name, updated_at) VALUES(?, ?, 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 = ?";
|
||||
pub const Q_005: &str = "UPDATE special_folders SET folder_name = ?, updated_at = CURRENT_TIMESTAMP WHERE folder_name = ?";
|
||||
pub const Q_006: &str = "DELETE FROM special_folders WHERE folder_name = ?";
|
||||
}
|
||||
|
||||
pub mod db_tags {
|
||||
pub const Q_001: &str = "INSERT INTO tags (id, name, color, imap_keyword) VALUES (?, ?, ?, ?)";
|
||||
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 = ?";
|
||||
pub const Q_004: &str =
|
||||
"UPDATE tags SET name = ?, color = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ?";
|
||||
pub const Q_005: &str = "DELETE FROM tags WHERE id = ?";
|
||||
pub const Q_006: &str =
|
||||
"INSERT IGNORE INTO message_tags (tag_id, message_uid, message_folder) VALUES (?, ?, ?)";
|
||||
pub const Q_007: &str =
|
||||
"DELETE FROM message_tags WHERE tag_id = ? AND message_uid = ? AND message_folder = ?";
|
||||
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 = ? AND mt.message_folder = ?
|
||||
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 = ?
|
||||
ORDER BY m.date_epoch DESC
|
||||
LIMIT ? OFFSET ?";
|
||||
pub const Q_010: &str = "SELECT COUNT(*) FROM message_tags WHERE tag_id = ?";
|
||||
pub const Q_011: &str = "INSERT IGNORE INTO folders (name) VALUES (?)";
|
||||
pub const Q_012: &str = "INSERT INTO messages (uid, folder, subject, from_address, from_name, to_addresses, date, flags, size, has_attachments, snippet)
|
||||
VALUES (?, ?, '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 IGNORE INTO trusted_senders(email) VALUES(?)";
|
||||
pub const Q_003: &str = "DELETE FROM trusted_senders WHERE email = ? ";
|
||||
}
|
||||
|
||||
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 ? ELSE flags || ',' || ? END WHERE folder = ? AND instr(flags, ?) = 0";
|
||||
pub const Q_002: &str = "UPDATE folders SET unread_count = 0 WHERE name = ?";
|
||||
pub const Q_003: &str = "SELECT uid FROM messages WHERE folder = ?";
|
||||
pub const Q_004: &str = "UPDATE folders SET total_count = 0, unread_count = 0, messages_updated_at = CURRENT_TIMESTAMP WHERE name = ?";
|
||||
}
|
||||
|
||||
pub mod routes_messages_mod {
|
||||
pub const Q_001: &str = "SELECT flags FROM messages WHERE folder = ? AND uid = ?";
|
||||
}
|
||||
|
||||
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,'')),' ','')=?";
|
||||
}
|
||||
|
||||
pub mod routes_special_folders {
|
||||
pub const Q_001: &str = "SELECT EXISTS(SELECT 1 FROM folders WHERE name = ?)";
|
||||
}
|
||||
|
||||
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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
account_id=VALUES(account_id), browser_id=VALUES(browser_id), email=VALUES(email),
|
||||
password_ciphertext=VALUES(password_ciphertext), user_hash=VALUES(user_hash), imap_host=VALUES(imap_host),
|
||||
imap_port=VALUES(imap_port), imap_tls=VALUES(imap_tls), imap_tls_verify=VALUES(imap_tls_verify),
|
||||
smtp_host=VALUES(smtp_host), smtp_port=VALUES(smtp_port), smtp_tls=VALUES(smtp_tls),
|
||||
smtp_tls_verify=VALUES(smtp_tls_verify), timeout_secs=VALUES(timeout_secs),
|
||||
last_accessed_unix=VALUES(last_accessed_unix), user_agent=VALUES(user_agent)"#;
|
||||
pub const BY_TOKEN: &str = "SELECT * FROM sessions WHERE token = ?";
|
||||
pub const BY_BROWSER: &str =
|
||||
"SELECT * FROM sessions WHERE browser_id = ? ORDER BY created_at_unix";
|
||||
pub const BY_USER: &str =
|
||||
"SELECT * FROM sessions WHERE user_hash = ? ORDER BY last_accessed_unix DESC";
|
||||
pub const BROWSER_EXISTS: &str = "SELECT COUNT(*) FROM sessions WHERE browser_id = ?";
|
||||
pub const DELETE_ACCOUNT: &str = "DELETE FROM sessions WHERE account_id = ?";
|
||||
pub const DELETE_BROWSER: &str = "DELETE FROM sessions WHERE browser_id = ?";
|
||||
pub const DELETE_EXPIRED: &str =
|
||||
"DELETE FROM sessions WHERE last_accessed_unix + timeout_secs < ?";
|
||||
}
|
||||
Reference in new issue
Block a user