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 (http://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!)

Another Dailie, PHP Willow Tree, Webdevelopment

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

  1. Pingback: Mijn links voor 1 december 2006 | el73

  2. Pingback: Bram.us » My inc.functions.php - Part 2 : Creating a post slug

  3. piR says:

    I think that sending @googlemail.com will also work.

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>