refine taro-reader, add MBOX_ROOT to config instead of using env, and adjust refresh logic

This commit is contained in:
Iris Lightshard 2023-03-25 11:25:50 -06:00
parent 5f77c7867e
commit 24baa38b38
Signed by: Iris Lightshard
GPG key ID: 3B7FBC22144E6398
4 changed files with 46 additions and 17 deletions

View file

@ -33,9 +33,9 @@ Left clicking on a mailbox switches to that mailbox. Left-clicking on mail selec
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 @@ Even messages go from `taro-ctl` to the `uxn` windows.
- `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 @@ Odd messages go from the `uxn` windows to `taro-ctl`.
- `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)

View file

@ -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"

View file

@ -86,12 +86,12 @@ module Taro
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,11 +156,16 @@ module Taro
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
puts cmdtxt
io = IO::Memory.new
@ -169,8 +174,11 @@ module Taro
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 @@ module Taro
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 @@ module Taro
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 @@ module Taro
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 @@ loop do
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 @@ loop do
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

View file

@ -53,13 +53,25 @@ open_attachments() {
done
}
keep_track_of_mailfile() {
orig=$1
stamp=${orig%,}
new=$(\ls -1 ${stamp}*)
printf "${new}"
}
mread() {
local META
mflag -S ${this}
local this=$(mseq $@)
local action="q"
mflag -S ${this}
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 @@ mread() {
111) #o
open_attachments;;
esac
done
}