dot

packages and services management
Log | Files | Refs | README

commit acdcc64485668f4b2a6b0b64ca8b001b7fc8df1c
parent a2b9378349ea44921e7596abcb767d7344d211a0
Author: Josuah Demangeon <mail@josuah.net>
Date:   Sun,  2 Dec 2018 16:34:12 +0100

sign and encrypt e-mails

Diffstat:
Mbin/mail-draft | 4++--
Dbin/mail-gpg | 27---------------------------
Abin/mail-gpg-encrypt | 35+++++++++++++++++++++++++++++++++++
Abin/mail-gpg-sign | 29+++++++++++++++++++++++++++++
4 files changed, 66 insertions(+), 29 deletions(-)

diff --git a/bin/mail-draft b/bin/mail-draft @@ -18,6 +18,6 @@ ifelse { test ${x} = e } { foreground { ${EDITOR} ${draft} } exit 101 } ifelse { test ${x} = s } { mail-send ${draft} } ifelse { test ${x} = c } { echo mail not sent, draft kept } ifelse { test ${x} = d } { rm -i ${draft} } -ifelse { test ${x} = gs } { mail-gpg -s ${draft} } -ifelse { test ${x} = ge } { mail-gpg -e ${draft} } +ifelse { test ${x} = gs } { if { mail-gpg-sign ${draft} } exit 101 } +ifelse { test ${x} = ge } { if { mail-gpg-encrypt ${draft} } exit 101 } exit 101 diff --git a/bin/mail-gpg b/bin/mail-gpg @@ -1,27 +0,0 @@ -#!/usr/bin/env execlineb - -importas -i flags 1 -importas -i draft 2 - -backtick -n x { - pipeline { mhdr -d -M -A -h from:to:cc:bcc: "${draft}" } - sort -u -} -importas -s recipients x - -fdmove -c 3 1 -if { echo "Version: 1" } - -fdmove -c 4 1 -if { pipeline { sed "1,/^$/ d" "${draft}" } gpg ${flags} -a -r${recipients} } - -ifte { mv ${draft}.mime ${draft} } - { if { rm ${draft}.mime } exit 1 } - -redirfd -w 1 ${draft}.mime -pipeline { - if { sed "/^$/ { p; q; }" ${draft} } - if { echo "#application/pgp-encrypted /dev/fd/3" } - if { echo "#application/octet-stream /dev/fd/4" } -} -mmime -t "multipart/encrypted; protocol=\"application/pgp-encrypted\"" diff --git a/bin/mail-gpg-encrypt b/bin/mail-gpg-encrypt @@ -0,0 +1,35 @@ +#!/usr/bin/env execlineb +# mail-gpg-encrypt mailfile - encrypt mailfile using PGP/MIME + +importas -i draft 1 + +backtick -n x { mktemp -d } +importas tmp x + +ifte { if { rm -rf "${tmp}" } mv "${draft}.mime" "${draft}" } + { if { rm -rf "${tmp}" "${draft}.mime" } exit 1 } + +if { + redirfd -w 1 "${tmp}/version" + echo "Version: 1" +} + +backtick -n x { + pipeline { mhdr -d -M -A -h from:to:cc:bcc: "${draft}" } + sort -u +} +importas -s -d "\n" recipients x + +if { + redirfd -w 1 "${tmp}/encrypted.asc" + pipeline { sed "1,/^$/ d" "${draft}" } + gpg -a -e -r${recipients} +} + +redirfd -w 1 "${draft}.mime" +pipeline { + if { sed "/^$/ { p; q; }" ${draft} } + if { echo "#mblaze/raw ${tmp}/version" } + if { echo "#application/octet-stream ${tmp}/encrypted.asc" } +} +mmime -t "multipart/encrypted; protocol=\"application/pgp-encrypted\"" diff --git a/bin/mail-gpg-sign b/bin/mail-gpg-sign @@ -0,0 +1,29 @@ +#!/usr/bin/env execlineb +# mail-gpg-sign mailfile - sign mailfile using PGP/MIME + +importas -i draft 1 + +backtick -n x { mktemp -d } +importas tmp x + +ifte { if { rm -rf "${tmp}" } mv "${draft}.mime" "${draft}" } + { if { rm -rf "${tmp}" "${draft}.mime" } exit 1 } + +if { + redirfd -w 1 "${tmp}/content" + pipeline { sed "1,/^$/ d" "${draft}" } + pipeline { mmime } + sed "s/$/\r/" +} + +if { + gpg -a -b -o "${tmp}/signature.asc" "${tmp}/content" +} + +redirfd -w 1 "${draft}.mime" +pipeline { + if { sed "/^$/ { p; q; }" ${draft} } + if { echo "#mblaze/raw ${tmp}/content" } + if { echo "#application/pgp-signature ${tmp}/signature.asc" } +} +mmime -t "multipart/signed; micalg=\"pgp-sha1\"; protocol=\"application/pgp-signature\""