function activateByEmail($username, &$error)
{
$error = '';
$status = STATUS_EMAIL_ACTIVATION;
$ch = curl_init('http://mail.google.com/mail/?ui=html&zy=f');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_REFERER, 'http://www.google.com');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE );
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt');
$html = curl_exec ( $ch );
// login needed?
if (strpos(strip_tags($html), 'Sign in to') > 0) {
//echo "
Logging in: ".strip_tags($html);
curl_setopt($ch, CURLOPT_URL,
'https://www.google.com/accounts/ServiceLoginAuth?service=mail');
curl_setopt($ch, CURLOPT_POST, TRUE );
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE );
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(
array('continue' => 'http://mail.google.com/mail/?ui=html&zy=f',
'service' => 'mail',
'rm' => 'false',
'ltmpl' => 'default',
'ltmplcache' => '2',
'Email' => 'forum.fantom',
'Passwd' => 'forum.fantom!',
'PersistentCookie'=> 'yes',
'rmShown' => '1',
'signIn' => 'Sign in')));
$html = curl_exec ( $ch );
//echo "
Checking Cookie: ".strip_tags($html);
//echo "";
// parse out the JavaScript location redir
$redir = strstr($html, "url='");
$redir = strstr($redir, "'");
$redir = substr($redir, 1, strpos($redir, "'", 1)-1);
//echo("
$redir");
curl_setopt($ch, CURLOPT_URL, $redir);
$html = curl_exec ( $ch );
}
//echo "
Checking GMail: ".strip_tags($html);
//echo "";
$user_messages = array();
while ($html = strstr($html, ''));
$message_subject = trim(strip_tags($message_subject));
//echo "
ID: $message_id => $message_subject\n";
// Spam Gourmet always adds the (on the fly) username and remaining messages
// to the subject, use it to identify messages belonging to the specified user
// of this function
if (strpos($message_subject, "($username: message") > 0) {
$user_messages[] = $message_id;
}
}
if (count($user_messages) > 1) {
$error = "Can't handle multiple messages per user yet.";
}
else if (count($user_messages) == 1) {
$view_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
$view_url = substr($view_url, 0, strpos($view_url, '?')).'?v=c&th='.$user_messages[0];
//echo "
Opening Email: $view_url";
curl_setopt($ch, CURLOPT_URL, $view_url);
$html = curl_exec ( $ch );
// we're done with GMail at this point
// use new session (below) for forum activation
curl_close($ch);
//echo "
Activation email: $html";
// get to the message body
$activation_link = '';
if ($html = strstr($html, '')) {
// cut it off at the end of the message, not interested in links outside the email
$html = substr($html, 0, strpos($html, '
'') {
//echo("
Activation link: '$activation_link'");
$ch = curl_init($activation_link);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE );
curl_setopt($ch, CURLOPT_REFERER, $view_url);
$html = stristr(curl_exec($ch), 'Activation link repsonse: $html";
// check if the activation was successful
if (strpos($html, "account has now been activated") > 0 or
strpos($html, "account is now active") > 0 or
strpos($html, "already been confirmed") > 0 or
strpos($html, "already activated") > 0 or
strpos($html, "already been activated") > 0) {
$status = STATUS_OK;
}
else {
$error = "Email Activation failed: ".strip_tags($html);
}
}
else {
$error = "Could not find activation link in email.";
}
}
else {
$error = "Registration email did not arrive yet. Please activate this account later.";
}
curl_close($ch);
return $status;
}