-
Notifications
You must be signed in to change notification settings - Fork 0
/
email_verify.install
114 lines (99 loc) · 3.05 KB
/
email_verify.install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
/**
* @file
* Install the email verify module
*/
/**
* Implementation of hook_schema().
*/
function email_verify_schema() {
$schema['email_verify'] = array(
'description' => 'Stores domains that were properly validated.',
'fields' => array(
'domain' => array(
'type' => 'varchar',
'length' => 64,
'not null' => FALSE,
'default' => '',
'description' => "Email domain.",
),
'validated' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'Timestamp for when domain was validated.',
),
'status' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'size' => 'tiny',
'description' => 'Whether the domain is valid(1) or invalid(0)',
),
),
'primary key' => array('domain'),
'indexes' => array(
'domain_status' => array('domain', 'status'),
),
);
return $schema;
}
/**
* Implementation of hook_install().
*/
function email_verify_install() {
drupal_install_schema('email_verify');
}
/**
* Implementation of hook_uninstall().
*/
function email_verify_uninstall() {
drupal_uninstall_schema('email_verify');
}
/**
* Implementation of hook_enable().
*/
function email_verify_enable() {
// 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().
$host = 'drupal.org';
// What SMTP servers should we contact?
$mx_hosts = array();
include_once dirname(__FILE__) .'/windows_compat.inc';
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 (ereg("^220", $out = fgets($connect, 1024))) {
// OK, we have a SMTP connection
break;
}
}
if (!$connect) {
$message = t('Email verify has tried contacting the mail host but did not receive a reply.'
.' Check with your hosting provider that the function fsockopen() is properly configured on your server,'
.' and that port 25 is open. The module has been disabled.');
watchdog('email_verify', $message, WATCHDOG_ERROR);
drupal_set_message(check_plain($message), 'error');
module_disable(array('email_verify'));
}
}
/**
* Update 6101 - Install database schema.
*/
function email_verify_update_6101() {
drupal_install_schema('email_verify');
}