function email_verify_enable_module in Email Verify 7
Same name and namespace in other branches
- 7.2 email_verify.admin.inc \email_verify_enable_module()
Checks the system for the capability to use this module.
@todo This function works, but it needs some thought and potential rework, now that it is not in email_verify.install.
1 call to email_verify_enable_module()
- email_verify_admin_settings_submit in ./
email_verify.admin.inc - Form submit function.
File
- ./
email_verify.admin.inc, line 75 - This is for the administrative settings for this module.
Code
function email_verify_enable_module() {
// Check that fsockopen() works on port 25.
// See: http://drupal.org/node/147883
// What follows is an adapted version of email_verify_check().
// The documentation http://api.drupal.org/api/5/function/hook_install says:
// "Note that since this function is called from a full bootstrap, all
// functions (including those in modules enabled by the current page
// request) are available when this hook is called. Use cases could be
// displaying a user message, or calling a module function necessary for
// initial setup, etc."
// However, this does not seem to be the case, so we can't reuse
// email_verify_check().
// If a previous enable found port 25 closed or fsockopen() disabled, don't
// test it again. Testing can cause a long delay on module enable. Completely
// uninstall and then re-install this module to re-test.
if (variable_get('email_verify_skip_mailbox', FALSE)) {
return;
}
// Check if fsockopen() is disabled.
if (!function_exists('fsockopen')) {
$message = t('Email Verify will test email domains but not mailboxes because the fsockopen() function has been disabled.');
variable_set('email_verify_skip_mailbox', TRUE);
drupal_set_message($message, 'warning');
return;
}
$host = 'drupal.org';
// What SMTP servers should we contact?
$mx_hosts = array();
module_load_include('inc', 'email_verify', 'windows_compat');
if (!getmxrr($host, $mx_hosts)) {
// When there is no MX record, the host itself should be used.
$mx_hosts[] = $host;
}
// Try to connect to one SMTP server.
foreach ($mx_hosts as $smtp) {
$connect = @fsockopen($smtp, 25, $errno, $errstr, 15);
if (!$connect) {
continue;
}
if (preg_match("/^220/", $out = fgets($connect, 1024))) {
// OK, we have a SMTP connection.
break;
}
}
if (!$connect) {
variable_set('email_verify_skip_mailbox', TRUE);
$message = t('Email Verify will test email domains but not mailboxes because port 25 is closed on your host\'s firewall for security.');
watchdog('email_verify', $message, array(), WATCHDOG_WARNING);
drupal_set_message($message, 'warning');
}
}