toggle_read.lua

 1-- toggle_read.lua
 2-- Toggle read/unread on the selected email. Keybind is configurable.
 3
 4local matcha = require("matcha")
 5
 6local cfg = matcha.settings({
 7    key = {
 8        type        = "string",
 9        default     = "u",
10        label       = "Toggle key",
11        description = "Key to press in inbox and email_view to toggle read/unread. Takes effect after restart.",
12    },
13})
14
15local function toggle(email)
16    if not email then return end
17    local folder = email.folder ~= "" and email.folder or "INBOX"
18    if email.is_read then
19        matcha.mark_unread(email.uid, email.account_id, folder)
20        matcha.notify("Marked as unread")
21    else
22        matcha.mark_read(email.uid, email.account_id, folder)
23        matcha.notify("Marked as read")
24    end
25end
26
27matcha.bind_key(cfg.key, "email_view", "Toggle read/unread", toggle)
28matcha.bind_key(cfg.key, "inbox", "Toggle read/unread", toggle)