first complete version

This commit is contained in:
2026-03-17 11:01:45 +01:00
parent 28aca1a82b
commit af8c7efae9
12 changed files with 334 additions and 77 deletions

View File

@@ -5,6 +5,12 @@ set -eu
# Application info
. "sh/info.sh"
# helper functions
. "sh/helper.sh"
# tools
. "sh/tools.sh"
# Configuration
. "sh/config.sh"
@@ -14,9 +20,6 @@ set -eu
# awk scripts
. "sh/awk.sh"
# tools
. "sh/tools.sh"
# query history
. "sh/history.sh"
@@ -38,6 +41,9 @@ set -eu
# keys
. "sh/keys.sh"
# send emails
. "sh/send.sh"
if [ "${1:-}" = "--list-threads" ]; then
shift
nmquery="$1"
@@ -153,6 +159,27 @@ if [ "${1:-}" = "--undelete" ]; then
exit
fi
if [ "${1:-}" = "--flag" ]; then
shift
[ "$1" = "thread" ] && thread=1
shift
[ "${thread:-}" ] && field="thread" || field="id"
query="$(echo " $@" | sed "s/\s\(\S\)/ $field:\1/g")"
$NOTMUCH tag +"$TAG_FLAGGED" "$query"
exit
fi
if [ "${1:-}" = "--unflag" ]; then
shift
[ "$1" = "thread" ] && thread=1
shift
[ "${thread:-}" ] && field="thread" || field="id"
query="$(echo " $@" | sed "s/\s\(\S\)/ $field:\1/g")"
$NOTMUCH tag -"$TAG_FLAGGED" "$query"
exit
fi
if [ "${1:-}" = "--purge" ]; then
shift
# query="$(echo " $@" | sed "s/\s\(\S*\)/ (thread:\1 and tag:del)/g" | sed 's/)\(\s\+\)(/) or (/g')"
@@ -226,9 +253,11 @@ if [ "${1:-}" = "--show-thread" ]; then
--bind="$KEYS_ARCHIVE:execute($0 --archive message {+5})+reload:$0 --list-messages-in-thread \"$thread\"" \
--bind="$KEYS_DELETE:execute($0 --delete message {+5})+reload:$0 --list-messages-in-thread \"$thread\"" \
--bind="$KEYS_OPEN:execute:$0 --open-part {5}" \
--bind="$KEYS_FLAG_TOGGLE:execute:echo NOT IMPLEMENTED;read -r t" \
--bind="$KEYS_REPLY:execute:echo NOT IMPLEMENTED;read -r t" \
--bind="$KEYS_COMPOSE:execute:echo NOT IMPLEMENTED;read -r t" \
--bind="$KEYS_FLAG:execute($0 --flag message {+5})+reload:$0 --list-messages-in-thread \"$thread\"" \
--bind="$KEYS_UNFLAG:execute($0 --unflag message {+5})+reload:$0 --list-messages-in-thread \"$thread\"" \
--bind="$KEYS_REPLY:execute:$0 --reply {5}" \
--bind="$KEYS_VIEW_LOGS:execute:$0 --view-logs" \
--bind="$KEYS_COMPOSE:execute:$0 --compose" \
--bind="focus:change-preview($0 --preview-message {5})+transform-footer:printf '\033[4mMesssage parts\033[0m\n';$0 --show-message-parts {5}" \
--preview="$0 --preview-message {5}" \
--preview-window="$FZF_DEFAULT_PREVIEW_WINDOW" || true)
@@ -255,10 +284,100 @@ if [ "${1:-}" = "--list-deleted" ]; then
--bind="$KEYS_ENTER:" \
--bind="$KEYS_PURGE_ALL:select-all+execute($0 --purge {+4})+reload:$0 --list-threads \"tag:$TAG_DEL\"" \
--bind="$KEYS_DELETE:execute($0 --purge {+4})+reload:$0 --list-threads \"tag:$TAG_DEL\"" \
--bind="$KEYS_ENTER_ALTERNATIVE:execute($0 --undelete {+4})+reload:$0 --list-threads \"tag:$TAG_DEL\""
--bind="$KEYS_ENTER_ALTERNATIVE:execute($0 --undelete {+4})+reload:$0 --list-threads \"tag:$TAG_DEL\"" \
--bind="$KEYS_VIEW_LOGS:execute:$0 --view-logs"
exit
fi
if [ "${1:-}" = "--compose" ]; then
label_text=" Select sender "
address=$(list_addresses | $FZF \
--delimiter="$(printf '\t')" \
--with-nth=2 \
--accept-nth=1 \
--color="label:$ANSICOLORFROM" \
--tiebreak=index \
--margin='20%' \
--bind="$KEYS_DOWN_HP:half-page-down" \
--bind="$KEYS_UP_HP:half-page-up" \
--bind="$KEYS_ENTER:accept-or-print-query" \
--bind="$KEYS_ENTER_ALTERNATIVE:transform:echo \"print(\$FZF_QUERY)+accept\"" \
--bind="$KEYS_CANCEL:print()+accept" \
--border=double \
--border-label="$label_text" | head -1 || true)
tmpfile=$(mktemp --suffix='.eml')
{
echo "From: $PRIMARY_NAME <$PRIMARY_EMAIL>"
echo "To: $address"
echo "Cc: "
echo "Subject: "
echo ""
echo "Message body goes here"
} > "$tmpfile"
$EDITOR "$tmpfile"
# Confirm and send
send "$tmpfile"
rm -f "$tmpfile"
exit
fi
if [ "${1:-}" = "--reply" ]; then
shift
messageid="$1"
tmpfile=$(mktemp --suffix='.eml')
$NOTMUCH reply id:"$messageid" > "$tmpfile"
$EDITOR "$tmpfile"
# Confirm and send
send "$tmpfile"
rm -f "$tmpfile"
exit
fi
if [ "${1:-}" = "--sync" ]; then
$NOTMUCH new && $MBSYNC -a && $NOTMUCH new
exit
fi
if [ "${1:-}" = "--send-test-email" ]; then
tmpfile=$(mktemp --suffix='.eml')
{
echo "From: $PRIMARY_NAME <$PRIMARY_EMAIL>"
echo "To: $PRIMARY_NAME <$PRIMARY_EMAIL>"
echo "Subject: Test E-Mail from $APP_NAME version $APP_VERSION"
echo ""
echo "This is a test email sent from from [$APP_NAME]($APP_WEBSITE)."
} > "$tmpfile"
send "$tmpfile" "force"
rm -f "$tmpfile"
exit
fi
if [ "${1:-}" = "--view-logs" ]; then
shift
printf "0 Send test message\n1 Close\n" |
$FZF \
--sync \
--bind='start:pos(2)' \
--bind='ctrl-c,ctrl-g,ctrl-q,esc:pos(2)+accept' \
--bind="enter:transform: [ {1} = 0 ] && $0 --send-test-email || echo accept" \
--reverse \
--no-input \
--header="Here are the latest SMTP logs" \
--preview-window='60%,border-line,wrap-word,follow,noinfo' \
--margin='5%,5%,5%,15%' \
--preview="tail -f \"$SMTPLOGFILE\" | $CATLOG" \
--with-nth=2.. \
--accept-nth=1 \
--header-border='line' \
--color='border:yellow,header:yellow' || true
exit
fi
# Set terminal title
if [ "$SET_TERMINAL_TITLE" = "yes" ]; then
printf '\033]0;%s\007' "$WINDOW_TITLE"
fi
# Modes
APPEND="append"
NWSRCH="search"
@@ -268,11 +387,14 @@ ADDRESS_FROM="from-"
CMD_SEARCH_ADDRESS="address-"
CMD_EDIT_QUERY="edit-query"
CMD_GOTO_INBOX="go-to-inbox"
CMD_GOTO_UNREAD="go-to-unread"
CMD_GOTO_FLAGGED="go-to-flagged"
while true; do
nmquery="${nmquery:-tag:$TAG_INBOX}"
[ "$(tail -1 "$NMFHIST")" = "$nmquery" ] || echo "$nmquery" >> "$NMFHIST"
cmd=$(list_threads "$nmquery" | $FZF \
--no-clear \
--header-first \
--header="Query: $nmquery" \
--tiebreak=index \
@@ -301,8 +423,15 @@ while true; do
--bind="$KEYS_TAG_REMOVE:execute($0 --tag-modify thread del {+4})+reload:$0 --list-threads \"$nmquery\"" \
--bind="$KEYS_ARCHIVE:execute($0 --archive thread {+4})+reload:$0 --list-threads \"$nmquery\"" \
--bind="$KEYS_DELETE:execute($0 --delete thread {+4})+reload:$0 --list-threads \"$nmquery\"" \
--bind="$KEYS_FLAG:execute($0 --flag thread {+4})+reload:$0 --list-threads \"$nmquery\"" \
--bind="$KEYS_UNFLAG:execute($0 --unflag thread {+4})+reload:$0 --list-threads \"$nmquery\"" \
--bind="$KEYS_SEARCH_DELETED:execute:$0 --list-deleted" \
--bind="$KEYS_SEARCH_INBOX:print($CMD_GOTO_INBOX)+accept" \
--bind="$KEYS_SEARCH_UNREAD:print($CMD_GOTO_UNREAD)+accept" \
--bind="$KEYS_SEARCH_FLAGGED:print($CMD_GOTO_FLAGGED)+accept" \
--bind="$KEYS_VIEW_LOGS:execute:$0 --view-logs" \
--bind="$KEYS_SYNC:execute($0 --sync)+reload:$0 --list-threads \"$nmquery\"" \
--bind="$KEYS_COMPOSE:execute:$0 --compose" \
--bind="focus:change-preview:$0 --preview-thread {4}" \
--preview="$0 --preview-thread {4}" \
--preview-window="$FZF_DEFAULT_PREVIEW_WINDOW" | head -1 || true)
@@ -335,7 +464,9 @@ while true; do
;;
esac
address=$(list_addresses | $FZF \
--color="border:$ANSICOLORFROM" \
--delimiter="$(printf '\t')" \
--with-nth=2 \
--accept-nth=1 \
--color="label:$ANSICOLORFROM" \
--tiebreak=index \
--margin='20%' \
@@ -372,9 +503,9 @@ while true; do
--border=double \
--border-label=' Query history ' | head -1 || true)
;;
$CMD_GOTO_INBOX)
nmquery="tag:$TAG_INBOX"
;;
$CMD_GOTO_INBOX) nmquery="tag:$TAG_INBOX" ;;
$CMD_GOTO_UNREAD) nmquery="tag:$TAG_UNREAD" ;;
$CMD_GOTO_FLAGGED) nmquery="tag:$TAG_FLAGGED" ;;
*)
;;
esac