rp

simple email tools
git clone https://git.parazyd.org/rp
Log | Files | Refs | README | LICENSE

commit ff87e0f95666f2fc496459a183ebd22969e229f8
parent a06b231d6e15359eae4830f9bde2b3b7d953404b
Author: parazyd <parazyd@dyne.org>
Date:   Sat, 28 Mar 2020 21:53:22 +0100

Rework rpencrypt.

It now works better with attachments, and automatically signs.

Diffstat:
Mbin/rpencrypt | 57+++++++++++++++++++++++++++------------------------------
1 file changed, 27 insertions(+), 30 deletions(-)

diff --git a/bin/rpencrypt b/bin/rpencrypt @@ -1,48 +1,45 @@ #!/bin/sh -# -# Copy me if you can -# by parazyd -# - -boundary="$(rputil -e genmimeb)" email="$(cat)" +email_headers="$(printf "%s" "$email" | sed '/^$/q')" +content_type="$(printf "%s" "$email_headers" | grep -i '^content-type:' | cut -d' ' -f2-)" +email_headers="$(printf "%s" "$email" | sed '/^$/q' | grep -vi '^content-type:')" +email_body="$(printf "%s" "$email" | sed '1,/^$/d')" + +mime_boundary="$(rputil -e genmimeb)" if [ $# -gt 0 ]; then - to="-r $1" + to="$1" else - to="-r $(echo "$email" | rpheaders To | awk -F'<' '{print $NF}' | tr -d '><')" + to="$(printf "%s" "$email_headers" | rpheaders To | awk -F'[<>]' '{print $2}')" fi -headers="$(echo "$email" | \ - sed '/^$/q' | \ - sed '/^\r/q' | \ - sed "/Content-Type: /d" | \ - sed "/^ /d" | \ - head -n-1)" - -emabody="$(echo "$email" | sed '1,/^$/d' )" -[ -n "$emabody" ] || \ -emabody="$(echo "$email" | sed '1,/^\r/d' )" - - -encr="$(echo "$emabody" | sed 's/$/\r/' | gpg -eaq --batch "$to" -)" - cat <<EOF -$headers -Content-Type: multipart/encrypted; protocol="application/pgp-encrypted"; - boundary="$boundary" - +$email_headers +Content-Type: multipart/encrypted; protocol="application/pgp-encrypted"; boundary="$mime_boundary" ---$boundary +--$mime_boundary Content-Type: application/pgp-encrypted Version: 1 ---$boundary +--$mime_boundary Content-Type: application/octet-stream -$encr +EOF + +if echo "$content_type" | grep -q boundary ; then + cat <<EOF | gpg -q --encrypt --sign --armor -r "$to" - +Content-Type: $content_type +Content-Disposition: inline ---$boundary-- + +$email_body EOF +else + cat <<EOF | gpg -q --encrypt --sign --armor -r "$to" - +$email_body +EOF +fi + +printf "\n--%s--\n" "$mime_boundary"