Skip to content

Commit

Permalink
mta: improve dma message
Browse files Browse the repository at this point in the history
- mua: replace uriencode, add tests
- mt: fix accessing unset var
- mt: skip sleep when no tty
  • Loading branch information
msimerson committed Mar 27, 2024
1 parent 59af4d8 commit 31cef47
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 28 deletions.
2 changes: 1 addition & 1 deletion include/mta.sh
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ enable_dma()
tell_status "setting up dma"
cp "$_base/usr/share/examples/dma/mailer.conf" "$_base/etc/mail/mailer.conf"

echo "dma.conf: $_base/etc/dma/dma.conf"
echo "editing $_base/etc/dma/dma.conf"
sed -i '' \
-e "s/^#SMARTHOST/SMARTHOST $TOASTER_MSA/" \
"$_base/etc/dma/dma.conf"
Expand Down
33 changes: 14 additions & 19 deletions include/mua.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

set -e
set -e -u

# shellcheck disable=3003
test_imap_empty()
Expand Down Expand Up @@ -44,7 +44,7 @@ test_imap_curl()
{
# shellcheck disable=SC2001
curl -k -v --login-options 'AUTH=PLAIN' \
"imaps://$(uriencode $MUA_TEST_USER):$(uriencode MUA_TEST_PASS)@${MUA_TEST_HOST}/"
"imaps://$(uriencode $MUA_TEST_USER):$(uriencode $MUA_TEST_PASS)@${MUA_TEST_HOST}/"
}

test_imap()
Expand Down Expand Up @@ -81,26 +81,21 @@ test_pop3_empty()

test_pop3()
{
# shellcheck disable=SC2001
# shellcheck disable=2001
curl -k -v --login-options 'AUTH=PLAIN' \
"pop3s://$(uriencode $MUA_TEST_USER):$(uriencode MUA_TEST_PASS)@${MUA_TEST_HOST}/"
"pop3s://$(uriencode $MUA_TEST_USER):$(uriencode $MUA_TEST_PASS)@${MUA_TEST_HOST}/"
}

# https://stackoverflow.com/questions/296536/how-to-urlencode-data-for-curl-command
# shellcheck disable=3005,3018,3024,3045,3057
uriencode() {
local string="${1}"
local strlen=${#string}
local encoded=""
local pos c o

for (( pos=0 ; pos<strlen ; pos++ )); do
c=${string:$pos:1}
case "$c" in
[-_.~a-zA-Z0-9] ) o="${c}" ;;
* ) printf -v o '%%%02x' "'$c"
esac
encoded+="${o}"
string=$1
while [ -n "$string" ]; do
tail=${string#?}
head=${string%"$tail"}
case $head in
[-._~0-9A-Za-z]) printf %c "$head";;
*) printf %%%02x "'$head"
esac
string=$tail
done
echo "${encoded}"
echo
}
8 changes: 5 additions & 3 deletions mail-toaster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,22 @@ get_random_ip6net()
tell_status()
{
echo; echo " *** $1 ***"; echo
sleep 1
if [ -t 0 ]; then sleep 1; fi
}

store_config()
{
# $1 - path to config file, $2 - overwrite, STDIN is file contents
local _overwrite=${2:-""}

if [ ! -d "$(dirname $1)" ]; then
tell_status "creating $(dirname $1)"
mkdir -p "$(dirname $1)"
fi

cat - > "$1.mt6"

if [ ! -f "$1" ] || [ -n "$2" ]; then
if [ ! -f "$1" ] || [ "$_overwrite" = "overwrite" ]; then
tell_status "installing $1"
cp "$1.mt6" "$1"
else
Expand Down Expand Up @@ -812,7 +814,7 @@ tell_settings()
echo; echo " *** Configured $1 settings: ***"; echo
set | grep "^$1_"
echo
sleep 2
if [ -t 0 ]; then sleep 2; fi
}

proclaim_success()
Expand Down
10 changes: 5 additions & 5 deletions provision/dovecot.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

set -e
set -e -u

. mail-toaster.sh

Expand Down Expand Up @@ -534,11 +534,11 @@ int_ip6 = "$(get_jail_ip6 dovecot)"
# to permit legacy users to access insecure POP3 & IMAP, add their IPs/masks
table <insecure_mua> persist file "$_pf_etc/insecure_mua"
rdr inet proto tcp from any to <ext_ip4> port { 993 995 } -> $int_ip4
rdr inet6 proto tcp from any to <ext_ip6> port { 993 995 } -> $int_ip6
rdr inet proto tcp from any to <ext_ip4> port { 993 995 } -> \$int_ip4
rdr inet6 proto tcp from any to <ext_ip6> port { 993 995 } -> \$int_ip6
rdr inet proto tcp from <insecure_mua> to <ext_ip4> port { 110 143 } -> $int_ip4
rdr inet6 proto tcp from <insecure_mua> to <ext_ip6> port { 110 143 } -> $int_ip6
rdr inet proto tcp from <insecure_mua> to <ext_ip4> port { 110 143 } -> \$int_ip4
rdr inet6 proto tcp from <insecure_mua> to <ext_ip6> port { 110 143 } -> \$int_ip6
EO_PF_RDR
store_config "$_pf_etc/allow.conf" <<EO_PF_ALLOW
Expand Down

0 comments on commit 31cef47

Please sign in to comment.