1
0
mirror of https://github.com/kmein/niveum synced 2026-03-16 10:11:08 +01:00

feat(scripts): mail-reply, much-current-query

This commit is contained in:
2021-03-03 19:03:59 +01:00
parent 5dccdfee83
commit 12698d9f48
4 changed files with 25 additions and 16 deletions

View File

@@ -42,20 +42,30 @@ in rec {
${pkgs.coreutils}/bin/printf '%s\n' 'nameserver 1.1.1.1' 'options edns0' > /etc/resolv.conf
'';
much-scripts = pkgs.symlinkJoin {
much-scripts = let
much-current-query = wrapScript {
packages = [ pkgs.curl ];
name = "much-current-query";
script = ./much-current-query.sh;
};
mail-send = wrapScript {
packages = [ pkgs.notmuch pkgs.msmtp pkgs.jq ];
name = "mail-send";
script = ./mail-send.sh;
};
mail-reply = wrapScript {
packages = [ much-current-query pkgs.notmuch pkgs.gnused pkgs.jq ];
name = "mail-reply";
script = ./mail-reply.sh;
};
mail-kill = wrapScript {
name = "mail-kill";
script = ./mail-kill.sh;
packages = [ pkgs.notmuch ];
};
in pkgs.symlinkJoin {
name = "much-scripts";
paths = [
(wrapScript {
packages = [ pkgs.notmuch pkgs.msmtp pkgs.jq ];
name = "mail-send";
script = ./mail-send.sh;
})
(wrapScript {
name = "mail-kill";
script = ./mail-kill.sh;
packages = [ pkgs.notmuch ];
})
];
paths = [ mail-send much-current-query mail-reply mail-kill ];
};
showkeys-toggle = pkgs.writers.writeDashBin "showkeys-toggle" ''

47
packages/scripts/mail-reply.sh Executable file
View File

@@ -0,0 +1,47 @@
#! /bin/sh
set -efu
reply_to=$(much-current-query)
if ! test "$(notmuch search --output=messages "$reply_to" | wc -l)" = 1; then
echo "current query doesn't point to exactly one message. abort." >&2
exit 1
fi
# TODO update headers
notmuch reply "$reply_to" |
sed '
/^Non-text part: /d
/^Attachment: /d
' |
jq -Rrs '
# TODO dedup with mail-send
split("\n") |
index("") as $i |
.[:$i] as $head |
.[$i:] as $body |
{
"MIME-Version": "1.0",
"Content-Type": "text/plain; charset=UTF-8; format=flowed",
"Content-Transfer-Encoding": "8bit"
} as $extra_head |
($extra_head | keys | join("|")) as $extra_head_regex |
($extra_head | to_entries | map("\(.key): \(.value)")) as $extra_head_lines |
# TODO each of these could be followed by multiple lines starting with spaces
($head | map(select(test("^(\($extra_head_regex)):";"i") | not))) as $head |
($head + $extra_head_lines) as $head |
($head + $body) | join("\n")
'
# TODO fix From:
# TODO tune quote
# TODO write draft
# TODO send mail

View File

@@ -41,8 +41,7 @@ mail=$(
printf %s "$mail" | msmtpq --read-recipients --read-envelope-from
# insertion is done upstream (by gmail, posteo, and the like)
# printf %s "$mail" | notmuch insert
printf %s "$mail" | notmuch insert
if in_reply_to=$(printf %s "$mail" | get_in_reply_to); then
if test "$(notmuch search --output=messages "id:$in_reply_to")" != "id:$in_reply_to"; then

View File

@@ -0,0 +1,3 @@
#! /bin/sh
set -efu
exec curl -fSs --unix-socket /tmp/much.api.sock http://localhost/current/query