bash | mail | encode + decode utf-8 subjects

function encDec() {
    CTXT="$@"
    echo "$CTXT" | grep '=?' >/dev/null
    if [ $? -ne 0 ]; then
	echo -n "=?UTF-8?B?$(echo "$CTXT" | base64 -i)?="
    else
	CONTENT="$(echo "$CTXT" | sed 's|^\=?||' | sed 's|?\=$||')"
	A_CONTENT=(${CONTENT//\?/ })
	if [ "x${A_CONTENT[1]}" == "xQ" -o "x${A_CONTENT[1]}" == "xq" ]; then
	    CRES="$(echo "${A_CONTENT[2]}" | qprint -d | iconv -t ${A_CONTENT[0]})"
	else
	    CRES="$(echo "${A_CONTENT[2]}" | base64 -i -d | iconv -t ${A_CONTENT[0]} )"
	fi
	echo -n "$CRES"
	return 0
    fi
}
sdfsf

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.