| 1 |
<?php
|
| 2 |
// $Id: email_verify.install,v 1.2 2009/02/04 22:01:18 dbr Exp $
|
| 3 |
/**
|
| 4 |
* @file
|
| 5 |
* Install the email verify module
|
| 6 |
*/
|
| 7 |
|
| 8 |
/**
|
| 9 |
* Implementation of hook_enable().
|
| 10 |
*/
|
| 11 |
function email_verify_enable() {
|
| 12 |
// Check that fsockopen() works on port 25.
|
| 13 |
// See: http://drupal.org/node/147883
|
| 14 |
|
| 15 |
// What follows is an adapted version of email_verify_check().
|
| 16 |
// The documentation http://api.drupal.org/api/5/function/hook_install says:
|
| 17 |
// "Note that since this function is called from a full bootstrap, all functions
|
| 18 |
// (including those in modules enabled by the current page request) are available
|
| 19 |
// when this hook is called. Use cases could be displaying a user message, or
|
| 20 |
// calling a module function necessary for initial setup, etc."
|
| 21 |
// However, this does not seem to be the case, so we can't reuse email_verify_check().
|
| 22 |
|
| 23 |
$host = 'drupal.org';
|
| 24 |
// What SMTP servers should we contact?
|
| 25 |
$mx_hosts = array();
|
| 26 |
|
| 27 |
if (!getmxrr($host, $mx_hosts)) {
|
| 28 |
// When there is no MX record, the host itself should be used
|
| 29 |
$mx_hosts[] = $host;
|
| 30 |
}
|
| 31 |
|
| 32 |
// Try to connect to one SMTP server
|
| 33 |
foreach ($mx_hosts as $smtp) {
|
| 34 |
$connect = @fsockopen($smtp, 25, $errno, $errstr, 15);
|
| 35 |
if (!$connect) {
|
| 36 |
continue;
|
| 37 |
}
|
| 38 |
|
| 39 |
if (ereg("^220", $out = fgets($connect, 1024))) {
|
| 40 |
// OK, we have a SMTP connection
|
| 41 |
break;
|
| 42 |
}
|
| 43 |
|
| 44 |
}
|
| 45 |
|
| 46 |
if (!$connect) {
|
| 47 |
$message = t('Email verify has tried contacting the mail host but did not receive a reply.'
|
| 48 |
.' Check with your hosting provider that the function fsockopen() is properly configured on your server,'
|
| 49 |
.' and that port 25 is open. The module has been disabled.');
|
| 50 |
|
| 51 |
watchdog('email_verify', $message, WATCHDOG_ERROR);
|
| 52 |
drupal_set_message($message, 'error');
|
| 53 |
module_disable(array('email_verify'));
|
| 54 |
}
|
| 55 |
}
|
| 56 |
|