importContacts(); class aol { var $_username; var $_password; function aol( $username, $password ) { $username = trim( $username ); $password = trim( $password ); if( empty( $username ) || empty( $password ) ) { die( 'Please fill all the fields' ); } $this->_setUsername( $username ); $this->_setPassword( $password ); } function _setUsername( $username ) { $this->_username = $username; } function _setPassword( $password ) { $this->_password = $password; } function _getUsername() { return $this->_username; } function _getPassword() { return $this->_password; } function importContacts() { $cookieFile = '/var/tmp/aol_'.$this->_getUsername().'_cookiejar.txt'; $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, 'http://my.screenname.aol.com/_cqr/login/login.psp?sitedomain=sns.webmail.aol.com&authLev=2&siteState=ver%3A2%7Cac%3AWS%7Cat%3ASNS%7Cld%3Awebmail.aol.com%7Cuv%3AAOL%7Clc%3Aen-us&lang=en&locale=us&seamless=novl' ); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1'); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile); curl_setopt($ch, CURLOPT_COOKIEFILE,$cookieFile); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); $return = curl_exec( $ch ); $data = $this->_parseContent( '/goToLoginUrl\(\)(.*?)"\);/s', $return ); $loginURL = ''.$data[1][0]; $data2 = $this->_parseContent( '/snsRedir(.*?)novl/s', $loginURL ); $loginUrl = str_replace( 'snsRedir("', '', $data2[0][0] ); unset( $data ); unset( $data2 ); curl_setopt( $ch, CURLOPT_URL, $loginUrl ); $return = curl_exec( $ch ); $data = $this->_parseContent( '/
/s', $return ); $hidden = explode( '_getUsername() ); $upass = 'password='.urlencode( $this->_getPassword() ); $postFields = ''; foreach( $hidden as $field ) { $field = trim( $field ); $tmp = explode( ' ', $field ); $removal = array( 'name=', 'value=', '"', '>', '_parseContent( '/LoginSuccess.aspx(.*?)\'/s', $return ); $loginParts = explode( '&', $logIn[1][0] ); $targetSuccessUrl = ''; foreach( $loginParts as $part ) { $tmp = explode( '=', trim( $part ) ); if( $tmp[0] == 'siteState' ) { $tmp[1] = urlencode( $tmp[1] ); } $targetSuccessUrl .= $tmp[0].'='.$tmp[1].'&'; } $targetSuccessUrl = substr_replace( $targetSuccessUrl , '', -1 ); $loginSuccessUrl = 'http://webmail.aol.com/_cqr/LoginSuccess.aspx'.$targetSuccessUrl; curl_setopt($ch, CURLOPT_URL, $loginSuccessUrl); curl_setopt($ch, CURLOPT_REFERER, $loginSuccessUrl ); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile); curl_setopt($ch, CURLOPT_COOKIEFILE,$cookieFile); $successPath = curl_exec( $ch ); $gSuccessPath = $this->_parseContent( '/var gSuccessPath =(.*?);/s', $successPath ); $path = 'http://webmail.aol.com'; $gSuccessfull = trim( $gSuccessPath[1][0] ); $path .= str_replace( '"', '', $gSuccessfull ); curl_setopt( $ch, CURLOPT_URL, $path ); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); // by here we have successfully logged in $weAreIn = curl_exec( $ch ); // from this point we are trying to go to the contacts page $homePage = $this->_parseContent( '/padding(.*?)true/s', $weAreIn ); $homePageLink = ''.$homePage[0][0]; $landingPageUrl = $this->_parseContent( '/http(.*?)true/s', $homePageLink ); // now go to the landing page curl_setopt( $ch, CURLOPT_URL, $landingPageUrl[0][0] ); $landingPage = curl_exec( $ch ); $contactsUrlArr = $this->_parseContent( '/action="(.*?)Lite/s', $landingPage ); $contactsUrl = $contactsUrlArr[1][0].'Lite/ContactList.aspx?folder=New Mail&showUserFolders=False'; curl_setopt( $ch, CURLOPT_URL, $contactsUrl ); $contactsPage = curl_exec( $ch ); //we need the value of the "user" element in order to proceed $firstUserPattern = $this->_parseContent( '/ProcessCommand(.*?)toolbarType/s', $contactsPage ); $secondUserPattern= $this->_parseContent( '/\.com(.*?)class/s', $firstUserPattern[1][0] ); $userArray = explode( ',', $secondUserPattern[1][0] ); $user = str_replace( array('\'', ')', ';', '"'), '', $userArray[1] ); // by here we are in, now we need to get all the pages that contains the contacts // am not navigating throught the whole pages, but rather i am using the print // functionality that AOL is providing for their users in order to get the whole // bunch of contacts in one single step. $printContactsPage = $contactsUrlArr[1][0].'Lite/addresslist-print.aspx?command=all&sort=FirstLastNick&sortDir=Ascending&nameFormat=FirstLastNick&user='.$user; curl_setopt( $ch, CURLOPT_URL, $printContactsPage ); $contactsRecords = curl_exec( $ch ); // ok, now we have the contacts bunch and we need to filter them ... $firstPhaseFilter = $this->_parseContent( '/fullName(.*?)contactSeparator/s',$contactsRecords ); $finalPhaseFilter = array(); foreach( $firstPhaseFilter[0] as $value ) { $value = ''.$value; //don't ask me why i did that, it just didn't work except like this!!! // filter contact's full name $contactName = $this->_parseContent( '/fullName">(.*?)<\/span/s', $value ); // filter contact's email $contactEmail= $this->_parseContent( '/Email 1:<\/span> (.*?)<\/span>/s', $value); $finalPhaseFilter[strip_tags($contactName[1][0])] = $contactEmail[1][0]; } echo 'You have the following contacts in your AOL account:

'; echo '
'; foreach( $finalPhaseFilter as $fullname => $email ) { echo ''; } echo '
Contact Full NameContact Email
'.$fullname.''.$email.'
'; } function _parseContent( $pattern, $subject ) { $array = array(); preg_match_all( $pattern,$subject, $array ); return $array; } } ?>