| 1 | -- widget type providing the subject of last e-mail in a mbox file |
| 2 | -- Copyright (C) 2010 Adrian C. <[email protected]> |
| 3 | -- Copyright (C) 2017 mutlusun <[email protected]> |
| 4 | -- Copyright (C) 2018 Nguyễn Gia Phong <[email protected]m> |
| 5 | -- |
| 6 | -- This file is part of Vicious. |
| 7 | -- |
| 8 | -- Vicious is free software: you can redistribute it and/or modify |
| 9 | -- it under the terms of the GNU General Public License as |
| 10 | -- published by the Free Software Foundation, either version 2 of the |
| 11 | -- License, or (at your option) any later version. |
| 12 | -- |
| 13 | -- Vicious is distributed in the hope that it will be useful, |
| 14 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | -- GNU General Public License for more details. |
| 17 | -- |
| 18 | -- You should have received a copy of the GNU General Public License |
| 19 | -- along with Vicious. If not, see <https://www.gnu.org/licenses/>. |
| 20 | |
| 21 | -- {{{ Grab environment |
| 22 | local type = type |
| 23 | local io = { open = io.open } |
| 24 | local helpers = require("vicious.helpers") |
| 25 | -- }}} |
| 26 | |
| 27 | -- Initialize variables |
| 28 | local subject = "N/A" |
| 29 | |
| 30 | -- {{{ Mailbox widget type |
| 31 | return helpers.setcall(function (format, warg) |
| 32 | if not warg then return end |
| 33 | |
| 34 | local f = io.open(type(warg) == "table" and warg[1] or warg) |
| 35 | f:seek("end", -30720) |
| 36 | -- mbox could be huge, get a 30kb chunk from EOF |
| 37 | -- * attachment could be much bigger than 30kb |
| 38 | local txt = f:read("*all") |
| 39 | f:close() |
| 40 | |
| 41 | -- Find all Subject lines |
| 42 | for i in txt:gmatch"Subject: ([^\n]*)" do subject = i end |
| 43 | |
| 44 | -- Check if we should scroll, or maybe truncate |
| 45 | if type(warg) == "table" then |
| 46 | if warg[3] ~= nil then |
| 47 | subject = helpers.scroll(subject, warg[2], warg[3]) |
| 48 | else |
| 49 | subject = helpers.truncate(subject, warg[2]) |
| 50 | end |
| 51 | end |
| 52 | |
| 53 | return { subject } |
| 54 | end) |
| 55 | -- }}} |