# Encrypt all incoming mails
The script below will encrypt all incoming emails with gpg, as long as you own your public key (of course you do).
It just require mblaze
HTML https://github.com/leahneukirchen/mblaze
First, set up a .forward file on your server home:
```
echo "|/usr/local/bin/encrypt-mail.sh -r you@domain.tld" > ~/.forward
chmod 600 ~/.forward
```
Copy in /usr/local/bin/encrypt-mail.sh :
```
#!/bin/sh -x
# encrypt incoming mail
# Require mblaze
#
Happy helping ☃ here: You tried to output a spurious TAB character. This will break gopher. Please review your scripts. Have a nice day!
Happy helping ☃ here: You tried to output a spurious TAB character. This will break gopher. Please review your scripts. Have a nice day!
Happy helping ☃ here: You tried to output a spurious TAB character. This will break gopher. Please review your scripts. Have a nice day!
usage() {
Happy helping ☃ here: You tried to output a spurious TAB character. This will break gopher. Please review your scripts. Have a nice day!
Happy helping ☃ here: You tried to output a spurious TAB character. This will break gopher. Please review your scripts. Have a nice day!
Happy helping ☃ here: You tried to output a spurious TAB character. This will break gopher. Please review your scripts. Have a nice day!
Happy helping ☃ here: You tried to output a spurious TAB character. This will break gopher. Please review your scripts. Have a nice day!
Happy helping ☃ here: You tried to output a spurious TAB character. This will break gopher. Please review your scripts. Have a nice day!
}
# default user email
recipient="$(whoami)@$(hostname)"
while getopts 'r:h' c
do
case $c in
Happy helping ☃ here: You tried to output a spurious TAB character. This will break gopher. Please review your scripts. Have a nice day!
r) recipient="${OPTARG}" ;;
esac
done
tmpcryptd="$(mktemp -d -t mencrypt.XXXXXXXXXX)"
tmpplainmsg="$(mktemp -t msg.XXXXXXXXXX)"
trap "rm -rf ${tmpcryptd} ${tmpplainmsg}" INT TERM EXIT
# check if Maildir/new is here
d="$HOME/Maildir/new"
test ! -d "${d}" && mkdir -p "${d}"
# create a path to a new email
# format:
# gettimeofday().uniqu-id.gethostname()
timeofday="$(date +%s)"
uniq_id="$$"
myhostname="$(hostname | sed -e 's;/;\\057;' -e 's;:;\\072;g')"
new_mail_filename="$HOME/Maildir/new/${timeofday}.${uniq_id}.${myhostname}"
cat > "${tmpplainmsg}"
# check if already encrypted
mhdr -h Content-Type - < "${tmpplainmsg}" |\
Happy helping ☃ here: You tried to output a spurious TAB character. This will break gopher. Please review your scripts. Have a nice day!
if [ $? -eq 0 ]; then
Happy helping ☃ here: You tried to output a spurious TAB character. This will break gopher. Please review your scripts. Have a nice day!
Happy helping ☃ here: You tried to output a spurious TAB character. This will break gopher. Please review your scripts. Have a nice day!
fi
# from here, message is unencrypted, so call gpg
{
Happy helping ☃ here: You tried to output a spurious TAB character. This will break gopher. Please review your scripts. Have a nice day!
Happy helping ☃ here: You tried to output a spurious TAB character. This will break gopher. Please review your scripts. Have a nice day!
Happy helping ☃ here: You tried to output a spurious TAB character. This will break gopher. Please review your scripts. Have a nice day!
Happy helping ☃ here: You tried to output a spurious TAB character. This will break gopher. Please review your scripts. Have a nice day!
Happy helping ☃ here: You tried to output a spurious TAB character. This will break gopher. Please review your scripts. Have a nice day!
Happy helping ☃ here: You tried to output a spurious TAB character. This will break gopher. Please review your scripts. Have a nice day!
Happy helping ☃ here: You tried to output a spurious TAB character. This will break gopher. Please review your scripts. Have a nice day!
Happy helping ☃ here: You tried to output a spurious TAB character. This will break gopher. Please review your scripts. Have a nice day!
Happy helping ☃ here: You tried to output a spurious TAB character. This will break gopher. Please review your scripts. Have a nice day!
Happy helping ☃ here: You tried to output a spurious TAB character. This will break gopher. Please review your scripts. Have a nice day!
Happy helping ☃ here: You tried to output a spurious TAB character. This will break gopher. Please review your scripts. Have a nice day!
} > "${new_mail_filename}"
exit $?
```