imprv: reply

This commit is contained in:
2026-03-17 14:25:03 +01:00
parent ce9f16e293
commit aa25dc2530
4 changed files with 16 additions and 20 deletions

View File

@@ -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')
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" \

View File

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

View File

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

View File

@@ -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
# }