1-- subject_length_warn.lua
2-- Warns when your subject line is getting too long.
3-- Most email clients truncate subjects beyond ~60 characters.
4--
5-- Thresholds are configurable in Settings → Plugins.
6
7local matcha = require("matcha")
8
9local cfg = matcha.settings({
10 enabled = {
11 type = "boolean",
12 default = true,
13 label = "Enable subject length warnings",
14 },
15 soft_limit = {
16 type = "number",
17 default = 60,
18 label = "Soft limit (chars)",
19 description = "Warn that the subject may truncate above this length.",
20 },
21 hard_limit = {
22 type = "number",
23 default = 78,
24 label = "Hard limit (chars)",
25 description = "Warn that the subject is too long above this length.",
26 },
27})
28
29matcha.on("composer_updated", function(state)
30 if not cfg.enabled then
31 return
32 end
33 local len = #state.subject
34 if len > cfg.hard_limit then
35 matcha.set_status("composer", "Subject too long (" .. len .. " chars)")
36 elseif len > cfg.soft_limit then
37 matcha.set_status("composer", "Subject may truncate (" .. len .. " chars)")
38 end
39end)