View source
<?php
function email_verify_help($section = '') {
$output = '';
switch ($section) {
case '':
$output = '';
break;
}
return $output;
}
function email_verify_user($type, &$edit, &$user, $category = NULL) {
if ($type == 'validate' && $category == 'account') {
return email_verify_edit_validate(arg(1), $edit);
}
}
function email_verify_edit_validate($uid, &$edit) {
if ($error = email_verify_check($edit['mail'])) {
form_set_error('mail', $error);
}
return $edit;
}
function email_verify_check($mail) {
if (!valid_email_address($mail)) {
return;
}
$host = substr(strchr($mail, '@'), 1);
if (!checkdnsrr($host, 'ANY')) {
return t('Email host %host does not seem valid', array(
'%host' => "{$host}",
));
}
$mxHosts = array();
if (!getmxrr($host, $mxHosts)) {
$mxHosts[] = $host;
}
foreach ($mxHosts as $smtpServer) {
$connect = @fsockopen($smtpServer, 25, $errno, $errstr, 15);
if (!$connect) {
continue;
}
if (ereg("^220", $out = fgets($connect, 1024))) {
break;
}
else {
watchdog('email_verify', "Could not verify email address at host {$host}: {$out}");
return;
}
}
if (!$connect) {
return t('Email host %host does not seem valid, it does not answer', array(
'%host' => "{$host}",
));
}
$from = variable_get('site_mail', ini_get('sendmail_from'));
if (preg_match('/\\<(.*)\\>/', $from, $match) > 0) {
$from = $match[1];
}
$localhost = $_SERVER["HTTP_HOST"];
if (!$localhost) {
$localhost = 'localhost';
}
fputs($connect, "HELO {$localhost}\r\n");
$out = fgets($connect, 1024);
fputs($connect, "MAIL FROM: <{$from}>\r\n");
$from = fgets($connect, 1024);
fputs($connect, "RCPT TO: <{$mail}>\r\n");
$to = fgets($connect, 1024);
fputs($connect, "QUIT\r\n");
fclose($connect);
if (!ereg("^250", $from)) {
watchdog('email_verify', "Could not verify email address at host {$host}: {$from}");
return;
}
if (ereg("(Client host|Helo command) rejected", $to)) {
watchdog('email_verify', "Could not verify email address at host {$host}: {$to}");
return;
}
if (!ereg("^250", $to)) {
watchdog('email_verify', "Rejected email address: {$mail}. Reason: {$to}");
return t('Email address %mail does not seem valid', array(
'%mail' => "{$mail}",
));
}
return;
}
function email_verify_menu() {
$items = array();
$items[] = array(
'path' => 'email_verify',
'title' => t('Verify user emails'),
'callback' => 'email_verify_checkall',
'access' => user_access('administer users'),
'type' => MENU_CALLBACK,
);
return $items;
}
function email_verify_checkall() {
$content = "<table>";
$found = 0;
$result = db_query('SELECT uid,name,mail FROM {users}');
while ($row = db_fetch_object($result)) {
if (email_verify_check($row->mail)) {
$content .= "<tr><td><a href='?q=user/{$row->uid}/edit'>" . check_plain($row->name) . "</a><td>" . check_plain($row->mail);
if (++$found >= 100) {
break;
}
}
}
$content .= "</table>";
print theme("page", $content);
}