#!/usr/bin/ksh93
################################################################
#### Copyright 2007 By Dana French, All Rights Reserved
#################################################################
function usagemsg_email2hex {
print -- "
Program: email2hex
Generate a javascript and HEX code representation of an
HTML Anchor HREF tag containing a \"mailto:\" email
address. The generated javascript can then be imbedded
within an HTML document and the email addresses can only
be viewed when processed by a browser. This makes it much
more difficult to scrape email addresses from the source
code of an HTML document.
Usage: ${1##*/} [-?vV] -e 'emailAddress' -t 'Link Text String'
[-p 'Prepended Text'] [-s 'Suffix Text']
Where:
-e emailAddress = Email address to encode as HEX
-t linkText = HTML Link text string to encode as HEX
-p PrependText = Text string to prepend before the Anchor HREF Tag
-s SuffixText = Text string to attach to the end of the Anchor HREF Tag
-v = Verbose mode - displays email2hex function info
-V = Very Verbose Mode - debug output displayed
Author: Dana French (dfrench@mtxia.com)
Copyright 2007 By Dana French, All Rights Reserved
\"AutoContent\" enabled
"
}
################################################################
####
#### Description:
####
#### Generate a javascript and HEX code representation of an
#### HTML Anchor HREF tag containing a \"mailto:\" email
#### address. The generated javascript can then be imbedded
#### within an HTML document and the email addresses cannot
#### be viewed or easily scraped from the pages.
####
#### Assumptions:
####
#### This script will probably not work with IBM's version of
#### ksh93 since IBM's ksh93 is about 7 years out of date. You
#### will need to download a recent version of ksh93 from
#### www.kornshell.com to run this script with IBM AIX.
####
#### Dependencies:
####
#### None
####
#### Products:
####
#### This script generates a snippit of HTML code as a SCRIPT
#### tag. The SCRIPT tag contains HEX code representations of
#### the email address and descriptions provided on the
#### command line of this shell script.
####
#### Configured Usage:
####
#### This script can be run as a function or from the command
#### line. A typical command line would appear as:
####
#### email2hex -e "info@mtxia.com" -t "Mt Xia Information" -p "For Info: "
####
#### Details:
####
################################################################
function mkascii
{
typeset VAL='${CNT}'
[[ "_${2}" != "_" && "_${2}" = "_8" ]] && VAL='$( printf "%o" 0x${i}${j} )'
[[ "_${2}" != "_" && "_${2}" = "_16" ]] && VAL='${i}${j}'
nameref ASCII_TABLE=$1
typeset CNT=0
for i in 0 1 2 3 4 5 6 7 8 9 A B C D E F
do
for j in 0 1 2 3 4 5 6 7 8 9 A B C D E F
do
eval ASCII_TABLE[\\$(print -- $( printf "\\\0%o" 0x${i}${j} ) )]=\"${VAL}\" 2>/dev/null
(( CNT = CNT + 1 ))
done
done
}
################################################################
function email2hex {
typeset VERSION="1.0"
typeset TRUE="1"
typeset FALSE="0"
typeset EXITCODE="0"
typeset VERBOSE="${FALSE}"
typeset VERYVERB="${FALSE}"
typeset EMAIL=""
typeset LINKTEXT=""
typeset PREPTEXT=""
typeset SUFFTEXT=""
typeset MSG="${LINKTEXT}"
typeset SCRIPT_TAGBEG=""
typeset DENOM="16"
typeset -A HEX
typeset IDX
####
#### Process the command line options and arguments, saving
#### the values as appropriate.
####
while getopts ":vVe:t:p:s:" OPTION
do
case "${OPTION}" in
'e') EMAIL="${OPTARG}";;
't') LINKTEXT="${OPTARG}";;
'p') PREPTEXT="${OPTARG}";;
's') SUFFTEXT="${OPTARG}";;
'v') VERBOSE="${TRUE}";;
'V') VERYVERB="${TRUE}";;
[?:#]) usagemsg_email2hex "${0}" && return 1 ;;
esac
done
shift $(( ${OPTIND} - 1 ))
trap "usagemsg_email2hex ${0}" EXIT
if [[ "_${EMAIL}" == "_" ]]
then
print -u 2 "# ERROR: Email address not specified"
return 2
fi
if [[ "_${LINKTEXT}" == "_" ]]
then
print -u 2 "# ERROR: Link text not specified"
return 3
fi
trap "-" EXIT
####
#### Display some program info and the command line arguments specified
#### if "VERBOSE" mode was specified.
####
(( VERYVERB == TRUE )) && set -x
(( VERBOSE == TRUE )) && print -u 2 "# Version........: ${VERSION}"
(( VERBOSE == TRUE )) && print -u 2 "# Email Address..: ${EMAIL}"
(( VERBOSE == TRUE )) && print -u 2 "# Link Text......: ${LINKTEXT}"
(( VERBOSE == TRUE )) && print -u 2 "# Prepended Text.: ${PREPTEXT}"
(( VERBOSE == TRUE )) && print -u 2 "# Suffix Text....: ${SUFFTEXT}"
################################################################
MSG="${PREPTEXT}${LINKTEXT}${SUFFTEXT}"
mkascii HEX 16
(( VERBOSE == TRUE )) && print -u 2 "# HREF Anchor Tag: ${MSG}"
for (( i=0; i<${#MSG}; ++i ))
do
PARS[i]="${MSG:i:1}"
done
#### The substitution operator with pattern replacement does not
#### seem to work under the cygwin implementation of ksh93. The
#### above "for" loop was added to replace the following code.
# IFS=$'|'
# PARS=( ${MSG//(?)/|\1} )
# unset PARS[0]
# IFS=$' \t\n'
(( VERBOSE == TRUE )) && print -u 2 "# Parsed Array...: ${PARS[@]}"
print -n -- "${SCRIPT_TAGBEG}"
for IDX in "${!PARS[@]}"
do
(( VERBOSE == TRUE )) && print -u 2 "# Char: ${PARS[IDX]} HEX: ${HEX[${PARS[${IDX}]}]}"
print -n -r -- "%${HEX[${PARS[${IDX}]}]}"
(( ( IDX % DENOM ) == 0 )) && print -n -- "'+\n'"
done
print -- "'))\n${SCRIPT_TAGEND}"
return 0
}
################################################################
email2hex "${@}"