mirror of
https://github.com/kmein/niveum
synced 2026-03-16 18:21:07 +01:00
feat: package much-secripts and dns-sledgehammer
This commit is contained in:
@@ -21,6 +21,26 @@ in rec {
|
||||
name = "instaget";
|
||||
};
|
||||
|
||||
dns-sledgehammer = pkgs.writers.writeDashBin "dns-sledgehammer" ''
|
||||
${pkgs.coreutils}/bin/printf '%s\n' 'nameserver 1.1.1.1' 'options edns0' > /etc/resolv.conf
|
||||
'';
|
||||
|
||||
much-scripts = 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 ];
|
||||
})
|
||||
];
|
||||
};
|
||||
|
||||
showkeys-toggle = pkgs.writers.writeDashBin "showkeys-toggle" ''
|
||||
if ${pkgs.procps}/bin/pgrep screenkey; then
|
||||
exec ${pkgs.procps}/bin/pkill screenkey
|
||||
|
||||
20
packages/scripts/mail-kill.sh
Normal file
20
packages/scripts/mail-kill.sh
Normal file
@@ -0,0 +1,20 @@
|
||||
#! /bin/sh
|
||||
set -efu
|
||||
|
||||
if ! notmuch search --exclude=false tag:deleted | tac | grep .; then
|
||||
echo 'No killed mail.'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf 'want do rm these mail? [y/N] '
|
||||
read REPLY
|
||||
case "$REPLY" in
|
||||
y|Y) :;; # continue
|
||||
*)
|
||||
echo 'abort.'
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
|
||||
notmuch search --output=files --exclude=false tag:deleted | xargs -l rm -v
|
||||
notmuch new
|
||||
57
packages/scripts/mail-send.sh
Executable file
57
packages/scripts/mail-send.sh
Executable file
@@ -0,0 +1,57 @@
|
||||
#! /bin/sh
|
||||
# usage: mail-send < FILE
|
||||
set -efu
|
||||
|
||||
get_in_reply_to() {
|
||||
sed -n '/^In-Reply-to:/I{s/In-Reply-to:\s*//I;h;:a;n;/^\s/{s/^\s*//;H;ba};x;p;q}' |
|
||||
sed -n 's/^<\(.*\)>$/\1/p' |
|
||||
grep .
|
||||
}
|
||||
|
||||
now=$(date --rfc-email)
|
||||
id=$(whoami)+$(date +%s -d "$now")@$(hostname -f)
|
||||
|
||||
# TODO check if mail with that ID already exists
|
||||
|
||||
# TODO encode subject https://ncona.com/2011/06/using-utf-8-characters-on-an-e-mail-subject/
|
||||
# and maybe recipients
|
||||
|
||||
# TODO use tmpfile instead?
|
||||
mail=$(
|
||||
env now="$now" id="$id" \
|
||||
jq -Rrs '
|
||||
# TODO dedup with mail-reply
|
||||
split("\n") |
|
||||
index("") as $i |
|
||||
.[:$i] as $head |
|
||||
.[$i:] as $body |
|
||||
|
||||
# TODO each of these could be followed by multiple lines starting with spaces
|
||||
($head | map(select(test("^(Date|Message-ID|User-Agent):";"i") | not))) as $head |
|
||||
|
||||
($head + [
|
||||
"Date: \(env.now)",
|
||||
"Message-ID: <\(env.id)>",
|
||||
"User-Agent: much"
|
||||
]) as $head |
|
||||
|
||||
($head + $body) | join("\n")
|
||||
'
|
||||
)
|
||||
|
||||
printf %s "$mail" | msmtpq --read-recipients --read-envelope-from
|
||||
|
||||
# insertion is done upstream (by gmail, posteo, and the like)
|
||||
# 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
|
||||
echo "while trying to put replied tag, failed to find exactly one message" >&2
|
||||
echo " query = id:$in_reply_to" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
notmuch tag +replied -unread -- "id:$in_reply_to"
|
||||
fi
|
||||
|
||||
echo "id:$id"
|
||||
Reference in New Issue
Block a user