Skip to content

Commit

Permalink
mua: replace uriencode
Browse files Browse the repository at this point in the history
  • Loading branch information
msimerson committed Mar 27, 2024
1 parent 87e9046 commit eba1f23
Showing 1 changed file with 32 additions and 16 deletions.
48 changes: 32 additions & 16 deletions include/mua.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,37 @@ test_pop3()
"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}"
done
echo "${encoded}"
s="${1//'%'/%25}"
s="${s//' '/%20}"
s="${s//'!'/%21}"
s="${s//'"'/%22}"
s="${s//'#'/%23}"
s="${s//'$'/%24}"
s="${s//'&'/%26}"
s="${s//"'"/%27}"
s="${s//'('/%28}"
s="${s//')'/%29}"
s="${s//'*'/%2A}"
s="${s//'+'/%2B}"
s="${s//','/%2C}"
s="${s//'-'/%2D}"
s="${s//'.'/%2E}"
s="${s//'/'/%2F}"
s="${s//':'/%3A}"
s="${s//';'/%3B}"
s="${s//'='/%3D}"
s="${s//'?'/%3F}"
s="${s//'@'/%40}"
s="${s//'['/%5B}"
s="${s//'\'/%5C}"
s="${s//']'/%5D}"
s="${s//'^'/%5E}"
s="${s//'_'/%5F}"
s="${s//'`'/%60}"
s="${s//'{'/%7B}"
s="${s//'|'/%7C}"
s="${s//'}'/%7D}"
s="${s//'~'/%7E}"
printf %s "$s"
}

0 comments on commit eba1f23

Please sign in to comment.