refine taro-reader, add MBOX_ROOT to config instead of using env, and adjust refresh logic
Iris Lightshard nilix@nilfm.cc
PGP Signature
-----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEkFh6dA+k/6CXFXU4O3+8IhROY5gFAmQfLp4ACgkQO3+8IhRO Y5jpDBAAg2iklmrp+PtNybaaCzdonJdZ7sP6Ra260i9uLQnkwkJOsmQIt3xG6nxE dW7FZYXQteRoPGH+Q1FgwVA92+syqK6I1h4e93D2IaCo2MXyqLNM+f0qA/MdVOTR N1IHCS9PyRsr1TJqENo3iyFl+zh1zBuQcpUWj9vkNY0lbs2ttnSmz2q9Tj370wd4 aUhYGOZXB+21kN06iIP9Xk3R64pOq7dUvL5N7qQn/QZNgjY8sviRtx6hBgjT25v3 32aoOnVJE2TbHEPljZ+j0VfFgWPuIzyuIzeWxAJBjBQmjoPxOIvCY/2P3p6NkfPs RnoFXXULuUUQ83jTglMcGnJTs8g3eHhj7Abj7tKsBbFHDo/8/L3reyIj70YkrUKo LeDomt58Vvik9jLrNh5HMu0N2WwyaYqmjOyWNiEH/eyUDs48oh+uo6nfs09Dodqt CZyzppIoQzf8Ah63TLjHwWVsmTpZo4VJgdTW7qlA6OPrSXeTDWKmWoq7vYn7a7+g G2SCYTAyjU/sfVfEhMiCBkOM7pZnFFMJfUf2o1NJBUrBa7kDIkqGvcqrhKgr73lD U3NXmIW/8yPexcys+yWMMGf1w9JN2Gt33tl49C4n9Dk66yRTaazuo3f7Hr3uNL29 3Tkd75X/0b1qR0YVhV0XZ18lJceQxLmJAf6WwKiVtSQe19tZbOI= =0a7k -----END PGP SIGNATURE-----
4 files changed,
46 insertions(+),
17 deletions(-)
M
README.md
→
README.md
@@ -33,9 +33,9 @@
The buttons on the bottom are as follows (with equivalent keybinds): - compose [`n`]: open a compose window to write new mail -- refresh [`r`]: refresh the current mailbox +- refresh [`r`]: refresh the current mailbox, removing search query - mark all read ['.']: this -- search [`/`]: search mail with a regex (only headers, case sensitive) +- search [`/`]: search mail with a regex (only headers, case insensitive) - refile [`m`]: move mail to the given folder - trash [`Del`]: move mail to the Trash folder, unless it's already in the Trash, in which case it's deleted@@ -82,7 +82,7 @@
- `0`: mailbox list (truncated to 4k - this should be enough) - `2`: list mail in current mailbox (or search results) (truncated to 32k - if you need more, use search) -Odd messages go from the `uxn` windows to `taro-ctl`. +Odd messages go from the `uxn` windows to `taro-ctl` (or from `taro-ctl` to itself). - `1`: change/refresh mailbox; payload is the mailbox to read - `3`: mark all as read in current mailbox; no payload@@ -91,3 +91,4 @@ - `7`: refile mail; payload is the beginning and end of the mmsg range in u16, and then the mailbox name
- `9`: trash mail; payload is the beginning and end of the mmsg range in u16 - `11`: read mail; payload is a single u16 message number in the current sequence - `13`: compose mail; no payload +- `15`: push view update (keeps search query, for after replying/writing mail)
M
config.cr
→
config.cr
@@ -1,8 +1,11 @@
-# where the rom and scripts will live +# where your maildir folders live +MBOX_ROOT = "/home/nilix/lib/mail/zoho" +# where the rom and scripts will live (probably the git repo) TARO_LIB = "/home/nilix/src/taro" # where attachments are saved TARO_DOWNLOADS = "/home/nilix/tmp" # terminal commands to wrap reading and writing mail +# use your own favorite terminal - cmdline syntax may differ READER_PROG = "TARO_DOWNLOADS=#{TARO_DOWNLOADS} LESSKEYIN=#{TARO_LIB}/lesskey st -t \"taro-reader\" -e #{TARO_LIB}/taro-reader" COMPOSE_PROG = "st -t \"taro-compose\" -e mcom"
M
taro-ctl.cr
→
taro-ctl.cr
@@ -86,12 +86,12 @@ end
when WinType::READER then spawn do Process.run(command: READER_PROG + " " + arg, shell: true) - @@msg.send(Mesg.new(1_u8, MblazeProxy.mailbox.to_slice)) + @@msg.send(Mesg.new(15_u8, Slice(UInt8).new(0))) end when WinType::COMPOSE then spawn do Process.run(command: COMPOSE_PROG, shell: true) - @@msg.send(Mesg.new(1_u8, MblazeProxy.mailbox.to_slice)) + @@msg.send(Mesg.new(15_u8, Slice(UInt8).new(0))) end end@@ -156,9 +156,14 @@ end
class MblazeProxy @@mailbox : String = "INBOX" + @@search_regex : String = "" def self.mailbox @@mailbox + end + + def self.search_regex + @@search_regex end private def run_cmd(cmdtxt : String) : String@@ -169,8 +174,11 @@ return io.to_s
end def list_mail : String + if @@search_regex != "" + return search_mail(@@search_regex, false, false) + end cmd = " - mbox=${MBOX_ROOT}/#{@@mailbox} + mbox=#{MBOX_ROOT}/#{@@mailbox} mdirs ${mbox} | xargs minc > /dev/null mlist ${mbox} | msort -dr | mseq -S | mscan"@@ -179,7 +187,7 @@ return run_cmd(cmd)
end def list_mboxes : String - cmd = "echo 'INBOX' ; for x in $(mdirs -a ${MBOX_ROOT} | sort | grep -v INBOX); do echo ${x#$MBOX_ROOT/}; done" + cmd = "echo 'INBOX' ; for x in $(mdirs -a #{MBOX_ROOT} | sort | grep -v INBOX); do echo ${x##{MBOX_ROOT}/}; done" return run_cmd(cmd) end@@ -191,10 +199,11 @@ end
def set_mbox(box : String) @@mailbox = box + @@search_regex = "" end def trash_mail(range_start : UInt16, range_end : UInt16) - cmd = "mrefile #{range_start}:#{range_end} ${MBOX_ROOT}/Trash" + cmd = "mrefile #{range_start}:#{range_end} #{MBOX_ROOT}/Trash" # destroy mail if we are trashing what's already in the trash! if @@mailbox == "Trash"@@ -204,12 +213,13 @@ run_cmd(cmd)
end def refile_mail(range_start : UInt16, range_end : UInt16, to_mbox : String) - cmd = "mrefile #{range_start}:#{range_end} ${MBOX_ROOT}/#{to_mbox}" + cmd = "mrefile #{range_start}:#{range_end} #{MBOX_ROOT}/#{to_mbox}" run_cmd(cmd) end - def search_mail(query : String, body : Bool) : String - cmd = "mlist ${MBOX_ROOT}/#{@@mailbox} | magrep #{body ? "/" : "*"}:#{query} | msort -dr | uniq | mseq -S | mscan" + def search_mail(query : String, body : Bool, case_sensitive : Bool) : String + @@search_regex = query + cmd = "mlist #{MBOX_ROOT}/#{@@mailbox} | magrep #{case_sensitive ? "" : "-i"} #{body ? "/" : "*"}:#{query} | msort -dr | uniq | mseq -S | mscan" return run_cmd(cmd) end end@@ -267,7 +277,7 @@ when 3 then
taro.mblaze.mark_all_read taro.mainWindow.write_msg(2_u8, taro.mblaze.list_mail.to_slice) when 5 then - search_results = taro.mblaze.search_mail(String.new(m.data), false) + search_results = taro.mblaze.search_mail(String.new(m.data), false, false) taro.mainWindow.write_msg(2_u8, search_results.to_slice) when 7 then range_start = u8arr_tou16(m.data[0..1])@@ -285,6 +295,8 @@ mmsg = u8arr_tou16(m.data[0..1])
Taro::ChildWindow.new(Taro::WinType::READER, mmsg.to_s) when 13 then Taro::ChildWindow.new(Taro::WinType::COMPOSE) + when 15 then + taro.mainWindow.write_msg(2_u8, taro.mblaze.list_mail.to_slice) end end end
M
taro-reader
→
taro-reader
@@ -53,13 +53,25 @@ esac
done } +keep_track_of_mailfile() { + orig=$1 + stamp=${orig%,} + new=$(\ls -1 ${stamp}*) + printf "${new}" +} + mread() { - local META + local this=$(mseq $@) mflag -S ${this} - local this=$(mseq $@) - local action="q" while true; do - (mshow ${this} ; printf "\n"; mshow -t ${this}; printf "\n" ; printf "[o]pen or [s]ave attachments\n" ; printf "[r]reply, [f]orward, [q]uit\n")| less --mouse + this=$(keep_track_of_mailfile ${this}) + if [ ! -e ${this} ]; then + printf "Looks like this email was refiled... Press Enter to close this window. " + read + break + fi + + (mshow ${this} ; printf "\n"; mshow -t ${this})| less --mouse -Ps"[o]pen or [s]ave attachments, [r]reply, [f]orward, [q]uit"$ case $? in 113) #q@@ -73,6 +85,7 @@ save_attachments;;
111) #o open_attachments;; esac + done }