-- Read the most recent email in the default Inbox: speak FROM + SUBJECT + -- a 1-sentence preview (~200 chars, HTML stripped) of the body. local lang = jarvis.context.language local helper = jarvis.context.command_path .. "\\_outlook.ps1" local cmd = string.format( 'powershell -NoProfile -ExecutionPolicy Bypass -File "%s" -Action latest', helper ) local res = jarvis.system.exec(cmd) local out = (res.stdout or ""):gsub("\r", "") if not res.success or out == "" then jarvis.log("error", "outlook latest exec failed: " .. tostring(res.stderr)) return jarvis.cmd.error(lang == "ru" and "Outlook недоступен — запусти Outlook сначала." or "Outlook is unavailable — start Outlook first.") end local lines = {} for line in out:gmatch("[^\n]+") do table.insert(lines, line) end local status = lines[1] or "" if status:sub(1, 3) == "ERR" then if status:find("empty_inbox", 1, true) then return jarvis.cmd.not_found(lang == "ru" and "Входящие пусты." or "Inbox is empty.") end jarvis.log("warn", "outlook latest: " .. status) return jarvis.cmd.error(lang == "ru" and "Outlook недоступен — запусти Outlook сначала." or "Outlook is unavailable — start Outlook first.") end local from, subject, preview = "", "", "" for i = 2, #lines do local key, val = lines[i]:match("^([A-Z]+)\t(.*)$") if key == "FROM" then from = val or "" end if key == "SUBJECT" then subject = val or "" end if key == "PREVIEW" then preview = val or "" end end if from == "" and subject == "" then return jarvis.cmd.error(lang == "ru" and "Не получилось прочитать письмо." or "Could not read the email.") end local speech if lang == "ru" then speech = string.format("Последнее письмо от %s. Тема: %s. %s", from ~= "" and from or "неизвестного отправителя", subject ~= "" and subject or "без темы", preview) else speech = string.format("Latest email from %s. Subject: %s. %s", from ~= "" and from or "unknown sender", subject ~= "" and subject or "no subject", preview) end jarvis.system.notify( lang == "ru" and "Последнее письмо" or "Latest email", string.format("%s\n%s\n%s", from, subject, preview) ) return jarvis.cmd.ok(speech)