citadel

My dotfiles, scripts and nix configs
git clone git://jb55.com/citadel
Log | Files | Refs | README | LICENSE

commit a5049b9984062949d54dc982da8a44666cfab49c
parent 79cebe1d008b0b340694f8dcae626663facf6640
Author: William Casarin <jb55@jb55.com>
Date:   Mon, 12 Apr 2021 12:05:46 -0700

hashcash'd sendmail

Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Abin/hashcash-mail | 7+++++++
Mbin/sendmail | 16+++-------------
Abin/sendmail-bg | 30++++++++++++++++++++++++++++++
Mnix-config/environment/default.nix | 1+
4 files changed, 41 insertions(+), 13 deletions(-)

diff --git a/bin/hashcash-mail b/bin/hashcash-mail @@ -0,0 +1,7 @@ + +#!/usr/bin/env bash + +email=${1:-"jb55@jb55.com"} +hcash=$(hashcash -mb26 "$email") + +sed "/^From:.*/i X-Hashcash: $hcash" diff --git a/bin/sendmail b/bin/sendmail @@ -1,18 +1,8 @@ #! /usr/bin/env sh -export EMAIL_CUSTOM_CONN_TEST=/home/jb55/bin/email-conn-test -export EMAIL_CONN_TEST=c - -# pass all params to msmtpq & redirect output -output=$(msmtpq "$@" 2> /tmp/msmtp.err) -echo "$output" >> /tmp/msmtp.log - -if grep -E '^\s+enqueued' <<<"$output" -then - if command -v notify-send &> /dev/null; then - notify-send -u critical "$output" - fi -fi +file="$(mktemp)" +cat > "$file" +sendmail-bg "$file" "$@" & disown # always succeed, even on connection/mail failure # we'll simply queue the mail in our outbox diff --git a/bin/sendmail-bg b/bin/sendmail-bg @@ -0,0 +1,30 @@ +#! /usr/bin/env sh + +export EMAIL_CUSTOM_CONN_TEST=/home/jb55/bin/email-conn-test +export EMAIL_CONN_TEST=c + +src="$1" +shift +file=$(mktemp) + +from_email=$(<"$src" grep '^From:' | sed -n 's,.*<\([^>]\+\)>.*,\1,p') +from_email=${from_email:-"jb55@jb55.com"} + +<"$src" /home/jb55/bin/hashcash-mail "$from_email" > "$file" + +# pass all params to msmtpq & redirect output +output=$(<"$file" msmtpq "$@" 2> /tmp/msmtp.err) +echo "$output" >> /tmp/msmtp.log + +if grep -E '^\s+enqueued' <<<"$output" +then + if command -v notify-send &> /dev/null; then + notify-send "$output" + fi +fi + +rm -f "$src" "$file" + +# always succeed, even on connection/mail failure +# we'll simply queue the mail in our outbox +exit 0 diff --git a/nix-config/environment/default.nix b/nix-config/environment/default.nix @@ -46,6 +46,7 @@ let jb55pkgs = import <jb55pkgs> { inherit pkgs; }; dateutils direnv du-dust + hashcash file fzf git-tools