sender_frequency.lua

 1-- sender_frequency.lua
 2-- Tracks how many emails each sender sends you and shows repeat senders.
 3
 4local matcha = require("matcha")
 5
 6local senders = {}
 7
 8matcha.on("email_received", function(email)
 9    local from = email.from
10    senders[from] = (senders[from] or 0) + 1
11    if senders[from] == 3 then
12        matcha.notify("Frequent sender: " .. from .. " (3+ emails)", 2)
13    end
14end)
15
16matcha.on("shutdown", function()
17    local sorted = {}
18    for sender, count in pairs(senders) do
19        if count > 1 then
20            table.insert(sorted, { addr = sender, count = count })
21        end
22    end
23    table.sort(sorted, function(a, b) return a.count > b.count end)
24
25    for i = 1, math.min(5, #sorted) do
26        matcha.log("Top sender: " .. sorted[i].addr .. " (" .. sorted[i].count .. " emails)")
27    end
28end)