rp

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

rpencrypt (1022B)


      1 #!/bin/sh
      2 
      3 email="$(cat)"
      4 email_headers="$(printf "%s" "$email" | sed '/^$/q')"
      5 content_type="$(printf "%s" "$email_headers" | grep -i '^content-type:' | cut -d' ' -f2-)"
      6 email_headers="$(printf "%s" "$email" | sed '/^$/q' | grep -vi '^content-type:')"
      7 email_body="$(printf "%s" "$email" | sed '1,/^$/d')"
      8 
      9 mime_boundary="$(rputil -e genmimeb)"
     10 
     11 if [ $# -gt 0 ]; then
     12 	to="$1"
     13 else
     14 	to="$(printf "%s" "$email_headers" | rpheaders To | awk -F'[<>]' '{print $2}')"
     15 fi
     16 
     17 cat <<EOF
     18 $email_headers
     19 Content-Type: multipart/encrypted; protocol="application/pgp-encrypted"; boundary="$mime_boundary"
     20 
     21 --$mime_boundary
     22 Content-Type: application/pgp-encrypted
     23 
     24 Version: 1
     25 
     26 --$mime_boundary
     27 Content-Type: application/octet-stream
     28 
     29 EOF
     30 
     31 if echo "$content_type" | grep -q boundary ; then
     32 	cat <<EOF | gpg -q --encrypt --sign --armor -r "$to" -
     33 Content-Type: $content_type
     34 Content-Disposition: inline
     35 
     36 
     37 $email_body
     38 EOF
     39 else
     40 	cat <<EOF | gpg -q --encrypt --sign --armor -r "$to" -
     41 $email_body
     42 EOF
     43 fi
     44 
     45 printf "\n--%s--\n" "$mime_boundary"