My inc.functions.php – Part 1 : Fixing those gmail.com e-mail addresses.

PHP Willow TreeAfter seeing Shaun’s Fixing the $_FILES superglobal I found myself browsing around in the inc.functions.php file I’ve been using and maintaining project by project. To my own surprise I noticed that the file itself has grown over time and kind of is stuffed with some darn handy functions! Time to spread them out, starting with this one right here: fixGmail();

Whilst coding Iedereenleeftmee back in May fixGmail() was created to rework gmail.com addresses. Reason for reworking all those addresses was the fact that Iedereenleeftmee was/is based upon unique e-mail addresses. But what is there to rework on an e-mail address? And why only GMail?

As one might know, gmail accounts are in and have some bugs the Google team would like to call features:

  • Period Stuffing
  • Plussing

Period Stuffing

Period Stuffing – as I like to call it – implies that periods can be added anywhere in the username without affecting it at all

For example think of me having [email protected] (which I don’t!). The first "feature" implies that all of the following e-mail addresses will arrive to [email protected]:

As you can see this was an issue with Iedereenleeftmee since some handy dudes would just invite themselves 9 times (with each having a period on a different spot), thus receiving 10 free entrance tickets to an amusement park of choice.

Plussing

Plussing can be taken quite literally: use a plus sign (+) to add an extra parameter/piece of text to to your e-mail address

Take that [email protected] account again … what if I had to subscribe to some forum leaving behind my e-mail address. How would I ever possibly know if they sold/gave my e-mailaddy to someone else? This is where PA kicks in: one can actually enter [email protected] and the mails would still arriving! Quite handy imo (so you can really track who’s selling what and/or even filter some stuff), yet not handy for the webdeveloper who wants users to be unique by their e-mailaddress…

The PHP Code

The PHP Code is quite simple and laid upon thee here for grabbing:

// Bramus! pwnge! : fixes gmail.com mail addresses (https://www.bram.us/)
function fixGmail($emailaddy) {

	// $emailaddy is an '@gmail.com'-address
	if (eregi('@gmail.com', $emailaddy)) {

		// make lowercase, strip out periods (but fix gmailcom)
		$emailaddy	= str_replace("@gmailcom","@gmail.com",str_replace(".", "", strtolower($emailaddy)));

		// a plus sign is found in $emailaddy
		if (eregi('\+', $emailaddy)) {

			// grab the substring from the start up to the first plus sign and add @gmail.com
			$emailaddy	= substr($emailaddy,0, strpos($emailaddy,"+"))."@gmail.com";

		}
	}

	// now return it
	return $emailaddy;
}

Successfully tested with a series of e-mail addresses, all resulting [email protected]

That’s it for now…

Stay tuned for more PHP Geekery!

B!

(post scriptum: Icon companioning this post is a Willow Tree, influenced by Fat Freddy’s Drop!)

Join the Conversation

3 Comments

Leave a comment

Your email address will not be published. Required fields are marked *

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