diff options
Diffstat (limited to 'lua/inbox/indexers/notmuch.lua')
-rw-r--r-- | lua/inbox/indexers/notmuch.lua | 56 |
1 files changed, 49 insertions, 7 deletions
diff --git a/lua/inbox/indexers/notmuch.lua b/lua/inbox/indexers/notmuch.lua index 171fabf..c13e898 100644 --- a/lua/inbox/indexers/notmuch.lua +++ b/lua/inbox/indexers/notmuch.lua @@ -4,6 +4,7 @@ local Path = require("plenary.path") ---@class inbox.Indexer.Notmuch.Config local default_config = { database_dir = Path:new(vim.env.XDG_DATA_HOME, "mail").filename, + map_tag_signs = {}, } ---@class inbox.Indexer.Notmuch: inbox.Indexer, inbox.Indexer.Notmuch.Config @@ -24,12 +25,27 @@ function M.index(callback, filters) json = json .. stdout end), on_exit = vim.schedule_wrap(function(_, _, _) - if json == "" then - json = "[]" + local entries = {} + + if json and json ~= "" then + entries = vim.json.decode(json) or {} + end + + local rows = {} + local signs = {} + + for lnum, entry in ipairs(entries) do + local cols = M.summarize(entry) + + for _, tag in ipairs(entry.tags) do + local sign = M.map_tag_signs[tag] or tag + table.insert(signs, { sign, lnum }) + end + + table.insert(rows, cols) end - local entries = vim.json.decode(json) - callback(entries) + callback(rows, signs) end), }) @@ -38,16 +54,42 @@ function M.index(callback, filters) for name, value in pairs(filters) do table.insert(filter_args, ("%s:%s"):format(name, value)) end + local filter_args_str = table.concat(filter_args, " and ") vim.list_extend(job.args, vim.split(filter_args_str, " ")) - vim.print(job.args) - job:start() end +---@param summary inbox.Summary +---@return table sanitized sanitized summary +function M.summarize(summary) + local date = summary.date_relative + + local from + if type(summary.authors) == "table" then + from = summary.authors[1] --[[@as string]] + else + from = summary.authors --[[@as string]] + end + + local subject + if type(summary.subject) == "table" then + subject = summary.subject[1] --[[@as string]] + else + subject = summary.subject --[[@as string]] + end + subject = subject:gsub("\r?\n", " ") + + return { + date, + from, + subject, + } +end + ---@param opts inbox.Indexer.Notmuch.Config -M.setup = function(opts) +function M.setup(opts) local config = vim.tbl_deep_extend("keep", opts or {}, default_config) for k, v in pairs(config) do |