Skip to content

Instantly share code, notes, and snippets.

@JackZielke
Last active February 20, 2022 19:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JackZielke/703f686bd7e5402a431d34ec933c9c5f to your computer and use it in GitHub Desktop.
Save JackZielke/703f686bd7e5402a431d34ec933c9c5f to your computer and use it in GitHub Desktop.
Convert email address into html codes @
#!/bin/bash
if [ $# -ne 1 ]
then
echo
echo "usage: $0 <email@address>"
echo
echo
exit 1
fi
echo -n "mailto:"
COUNT=1
CHAR=`echo $1|cut -c 1`
while [ "$CHAR" != "" ]
do
DEC=`echo $CHAR|perl -e 'print ord <STDIN>'`
echo -n "&#${DEC};"
COUNT=$[COUNT+1]
CHAR=`echo $1|cut -c $COUNT`
done
echo
@JackZielke
Copy link
Author

I don't know if this is the approach I would take if I were doing this now, but it seemed like a good idea in 2004. I tested it and it still works. I don't know if they have code to prevent accidentally putting email addresses in comments, but let's see what happens.

$ hideemail.sh

usage: ./hideemail <email@address>

$ hideemail.sh ceo@example.com
mailto:&#99;&#101;&#111;&#64;&#101;&#120;&#97;&#109;&#112;&#108;&#101;&#46;&#99;&#111;&#109;

It just converts all of the text to HTML Codes and puts a mailto: in the front. I don't know if email address scapers decode these now or not, but it used to work really well to keep the spam down and still have a working email link.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment