From aa25dc25302d4c72f65512fe58207cb5658b4a19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=84min=20Baumeler?= Date: Tue, 17 Mar 2026 14:25:03 +0100 Subject: [PATCH] imprv: reply --- src/main.sh | 16 +++++++++++++--- src/sh/config.sh | 3 ++- src/sh/notmuch.sh | 3 +-- src/sh/varia.sh | 14 -------------- 4 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/main.sh b/src/main.sh index 786d99f..7f87b1d 100755 --- a/src/main.sh +++ b/src/main.sh @@ -254,7 +254,7 @@ if [ "${1:-}" = "--show-thread" ]; then --bind="$KEYS_OPEN:execute:$0 --open-part {5}" \ --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_REPLY:execute:$0 --reply message {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}" \ @@ -309,6 +309,7 @@ if [ "${1:-}" = "--compose" ]; then echo "From: $PRIMARY_NAME <$PRIMARY_EMAIL>" echo "To: $address" echo "Cc: " + [ "$BCC_TO_SELF" ] && echo "Bcc: $PRIMARY_NAME <$PRIMARY_EMAIL>" echo "Subject: " echo "" echo "Message body goes here" @@ -322,9 +323,16 @@ fi if [ "${1:-}" = "--reply" ]; then shift - messageid="$1" + [ "$1" = "thread" ] && thread=1 + shift + [ ! "${thread:-}" ] && messageid="$1" || messageid="$(nm_last_message_in_thread "$1")" tmpfile=$(mktemp --suffix='.eml') - $NOTMUCH reply id:"$messageid" > "$tmpfile" + if [ "$BCC_TO_SELF" ]; then + $NOTMUCH reply id:"$messageid" | + awk '!f && /^From:/ { print "Bcc: "substr($0, 7); f=1 } {print}' > "$tmpfile" + else + $NOTMUCH reply id:"$messageid" > "$tmpfile" + fi $EDITOR "$tmpfile" # Confirm and send send "$tmpfile" @@ -342,6 +350,7 @@ if [ "${1:-}" = "--send-test-email" ]; then { echo "From: $PRIMARY_NAME <$PRIMARY_EMAIL>" echo "To: $PRIMARY_NAME <$PRIMARY_EMAIL>" + [ "$BCC_TO_SELF" ] && echo "Bcc: $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)." @@ -429,6 +438,7 @@ while true; do --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_REPLY:execute:$0 --reply thread {4}" \ --bind="$KEYS_SYNC:execute($0 --sync)+reload:$0 --list-threads \"$nmquery\"" \ --bind="$KEYS_COMPOSE:execute:$0 --compose" \ --bind="$KEYS_GOTO_FIRST:first" \ diff --git a/src/sh/config.sh b/src/sh/config.sh index 7d58684..7319e3d 100644 --- a/src/sh/config.sh +++ b/src/sh/config.sh @@ -14,13 +14,14 @@ if [ ! "${CONFIG_LOADED:-}" ]; then PRIMARY_NAME=${PRIMARY_NAME:-$($NOTMUCH config get user.name)} PRIMARY_EMAIL=${PRIMARY_EMAIL:-$($NOTMUCH config get user.primary_email)} + BCC_TO_SELF=${BCC_TO_SELF:-} if [ ! "${SMTPLOGFILE:-}" ]; then SMTPLOGFILE=$(mktemp) trap 'rm -f "$SMTPLOGFILE"' EXIT INT fi - export PRIMARY_NAME PRIMARY_EMAIL SET_TERMINAL_TITLE SMTPLOGFILE + export PRIMARY_NAME PRIMARY_EMAIL BCC_TO_SELF SET_TERMINAL_TITLE SMTPLOGFILE export CONFIG_LOADED=1 fi diff --git a/src/sh/notmuch.sh b/src/sh/notmuch.sh index 692c124..942854f 100644 --- a/src/sh/notmuch.sh +++ b/src/sh/notmuch.sh @@ -9,8 +9,7 @@ nm_new() { # Print the message id of the last message within a thread. # @argument $1: thread id nm_last_message_in_thread() { - # TODO: We may be smarter here that just incorporating excluded messages - $NOTMUCH search --output=messages --sort=oldest-first --offset=-1 thread:"$1" | sed 's/^...//' + $NOTMUCH search --output=messages --sort=newest-first --limit=1 thread:"$1" | sed 's/^...//' } # Print the header of a message (with trailing empty line) diff --git a/src/sh/varia.sh b/src/sh/varia.sh index bfc8e99..c6b2345 100644 --- a/src/sh/varia.sh +++ b/src/sh/varia.sh @@ -43,17 +43,3 @@ multiprompt() { --bind="ctrl-c,esc,ctrl-q:" \ --color='border:yellow,header:yellow' | head -1 || true } - -# ASCII-encode address -# asciiaddress() { -# firstword=1 -# for word in $*; do -# [ "${firstword:-}" ] || echo -n ' ' && firstword= -# case $word in -# *[![:cntrl:][:print:]]*) echo -n $word ;; -# *) return 0 ;; -# esac -# isascii "$word" && echo -n "$word" || echo -n "=?UTF-8?B?$(echo -n "$word" | base64)?=" -# done -# } -