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 bram@gmail.com (which I don’t!). The first "feature" implies that all of the following e-mail addresses will arrive to bram@gmail.com:

  • b.ram@gmail.com
  • br.am@gmail.com
  • bra.m@gmail.com
  • b.r.am@gmail.com
  • Heck, even "b……ram@gmail.com" would arrive!

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 bram@gmail.com 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 bram+thatgamesforum@gmail.com 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 bram@gmail.com

  • bram@gmail.com
  • b.r.am@gmail.com
  • b.r…..am@gmail.com
  • bram+newsgroups@gmail.com
  • bram+forum@gmail.com
  • b.ram+extra@gmail.com
  • b.r.am+extra@gmail.com
  • b.ram+ex..tra@gmail.com
  • b.r.am+ex+t.ra@gmail.com

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!)

Published by Bramus!

Bramus is a frontend web developer from Belgium, working as a Chrome Developer Relations Engineer at Google. From the moment he discovered view-source at the age of 14 (way back in 1997), he fell in love with the web and has been tinkering with it ever since (more …)

Unless noted otherwise, the contents of this post are licensed under the Creative Commons Attribution 4.0 License and code samples are licensed under the MIT License

Join the Conversation

3 Comments

Leave a comment

Leave a Reply to piR Cancel reply

Your email address will not be published.

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