Compare commits
7 Commits
7653f052b7
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| af8c7efae9 | |||
| 28aca1a82b | |||
| 8a0c8bc2d7 | |||
| 1453fdb3ad | |||
| eb8f4574bf | |||
| 60f763df19 | |||
| 3210a8bbcf |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
|||||||
nmf
|
nmf
|
||||||
|
.tags
|
||||||
|
|||||||
@@ -1,49 +0,0 @@
|
|||||||
BEGIN {
|
|
||||||
RS = "\x0c"
|
|
||||||
FS = "\n"
|
|
||||||
}
|
|
||||||
|
|
||||||
/^message}/ {
|
|
||||||
mheader = header
|
|
||||||
mpart = part
|
|
||||||
mparts = parts
|
|
||||||
level = 0
|
|
||||||
multipart = ""
|
|
||||||
header = ""
|
|
||||||
part = ""
|
|
||||||
parts = ""
|
|
||||||
}
|
|
||||||
/^header{/ {
|
|
||||||
header = $0
|
|
||||||
}
|
|
||||||
/^(part|attachment)}/ {
|
|
||||||
level--
|
|
||||||
}
|
|
||||||
/^(part|attachment){/ {
|
|
||||||
parts = sprintf("%s\n%"(2*level)"s%s", parts, "", substr($1, index($1, "ID")))
|
|
||||||
level++
|
|
||||||
}
|
|
||||||
# /^part{ ID: [[:digit:]]+, Content-type: multipart\/alternative/ {
|
|
||||||
# multipart = "alternative"
|
|
||||||
# }
|
|
||||||
# /^part{ ID: [[:digit:]]+, Content-type: multipart\/mixed/ {
|
|
||||||
# multipart = "mixed"
|
|
||||||
# }
|
|
||||||
/^part{ ID: [[:digit:]]+, Content-type: text\/plain/ {
|
|
||||||
part = $0
|
|
||||||
}
|
|
||||||
|
|
||||||
END {
|
|
||||||
split(mheader, a, "\n")
|
|
||||||
delete a[1]
|
|
||||||
# delete a[2]
|
|
||||||
for (line in a) {
|
|
||||||
print a[line]
|
|
||||||
}
|
|
||||||
split(mpart, a, "\n")
|
|
||||||
delete a[1]
|
|
||||||
for (line in a) {
|
|
||||||
print a[line]
|
|
||||||
}
|
|
||||||
print "Parts:"mparts
|
|
||||||
}
|
|
||||||
13
src/awk/messageheader.awk
Normal file
13
src/awk/messageheader.awk
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
BEGIN {
|
||||||
|
RS = "\x0c"
|
||||||
|
FS = "\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
/^header{/ {
|
||||||
|
split($0, a, "\n")
|
||||||
|
delete a[1]
|
||||||
|
delete a[2]
|
||||||
|
for (line in a)
|
||||||
|
print a[line]
|
||||||
|
exit
|
||||||
|
}
|
||||||
12
src/awk/messageparts.awk
Normal file
12
src/awk/messageparts.awk
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
BEGIN {
|
||||||
|
RS = "\x0c"
|
||||||
|
FS = "\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
/^(part|attachment)}/ {
|
||||||
|
level--
|
||||||
|
}
|
||||||
|
/^(part|attachment){/ {
|
||||||
|
printf "%"(2*level)"s%s\n", "", substr($1, index($1, "ID"))
|
||||||
|
level++
|
||||||
|
}
|
||||||
14
src/awk/partnr.awk
Normal file
14
src/awk/partnr.awk
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
# Return the part number of the first text/plain part, or, if the variable
|
||||||
|
# `html` is set, of the first text/html part.
|
||||||
|
BEGIN {
|
||||||
|
RS = "\x0c"
|
||||||
|
FS = "\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
/^part{.*Content-type: text\// {
|
||||||
|
match($1, "ID: ([[:digit:]]+).* Content-type: text/([[:alpha:]]+)", a)
|
||||||
|
if ((html && a[2] == "html") || (!html && a[2] == "plain")) {
|
||||||
|
print a[1]
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
}
|
||||||
468
src/main.sh
468
src/main.sh
@@ -5,95 +5,379 @@ set -eu
|
|||||||
# Application info
|
# Application info
|
||||||
. "sh/info.sh"
|
. "sh/info.sh"
|
||||||
|
|
||||||
|
# helper functions
|
||||||
|
. "sh/helper.sh"
|
||||||
|
|
||||||
|
# tools
|
||||||
|
. "sh/tools.sh"
|
||||||
|
|
||||||
|
# Configuration
|
||||||
|
. "sh/config.sh"
|
||||||
|
|
||||||
# Theme
|
# Theme
|
||||||
. "sh/theme.sh"
|
. "sh/theme.sh"
|
||||||
|
|
||||||
# awk scripts
|
# awk scripts
|
||||||
. "sh/awk.sh"
|
. "sh/awk.sh"
|
||||||
|
|
||||||
# tools
|
# query history
|
||||||
. "sh/tools.sh"
|
|
||||||
|
|
||||||
# history
|
|
||||||
. "sh/history.sh"
|
. "sh/history.sh"
|
||||||
|
|
||||||
__notmuch_search() {
|
# notmuch functions
|
||||||
$NOTMUCH search "$*" \
|
. "sh/notmuch.sh"
|
||||||
| sed "s/^thread:\([[:xdigit:]]\+\)\s\+\([^[]\+\)\s\+\[\([^]]\+\)\]\([^;]*\); \(.*\) (\([^(]*\))$/${COLDATE}\2${COLRESET}\t${COLCNTS}\3${COLRESET}\t${COLFROM}\4${COLRESET}\t${COLSUBJ}\5${COLRESET}\t${COLTAGS}\6${COLRESET}\t\1/" \
|
|
||||||
| column -s "$(printf '\t')" -t -l 3 -R 1,2
|
|
||||||
}
|
|
||||||
|
|
||||||
__notmuch_thread() {
|
# list generators
|
||||||
$NOTMUCH show thread:"$1" \
|
. "sh/lists.sh"
|
||||||
| awk "$AWK_THREADOVERVIEW" \
|
|
||||||
| sed "s/^\(\S*\)\t\([^\t]*\)\t\(.*\) (\([^()]*\)) (\([^()]*\))$/${COLFROM}\3${COLRESET}\t${COLSUBJ}\2${COLRESET}\t${COLDATE}\4${COLRESET}\t${COLTAGS}\5${COLRESET}\t\1/"
|
|
||||||
}
|
|
||||||
|
|
||||||
__notmuch_list_tags() {
|
# preview functions
|
||||||
$NOTMUCH search --output=tags tag:/./
|
. "sh/preview.sh"
|
||||||
}
|
|
||||||
|
|
||||||
__notmuch_list_address() {
|
# varia functions
|
||||||
$NOTMUCH address '*'
|
. "sh/varia.sh"
|
||||||
}
|
|
||||||
|
|
||||||
|
# tags
|
||||||
|
. "sh/tags.sh"
|
||||||
|
|
||||||
|
# keys
|
||||||
|
. "sh/keys.sh"
|
||||||
|
|
||||||
|
# send emails
|
||||||
|
. "sh/send.sh"
|
||||||
|
|
||||||
|
if [ "${1:-}" = "--list-threads" ]; then
|
||||||
|
shift
|
||||||
|
nmquery="$1"
|
||||||
|
list_threads "$nmquery"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${1:-}" = "--list-messages-in-thread" ]; then
|
||||||
|
shift
|
||||||
|
thread="$1"
|
||||||
|
list_messages_in_thread "$thread"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "${1:-}" = "--preview-thread" ]; then
|
if [ "${1:-}" = "--preview-thread" ]; then
|
||||||
shift
|
shift
|
||||||
thread="$1"
|
threadid="$1"
|
||||||
$NOTMUCH show thread:$thread \
|
preview_message "thread" "$threadid"
|
||||||
| awk "$AWK_LASTMESSAGEINTHREAD" \
|
exit
|
||||||
| tail -n +2 \
|
fi
|
||||||
| $CAT
|
|
||||||
|
if [ "${1:-}" = "--preview-html-thread" ]; then
|
||||||
|
shift
|
||||||
|
threadid="$1"
|
||||||
|
preview_message "thread" "$threadid" "html"
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "${1:-}" = "--preview-message" ]; then
|
if [ "${1:-}" = "--preview-message" ]; then
|
||||||
shift
|
shift
|
||||||
messageid="$1"
|
messageid="$1"
|
||||||
$NOTMUCH show id:$messageid \
|
preview_message "id" "$messageid"
|
||||||
| awk "$AWK_LASTMESSAGEINTHREAD" \
|
exit
|
||||||
| tail -n +2 \
|
fi
|
||||||
| $CAT
|
|
||||||
|
if [ "${1:-}" = "--preview-html-message" ]; then
|
||||||
|
shift
|
||||||
|
messageid="$1"
|
||||||
|
preview_message "id" "$messageid" "html"
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "${1:-}" = "--view-source" ]; then
|
if [ "${1:-}" = "--view-source" ]; then
|
||||||
shift
|
shift
|
||||||
messageid="$1"
|
messageid="$1"
|
||||||
less $($NOTMUCH search --output=files id:$messageid)
|
$NOTMUCH show --part=0 id:"$messageid" | $CATEMAIL | less
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# FZF default configs
|
if [ "${1:-}" = "--show-message-parts" ]; then
|
||||||
|
shift
|
||||||
|
messageid="$1"
|
||||||
|
nm_message_parts "$messageid"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
# FZF defaults
|
||||||
FZF_DEFAULT_PREVIEW_WINDOW="right,80,border-line,wrap-word"
|
FZF_DEFAULT_PREVIEW_WINDOW="right,80,border-line,wrap-word"
|
||||||
FZF_ALTERNATE_PREVIEW_WINDOW="bottom,80%,border-line,wrap-word"
|
FZF_ALTERNATE_PREVIEW_WINDOW="bottom,80%,border-line,wrap-word"
|
||||||
FZF_DEFAULT_THREAD_LINE="{1} {3} ({4})"
|
FZF_DEFAULT_THREAD_LINE="{1} {3} ({4})"
|
||||||
|
|
||||||
|
if [ "${1:-}" = "--open-part" ]; then
|
||||||
|
shift
|
||||||
|
messageid="$1"
|
||||||
|
res=$(nm_message_parts "$messageid" | awk '{print NR"\t"$0}' | $FZF \
|
||||||
|
--raw \
|
||||||
|
--reverse \
|
||||||
|
--wrap=word \
|
||||||
|
--delimiter="$(printf '\t')" \
|
||||||
|
--with-nth=2 \
|
||||||
|
--accept-nth=1 \
|
||||||
|
--margin='30%' \
|
||||||
|
--bind='change:best' \
|
||||||
|
--bind="$KEYS_DOWN_HP:half-page-down" \
|
||||||
|
--bind="$KEYS_UP_HP:half-page-up" \
|
||||||
|
--bind="$KEYS_ENTER:accept" \
|
||||||
|
--bind="$KEYS_BACK,$KEYS_CANCEL,backward-eof:abort" || true)
|
||||||
|
[ "$res" ] || exit
|
||||||
|
tmpfile=$(mktemp)
|
||||||
|
nm_message_get_part "$messageid" "$res" > "$tmpfile"
|
||||||
|
if ynprompt "Are you sure you want to open this file?" "$(ls -lh "$tmpfile")\n$(file -b "$tmpfile")"; then
|
||||||
|
# TODO: should we clean up at some point?
|
||||||
|
open "$tmpfile" >/dev/null 2>/dev/stdout
|
||||||
|
fi
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${1:-}" = "--archive" ]; then
|
||||||
|
shift
|
||||||
|
[ "$1" = "thread" ] && thread=1
|
||||||
|
shift
|
||||||
|
[ "${thread:-}" ] && field="thread" || field="id"
|
||||||
|
query="$(echo " $@" | sed "s/\s\(\S\)/ $field:\1/g")"
|
||||||
|
tagmod="$(echo " $TAG_INBOX $TAGS_NEW" | sed "s/\s\(\S\)/ -\1/g")"
|
||||||
|
$NOTMUCH tag $tagmod "$query"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${1:-}" = "--delete" ]; then
|
||||||
|
shift
|
||||||
|
[ "$1" = "thread" ] && thread=1
|
||||||
|
shift
|
||||||
|
[ "${thread:-}" ] && field="thread" || field="id"
|
||||||
|
query="$(echo " $@" | sed "s/\s\(\S\)/ $field:\1/g")"
|
||||||
|
$NOTMUCH tag -$TAG_INBOX +$TAG_DEL "$query"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${1:-}" = "--undelete" ]; then
|
||||||
|
shift
|
||||||
|
query="$(echo " $@" | sed "s/\s\(\S\)/ thread:\1/g")"
|
||||||
|
$NOTMUCH tag -$TAG_DEL "$query"
|
||||||
|
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')"
|
||||||
|
query="tag:$TAG_DEL and ("$(echo " $@" | sed "s/\s\(\S\)/ thread:\1/g")")"
|
||||||
|
files=$(nm_files_all "$query")
|
||||||
|
if ynprompt "Are you sure you want to purge these files?" "$files"; then
|
||||||
|
echo -n "$files" | xargs -d "\n" rm
|
||||||
|
nm_new
|
||||||
|
fi
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${1:-}" = "--tag-modify" ]; then
|
||||||
|
shift
|
||||||
|
[ "$1" = "thread" ] && thread=1
|
||||||
|
shift
|
||||||
|
[ "$1" = "add" ] && sign=+ || sign=-
|
||||||
|
shift
|
||||||
|
[ "${thread:-}" ] && field="thread" || field="id"
|
||||||
|
query="$(echo " $@" | sed "s/\s\(\S\)/ $field:\1/g")"
|
||||||
|
if [ "$sign" = "+" ]; then
|
||||||
|
tagquery=""
|
||||||
|
label_text="Add tag"
|
||||||
|
else
|
||||||
|
tagquery="$query"
|
||||||
|
label_text="Remove tag"
|
||||||
|
fi
|
||||||
|
res=$(list_tags "$tagquery" | $FZF \
|
||||||
|
--color="border:$ANSICOLORTAGS" \
|
||||||
|
--color="label:$ANSICOLORTAGS" \
|
||||||
|
--tac \
|
||||||
|
--bind="$KEYS_DOWN_HP:half-page-down" \
|
||||||
|
--bind="$KEYS_UP_HP:half-page-up" \
|
||||||
|
--bind="$KEYS_BACK,$KEYS_CANCEL,backward-eof:abort" \
|
||||||
|
--bind="$KEYS_ENTER:accept-or-print-query" \
|
||||||
|
--bind="$KEYS_ENTER_ALTERNATIVE:transform:echo \"print(\$FZF_QUERY)+accept\"" \
|
||||||
|
--margin='20%' \
|
||||||
|
--border=double \
|
||||||
|
--border-label=" $label_text " | head -1 || true)
|
||||||
|
[ "$res" ] || exit
|
||||||
|
$NOTMUCH tag $sign$res "$query"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
if [ "${1:-}" = "--show-thread" ]; then
|
if [ "${1:-}" = "--show-thread" ]; then
|
||||||
shift
|
shift
|
||||||
thread="$1"
|
thread="$1"
|
||||||
res=$(__notmuch_thread "$thread" | fzf \
|
res=$(list_messages_in_thread "$thread" | $FZF \
|
||||||
--raw \
|
--raw \
|
||||||
--ansi \
|
|
||||||
--reverse \
|
--reverse \
|
||||||
--multi \
|
--multi \
|
||||||
--delimiter="$(printf '\t')" \
|
--delimiter="$(printf '\t')" \
|
||||||
--with-nth="$FZF_DEFAULT_THREAD_LINE" \
|
--with-nth="$FZF_DEFAULT_THREAD_LINE" \
|
||||||
--bind="alt-s:change-with-nth({1} {2} {3} ({4})|$FZF_DEFAULT_THREAD_LINE)" \
|
|
||||||
--accept-nth=5 \
|
--accept-nth=5 \
|
||||||
--bind='alt-j:preview-down,alt-k:preview-up' \
|
--bind="$KEYS_CANCEL:transform:[ \$FZF_SELECT_COUNT -gt 0 ] && echo clear-multi || echo abort" \
|
||||||
--bind='ctrl-d:half-page-down,ctrl-u:half-page-up' \
|
--bind="$KEYS_PREVIEW_DOWN:preview-down" \
|
||||||
--bind='page-up:preview-half-page-up,page-down:preview-half-page-down' \
|
--bind="$KEYS_PREVIEW_UP:preview-up" \
|
||||||
--bind="enter:" \
|
--bind="$KEYS_PREVIEW_DOWN_HP:preview-half-page-down" \
|
||||||
--bind="ctrl-h,backward-eof:abort" \
|
--bind="$KEYS_PREVIEW_UP_HP:preview-half-page-up" \
|
||||||
--bind="alt-/:change-preview-window($FZF_ALTERNATE_PREVIEW_WINDOW|$FZF_DEFAULT_PREVIEW_WINDOW)" \
|
--bind="$KEYS_CYCLE_DISPLAY:change-with-nth({1} {2} {3} ({4})|$FZF_DEFAULT_THREAD_LINE)" \
|
||||||
--bind="alt-v:execute:$0 --view-source {5}" \
|
--bind="$KEYS_DOWN_HP:half-page-down" \
|
||||||
|
--bind="$KEYS_UP_HP:half-page-up" \
|
||||||
|
--bind="$KEYS_ENTER:" \
|
||||||
|
--bind="$KEYS_BACK,$KEYS_CANCEL,backward-eof:abort" \
|
||||||
|
--bind="$KEYS_PREVIEW_TOGGLE_SIZE:change-preview-window($FZF_ALTERNATE_PREVIEW_WINDOW|$FZF_DEFAULT_PREVIEW_WINDOW)" \
|
||||||
|
--bind="$KEYS_VIEW_SOURCE:execute:$0 --view-source {5}" \
|
||||||
|
--bind="$KEYS_HTML_PREVIEW:change-preview:$0 --preview-html-message {5}" \
|
||||||
|
--bind="$KEYS_TAG_ADD:execute($0 --tag-modify message add {+5})+reload:$0 --list-messages-in-thread \"$thread\"" \
|
||||||
|
--bind="$KEYS_TAG_REMOVE:execute($0 --tag-modify message del {+5})+reload:$0 --list-messages-in-thread \"$thread\"" \
|
||||||
|
--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: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="$0 --preview-message {5}" \
|
||||||
--preview-window="$FZF_DEFAULT_PREVIEW_WINDOW" || true)
|
--preview-window="$FZF_DEFAULT_PREVIEW_WINDOW" || true)
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ "${1:-}" = "--list-deleted" ]; then
|
||||||
|
shift
|
||||||
|
list_threads "tag:$TAG_DEL" | $FZF \
|
||||||
|
--header-first \
|
||||||
|
--margin='5%' \
|
||||||
|
--header='DELETED MESSAGES' \
|
||||||
|
--footer="$KEYS_PURGE_ALL: purge ALL threads / $KEYS_DELETE: purge selected threads / $KEYS_ENTER_ALTERNATIVE: undelete selected threads" \
|
||||||
|
--border='double' \
|
||||||
|
--color="header:red:bold:underline,border:red,selected-bg:88" \
|
||||||
|
--tiebreak=index \
|
||||||
|
--reverse \
|
||||||
|
--multi \
|
||||||
|
--delimiter="$(printf '\t')" \
|
||||||
|
--with-nth='{1} {2} ({3})' \
|
||||||
|
--bind="$KEYS_CANCEL:transform:[ \$FZF_SELECT_COUNT -gt 0 ] && echo clear-multi || echo abort" \
|
||||||
|
--bind="$KEYS_DOWN_HP:half-page-down" \
|
||||||
|
--bind="$KEYS_UP_HP:half-page-up" \
|
||||||
|
--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_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
|
# Modes
|
||||||
APPEND="append"
|
APPEND="append"
|
||||||
NWSRCH="search"
|
NWSRCH="search"
|
||||||
@@ -102,66 +386,96 @@ ADDRESS_TO="to-"
|
|||||||
ADDRESS_FROM="from-"
|
ADDRESS_FROM="from-"
|
||||||
CMD_SEARCH_ADDRESS="address-"
|
CMD_SEARCH_ADDRESS="address-"
|
||||||
CMD_EDIT_QUERY="edit-query"
|
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
|
while true; do
|
||||||
nmquery="${nmquery:-tag:inbox}"
|
nmquery="${nmquery:-tag:$TAG_INBOX}"
|
||||||
[ "$(tail -1 "$NMFHIST")" = "$nmquery" ] || echo "$nmquery" >> "$NMFHIST"
|
[ "$(tail -1 "$NMFHIST")" = "$nmquery" ] || echo "$nmquery" >> "$NMFHIST"
|
||||||
cmd=$(__notmuch_search "$nmquery" | fzf \
|
cmd=$(list_threads "$nmquery" | $FZF \
|
||||||
|
--no-clear \
|
||||||
|
--header-first \
|
||||||
--header="Query: $nmquery" \
|
--header="Query: $nmquery" \
|
||||||
--ansi \
|
|
||||||
--tiebreak=index \
|
--tiebreak=index \
|
||||||
--reverse \
|
--reverse \
|
||||||
--multi \
|
--multi \
|
||||||
--delimiter="$(printf '\t')" \
|
--delimiter="$(printf '\t')" \
|
||||||
--with-nth="{1} {2} ({3})" \
|
--with-nth="{1} {2} ({3})" \
|
||||||
--bind="alt-t:print($CMD_SEARCH_TAG$NWSRCH)+accept" \
|
--bind="$KEYS_SEARCH_TAG_REPLCE:print($CMD_SEARCH_TAG$NWSRCH)+accept" \
|
||||||
--bind="alt-T:print($CMD_SEARCH_TAG$APPEND)+accept" \
|
--bind="$KEYS_SEARCH_TAG_APPEND:print($CMD_SEARCH_TAG$APPEND)+accept" \
|
||||||
--bind="alt-s:print($CMD_SEARCH_ADDRESS$ADDRESS_FROM$NWSRCH)+accept" \
|
--bind="$KEYS_SEARCH_FROM_REPLCE:print($CMD_SEARCH_ADDRESS$ADDRESS_FROM$NWSRCH)+accept" \
|
||||||
--bind="alt-S:print($CMD_SEARCH_ADDRESS$ADDRESS_FROM$APPEND)+accept" \
|
--bind="$KEYS_SEARCH_FROM_APPEND:print($CMD_SEARCH_ADDRESS$ADDRESS_FROM$APPEND)+accept" \
|
||||||
--bind="alt-r:print($CMD_SEARCH_ADDRESS$ADDRESS_TO$NWSRCH)+accept" \
|
--bind="$KEYS_SEARCH_TO_REPLCE:print($CMD_SEARCH_ADDRESS$ADDRESS_TO$NWSRCH)+accept" \
|
||||||
--bind="alt-R:print($CMD_SEARCH_ADDRESS$ADDRESS_TO$APPEND)+accept" \
|
--bind="$KEYS_SEARCH_TO_APPEND:print($CMD_SEARCH_ADDRESS$ADDRESS_TO$APPEND)+accept" \
|
||||||
--bind="alt-q:print($CMD_EDIT_QUERY)+accept" \
|
--bind="$KEYS_SEARCH_EDIT_QUERY:print($CMD_EDIT_QUERY)+accept" \
|
||||||
--bind='alt-j:preview-down,alt-k:preview-up' \
|
--bind="$KEYS_PREVIEW_DOWN:preview-down" \
|
||||||
--bind='ctrl-d:half-page-down,ctrl-u:half-page-up' \
|
--bind="$KEYS_PREVIEW_UP:preview-up" \
|
||||||
--bind='page-up:preview-half-page-up,page-down:preview-half-page-down' \
|
--bind="$KEYS_PREVIEW_DOWN_HP:preview-half-page-down" \
|
||||||
--bind="enter,ctrl-l:execute:$0 --show-thread {4}" \
|
--bind="$KEYS_PREVIEW_UP_HP:preview-half-page-up" \
|
||||||
--bind="alt-/:change-preview-window($FZF_ALTERNATE_PREVIEW_WINDOW|$FZF_DEFAULT_PREVIEW_WINDOW)" \
|
--bind="$KEYS_CANCEL:clear-multi" \
|
||||||
|
--bind="$KEYS_ENTER:execute($0 --show-thread {4})+reload:$0 --list-threads \"$nmquery\"" \
|
||||||
|
--bind="$KEYS_DOWN_HP:half-page-down" \
|
||||||
|
--bind="$KEYS_UP_HP:half-page-up" \
|
||||||
|
--bind="$KEYS_PREVIEW_TOGGLE_SIZE:change-preview-window($FZF_ALTERNATE_PREVIEW_WINDOW|$FZF_DEFAULT_PREVIEW_WINDOW)" \
|
||||||
|
--bind="$KEYS_HTML_PREVIEW:change-preview:$0 --preview-html-thread {4}" \
|
||||||
|
--bind="$KEYS_TAG_ADD:execute($0 --tag-modify thread add {+4})+reload:$0 --list-threads \"$nmquery\"" \
|
||||||
|
--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="$0 --preview-thread {4}" \
|
||||||
--preview-window="$FZF_DEFAULT_PREVIEW_WINDOW" | head -1 || true)
|
--preview-window="$FZF_DEFAULT_PREVIEW_WINDOW" | head -1 || true)
|
||||||
[ -n "$cmd" ] || exit 0
|
[ -n "$cmd" ] || exit 0
|
||||||
case "$cmd" in
|
case "$cmd" in
|
||||||
$CMD_SEARCH_TAG*)
|
$CMD_SEARCH_TAG*)
|
||||||
tag=$(__notmuch_list_tags | fzf \
|
tag=$(list_tags | $FZF \
|
||||||
--ansi \
|
--color="border:$ANSICOLORTAGS" \
|
||||||
--cycle \
|
--color="label:$ANSICOLORTAGS" \
|
||||||
--bind='ctrl-d:half-page-down,ctrl-u:half-page-up' \
|
--tac \
|
||||||
--margin='20%' \
|
--margin='20%' \
|
||||||
--bind='enter:accept-or-print-query' \
|
--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\"" \
|
||||||
--border=double \
|
--border=double \
|
||||||
--border-label='Select tag' || true)
|
--border-label=" Select tag " | head -1 || true)
|
||||||
[ -n "$tag" ] || continue
|
[ -n "$tag" ] || continue
|
||||||
[ "$cmd" = "$CMD_SEARCH_TAG$APPEND" ] && nmquery="$nmquery and tag:$tag" || nmquery="tag:$tag"
|
[ "$cmd" = "$CMD_SEARCH_TAG$APPEND" ] && nmquery="$nmquery and tag:$tag" || nmquery="tag:$tag"
|
||||||
;;
|
;;
|
||||||
$CMD_SEARCH_ADDRESS*)
|
$CMD_SEARCH_ADDRESS*)
|
||||||
case "$cmd" in
|
case "$cmd" in
|
||||||
*$ADDRESS_FROM*)
|
*$ADDRESS_FROM*)
|
||||||
label_text='Select sender'
|
label_text=" Select sender "
|
||||||
field='from'
|
field='from'
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
label_text='Select recipient'
|
label_text=" Select recipient "
|
||||||
field='to'
|
field='to'
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
address=$(__notmuch_list_address | fzf \
|
address=$(list_addresses | $FZF \
|
||||||
--ansi \
|
--delimiter="$(printf '\t')" \
|
||||||
|
--with-nth=2 \
|
||||||
|
--accept-nth=1 \
|
||||||
|
--color="label:$ANSICOLORFROM" \
|
||||||
--tiebreak=index \
|
--tiebreak=index \
|
||||||
--cycle \
|
|
||||||
--bind='ctrl-d:half-page-down,ctrl-u:half-page-up' \
|
|
||||||
--margin='20%' \
|
--margin='20%' \
|
||||||
--bind='enter:accept-or-print-query' \
|
--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\"" \
|
||||||
--border=double \
|
--border=double \
|
||||||
--border-label="$label_text" || true)
|
--border-label="$label_text" | head -1 || true)
|
||||||
[ -n "$address" ] || continue
|
[ -n "$address" ] || continue
|
||||||
case "$cmd" in
|
case "$cmd" in
|
||||||
*$APPEND)
|
*$APPEND)
|
||||||
@@ -173,19 +487,25 @@ while true; do
|
|||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
$CMD_EDIT_QUERY*)
|
$CMD_EDIT_QUERY*)
|
||||||
nmquery=$(fzf \
|
nmquery=$(list_query_history | $FZF \
|
||||||
--ansi \
|
--color="border:$ANSICOLORSUBJ" \
|
||||||
|
--color="label:$ANSICOLORSUBJ" \
|
||||||
--tac \
|
--tac \
|
||||||
--bind='ctrl-d:half-page-down,ctrl-u:half-page-up' \
|
|
||||||
--margin='20%' \
|
--margin='20%' \
|
||||||
--query="$nmquery" \
|
--query="$nmquery" \
|
||||||
--disabled \
|
--disabled \
|
||||||
--print-query \
|
--print-query \
|
||||||
--prompt="Query: " \
|
--prompt="Query: " \
|
||||||
--bind='focus:replace-query' \
|
--bind='focus:replace-query' \
|
||||||
|
--bind="$KEYS_DOWN_HP:half-page-down" \
|
||||||
|
--bind="$KEYS_UP_HP:half-page-up" \
|
||||||
|
--bind="$KEYS_ENTER:accept" \
|
||||||
--border=double \
|
--border=double \
|
||||||
--border-label='Query history' < "$NMFHIST" | head -1 || true)
|
--border-label=' Query history ' | head -1 || true)
|
||||||
;;
|
;;
|
||||||
|
$CMD_GOTO_INBOX) nmquery="tag:$TAG_INBOX" ;;
|
||||||
|
$CMD_GOTO_UNREAD) nmquery="tag:$TAG_UNREAD" ;;
|
||||||
|
$CMD_GOTO_FLAGGED) nmquery="tag:$TAG_FLAGGED" ;;
|
||||||
*)
|
*)
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|||||||
@@ -1,11 +1,4 @@
|
|||||||
if [ ! "${AWK_LOADED:-}" ]; then
|
if [ ! "${AWK_LOADED:-}" ]; then
|
||||||
AWK_LASTMESSAGEINTHREAD=$(
|
|
||||||
cat <<'EOF'
|
|
||||||
@@include awk/lastmessageinthread.awk
|
|
||||||
EOF
|
|
||||||
)
|
|
||||||
export AWK_LASTMESSAGEINTHREAD
|
|
||||||
|
|
||||||
AWK_THREADOVERVIEW=$(
|
AWK_THREADOVERVIEW=$(
|
||||||
cat <<'EOF'
|
cat <<'EOF'
|
||||||
@@include awk/threadoverview.awk
|
@@include awk/threadoverview.awk
|
||||||
@@ -13,5 +6,26 @@ EOF
|
|||||||
)
|
)
|
||||||
export AWK_THREADOVERVIEW
|
export AWK_THREADOVERVIEW
|
||||||
|
|
||||||
|
AWK_MESSAGEHEADER=$(
|
||||||
|
cat <<'EOF'
|
||||||
|
@@include awk/messageheader.awk
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
export AWK_MESSAGEHEADER
|
||||||
|
|
||||||
|
AWK_MESSAGEPARTS=$(
|
||||||
|
cat <<'EOF'
|
||||||
|
@@include awk/messageparts.awk
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
export AWK_MESSAGEPARTS
|
||||||
|
|
||||||
|
AWK_PARTNR=$(
|
||||||
|
cat <<'EOF'
|
||||||
|
@@include awk/partnr.awk
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
export AWK_PARTNR
|
||||||
|
|
||||||
export AWK_LOADED=1
|
export AWK_LOADED=1
|
||||||
fi
|
fi
|
||||||
|
|||||||
26
src/sh/config.sh
Normal file
26
src/sh/config.sh
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
if [ ! "${CONFIG_LOADED:-}" ]; then
|
||||||
|
# Main application configuration. This application does not require a
|
||||||
|
# configuration file. However, a configuration file may be stored as
|
||||||
|
# `CONFIGFILE_DEFAULT`. If that file exists, it will be sourced. The path to
|
||||||
|
# the file may be overwritten by specifying the environment variable
|
||||||
|
# `CONFIGFILE`. If a configuration file is specified, then it must also exist.
|
||||||
|
# A configuration file comprises the specification of environment variables
|
||||||
|
# that are allowed to be set.
|
||||||
|
CONFIGFILE_DEFAULT="${XDG_CONFIG_HOME:-"$HOME/.config"}/$APP_NAME/config"
|
||||||
|
CONFIGFILE="${CONFIGFILE:-"$CONFIGFILE_DEFAULT"}"
|
||||||
|
[ "$CONFIGFILE" != "$CONFIGFILE_DEFAULT" ] && [ ! -f "$CONFIGFILE" ] && err "The configuration file manually specified with the environment variable CONFIGFILE=($CONFIGFILE) does not exist." && exit 1
|
||||||
|
[ -f "$CONFIGFILE" ] && . "$CONFIGFILE"
|
||||||
|
SET_TERMINAL_TITLE="${SET_TERMINAL_TITLE:-yes}"
|
||||||
|
|
||||||
|
PRIMARY_NAME=${PRIMARY_NAME:-$($NOTMUCH config get user.name)}
|
||||||
|
PRIMARY_EMAIL=${PRIMARY_EMAIL:-$($NOTMUCH config get user.primary_email)}
|
||||||
|
|
||||||
|
if [ ! "${SMTPLOGFILE:-}" ]; then
|
||||||
|
SMTPLOGFILE=$(mktemp)
|
||||||
|
trap 'rm -f "$SMTPLOGFILE"' EXIT INT
|
||||||
|
fi
|
||||||
|
|
||||||
|
export PRIMARY_NAME PRIMARY_EMAIL SET_TERMINAL_TITLE SMTPLOGFILE
|
||||||
|
|
||||||
|
export CONFIG_LOADED=1
|
||||||
|
fi
|
||||||
0
src/sh/email.sh
Normal file
0
src/sh/email.sh
Normal file
5
src/sh/helper.sh
Normal file
5
src/sh/helper.sh
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# Print error message
|
||||||
|
err() {
|
||||||
|
echo "$APP_NAME ERROR: $1" > /dev/stderr
|
||||||
|
}
|
||||||
|
|
||||||
@@ -2,5 +2,6 @@ if [ ! "${HISTORY_LOADED:-}" ]; then
|
|||||||
export NMFHIST=$(mktemp)
|
export NMFHIST=$(mktemp)
|
||||||
touch "$NMFHIST"
|
touch "$NMFHIST"
|
||||||
trap 'rm -f "$NMFHIST"' EXIT INT
|
trap 'rm -f "$NMFHIST"' EXIT INT
|
||||||
|
|
||||||
export HISTORY_LOADED=1
|
export HISTORY_LOADED=1
|
||||||
fi
|
fi
|
||||||
|
|||||||
63
src/sh/keys.sh
Normal file
63
src/sh/keys.sh
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
if [ ! "${KEYS_LOADED:-}" ]; then
|
||||||
|
# This file defines the keys used in the keybindings
|
||||||
|
# The keys are comma separated. See `fzf --man` for the possible keys.
|
||||||
|
|
||||||
|
# List
|
||||||
|
KEYS_DOWN_HP="ctrl-d"
|
||||||
|
KEYS_UP_HP="ctrl-u"
|
||||||
|
KEYS_BACK="ctrl-h"
|
||||||
|
KEYS_ENTER="enter,ctrl-l"
|
||||||
|
KEYS_CANCEL="esc"
|
||||||
|
KEYS_ENTER_ALTERNATIVE="alt-enter"
|
||||||
|
KEYS_CYCLE_DISPLAY="ctrl-space"
|
||||||
|
|
||||||
|
KEYS_VIEW_SOURCE="alt-v"
|
||||||
|
KEYS_HTML_PREVIEW="alt-h"
|
||||||
|
KEYS_TAG_ADD="alt-+"
|
||||||
|
KEYS_TAG_REMOVE="alt--"
|
||||||
|
KEYS_ARCHIVE="ctrl-a"
|
||||||
|
KEYS_DELETE="ctrl-delete"
|
||||||
|
KEYS_FLAG="ctrl-x"
|
||||||
|
KEYS_UNFLAG="ctrl-alt-x"
|
||||||
|
KEYS_OPEN="ctrl-o"
|
||||||
|
KEYS_REPLY="ctrl-r"
|
||||||
|
KEYS_COMPOSE="ctrl-n"
|
||||||
|
KEYS_VIEW_LOGS="alt-0"
|
||||||
|
KEYS_SYNC="ctrl-s"
|
||||||
|
|
||||||
|
# Preview window
|
||||||
|
KEYS_PREVIEW_DOWN="alt-j"
|
||||||
|
KEYS_PREVIEW_UP="alt-k"
|
||||||
|
KEYS_PREVIEW_DOWN_HP="page-up"
|
||||||
|
KEYS_PREVIEW_UP_HP="page-down"
|
||||||
|
KEYS_PREVIEW_TOGGLE_SIZE="alt-/"
|
||||||
|
|
||||||
|
# Keys specific to purge window
|
||||||
|
KEYS_PURGE_ALL="ctrl-alt-d"
|
||||||
|
|
||||||
|
# Change main views
|
||||||
|
KEYS_SEARCH_TAG_REPLCE="alt-t"
|
||||||
|
KEYS_SEARCH_TAG_APPEND="alt-T"
|
||||||
|
KEYS_SEARCH_FROM_REPLCE="alt-s"
|
||||||
|
KEYS_SEARCH_FROM_APPEND="alt-S"
|
||||||
|
KEYS_SEARCH_TO_REPLCE="alt-r"
|
||||||
|
KEYS_SEARCH_TO_APPEND="alt-R"
|
||||||
|
KEYS_SEARCH_EDIT_QUERY="alt-q"
|
||||||
|
KEYS_SEARCH_DELETED="alt-d"
|
||||||
|
KEYS_SEARCH_INBOX="alt-1"
|
||||||
|
KEYS_SEARCH_UNREAD="alt-2"
|
||||||
|
KEYS_SEARCH_FLAGGED="alt-3"
|
||||||
|
|
||||||
|
export KEYS_DOWN_HP KEYS_UP_HP KEYS_BACK KEYS_ENTER KEYS_CANCEL \
|
||||||
|
KEYS_ENTER_ALTERNATIVE KEYS_CYCLE_DISPLAY KEYS_VIEW_SOURCE \
|
||||||
|
KEYS_HTML_PREVIEW KEYS_TAG_ADD KEYS_TAG_REMOVE KEYS_ARCHIVE KEYS_DELETE \
|
||||||
|
KEYS_FLAG KEYS_UNFLAG KEYS_OPEN KEYS_REPLY KEYS_COMPOSE KEYS_VIEW_LOGS \
|
||||||
|
KEYS_SYNC KEYS_PREVIEW_DOWN KEYS_PREVIEW_UP KEYS_PREVIEW_DOWN_HP \
|
||||||
|
KEYS_PREVIEW_UP_HP KEYS_PREVIEW_TOGGLE_SIZE KEYS_SEARCH_TAG_REPLCE \
|
||||||
|
KEYS_SEARCH_TAG_APPEND KEYS_SEARCH_FROM_REPLCE KEYS_SEARCH_FROM_APPEND \
|
||||||
|
KEYS_SEARCH_TO_REPLCE KEYS_SEARCH_TO_APPEND KEYS_SEARCH_EDIT_QUERY \
|
||||||
|
KEYS_SEARCH_DELETED KEYS_SEARCH_INBOX KEYS_SEARCH_UNREAD \
|
||||||
|
KEYS_SEARCH_FLAGGED
|
||||||
|
|
||||||
|
export KEYS_LOADED=1
|
||||||
|
fi
|
||||||
35
src/sh/lists.sh
Normal file
35
src/sh/lists.sh
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
# These functions generate the lists that are fed into fzf
|
||||||
|
|
||||||
|
# List the messages within a thread
|
||||||
|
# @argument $1: thread id
|
||||||
|
list_messages_in_thread() {
|
||||||
|
$NOTMUCH show --body=false thread:"$1" \
|
||||||
|
| awk "$AWK_THREADOVERVIEW" \
|
||||||
|
| sed "s/^\(\S*\)\t\([^\t]*\)\t\(.*\) (\([^()]*\)) (\([^()]*\))$/${COLFROM}\3${COLRESET}\t${COLSUBJ}\2${COLRESET}\t${COLDATE}\4${COLRESET}\t${COLTAGS}\5${COLRESET}\t\1/"
|
||||||
|
}
|
||||||
|
|
||||||
|
# List all threads that match a query
|
||||||
|
# @argument $1: query
|
||||||
|
list_threads() {
|
||||||
|
$NOTMUCH search "$1" \
|
||||||
|
| sed "s/^thread:\([[:xdigit:]]\+\)\s\+\([^[]\+\)\s\+\[\([^]]\+\)\]\([^;]*\); \(.*\) (\([^(]*\))$/${COLDATE}\2${COLRESET}\t${COLCNTS}\3${COLRESET}\t${COLFROM}\4${COLRESET}\t${COLSUBJ}\5${COLRESET}\t${COLTAGS}\6${COLRESET}\t\1/" \
|
||||||
|
| column -s "$(printf '\t')" -t -l 3 -R 1,2
|
||||||
|
}
|
||||||
|
|
||||||
|
# List all tags of matching entries. If not query is provided, all tags are
|
||||||
|
# listed.
|
||||||
|
# @argument $1: query (optional)
|
||||||
|
list_tags() {
|
||||||
|
[ "${1:-}" ] && query="$1" || query="*"
|
||||||
|
$NOTMUCH search --output=tags "$query"
|
||||||
|
}
|
||||||
|
|
||||||
|
# List all email addresses
|
||||||
|
list_addresses() {
|
||||||
|
$NOTMUCH address '*' | sed "s/^\(.*[^>]\) \?\(<.*>\)\?$/\1 \2\t${COLFROM}\1${COLRESET} ${COLSUBJ}\2${COLRESET}/"
|
||||||
|
}
|
||||||
|
|
||||||
|
# List query history
|
||||||
|
list_query_history() {
|
||||||
|
cat "$NMFHIST"
|
||||||
|
}
|
||||||
53
src/sh/notmuch.sh
Normal file
53
src/sh/notmuch.sh
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
# Wrapper around notmuch
|
||||||
|
|
||||||
|
# notmuch new
|
||||||
|
# This is used for updating the notmuch database
|
||||||
|
nm_new() {
|
||||||
|
$NOTMUCH 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/^...//'
|
||||||
|
}
|
||||||
|
|
||||||
|
# Print the header of a message (with trailing empty line)
|
||||||
|
# @argument $1: message id
|
||||||
|
nm_message_header() {
|
||||||
|
$NOTMUCH show --body=false id:"$1" | awk "$AWK_MESSAGEHEADER"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Print the message parts (with indents)
|
||||||
|
# @argument $1: message id
|
||||||
|
nm_message_parts() {
|
||||||
|
$NOTMUCH show --body=true id:"$1" | awk "$AWK_MESSAGEPARTS"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Print the message part number for text/plain or text/html
|
||||||
|
# @argument $1: message id
|
||||||
|
# @argument $2: if set, then the html part number will be printed
|
||||||
|
nm_message_part_nr() {
|
||||||
|
$NOTMUCH show --body=true id:"$1" | awk -v html="${2:-}" "$AWK_PARTNR"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Print part of message
|
||||||
|
# @argument $1: message id
|
||||||
|
# @argument $2: part number
|
||||||
|
nm_message_get_part() {
|
||||||
|
$NOTMUCH show --part="$2" id:"$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Add/remove a tag
|
||||||
|
# @argument $1: [+/-]tag
|
||||||
|
# @argument $2: query
|
||||||
|
nm_tag() {
|
||||||
|
$NOTMUCH tag "$1" "$2"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get all files, also of excluded matches
|
||||||
|
# @argument $1: query
|
||||||
|
nm_files_all() {
|
||||||
|
$NOTMUCH search --output=files --exclude=false "$1"
|
||||||
|
}
|
||||||
21
src/sh/preview.sh
Normal file
21
src/sh/preview.sh
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
# Preview functions
|
||||||
|
|
||||||
|
# Preview email
|
||||||
|
# If a thread identifier is given, then the last message in the thread is
|
||||||
|
# shown. If the HTML flag is set, then the HTML message is parsed using pandoc.
|
||||||
|
# This functions reverts to the HTML method if no HTML flag is set yet no
|
||||||
|
# text/plain part is found.
|
||||||
|
#
|
||||||
|
# @argument $1: "id" or "thread"
|
||||||
|
# @argument $2: message id or thread id
|
||||||
|
# @argument #3: if set, then the HTML messages will be taken
|
||||||
|
preview_message() {
|
||||||
|
[ "$1" = "id" ] && messageid="$2" || messageid="$(nm_last_message_in_thread "$2")"
|
||||||
|
parts="$(nm_message_parts "$messageid")"
|
||||||
|
html="${3:-}"
|
||||||
|
nr="$(nm_message_part_nr "$messageid" "$html")"
|
||||||
|
[ ! "$nr" ] && [ ! "$html" ] && html="html" && nr="$(nm_message_part_nr "$messageid" "html")"
|
||||||
|
[ "$html" ] && parser="$PANDOC" || parser="cat"
|
||||||
|
nm_message_header "$messageid" | $CATEMAIL
|
||||||
|
[ "$nr" ] && (nm_message_get_part "$messageid" "$nr" | $parser | $CATMD)
|
||||||
|
}
|
||||||
20
src/sh/send.sh
Normal file
20
src/sh/send.sh
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# Send email
|
||||||
|
# @argument $1: Path to email file
|
||||||
|
# @argument $2: if set, don't prompt the user (optional)
|
||||||
|
send() {
|
||||||
|
if [ ! "${2:-}" ] && ! ynprompt "Do you want to send this email?" "$($CATEMAIL $tmpfile)"; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
$MSMTP -t --read-envelope-from -X "$SMTPLOGFILE" < "$1" >/dev/null 2>&1 || true
|
||||||
|
log=$(tail -1 "$SMTPLOGFILE")
|
||||||
|
if [ "${2:-}" ] || echo -n "$log" | grep -q '\bsmtpstatus=250\b'; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
# Handle errors
|
||||||
|
res=$(printf "0 Retry\n1 Edit email\n2 Abort\n" | multiprompt "Could not send the email. What's next?" "$(echo "$log" | $CATLOG)")
|
||||||
|
case "$res" in
|
||||||
|
0) send "$1" ;;
|
||||||
|
1) $EDITOR "$1"; send "$1" ;;
|
||||||
|
2) return ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
25
src/sh/tags.sh
Normal file
25
src/sh/tags.sh
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
if [ ! "${TAGS_LOADED:-}" ]; then
|
||||||
|
# Default tags
|
||||||
|
|
||||||
|
# The deleted tag is by default the first tag defined in the exclude settings.
|
||||||
|
# If that does not exist, then it is "deleted".
|
||||||
|
TAG_DEL=${TAG_DEL:-$($NOTMUCH config get search.exclude_tags|head -1)}
|
||||||
|
TAG_DEL=${TAG_DEL:-deleted}
|
||||||
|
|
||||||
|
# Tag for messages in the inbox
|
||||||
|
TAG_INBOX=${TAG_INBOX:-inbox}
|
||||||
|
|
||||||
|
# White-space separates list of tags that are automatically added to new
|
||||||
|
# emails. These tags will be removed when the message/tread is archived.
|
||||||
|
TAGS_NEW=${TAGS_NEW:-$($NOTMUCH config get new.tags | xargs echo)}
|
||||||
|
|
||||||
|
# Tag for messages that are unread
|
||||||
|
TAG_UNREAD=${TAG_UNREAD:-unread}
|
||||||
|
|
||||||
|
# Tag for flagged messages
|
||||||
|
TAG_FLAGGED=${TAG_FLAGGED:-flagged}
|
||||||
|
|
||||||
|
export TAG_DEL TAG_INBOX TAGS_NEW TAG_UNREAD TAG_FLAGGED
|
||||||
|
|
||||||
|
export TAGS_LOADED=1
|
||||||
|
fi
|
||||||
@@ -1,12 +1,18 @@
|
|||||||
# Default theme
|
# Default theme
|
||||||
if [ ! "${THEME_LOADED:-}" ]; then
|
if [ ! "${THEME_LOADED:-}" ]; then
|
||||||
COLDATE="$(printf '\033[38;5;195m')"
|
ANSICOLORDATE="${ANSICOLORDATE:-195}"
|
||||||
COLCNTS="$(printf '\033[38;5;244m')"
|
ANSICOLORCNTS="${ANSICOLORCNTS:-244}"
|
||||||
COLFROM="$(printf '\033[38;5;208m')"
|
ANSICOLORFROM="${ANSICOLORFROM:-208}"
|
||||||
COLSUBJ="$(printf '\033[38;5;179m\033[3m')"
|
ANSICOLORSUBJ="${ANSICOLORSUBJ:-179}"
|
||||||
COLTAGS="$(printf '\033[38;5;106m\033[2m')"
|
ANSICOLORTAGS="${ANSICOLORTAGS:-106}"
|
||||||
|
COLDATE="$(printf '\033[38;5;%sm' "$ANSICOLORDATE")"
|
||||||
|
COLCNTS="$(printf '\033[38;5;%sm' "$ANSICOLORCNTS")"
|
||||||
|
COLFROM="$(printf '\033[38;5;%sm' "$ANSICOLORFROM")"
|
||||||
|
COLSUBJ="$(printf '\033[38;5;%sm\033[3m' "$ANSICOLORSUBJ")"
|
||||||
|
COLTAGS="$(printf '\033[38;5;%sm\033[2m' "$ANSICOLORTAGS")"
|
||||||
COLRESET="$(printf '\033[0m')"
|
COLRESET="$(printf '\033[0m')"
|
||||||
|
|
||||||
|
export ANSICOLORDATE ANSICOLORCNTS ANSICOLORFROM ANSICOLORSUBJ ANSICOLORTAGS
|
||||||
export COLDATE COLCNTS COLFROM COLSUBJ COLTAGS COLRESET
|
export COLDATE COLCNTS COLFROM COLSUBJ COLTAGS COLRESET
|
||||||
|
|
||||||
export THEME_LOADED=1
|
export THEME_LOADED=1
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
if [ ! "${TOOLS_LOADED:-}" ]; then
|
if [ ! "${TOOLS_LOADED:-}" ]; then
|
||||||
if command -v "fzf" >/dev/null; then
|
if command -v "fzf" >/dev/null; then
|
||||||
FZF="fzf --black --ansi --cycle --tiebreak=chunk,index"
|
FZF="fzf --black --ansi --cycle --info=inline-right"
|
||||||
else
|
else
|
||||||
err "Did not find the command-line fuzzy finder fzf."
|
err "Did not find the command-line fuzzy finder fzf."
|
||||||
exit 1
|
exit 1
|
||||||
@@ -15,14 +15,40 @@ if [ ! "${TOOLS_LOADED:-}" ]; then
|
|||||||
fi
|
fi
|
||||||
export NOTMUCH
|
export NOTMUCH
|
||||||
|
|
||||||
|
if command -v "msmtp" >/dev/null; then
|
||||||
|
MSMTP="msmtp"
|
||||||
|
else
|
||||||
|
err "Did not find the command-line email sender msmtp."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
export MSMTP
|
||||||
|
|
||||||
|
if command -v "mbsync" >/dev/null; then
|
||||||
|
MBSYNC="mbsync"
|
||||||
|
else
|
||||||
|
err "Did not find the command-line IMAP synchronizer mbsync."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
export MBSYNC
|
||||||
|
|
||||||
if command -v "bat" >/dev/null; then
|
if command -v "bat" >/dev/null; then
|
||||||
CAT="bat"
|
CAT="bat"
|
||||||
elif command -v "batcat" >/dev/null; then
|
elif command -v "batcat" >/dev/null; then
|
||||||
CAT="batcat"
|
CAT="batcat"
|
||||||
fi
|
fi
|
||||||
CAT=${CAT:+$CAT -l email --style=plain --color=always --wrap}
|
CATEMAIL=${CAT:+$CAT -l email --style=plain --color=always}
|
||||||
CAT=${CAT:-cat}
|
CATMD=${CAT:+$CAT -l markdown --style=plain --color=always}
|
||||||
export CAT
|
CATLOG=${CAT:+$CAT -l log --style=plain --color=always}
|
||||||
|
CATEMAIL=${CATEMAIL:-cat}
|
||||||
|
CATMD=${CATMD:-cat}
|
||||||
|
CATLOG=${CATLOG:-cat}
|
||||||
|
export CATEMAIL CATMD CATLOG
|
||||||
|
|
||||||
|
if command -v "pandoc" >/dev/null; then
|
||||||
|
PANDOC="pandoc --from html --to markdown_strict-raw_html"
|
||||||
|
fi
|
||||||
|
PANDOC=${PANDOC:-cat}
|
||||||
|
export PANDOC
|
||||||
|
|
||||||
export TOOLS_LOADED=1
|
export TOOLS_LOADED=1
|
||||||
fi
|
fi
|
||||||
|
|||||||
59
src/sh/varia.sh
Normal file
59
src/sh/varia.sh
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
# Various functions
|
||||||
|
|
||||||
|
# This prompts the user for a "yes" or a "no"
|
||||||
|
# @argument $1: Question
|
||||||
|
# @argument $2: Content to show in preview window
|
||||||
|
# @return: 0 if the user answered "yes" and 1 otherwise.
|
||||||
|
ynprompt() {
|
||||||
|
return $(printf '0 \033[32myes\033[0m\n1 \033[31mno\033[0m\n' |
|
||||||
|
$FZF \
|
||||||
|
--sync \
|
||||||
|
--bind='start:pos(2)' \
|
||||||
|
--bind='ctrl-c,ctrl-g,ctrl-q,esc:pos(2)+accept' \
|
||||||
|
--reverse \
|
||||||
|
--no-input \
|
||||||
|
--header="$1" \
|
||||||
|
--preview-window='60%,border-line' \
|
||||||
|
--margin='5%,5%,5%,15%' \
|
||||||
|
--preview="echo \"$2\"" \
|
||||||
|
--with-nth=2.. \
|
||||||
|
--accept-nth=1 \
|
||||||
|
--header-border='line' \
|
||||||
|
--color='border:yellow,header:yellow')
|
||||||
|
}
|
||||||
|
|
||||||
|
# This prompts the user for a series of options.
|
||||||
|
# The options are read from stdin in the form "integer\toption\n".
|
||||||
|
# Prints number
|
||||||
|
#
|
||||||
|
# @argument $1: Question
|
||||||
|
# @argument $2: Content to show in preview window
|
||||||
|
multiprompt() {
|
||||||
|
cat |
|
||||||
|
$FZF \
|
||||||
|
--reverse \
|
||||||
|
--no-input \
|
||||||
|
--header="$1" \
|
||||||
|
--preview-window='60%,border-line,wrap-word' \
|
||||||
|
--margin='5%,5%,5%,15%' \
|
||||||
|
--preview="echo \"$2\"" \
|
||||||
|
--with-nth=2.. \
|
||||||
|
--accept-nth=1 \
|
||||||
|
--header-border='line' \
|
||||||
|
--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
|
||||||
|
# }
|
||||||
|
|
||||||
Reference in New Issue
Block a user